Skip to content

More ext4 tests#343

Merged
deitch merged 2 commits intomasterfrom
more-ext4-tests
Feb 12, 2026
Merged

More ext4 tests#343
deitch merged 2 commits intomasterfrom
more-ext4-tests

Conversation

@deitch
Copy link
Collaborator

@deitch deitch commented Feb 12, 2026

And fix many issues

Signed-off-by: Avi Deitcher <avi@deitcher.net>
Fix four bugs that caused ext4 images created with 2KB, 4KB, and 8KB
block sizes to be rejected by e2fsck as corrupt:

1. superblock.go toBytes(): s_log_cluster_size was serialized as 0 for
   non-bigalloc filesystems. The ext4 spec encodes this as
   cluster_size = 2^(10 + s_log_cluster_size), and e2fsck validates
   s_log_block_size <= s_log_cluster_size. For non-bigalloc where
   cluster == block, s_log_cluster_size must equal s_log_block_size.

2. superblock.go superblockFromBytes(): clusterSize was read using
   Exp2(raw_value) instead of Exp2(10 + raw_value), producing
   clusterSize=1 for 1KB blocks instead of 1024.

3. ext4.go writeGDT(): GDT byte offset was calculated as
   block*blockSize + 1024 + 1024 (hardcoded boot sector + superblock),
   which placed the GDT at byte 2048 regardless of block size. For 4KB
   blocks, the GDT must be at byte 4096 (block 1). Now uses block-
   aligned positioning: primary at (firstDataBlock+1)*blockSize, backups
   at (block+1)*blockSize.

4. ext4.go Create(): blocksPerGroup defaulted to 8*blocksize with no
   upper cap. For 8KB blocks this gives 65536, exceeding the e2fsprogs
   limit EXT2_MAX_CLUSTERS_PER_GROUP = (1<<16)-8 = 65528 (constrained
   by the 16-bit bg_free_blocks_count field). Now capped at 65528.

All block sizes (1KB, 2KB, 4KB, 8KB) now pass e2fsck validation.
The skipE2fsck test workaround has been removed.

Signed-off-by: Avi Deitcher <avi@deitcher.net>
@deitch deitch merged commit 6cfdf34 into master Feb 12, 2026
20 checks passed
@deitch deitch deleted the more-ext4-tests branch February 12, 2026 10:35
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.

1 participant