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 <mail@daniel-baumann.ch>
This commit is contained in:
Ulrich Mueller 2008-10-07 07:55:37 +02:00 committed by Daniel Baumann
parent 90102bcd54
commit e597cafef4
2 changed files with 15 additions and 2 deletions

View File

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

View File

@ -20,7 +20,6 @@
*/
# include <asm/types.h>
# define MSDOS_FAT12 4084 /* maximum number of clusters in a 12 bit FAT */
#ifndef _COMMON_H
#define _COMMON_H