Skip to content

don't use BPB_TotSec16 to determine FAT type#547

Open
Freax13 wants to merge 2 commits intomainfrom
fix/large-fat16
Open

don't use BPB_TotSec16 to determine FAT type#547
Freax13 wants to merge 2 commits intomainfrom
fix/large-fat16

Conversation

@Freax13
Copy link
Member

@Freax13 Freax13 commented Mar 5, 2026

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.

Closes #546

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.
@Freax13 Freax13 requested a review from phil-opp March 5, 2026 07:49
@Freax13
Copy link
Member Author

Freax13 commented Mar 5, 2026

@NikoPit Please give this a try and report back to us if this solves your issue.

Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you!

@NikoPit
Copy link

NikoPit commented Mar 16, 2026

lemme try it

@NikoPit
Copy link

NikoPit commented Mar 16, 2026

and btw how long does it take for you guys to load a ramdisk, it takes like 1 minute to load a 16mb ram disk. is this normal?

@Freax13
Copy link
Member Author

Freax13 commented Mar 16, 2026

Yeah, I noticed it's kinda slow though I also didn't use hardware acceleration to run the VM. Are you using hardware accelerated virtualization?

@NikoPit
Copy link

NikoPit commented Mar 16, 2026

nope im not using kvm

@Freax13
Copy link
Member Author

Freax13 commented Mar 16, 2026

Ok.

Does this PR resolve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panics when trying to add a ramdisk

3 participants