mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fs/fat: fix FAT32 detection
@ 2018-12-24 10:16 Alexander Kurz
  2019-01-03  9:27 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Kurz @ 2018-12-24 10:16 UTC (permalink / raw)
  To: barebox, Sascha Hauer; +Cc: Alexander Kurz

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

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

* Re: [PATCH] fs/fat: fix FAT32 detection
  2018-12-24 10:16 [PATCH] fs/fat: fix FAT32 detection Alexander Kurz
@ 2019-01-03  9:27 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-01-03  9:27 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: barebox

On Mon, Dec 24, 2018 at 10:16:42AM +0000, Alexander Kurz wrote:
> 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(-)

Applied, thanks

Sascha

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

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-01-03  9:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-24 10:16 [PATCH] fs/fat: fix FAT32 detection Alexander Kurz
2019-01-03  9:27 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox