All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anssi Hannula <anssi.hannula@bitwise.fi>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fs: fat: fix reading non-cluster-aligned root directory
Date: Sat,  6 Oct 2018 21:02:32 +0300	[thread overview]
Message-ID: <20181006180232.10235-1-anssi.hannula@bitwise.fi> (raw)

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

             reply	other threads:[~2018-10-06 18:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-06 18:02 Anssi Hannula [this message]
2018-11-08 12:19 ` [U-Boot] Antwort: [PATCH] fs: fat: fix reading non-cluster-aligned root directory 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181006180232.10235-1-anssi.hannula@bitwise.fi \
    --to=anssi.hannula@bitwise.fi \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.