#[non_exhaustive]pub struct Superblock {Show 28 fields
pub magic: [u8; 8],
pub csum: [u8; 4],
pub fsid: [u8; 16],
pub bytenr: u64,
pub flags: u64,
pub generation: u64,
pub root: u64,
pub chunk_root: u64,
pub log_root: u64,
pub total_bytes: u64,
pub bytes_used: u64,
pub root_dir_objectid: u64,
pub num_devices: u64,
pub sectorsize: u32,
pub nodesize: u32,
pub stripesize: u32,
pub sys_chunk_array_size: u32,
pub chunk_root_generation: u64,
pub compat_flags: u64,
pub compat_ro_flags: u64,
pub incompat_flags: u64,
pub csum_type: CsumType,
pub root_level: u8,
pub chunk_root_level: u8,
pub log_root_level: u8,
pub label: String,
pub sys_chunks: Vec<SysChunk>,
pub crc_valid: Option<bool>,
}Expand description
A parsed btrfs superblock — the filesystem geometry, tree-root logical
addresses, checksum descriptor, and the decoded sys_chunk_array bootstrap
map (the P1 seed for logical→physical translation).
#[non_exhaustive] so later phases add fields without a breaking change.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.magic: [u8; 8]The 8-byte magic at offset 0x40 — validated to equal BTRFS_MAGIC.
csum: [u8; 4]csum (offset 0x0) — the first 4 bytes of the 32-byte checksum field
(the crc32c digest for a crc32c filesystem), verbatim.
fsid: [u8; 16]fsid (offset 0x20) — the filesystem UUID.
bytenr: u64bytenr (offset 0x30) — the physical byte address of THIS superblock
copy (65536 for the primary).
flags: u64flags (offset 0x38).
generation: u64generation (offset 0x48) — the transaction id this superblock committed
(the highest valid copy is the latest committed state — the CoW lever).
root: u64root (offset 0x50) — logical address of the root tree.
chunk_root: u64chunk_root (offset 0x58) — logical address of the chunk tree.
log_root: u64log_root (offset 0x60) — logical address of the log tree (0 = none).
total_bytes: u64total_bytes (offset 0x70) — filesystem size in bytes.
bytes_used: u64bytes_used (offset 0x78) — bytes in use.
root_dir_objectid: u64root_dir_objectid (offset 0x80) — the root directory objectid (6).
num_devices: u64num_devices (offset 0x88).
sectorsize: u32sectorsize (offset 0x90) — data block size in bytes.
nodesize: u32nodesize (offset 0x94) — B-tree node size in bytes.
stripesize: u32stripesize (offset 0x9c).
sys_chunk_array_size: u32sys_chunk_array_size (offset 0xa0) — valid byte length of the
sys_chunk_array bootstrap region.
chunk_root_generation: u64chunk_root_generation (offset 0xa4).
compat_flags: u64compat_flags (offset 0xac).
compat_ro_flags: u64compat_ro_flags (offset 0xb4).
incompat_flags: u64incompat_flags (offset 0xbc).
csum_type: CsumTypecsum_type (offset 0xc4) — decoded checksum algorithm.
root_level: u8root_level (offset 0xc6) — B-tree level of the root tree (0 = leaf).
chunk_root_level: u8chunk_root_level (offset 0xc7) — B-tree level of the chunk tree.
log_root_level: u8log_root_level (offset 0xc8).
label: Stringlabel (offset 0xab within dev_item… → absolute 0x12b) — the
NUL-trimmed filesystem label, lossily decoded from up to 256 bytes.
sys_chunks: Vec<SysChunk>The decoded sys_chunk_array bootstrap chunk map — the SYSTEM
block-group logical→physical entries needed to read the chunk tree in P1.
Full chunk-tree walking is P1; P0 decodes the bootstrap structs only.
crc_valid: Option<bool>The crc32c status of this superblock over its sectorsize-byte block:
Some(true) if the stored csum verifies, Some(false) if it does not
(corrupt/tampered), or None for a non-crc32c checksum type (deferred).
Non-fatal — a bad csum does not fail the parse.
Implementations§
Source§impl Superblock
impl Superblock
Sourcepub fn parse(block: &[u8]) -> Result<Self, BtrfsError>
pub fn parse(block: &[u8]) -> Result<Self, BtrfsError>
Parse a btrfs superblock from the start of block.
block must begin at the superblock (the caller slices the 4096-byte
block at physical offset 65536; passing the whole sectorsize block lets
the crc32c cover the correct range). The magic is validated at offset
0x40 (not 0) — a wrong-image identity error names the offending 8 bytes.
§Errors
BtrfsError::BadMagicif offset 0x40 is not_BHRfS_M— the eight offending bytes are carried in the error.BtrfsError::Truncatedifblockis shorter than the scalar fields.
Sourcepub fn fsid_string(&self) -> String
pub fn fsid_string(&self) -> String
The filesystem UUID rendered as the canonical 8-4-4-4-12 string.
Trait Implementations§
Source§impl Clone for Superblock
impl Clone for Superblock
Source§fn clone(&self) -> Superblock
fn clone(&self) -> Superblock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more