From e597cafef44da9ca46eb2d4999a98c7e23072e46 Mon Sep 17 00:00:00 2001 From: Ulrich Mueller Date: Tue, 7 Oct 2008 07:55:37 +0200 Subject: [PATCH] Patch to check for bad number of clusters in dosfsck: * FAT16 filesystems with 65525 clusters or more will be rejected (Before, this was not tested for. Up to 65535 clusters were accepted as good). * For FAT32 filesystems with less than 65525 a warning message will be output. Macro MSDOS_FAT12 is now replaced by FAT12_THRESHOLD to make it consistent with the definition in mkdosfs and to remove the dependency on the kernel version. Signed-off-by: Daniel Baumann --- src/boot.c | 16 +++++++++++++++- src/common.h | 1 - 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/boot.c b/src/boot.c index 29eb18a..11e16ca 100644 --- a/src/boot.c +++ b/src/boot.c @@ -37,6 +37,10 @@ #define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0) /* don't divide by zero */ +/* cut-over cluster counts for FAT12 and FAT16 */ +#define FAT12_THRESHOLD 4085 +#define FAT16_THRESHOLD 65525 + static struct { __u8 media; char *descr; @@ -337,6 +341,13 @@ void read_boot(DOS_FS *fs) printf( "Warning: FAT32 root dir is in a cluster chain, but " "a separate root dir\n" " area is defined. Cannot fix this easily.\n" ); + if (fs->clusters < FAT16_THRESHOLD) + printf("Warning: Filesystem is FAT32 according to fat_length " + "and fat32_length fields,\n" + " but has only %lu clusters, less than the required " + "minimum of %d.\n" + " This may lead to problems on some systems.\n", + fs->clusters, FAT16_THRESHOLD); fs->backupboot_start = CF_LE_W(b.backup_boot)*logical_sector_size; check_backup_boot(fs,&b,logical_sector_size); @@ -346,7 +357,10 @@ void read_boot(DOS_FS *fs) else if (!atari_format) { /* On real MS-DOS, a 16 bit FAT is used whenever there would be too * much clusers otherwise. */ - fs->fat_bits = (fs->clusters > MSDOS_FAT12) ? 16 : 12; + fs->fat_bits = (fs->clusters >= FAT12_THRESHOLD) ? 16 : 12; + if (fs->clusters >= FAT16_THRESHOLD) + die("Too many clusters (%lu) for FAT16 filesystem.", + fs->clusters); } else { /* On Atari, things are more difficult: GEMDOS always uses 12bit FATs diff --git a/src/common.h b/src/common.h index fe4fa7e..99e0be1 100644 --- a/src/common.h +++ b/src/common.h @@ -20,7 +20,6 @@ */ # include -# define MSDOS_FAT12 4084 /* maximum number of clusters in a 12 bit FAT */ #ifndef _COMMON_H #define _COMMON_H