Skip to content

don't use BPB_TotSec16 to determine FAT type#547

Merged
Freax13 merged 2 commits into
mainfrom
fix/large-fat16
Mar 17, 2026
Merged

don't use BPB_TotSec16 to determine FAT type#547
Freax13 merged 2 commits into
mainfrom
fix/large-fat16

Conversation

@Freax13

@Freax13 Freax13 commented Mar 5, 2026

Copy link
Copy Markdown
Member

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

Freax13 commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

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

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

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

NikoPit commented Mar 16, 2026

Copy link
Copy Markdown

lemme try it

@NikoPit

NikoPit commented Mar 16, 2026

Copy link
Copy Markdown

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

Freax13 commented Mar 16, 2026

Copy link
Copy Markdown
Member Author

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

NikoPit commented Mar 16, 2026

Copy link
Copy Markdown

nope im not using kvm

@Freax13

Freax13 commented Mar 16, 2026

Copy link
Copy Markdown
Member Author

Ok.

Does this PR resolve your issue?

@NikoPit

NikoPit commented Mar 17, 2026

Copy link
Copy Markdown

yup! this fixed the issue

@NikoPit

NikoPit commented Mar 17, 2026

Copy link
Copy Markdown

please check #549 as well!

@Freax13 Freax13 merged commit 535a1cc into main Mar 17, 2026
18 checks passed
@phil-opp phil-opp mentioned this pull request Jul 7, 2026
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