Skip to contentSkip to conversation

fs/fat: fix FAT32 detection

PATCH Applied Alexander Kurz 2 participants 2 messages Dec 27, 2018 – Jan 3, 2019 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/fat: fix FAT32 detection

From: Alexander Kurz <[email protected]>

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).

---
 fs/fat/ff.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/fat/ff.c +7 -5
index 33f8b6195..ba4adfc13 100644
@@ -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 */
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 9 lines · Alexander Kurz

From: Alexander Kurz <[email protected]>

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).

Quoted 4 lines
---
 fs/fat/ff.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

Quoted 38 lines
fs/fat/ff.c +7 -5
index 33f8b6195..ba4adfc13 100644
@@ -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 */
Signature · 1 line
2.11.0
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox