Skip to content

ext4: fix journal superblock maxLen exceeding allocated blocks#365

Merged
deitch merged 1 commit intodiskfs:masterfrom
djs55:fix-journal-maxlen
Apr 3, 2026
Merged

ext4: fix journal superblock maxLen exceeding allocated blocks#365
deitch merged 1 commit intodiskfs:masterfrom
djs55:fix-journal-maxlen

Conversation

@djs55
Copy link
Copy Markdown
Contributor

@djs55 djs55 commented Apr 2, 2026

I found this while benchmarking creating 20GB ext4 disks (I'll make a separate PR for the benchmark, in case you want it!)

I'm not familiar with ext4 (yet), but Claude claims

When creating a filesystem larger than ~4 GB with 4096-byte blocks, journalBlocks is computed as blockCount/32 which can exceed 32768 (the number of blocks in journalMaxSize=128MB). The journal size is correctly capped to 128 MB, but the original journalBlocks value was passed to NewJournalSuperblock as maxLen. This caused e2fsck to report "journal too short" because the superblock claimed more blocks than were allocated.

Recompute journalBlocks after capping journalSize so maxLen matches the actual allocation.

Add TestCreateLargeFilesystemJournal which creates a 5 GB filesystem (the smallest size that triggers the bug) and validates it with e2fsck. Without the fix, e2fsck reports:

e2fsck: The journal superblock is corrupt: journal too short

(running regression tests with e2fsck is very nice!)

When creating a filesystem larger than ~4 GB with 4096-byte blocks,
journalBlocks is computed as blockCount/32 which can exceed 32768
(the number of blocks in journalMaxSize=128MB). The journal size is
correctly capped to 128 MB, but the original journalBlocks value was
passed to NewJournalSuperblock as maxLen. This caused e2fsck to report
"journal too short" because the superblock claimed more blocks than
were allocated.

Recompute journalBlocks after capping journalSize so maxLen matches
the actual allocation.

Add TestCreateLargeFilesystemJournal which creates a 5 GB filesystem
(the smallest size that triggers the bug) and validates it with e2fsck.
Without the fix, e2fsck reports:

  e2fsck: The journal superblock is corrupt: journal too short

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@deitch deitch left a comment

Choose a reason for hiding this comment

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

That simple? Thanks for fixing this.

@deitch deitch merged commit 75cc1e2 into diskfs:master Apr 3, 2026
20 checks passed
@deitch
Copy link
Copy Markdown
Collaborator

deitch commented Apr 3, 2026

This really needs all of of exec.Command("e2fsck") pulled out into a utility function, including testing for its existence. Not worth holding up here, though.

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