mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Kurz <akurz@blala.de>
To: barebox@lists.infradead.org, Sascha Hauer <s.hauer@pengutronix.de>
Cc: Alexander Kurz <akurz@blala.de>
Subject: [PATCH] fs/fat: fix FAT32 detection
Date: Mon, 24 Dec 2018 10:16:42 +0000	[thread overview]
Message-ID: <20181224101642.21722-1-user@vserver64> (raw)

From: Alexander Kurz <akurz@blala.de>

Limits for the number of clusters were used to determine the FAT fs type.
This fails e.g. for FAT32 fs with low cluster number that can be found
in certain Android images.
Sync the FAT fs type detection to the method used in linux by checking
the sectors/FAT entries at offset 0x16 (must be zero for FAT32) and offset
0x24 (must be non-zero for FAT32).

Signed-off-by: Alexander Kurz <akurz@blala.de>
---
 fs/fat/ff.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/fat/ff.c b/fs/fat/ff.c
index 33f8b6195..ba4adfc13 100644
--- a/fs/fat/ff.c
+++ b/fs/fat/ff.c
@@ -1591,9 +1591,14 @@ static int chk_mounted (	/* 0(0): successful, !=0: any error occurred */
 		return -EINVAL;
 
 	/* Number of sectors per FAT */
+	fmt = FS_FAT12;
 	fasize = LD_WORD(fs->win+BPB_FATSz16);
-	if (!fasize)
+	if (!fasize) {
 		fasize = LD_DWORD(fs->win+BPB_FATSz32);
+		if (fasize)
+			/* Must be FAT32 */
+			fmt = FS_FAT32;
+	}
 	fs->fsize = fasize;
 
 	/* Number of FAT copies */
@@ -1633,11 +1638,8 @@ static int chk_mounted (	/* 0(0): successful, !=0: any error occurred */
 	nclst = (tsect - sysect) / fs->csize;
 	if (!nclst)
 		return -EINVAL;	/* (Invalid volume size) */
-	fmt = FS_FAT12;
-	if (nclst >= MIN_FAT16)
+	if (fmt == FS_FAT12 && nclst >= MIN_FAT16)
 		fmt = FS_FAT16;
-	if (nclst >= MIN_FAT32)
-		fmt = FS_FAT32;
 
 	/* Boundaries and Limits */
 	/* Number of FAT entries */
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2018-12-27  8:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-24 10:16 Alexander Kurz [this message]
2019-01-03  9:27 ` Sascha Hauer

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=20181224101642.21722-1-user@vserver64 \
    --to=akurz@blala.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox