[U-Boot] [PATCH] fs: fat: fix reading non-cluster-aligned root directory
Anssi Hannula
anssi.hannula at bitwise.fi
Sat Oct 6 18:02:32 UTC 2018
FAT16 root directory might not start at a cluster boundary (though it
always ends on one).
However, next_dent() always starts reading the directory at the
beginning of the cluster, causing no files to be found (at least if the
beginning of the cluster contains zeroes).
Fix that by skipping to the actual start of the root directory in such a
case.
This is a relatively common case as at least the filesystem formatter on
Win7 seems to create such filesystems by default on 2GB USB sticks
(cluster size 64 sectors, rootdir size 32 sectors).
dosfstools mkfs.vfat does not seem to create such filesystems.
Signed-off-by: Anssi Hannula <anssi.hannula at bitwise.fi>
---
fs/fat/fat.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index b08949d370..4a0d4bb8bc 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -782,6 +782,20 @@ static dir_entry *next_dent(fat_itr *itr)
itr->remaining = nbytes / sizeof(dir_entry) - 1;
itr->dent = dent;
+
+ if (itr->fsdata->fatsize != 32 &&
+ itr->clust == itr->fsdata->root_cluster) {
+ /* rootdir might not start at cluster boundary */
+ u32 sect_offset = itr->fsdata->rootdir_sect -
+ clust_to_sect(itr->fsdata,
+ itr->fsdata->root_cluster);
+ u32 dirent_offset = itr->fsdata->sect_size /
+ sizeof(dir_entry) * sect_offset;
+
+ itr->remaining -= dirent_offset;
+ itr->dent += dirent_offset;
+ }
+
} else {
itr->remaining--;
itr->dent++;
--
2.17.1
More information about the U-Boot
mailing list