From 21ec7e06f96074a6dce3a256120e58a770bb7b1e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 24 Jan 2010 16:55:22 -0800 Subject: [PATCH] FAT: be more explicit why we think a filesystem is bad Give readable error messages as to why we think a filesystem is bad. Given the current sizes of the installer, these extra strings are worth it. Signed-off-by: H. Peter Anvin --- libinstaller/syslxmod.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c index 9e1da44..88de375 100644 --- a/libinstaller/syslxmod.c +++ b/libinstaller/syslxmod.c @@ -52,19 +52,20 @@ const char *syslinux_check_bootsect(const void *bs) /* Must be 0xF0 or 0xF8..0xFF */ if (get_8(§buf->bsMedia) != 0xF0 && get_8(§buf->bsMedia) < 0xF8) - goto invalid; + return "invalid media signature (not a FAT filesystem?)"; sectorsize = get_16(§buf->bsBytesPerSec); - if (sectorsize == SECTOR_SIZE) ; /* ok */ + if (sectorsize == SECTOR_SIZE) + ; /* ok */ else if (sectorsize >= 512 && sectorsize <= 4096 && (sectorsize & (sectorsize - 1)) == 0) return "unsupported sectors size"; else - goto invalid; + return "impossible sector size"; clustersize = get_8(§buf->bsSecPerClust); if (clustersize == 0 || (clustersize & (clustersize - 1))) - goto invalid; /* Must be nonzero and a power of 2 */ + return "impossible cluster size"; sectors = get_16(§buf->bsSectors); sectors = sectors ? sectors : get_32(§buf->bsHugeSectors); @@ -79,8 +80,11 @@ const char *syslinux_check_bootsect(const void *bs) rootdirents = get_16(§buf->bsRootDirEnts); dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize; - if (dsectors < 0 || fatsectors == 0) - goto invalid; + if (dsectors < 0) + return "negative number of data sectors"; + + if (fatsectors == 0) + return "zero FAT sectors"; clusters = dsectors / clustersize; @@ -88,7 +92,7 @@ const char *syslinux_check_bootsect(const void *bs) /* FAT12 or FAT16 */ if (!get_16(§buf->bsFATsecs)) - goto invalid; + return "zero FAT sectors (FAT12/16)"; if (get_8(§buf->bs16.BootSignature) == 0x29) { if (!memcmp(§buf->bs16.FileSysType, "FAT12 ", 8)) { @@ -97,6 +101,8 @@ const char *syslinux_check_bootsect(const void *bs) } else if (!memcmp(§buf->bs16.FileSysType, "FAT16 ", 8)) { if (clusters < 0xFF5) return "less than 4084 clusters but claims FAT16"; + } else if (!memcmp(§buf->bs16.FileSysType, "FAT32 ", 8)) { + return "less than 65525 clusters but claims FAT32"; } else if (memcmp(§buf->bs16.FileSysType, "FAT ", 8)) { static char fserr[] = "filesystem type \"????????\" not supported"; @@ -105,19 +111,20 @@ const char *syslinux_check_bootsect(const void *bs) } } } else if (clusters < 0x0FFFFFF5) { - /* FAT32 */ - /* Moving the FileSysType and BootSignature was a lovely stroke of M$ idiocy */ + /* + * FAT32... + * + * Moving the FileSysType and BootSignature was a lovely stroke + * of M$ idiocy... + */ if (get_8(§buf->bs32.BootSignature) != 0x29 || memcmp(§buf->bs32.FileSysType, "FAT32 ", 8)) - goto invalid; + return "missing FAT32 signature"; } else { - goto invalid; + return "impossibly large number of clusters"; } return NULL; - -invalid: - return "this doesn't look like a valid FAT filesystem"; } /* -- 2.7.4