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
| words[i] = bytes.load(fromByteOffset: i * 4, as: UInt32.self) | ||
| } | ||
| } | ||
| words[15] = ji.sizeLow |
There was a problem hiding this comment.
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 |
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
- 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: