Skip to content

Update FAT32 FSInfo after root dir allocation - #108

Merged
rafalh merged 5 commits into
rafalh:masterfrom
cole-h:fixup-fat32-fsck
Mar 1, 2026
Merged

rafalh merged 5 commits into
rafalh:masterfrom
cole-h:fixup-fat32-fsck

Conversation

@cole-h

@cole-h cole-h commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Overwrite the FSInfo sector once the root directory cluster is allocated
so free-cluster counts match the FAT and fresh images pass fsck cleanly.

Prior to this change, FAT32 disks created by this library would fail fsck.vfat like so:

fsck.fat 4.2 (2021-01-31)
Free cluster summary uninitialized (should be 66535)
  Auto-setting.

*** Filesystem was changed ***
Writing changes.
/tmp/test-fat32.img: 0 files, 1/66536 clusters

Now, they pass:

fsck.fat 4.2 (2021-01-31)
/tmp/test-fat32.img: 0 files, 1/66536 clusters

fsck.vfat doesn't error when in `-n` mode, so we pass `-y` to have it
fix anything it finds, and if it fixes something it will exit with status
code 1.
@cole-h cole-h closed this Feb 2, 2026
@cole-h cole-h reopened this Feb 6, 2026
@cole-h

cole-h commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Didn't mean to close this, whoops.

@rafalh rafalh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice idea to initialize FSInfo sector with the actual data.
AFAIK the previous behavior was compliant with the spec - fields were initialized to -1/0xFFFFFFFF as indicated by the spec to indicate unknown values, but I get that not passing fsck is not nice + there is no reason to not fill those fields.
I left some suggestion to simplify the code.

Comment thread src/fs.rs
Comment thread tests/fsck.rs
Overwrite the FSInfo sector once the root directory cluster is allocated
so free-cluster counts match the FAT and fresh images pass fsck cleanly.

Prior to this change, FAT32 disks created by this library would fail `fsck.vfat` like so:

    fsck.fat 4.2 (2021-01-31)
    Free cluster summary uninitialized (should be 66535)
      Auto-setting.

    *** Filesystem was changed ***
    Writing changes.
    /tmp/test-fat32.img: 0 files, 1/66536 clusters

Now, they pass:

    fsck.fat 4.2 (2021-01-31)
    /tmp/test-fat32.img: 0 files, 1/66536 clusters
@cole-h
cole-h requested a review from rafalh February 8, 2026 19:52

@rafalh rafalh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please add FAT16 test.
I can see that build with old Rust fails, but don't worry about it. It can be fixed in a separate PR by bumping minimal Rust version.

@rafalh
rafalh merged commit 2f1bf3e into rafalh:master Mar 1, 2026
3 of 4 checks passed
@rafalh

rafalh commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Sorry for the delay. I didn't notice you added FAT 16, because you didn't request a re-review and I didn't get a notification. Thanks for the contribution!

@cole-h
cole-h deleted the fixup-fat32-fsck branch March 2, 2026 00:40
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.

2 participants