Expand description
Page-0 file header — encode / decode.
The on-disk layout is described byte-by-byte in docs/format.md;
this module is its reference implementation. Field offsets and
sizes are encoded as const items rather than magic numbers in the
function bodies so a reviewer can audit the layout against the spec
at a glance.
At milestone M2 the header’s header_crc32c field is reserved
(written as four zero bytes, not verified on read). Issue #6 wires
the CRC32C algorithm; this module is structured so that change is a
one-line edit to encode_header and decode_header.
Structs§
- File
Header - In-memory representation of the page-0 file header.
Constants§
- FEATURE_
FLAGS_ KNOWN - Mask of all
feature_flagsbits this build understands. Any bit set in the on-disk header but NOT in this mask is rejected at open time withError::InvalidFormat: an unknown flag might change how subsequent bytes are interpreted, and a reader that does not know what it means MUST refuse to guess. - FEATURE_
FLAG_ COMPRESSION feature_flagsbit indicating the file uses per-page LZ4 compression (Phase 3 issue #8). Set on creation by aPageropened withConfig::compression_mode = CompressionMode::Lz4.- FEATURE_
FLAG_ ENCRYPTION feature_flagsbit indicating the file uses per-pageXChaCha20-Poly1305encryption (Phase 4 issue #9). Set on creation by aPagerwhoseConfig::encryption_keyisSome(_). When this bit is set, every non-header page on disk is4096 + 24 + 16 = 4136bytes physical (ciphertext plus nonce plus Poly1305 tag), and the page-0kdf_saltfield (offset 72..104) carries the 32-byte HKDF-SHA256 salt used to derive the per-file page encryption key from the caller’s user key.- FORMAT_
MAJOR - Format major version implemented by this build.
- FORMAT_
MINOR - Format minor version implemented by this build.
- MAGIC
- File magic. ASCII
OBJF.
Functions§
- decode_
header - Decode the page-0 header from the given
pagebuffer. Validates magic, page-size, major version, the per-majorformat_minorconstraint, and theheader_crc32cfield. - encode_
header - Encode
headerintopage. Power-of-ten Rule 5: invariants the caller is supposed to uphold are documented viadebug_assert!.