All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fs: fat: fix reading non-cluster-aligned root directory
@ 2018-10-06 18:02 Anssi Hannula
  2018-11-08 12:19 ` [U-Boot] Antwort: " Bernhard Messerklinger
  0 siblings, 1 reply; 5+ messages in thread
From: Anssi Hannula @ 2018-10-06 18:02 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-10 12:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-06 18:02 [U-Boot] [PATCH] fs: fat: fix reading non-cluster-aligned root directory Anssi Hannula
2018-11-08 12:19 ` [U-Boot] Antwort: " Bernhard Messerklinger
2019-02-27 10:55   ` [U-Boot] [PATCH v2] " Anssi Hannula
2019-03-25  5:38     ` [U-Boot] Antwort: " Bernhard Messerklinger
2019-04-10 12:20     ` [U-Boot] [U-Boot, " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.