Expand description
Deterministic, streaming, pure-Rust ext4 image builder — plus a verification-grade reader.
Identical builder calls with identical Options produce
byte-identical images: UUID, htree hash seed, and every timestamp are
explicit inputs, and the crate never consults a clock or RNG. Output
streams through a RegionSink: every byte of the image is emitted
exactly once and is final — all metadata immediately at
Layout::writer, file data behind it at ascending offsets.
§Example
Build a small image in memory, then read it back:
use mkext4::sink::VecSink;
use mkext4::{FsBuilder, Meta, Options, ROOT};
let epoch = 1_704_067_200;
let mut opts = Options::new(16 << 20, [0x42; 16], epoch);
opts.label = Some("demo".into());
let mut b = FsBuilder::new(opts)?;
let etc = b.mkdir(ROOT, "etc", Meta::new(0o755, 0, 0, (epoch, 0)))?;
let f = b.file(etc, "hostname", Meta::new(0o644, 0, 0, (epoch, 0)), 5)?;
let layout = b.seal()?; // the complete physical layout is frozen here
let mut sink = VecSink::default();
let mut w = layout.writer(&mut sink)?;
w.fill(f, &mut &b"husky"[..])?;
w.finish()?;
// sink.buf now holds a complete ext4 image (e2fsck-clean, mountable).
let fs = mkext4::reader::Fs::open(&sink.buf[..])?;
assert_eq!(fs.read_file(fs.resolve("/etc/hostname")?)?, b"husky");Layer map (bottom-up):
csum/dirhash— ext4’s crc32c conventions and the half_md4 directory hash. Zero-allocation, append-style folds over borrowed slices; verified against byte vectors extracted from realmke2fsimages.spec— on-disk structures with byte-exactdecode/encodeinto caller-provided buffers.reader— walks and verifies complete filesystems (the differential oracle againstmke2fs, and the round-trip check for the writer).
Re-exports§
pub use build::Features;pub use build::FsBuilder;pub use build::InodeCount;pub use build::InodeHandle;pub use build::Layout;pub use build::Meta;pub use build::Options;pub use build::SparseSeg;pub use build::SpecialKind;pub use build::ROOT;pub use sink::RegionSink;
Modules§
- build
- The builder API: declare a namespace, seal it into a frozen layout, then stream file contents.
- csum
- ext4 checksum conventions.
- dirhash
- ext4 directory-name hashing (htree / dir_index).
- reader
- Verification-grade ext4 reader.
- sink
- The streaming output contract.
- spec
- On-disk ext4 structures: byte-exact
decode/encode.
Enums§
- Error
- Errors produced by this crate.
Type Aliases§
- Result
- Crate-wide result type.