Conversation
| // 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) |
There was a problem hiding this comment.
Do we need to check that blocks > 0 here?
There was a problem hiding this comment.
the numerator and denominator are both UInt64 (self.blockSize is UInt32) so that check would be dead code
There was a problem hiding this comment.
block would be 0 if size was less than self.blockSize.
There was a problem hiding this comment.
My brain is fried, I thought I was seeing "do we need to check for negative?"
There was a problem hiding this comment.
Actually this needs to be bounded at 1024 blocks minimum...
EXT4.Formatter
| journalInode.crtimeExtra = now.hi | ||
| journalInode.linksCount = 1 | ||
| journalInode.extraIsize = UInt16(EXT4.ExtraIsize) | ||
| journalInode.flags = EXT4.InodeFlag.extents.rawValue |
There was a problem hiding this comment.
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
2b3215f to
4639b7a
Compare
|
|
||
| // MARK: - Private helpers | ||
|
|
||
| private func calculateJournalSize(requestedSize: UInt64?, totalBlocks: UInt32) throws -> UInt32 { |
There was a problem hiding this comment.
JournalSize needs to account for optimizeBlockGroupLayout
The totalBlocks when this gets called is an estimate based on blockSize and diskSize. However, based on how much data is written, the layout changes (right after close() gets called.
The fix would be to either defer the size validation until after close() knows the real final block count, or to have calculateJournalSize use the post-optimizeBlockGroupLayout block count (i.e., account for the fact that close() will expand the image to fit). The totalBlocks / 2 guard should also be applied consistently to both paths.
- 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.
EXT4.Formatter.init(), with nil default specifying the current no-journal filesystem configuration. Otherwise the parameter value contains the journal size and mode.Due diligence already performed: