summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2012-11-18 15:18:02 -0800
committerSteve Kondik <shade@chemlab.org>2012-11-18 15:18:02 -0800
commit6ff3a58bcd3223f15def43ddd39d3921d855494b (patch)
treea7ba2a506d59419940f1ef418e2d05da8fc4139f
parentf9b92a9ae61fc0e147a068d4bd5396ce521176d1 (diff)
parented86a9f77e796aa5923a5b2d1455a7739b86e60b (diff)
downloadandroid_external_fsck_msdos-6ff3a58bcd3223f15def43ddd39d3921d855494b.tar.gz
android_external_fsck_msdos-6ff3a58bcd3223f15def43ddd39d3921d855494b.tar.bz2
android_external_fsck_msdos-6ff3a58bcd3223f15def43ddd39d3921d855494b.zip
-rw-r--r--boot.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/boot.c b/boot.c
index 54d800f..52bf011 100644
--- a/boot.c
+++ b/boot.c
@@ -193,12 +193,6 @@ readboot(dosfs, boot)
/* Check backup FSInfo? XXX */
}
- boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
- / boot->BytesPerSec
- + boot->ResSectors
- + boot->FATs * boot->FATsecs
- - CLUST_FIRST * boot->SecPerClust;
-
if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
pfatal("Invalid sector size: %u", boot->BytesPerSec);
return FSFATAL;
@@ -207,11 +201,26 @@ readboot(dosfs, boot)
pfatal("Invalid cluster size: %u", boot->SecPerClust);
return FSFATAL;
}
+ if (boot->BytesPerSec == 0) {
+ pfatal("Invalid sector size: %u", boot->BytesPerSec);
+ return FSFATAL;
+ }
+ if (boot->FATs == 0) {
+ pfatal("Invalid number of FATs: %u", boot->FATs);
+ return FSFATAL;
+ }
if (boot->Sectors) {
boot->HugeSectors = 0;
boot->NumSectors = boot->Sectors;
} else
boot->NumSectors = boot->HugeSectors;
+
+ boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
+ / boot->BytesPerSec
+ + boot->ResSectors
+ + boot->FATs * boot->FATsecs
+ - CLUST_FIRST * boot->SecPerClust;
+
boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->SecPerClust;
if (boot->flags&FAT32)