summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Sumrall <ksumrall@android.com>2013-06-25 20:02:00 -0700
committerKen Sumrall <ksumrall@android.com>2013-06-26 17:06:35 -0700
commitc0a43e474789a92f91930a1c875eb7ce48e335c8 (patch)
treed09c9552b273c6f4afbed7db6ba674539bcfde66
parented86a9f77e796aa5923a5b2d1455a7739b86e60b (diff)
downloadandroid_external_fsck_msdos-c0a43e474789a92f91930a1c875eb7ce48e335c8.tar.gz
android_external_fsck_msdos-c0a43e474789a92f91930a1c875eb7ce48e335c8.tar.bz2
android_external_fsck_msdos-c0a43e474789a92f91930a1c875eb7ce48e335c8.zip
Detect exFAT filesystems and abort if found
If fsck_msdos tries to fix an exFAT filesystem, it will damage it and it won't be mountable on systems that support exFAT. So just abort if the OEM name field is "EXFAT" or an invalid FAT32 Extended BIOS Parameter Block is detected. The test to detect an invalid BIOS Parameter Block was developed by Sony. Change-Id: I09e8457e399239e840c825b858a635a7d9462def
-rw-r--r--boot.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/boot.c b/boot.c
index 52bf011..5326a45 100644
--- a/boot.c
+++ b/boot.c
@@ -106,6 +106,25 @@ readboot(dosfs, boot)
boot->FSInfo = block[48] + (block[49] << 8);
boot->Backup = block[50] + (block[51] << 8);
+ /* If the OEM Name field is EXFAT, it's not FAT32, so bail */
+ if (!memcmp(&block[3], "EXFAT ", 8)) {
+ pfatal("exFAT filesystem is not supported.");
+ return FSFATAL;
+ }
+
+ /* check basic parameters */
+ if ((boot->FSInfo == 0) ||
+ (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) ||
+ (boot->BytesPerSec / DOSBOOTBLOCKSIZE == 0) ||
+ (boot->SecPerClust == 0)) {
+ /*
+ * Either the BIOS Parameter Block has been corrupted,
+ * or this is not a FAT32 filesystem, most likely an
+ * exFAT filesystem.
+ */
+ pfatal("Invalid FAT32 Extended BIOS Parameter Block");
+ return FSFATAL;
+ }
if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET)
!= boot->FSInfo * boot->BytesPerSec
|| read(dosfs, fsinfo, sizeof fsinfo)