Skip to content

Commit 8fa77f3

Browse files
committed
don't use BPB_TotSec16 to determine FAT type
Description for BPB_TotSec16: > This field is the old 16-bit total count of sectors on the volume. > This count includes the count of all sectors in all four regions of > the volume. This field can be 0; if it is 0, then BPB_TotSec32 must > be non-zero. For FAT32 volumes, this field must be 0. For FAT12 and > FAT16 volumes, this field contains the sector count, and BPB_TotSec32 > is 0 if the total sector count “fits” (is less than 0x10000). Source: https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc TL;DR: BPB_TotSec16 can be zero even for FAT12/FAT16 volumes if the sector count exceeds 0x10000. Instead, let's use BPB_FATSz16. Unlike BPB_TotSec16, BPB_FATSz16 must be non-zero for FAT12/FAT16 volumes because BPB_FATSz32 only exists in the FAT32 BPB. According to the document mentioned above, BPB_FATSz16 must be zero for FAT32 volumes.
1 parent 0b04f53 commit 8fa77f3

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

bios/stage-2/src/fat.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,14 @@ impl Bpb {
4848
let root_cluster;
4949
let fat_size_32;
5050

51-
if (total_sectors_16 == 0) && (total_sectors_32 != 0) {
51+
if fat_size_16 == 0 {
5252
// FAT32
5353
fat_size_32 = u32::from_le_bytes(raw[36..40].try_into().unwrap());
5454
root_cluster = u32::from_le_bytes(raw[44..48].try_into().unwrap());
55-
} else if (total_sectors_16 != 0) && (total_sectors_32 == 0) {
55+
} else {
5656
// FAT12 or FAT16
5757
fat_size_32 = 0;
5858
root_cluster = 0;
59-
} else {
60-
panic!("ExactlyOneTotalSectorsFieldMustBeZero");
6159
}
6260

6361
Self {

0 commit comments

Comments
 (0)