Skip to main content

Superblock

Struct Superblock 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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: u64

bytenr (offset 0x30) — the physical byte address of THIS superblock copy (65536 for the primary).

§flags: u64

flags (offset 0x38).

§generation: u64

generation (offset 0x48) — the transaction id this superblock committed (the highest valid copy is the latest committed state — the CoW lever).

§root: u64

root (offset 0x50) — logical address of the root tree.

§chunk_root: u64

chunk_root (offset 0x58) — logical address of the chunk tree.

§log_root: u64

log_root (offset 0x60) — logical address of the log tree (0 = none).

§total_bytes: u64

total_bytes (offset 0x70) — filesystem size in bytes.

§bytes_used: u64

bytes_used (offset 0x78) — bytes in use.

§root_dir_objectid: u64

root_dir_objectid (offset 0x80) — the root directory objectid (6).

§num_devices: u64

num_devices (offset 0x88).

§sectorsize: u32

sectorsize (offset 0x90) — data block size in bytes.

§nodesize: u32

nodesize (offset 0x94) — B-tree node size in bytes.

§stripesize: u32

stripesize (offset 0x9c).

§sys_chunk_array_size: u32

sys_chunk_array_size (offset 0xa0) — valid byte length of the sys_chunk_array bootstrap region.

§chunk_root_generation: u64

chunk_root_generation (offset 0xa4).

§compat_flags: u64

compat_flags (offset 0xac).

§compat_ro_flags: u64

compat_ro_flags (offset 0xb4).

§incompat_flags: u64

incompat_flags (offset 0xbc).

§csum_type: CsumType

csum_type (offset 0xc4) — decoded checksum algorithm.

§root_level: u8

root_level (offset 0xc6) — B-tree level of the root tree (0 = leaf).

§chunk_root_level: u8

chunk_root_level (offset 0xc7) — B-tree level of the chunk tree.

§log_root_level: u8

log_root_level (offset 0xc8).

§label: String

label (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

Source

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
Source

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

Source§

fn clone(&self) -> Superblock

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Superblock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Superblock

Source§

impl PartialEq for Superblock

Source§

fn eq(&self, other: &Superblock) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Superblock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.