1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! 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::{Features, FsBuilder, InodeCount, Meta, Options, ROOT};
//!
//! # fn main() -> mkext4::Result<()> {
//! let epoch = 1_704_067_200;
//! let mut b = FsBuilder::new(Options {
//! size_bytes: 16 << 20,
//! fs_uuid: [0x42; 16],
//! hash_seed: [1, 2, 3, 4],
//! epoch,
//! inodes: InodeCount::Auto,
//! label: Some("demo".into()),
//! reserved_percent: 5,
//! journal_blocks: None,
//! features: Features::LINUX_ROOTFS,
//! })?;
//! 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");
//! # Ok(()) }
//! ```
//!
//! See [DESIGN.md](https://github.com/cortexapps/mkext4/blob/main/DESIGN.md)
//! for the on-disk layout decisions, the determinism contract, and the
//! metadata-before-data emission argument.
//!
//! 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 real `mke2fs`
//! images.
//! - [`spec`] — on-disk structures with byte-exact `decode`/`encode` into
//! caller-provided buffers.
//! - [`reader`] — walks and verifies complete filesystems (the
//! differential oracle against `mke2fs`, and the round-trip check for
//! the writer).
pub
pub use ;
pub use RegionSink;
/// Errors produced by this crate.
/// Crate-wide result type.
pub type Result<T> = Result;
pub