pub struct BTreeKeyFormat {
pub big_keys: bool,
pub variable_index_keys: bool,
pub max_key_len: u16,
}Expand description
Describes how a B-tree encodes its keys, so the shared split / grow / rotate machinery below can serve both the classic-HFS 1-byte-key catalog and the HFS+ 2-byte (“big key”) trees without forking the algorithm.
The classic path threads BTreeKeyFormat::CLASSIC_CATALOG and is
byte-identical to the pre-descriptor code (the fixed 0x25 index key produced
by normalize_catalog_index_key); HFS+ threads the matching HFSPLUS_*
constant, which is what unlocks variable-length index keys so an HFS+ catalog
can split past a single leaf level without corrupting.
Derived from the BTHeaderRec attributes bitfield + maxKeyLength.
Fields§
§big_keys: boolkBTBigKeysMask: key-length prefix is 2 bytes (HFS+) vs 1 byte (classic).
variable_index_keys: boolkBTVariableIndexKeysMask: index records store the child’s
variable-length key verbatim. When clear, index keys are padded to
max_key_len.
max_key_len: u16Maximum key length — the fixed index-key width when variable_index_keys
is clear (classic catalog: 0x25; HFS+ extents-overflow: 10).
Implementations§
Source§impl BTreeKeyFormat
impl BTreeKeyFormat
Sourcepub const CLASSIC_CATALOG: BTreeKeyFormat
pub const CLASSIC_CATALOG: BTreeKeyFormat
Classic HFS catalog: 1-byte key length, fixed 0x25-byte index keys.
Sourcepub const HFSPLUS_CATALOG: BTreeKeyFormat
pub const HFSPLUS_CATALOG: BTreeKeyFormat
HFS+/HFSX catalog: 2-byte key length, variable-length index keys
(kHFSPlusCatalogKeyMaximumLength = 516).
Sourcepub const HFSPLUS_EXTENTS: BTreeKeyFormat
pub const HFSPLUS_EXTENTS: BTreeKeyFormat
HFS+ extents-overflow: 2-byte key length, fixed 10-byte index keys
(kHFSPlusExtentKeyMaximumLength = 10).
Sourcepub const HFSPLUS_ATTRIBUTES: BTreeKeyFormat
pub const HFSPLUS_ATTRIBUTES: BTreeKeyFormat
HFS+ attributes: 2-byte key length, variable-length index keys
(kHFSPlusAttrKeyMaximumLength = 264).
Sourcepub const CLASSIC_EXTENTS: BTreeKeyFormat
pub const CLASSIC_EXTENTS: BTreeKeyFormat
Classic HFS extents-overflow: 1-byte key length, fixed 7-byte keys.
Sourcepub fn from_header(attributes: u32, max_key_len: u16) -> Self
pub fn from_header(attributes: u32, max_key_len: u16) -> Self
Build a descriptor from a BTHeaderRec attributes bitfield and
maxKeyLength. The attributes field on hand-built volumes can be 0
(no flags) even for HFS+ trees, so callers that know the tree’s identity
should prefer the HFSPLUS_* / CLASSIC_CATALOG constants; this helper
is for code paths that only have the raw header bytes.
Sourcepub fn header_attributes(&self) -> u32
pub fn header_attributes(&self) -> u32
The BTHeaderRec attributes bits implied by this format.
Sourcepub fn len_prefix(&self) -> usize
pub fn len_prefix(&self) -> usize
Bytes occupied by the key-length prefix (1 classic, 2 big-key).
Sourcepub fn key_len(&self, record: &[u8]) -> usize
pub fn key_len(&self, record: &[u8]) -> usize
Read the key length stored at the front of record.
Sourcepub fn key_portion(&self, record: &[u8]) -> Vec<u8> ⓘ
pub fn key_portion(&self, record: &[u8]) -> Vec<u8> ⓘ
The key portion of a record — the length prefix plus key_len key
bytes. This is exactly the slice an index separator must carry, and what
the split helpers extract from a leaf/child’s first record.
Sourcepub fn make_index_key(&self, first_key: &[u8]) -> Vec<u8> ⓘ
pub fn make_index_key(&self, first_key: &[u8]) -> Vec<u8> ⓘ
Build the key bytes of an index record (length prefix + key) from a child node’s first-key portion.
- Classic HFS: the fixed 0x25 normalized key, identical to
normalize_catalog_index_key. - HFS+ variable-index-key trees (catalog, attributes): the key portion verbatim (2-byte length + key bytes).
- HFS+ fixed-index-key trees (extents-overflow): the key bytes padded to
max_key_len, length field forced tomax_key_len.