Skip to content

Adds journal modes to EXT4.Formatter#672

Open
jglogan wants to merge 8 commits intoapple:mainfrom
jglogan:ext4-journal
Open

Adds journal modes to EXT4.Formatter#672
jglogan wants to merge 8 commits intoapple:mainfrom
jglogan:ext4-journal

Conversation

@jglogan
Copy link
Copy Markdown
Contributor

@jglogan jglogan commented Apr 8, 2026


Due diligence already performed:

@dkovba dkovba requested a review from wlan0 April 8, 2026 23:38
// Clamp to UInt32.max: the kernel caps internal journals at 2^32 blocks
// (per §3.6.4 s_maxlen), and a caller-supplied size large enough to exceed
// that would otherwise trap on the narrowing conversion.
let blocks = size / UInt64(self.blockSize)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to check that blocks > 0 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the numerator and denominator are both UInt64 (self.blockSize is UInt32) so that check would be dead code

Copy link
Copy Markdown
Contributor

@dkovba dkovba Apr 9, 2026

Choose a reason for hiding this comment

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

block would be 0 if size was less than self.blockSize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My brain is fried, I thought I was seeing "do we need to check for negative?"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually this needs to be bounded at 1024 blocks minimum...

@dkovba dkovba changed the title Adds journal modes to EXT4.Formatter. Adds journal modes to EXT4.Formatter Apr 9, 2026
words[i] = bytes.load(fromByteOffset: i * 4, as: UInt32.self)
}
}
words[15] = ji.sizeLow
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The superblock is weird. It doesn't always follow the little endian convention: https://docs.kernel.org/filesystems/ext4/super.html (look for 0x10C)

words[15] and words[16] should be interchanged

journalInode.crtimeExtra = now.hi
journalInode.linksCount = 1
journalInode.extraIsize = UInt16(EXT4.ExtraIsize)
journalInode.flags = EXT4.InodeFlag.extents.rawValue
Copy link
Copy Markdown
Contributor

@wlan0 wlan0 Apr 9, 2026

Choose a reason for hiding this comment

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

journal Inodes and file Inodes will be of different sizes if EXT4_HUGE_FILE_FL is omitted here. Without that flag, the kernel accounts for blocks being 512 bytes in size. However, writeExtents works in blockSize units. This will cause accounting mismatches.

The fix is to set InodeFlag.hugeFile flag

- Set journal backup type.
- Trailing comment after superblock setup listing
  fields we implictly left zero.
- Enforce minimum journal size of 1024
  blocks (`EXT4_MIN_JOURNAL_BLOCKS`).
- Fix byte ordering of `i_size` and `i_size_hi`
  in the s_jnl_blocks.
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.

[Request]: ContainerizationEXT4: support journal modes

3 participants