190. ext4, read and write: a Rust implementation with libext2fs as the host-side oracle
calef's ext4 drives hold the family's borg repositories. They were formatted by Linux with
mke2fs defaults, metadata_csum among them, and they will not be reformatted. So nife reads and
writes ext4 as Linux wrote it. The requirement is standing and has no deadline.
The goal is a functional ext4 for nife that meets the bar of §46 (thin primitives or whole
subsystems; we write everything in between) and this block's done-when. The implementation is the
Rust crate rsext4, and there is no alternative. We offer every contribution upstream to
rcore-os/tgoskits. partsfoundry/rsext4 carries whatever upstream does not take and is maintained
indefinitely: the fork is the shipping source, not a stopgap (2026-11-25 UTC). We test it against
libext2fs and Linux, under §136 (a mature foreign implementation earns its place as an oracle, not
as a dependency). This is the ext4 row of milestone 140 (mount a drive this system did not create),
and leaves 140's order for FAT32 and ext2.
§34 (RedoxFS is the primary filesystem)
says why RedoxFS cannot stay. rsext4 replaces RedoxFS once the fork meets the bar, and we ask for the adoption
ruling then (2026-11-25 UTC). Milestone 982 (Retire RedoxFS once a launch store proves itself) holds
the inventory of what leaves.
Reuse: rsext4 0.9.2 on crates.io (Apache-2.0, no_std with alloc, depending on bitflags and
thiserror), developed in rcore-os/tgoskits under fs/rsext4, not in the Starry-OS/rsext4
its manifest names.
nife uses partsfoundry/rsext4, 0.9.2 with our fixes on
top, which its CHANGES.md lists.
e2fsprogs 1.47 and a Linux kernel are the host-side oracles. The other candidates and the
reason each lost are in the survey.
Why rsext4
It is the one Rust implementation that writes ext4 with metadata_csum and writes a jbd2 journal,
and it has a maintained upstream. Taking it is §46's 2026-10-04 default: a file format is the
exposure case, and code other systems have run carries evidence that code written here cannot.
What is measured
Measured 2026-11-14 (UTC) on a Linux host with e2fsprogs 1.47, against rsext4 0.9.2 through its
public API:
- Read. On a 640 MiB default
mke2fsimage (3,025 entries, a depth-2 extent tree, an htree), every file read back byte-identical. 1 KiB and 2 KiB blocks rightly fail to mount on 4,096-byte sectors (BUGS); 0.9.2 reports a bareIo, the fork the geometry refusal (item 7). - Read oracle, 2026-11-16 (UTC). Over seven generated images of 3,060 entries each, on 512-byte
and 4,096-byte sectors,
debugfsandrsext4agree on 3,057 entries of each image that mounts. In 0.9.2 three differ, the timesInodeInfodrops (item 8); in the fork none do.inline_datarefuses to mount. The images and tables are in the read-oracle appendix. - Write, bug 1. When a directory grows past its inline extents into a level-1 extent leaf, the
directory's
i_blockscomes out 16 sectors short.e2fsck -fnexits 4 ("i_blocks is 488, should be 504"). The directory's contents are correct. - Write, bug 2.
truncate_inodeon a file whose extent tree has depth 2 returnsCorrupted { op: "extent:empty_index" }in 2 of 8 seeds. It is not atomic: when it fails, the bytes from the new end of file to the end of that block are already zeroed. The fork fixes both (upstream items 2a and 2b). - Write, bug 3 (upstream item 9). At 1 KiB blocks
rsext4leaves clear the padding of an inode bitmap it initializes, ande2fsck -fnexits 4. The fork fixes it. - Write oracle, 2026-11-22 (UTC). Sixteen cases, extended attributes included, fail only on bugs 1 to 3 in 0.9.2 and on none of them in the fork (the write-oracle appendix).
- Journal. It writes descriptor, revoke and commit blocks with journal checksum v3, and Linux's
e2fsckreplays them. Across two images, 158 power-cut points all recovered to a clean volume. In 2 of 79 cuts on one image theneeds_recoveryflag was cleared before the journal's start was reset; both recovered, and the order is still wrong. unsafe. In 0.9.2, eleven uses. Nine are the hardware CRC32C paths for aarch64 and x86_64. Two are inblockgroup_description/table.rs, which casts a&[u8]to*const Ext4GroupDescand to*mut Ext4GroupDescwith noSAFETYcomment and no proof of alignment. In the fork the casts are gone, the crate deniesunsafecode outsidecrc32c, and each of the 12 remaining uses states its argument (item 5).- Fuzzing and proofs. 0.9.2 has no fuzz targets and no Kani harnesses. The fork carries item 4's
fuzz targets in
fuzz/, which itsfuzzworkflow runs weekly. It carries eight Kani harnesses in sixverification.rsmodules, each with a falsification patch infalsifications/, and itsproofsworkflow runs both and passes. - Targets. It builds unchanged for nife's three targets, measured by milestone 997 (ext4 through rsext4, under milestone 37's crash injector). Nothing has run it under nife.
Not yet tested, beyond the follow-on's list: concurrent callers, orphan_file and performance.
The bar, and where rsext4 stands
§46's four conditions, as amended:
| condition | rsext4 as nife takes it, from partsfoundry/rsext4 |
what closes it |
|---|---|---|
a safety argument on every use of unsafe |
the casts are gone, and each of the 12 uses states one | the review below, at the commit nife pins |
| proofs that match ours | eight Kani harnesses in the fork, passing in its proofs workflow; none upstream |
met in the fork |
| aarch64, riscv64 and x86_64 | builds for all three; hardware CRC32C on two, a software path on riscv64 | the oracle suite passing on each |
| maintained | upstream is active in tgoskits, at least 24 commits by six people from 2026-08-04 to 2026-11-08 |
met by partsfoundry/rsext4, maintained indefinitely |
What we contribute upstream
Every contribution goes to rcore-os/tgoskits, against fs/rsext4; the numbers and the commit
below are that repository's. We follow its policy on agent-written submissions.
- The
i_blocksfix, with its reproducer as a test in the crate: grow a directory to 300 entries, unmount, and requiree2fsck -fnto exit 0. Fixed upstream indde4020be; the fork carries the part that fixes it (4dc13db). - The truncate fix, with its reproducer: the failing seeds as fixed inputs, a check that
truncation of a depth-2 tree succeeds, and a check that a failed truncation leaves the file's
bytes as they were. 2a merged (
#2827). 2b open (#2829), with#2845stacked on it, which commits a shrink's new size before zeroing its tail. - The recovery-flag order. The journal's start is reset before
needs_recoveryis cleared, with the power-cut point that showed it as a test. Fixed upstream indde4020be; not in the fork. - Fuzz targets: mount and walk an arbitrary image; parse a superblock, a group descriptor
table, an extent tree, a directory block and an htree index; and replay an arbitrary journal.
Each target runs under
cargo fuzzwith a seed corpus of small imagesmke2fsmade. Merged (#2835). - The
unsafereview: aSAFETYcomment on each CRC32C use, naming the CPU feature it needs and where it is detected, and the group-descriptor casts replaced by decoding each field from its bytes, at both descriptor sizes. Merged: 5a (#2831), which takes hardware CRC32C availability from the environment, and 5b (#2833). - Kani harnesses that match ours. Decoding a superblock, a group descriptor, an extent header or
entry, or a directory entry reads only inside its slice, for every input up to a stated bound.
A directory block walk ends inside its block. The software CRC32C equals the bitwise definition.
Merged (
#2846), after issue#2836. They run in the fork. - Mount reports why it refused, rather than mapping every error from
read_superblockto a bareIo. Merged (#2839). InodeInforeports whole times: nanoseconds, times before 1970 and times past 2106. Open (#2840).- The inode bitmap's padding (bug 3), set as
e2fsckrequires when a groupmke2fsleftINODE_UNINITgets its first inode, with the crate's own allocation test strengthened. Merged (#2825).
Every issue and pull request text is shown to the architect before it is filed. An upstream
submission is an outward step, and the review is of the exact text, not of the idea. A fuzz finding
in rsext4 is reported the same way. Upstream merge is the goal of every contribution, not a
gate: partsfoundry/rsext4 carries every fix, and keeps carrying whatever upstream does not take.
No contribution is consumed from a branch. §305 (git dependencies are allowed on nifeos/* and
partsfoundry/* only, pinned to a landed commit) rules out a git dependency on tgoskits. A fix
counts once it is on partsfoundry/rsext4's main at the commit nife pins by rev under §305.
What we test on our side
Each of the four phases is useful alone, and the oracle judges each.
| phase | what | judged by |
|---|---|---|
| 1 | Read-only: one confined ext4_server holding one block-device capability, with rsext4 mounted read-only. nifeos/nife#4110 (provisional) builds the core: "Milestone 190 phase 1: a read-only ext4_server core, judged by the read oracle" |
the oracle, read half, over the corpus |
| 2 | The differential oracle: rsext4 against libext2fs and against Linux, in tools/, on the host |
itself, in CI, before any write is trusted |
| 3 | Write, metadata_csum on every write |
e2fsck -fn exits 0 after each operation; Linux reads back what nife wrote |
| 4 | jbd2: rsext4's journal, which Linux replays |
power cut, then Linux replay, then e2fsck -fn |
The oracle is a std host workspace in tools/ext4_oracle/, never in the shipping graph. It
requires every listing and file rsext4 reads to equal debugfs's, and judges each write with
e2fsck -fn and a debugfs readback.
The corpus is images mke2fs makes with its defaults and with 1 KiB, 2 KiB and 4 KiB blocks, on
devices with 512-byte and 4,096-byte sectors. It adds extent depths 0 to 2, htree directories,
orphan_file, and a volume over 1 GiB. calef's own drives join it read-only, after a dumpe2fs -h
on each shows the feature set phase 1 must support. Their borg repositories verify themselves, so
borg check after a round trip is an end-to-end result no synthetic image gives.
Write reordering. A block device between rsext4 and the image records every write and every
flush. For each interval between two flushes, the sweep persists the interval's writes in other
orders and cuts power after each prefix of each order, then lets Linux replay and runs
e2fsck -fn. A device may reorder writes between barriers, so a volume that recovers only from
the order it was written in is wrong.
Power cuts and lying devices. Milestone 997 puts rsext4 behind the injector of milestone 37
(Prove RedoxFS's crash consistency). Phase 4 reuses that glue, judges with Linux replay, and adds
a mount on a real Linux kernel in a virtual machine.
Hostile images. nife's fuzz rotation runs the upstream targets over this corpus, under the
runner of milestone 42 (supply chain and fuzzing in CI), and also drives ext4_server over the
block-device seam with mutated images. A drive nife did not write is untrusted input, and the
server holding it is confined so that a parser bug costs one server.
The adoption ruling it still needs
Each dependency is an architect's ruling, and rsext4 is not yet ruled. We ask for it once every
other condition of the done-when holds (2026-11-25 UTC). The proposal is its own pull request,
which carries needs-architect and shows, for the version it pins:
- each condition of the bar, with the commit or test that meets it;
- the crate's
unsafe, counted and located, with what checks each use; - its dependency graph from
cargo tree -e normalfor each target, which attgoskits' head addsspinning_top; - the oracle's results on that version, phase by phase;
- that it stays upgradable, under §81 (a dependency stays upgradable; we suppress churn, never the upgrade), and what an upgrade reruns.
Phase 1 may start against the oracle on the host before the ruling. Nothing links rsext4 into a
nife image until it is given.
The rule in force for the oracle, ruled 2026-11-16 (UTC) on pull request #3639: rsext4 is a
host-only dependency of tools/ext4_oracle, in a workspace and lockfile of its own. It is pinned to
partsfoundry/rsext4 at one commit by rev, under the 2026-11-23 (UTC) ruling to fork. It never
enters a nife image, kernel, program or the lockfile of a shipping package. deny.toml refuses the crate anywhere else, and the oracle is a test package, so no shipping package may link
it. That ruling is not the adoption ruling above, which stays open.
Done when
- Bugs 1 to 3 and the recovery-flag order are fixed in partsfoundry/rsext4 at the commit nife pins, each with its reproducer as a test.
- Every use of
unsafeat that commit carries a safety argument, and the group-descriptor casts are gone. - The Kani harnesses above pass in partsfoundry/rsext4.
- Fuzz targets are in partsfoundry/rsext4, and nife's rotation runs them and
ext4_server's with no open finding. - The oracle passes in CI on aarch64, riscv64 and x86_64, every image in the corpus included.
- The write-reordering and power-cut sweeps recover every point to a clean volume under Linux replay.
ext4_serverreads and writes a Linux-formatted drive on each architecture under QEMU, ande2fsck -fnandborg checkpass afterwards.- The adoption ruling is given.
What this milestone does not decide
- Whether nife hosts borg repositories or makes borg archives. Hosting needs only this milestone. Making them needs a borg client, and no Rust implementation of the repository format exists. That is a separate, larger block, minted only if calef wants nife to make backups.
- When RedoxFS leaves the tree: a milestone of its own, minted from milestone 982's inventory after adoption.
- FAT32 and ext2, which keep milestone 140's order.
BUGS
- Between commits, the journal protects nothing.
rsext4commits only onsync()or unmount, so a power cut loses every write since the last of them. For a borg repository this is mostly survivable, because borg discards a segment tail with no commit tag andborg checkverifies every chunk. That is a mitigation, not an equivalence, and the server must say so where a reader meets the feature. Whenext4_servercommits is a design question for phase 4. - ext4 checksums metadata, not file data, so a write the device drops reads back as stale bytes with no error.
e2fsckhas no Rust equivalent here. A drive damaged on nife is repaired by plugging it into Linux.- The
metadata_csumclaim about calef's drives is inferred frommke2fs's default until thedumpe2fs -hsurvey measures it. The read oracle covers images with and without it, and with and withoutmetadata_csum_seedandorphan_file, whichmke2fsenables by default only from e2fsprogs 1.47.0. - No reader can address a block smaller than the device's logical sector, so
rsext4refuses 1 KiB and 2 KiB blocks on a 4,096-byte-sector device, as Linux does. rsext4refuses to mount aninline_dataimage, even read-only.mke2fsdoes not enable it by default.write_filefails withCorrupted { op: "extent:parent_key" }when 1,500 single-block extents arrive shuffled, in 0.9.2 and ondev; in ascending order the file builds. No upstream draft yet.- The read oracle compares against
debugfs, which is libext2fs, not the Linux kernel; this host could not mount a loop device. - No phase is priced. The estimate comes after the corpus survey and the first upstream round.
Follow-on
- Done. Upstream merged items 2a, 4, 5a, 5b, 6, 7 and 9 (
rcore-os/tgoskits#2827,#2835,#2831,#2833,#2846,#2839,#2825). The drafts hold each text. - Outstanding. Upstream review of 2b (
#2829), the shrink commit stacked on it (#2845) and item 8 (#2840). - Done. The read and write oracle in
tools/ext4_oracle/and its CI jobext4-read-oracleon x86_64, with the sector-size reproducer as a test, takingrsext4from partsfoundry/rsext4 at a pinnedrev(388ebd6), where no write outcome holds ane2fsckfailure. - Done. In partsfoundry/rsext4: eight Kani harnesses in six
verification.rsmodules, each with a falsification patch, passing in itsproofsworkflow, and seven fuzz targets, which itsfuzzworkflow runs weekly. - Done. partsfoundry/rsext4 carries bugs 1, 2a, 2b, 2c and 3 (
4dc13db,#9,#10) and 5a as upstream merged it (#8). Its weekly workflow passes onmain. - Outstanding. partsfoundry/rsext4 lacks the recovery-flag order of
rcore-os/tgoskits@dde4020be. - Outstanding. partsfoundry/rsext4 carries 109 crate-standard exemptions for upstream code it keeps as written: 55 function lengths, 47 acronyms and 7 file lengths.
- Outstanding. Our side: the oracle on aarch64 and riscv64, the kernel as a second read oracle,
a volume over 1 GiB, the write-reordering and power-cut sweeps, hostile-image fuzzing in nife's
rotation, and
ext4_serverunder QEMU. - Outstanding. The adoption ruling under §46 (thin primitives or whole subsystems), once the fork meets the bar. No lane can give it.
Index row
calef's ext4 drives hold the family's borg repositories, so nife reads and writes the format Linux
wrote. The implementation is rsext4, with no alternative, from partsfoundry/rsext4: a fork that
offers every fix upstream, carries what upstream does not take, and is the shipping source.
Upstream work and the fork bring it to the bar of §46: write-path fixes, fuzz targets, safety
arguments, decoded group descriptors and Kani harnesses. A differential oracle against libext2fs
and Linux judges read, write and jbd2 replay, plus write reordering and hostile-image fuzzing. Once
the fork meets the bar, we ask for the adoption ruling, and rsext4 replaces RedoxFS.