summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2019-01-02 01:41:23 -0800
committerYe Li <ye.li@nxp.com>2020-04-26 23:26:38 -0700
commitd14c5de8387fb7d32ff487231a5113f24a3d0ca0 (patch)
treee26e3c77e7ef56afa53cef623d703c42b0d3501e /fs
parentf856ae3edddb7370e4015cab1f17f7770cf7932e (diff)
MLK-20668-2 fat: Fix issue in rootdir table flush for FAT16/12
The FAT16/12 has rootdir area before data area, and the clusters for rootdir are not mantained by FAT table. So we don't need to find empty cluster for next rootdir space, just use next dir cluster. And the FAT table don't need to update for this new dir cluster. Signed-off-by: Ye Li <ye.li@nxp.com> Acked-by: Peng Fan <peng.fan@nxp.com> (cherry picked from commit 9e0a33cacc0a7926d46c0ca184498ae88278816e) (cherry picked from commit da50714d2f758bea31f223e7ccec56be54c00f18)
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat_write.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 4f96699e36..d773ca71c0 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -630,14 +630,17 @@ static int new_dir_table(fat_itr *itr)
int dir_newclust = 0;
unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
- dir_newclust = find_empty_cluster(mydata);
- set_fatent_value(mydata, itr->clust, dir_newclust);
- if (mydata->fatsize == 32)
+ if (mydata->fatsize == 32) {
+ dir_newclust = find_empty_cluster(mydata);
+ set_fatent_value(mydata, itr->clust, dir_newclust);
set_fatent_value(mydata, dir_newclust, 0xffffff8);
- else if (mydata->fatsize == 16)
- set_fatent_value(mydata, dir_newclust, 0xfff8);
- else if (mydata->fatsize == 12)
- set_fatent_value(mydata, dir_newclust, 0xff8);
+ } else {
+ dir_newclust = itr->clust + 1;
+ if (dir_newclust > 1) {
+ printf("error: fail to get empty clust for directory entry\n");
+ return -1;
+ }
+ }
itr->clust = dir_newclust;
itr->next_clust = dir_newclust;