Skip to main content

ExtentBuffer

Struct ExtentBuffer 

Source
pub struct ExtentBuffer { /* private fields */ }
Expand description

A mutable tree block backed by a byte buffer.

Provides field-level read/write access to the 101-byte header, item descriptors (for leaves), and key pointers (for nodes). The buffer is always exactly nodesize bytes.

Implementations§

Source§

impl ExtentBuffer

Source

pub fn from_raw(data: Vec<u8>, logical: u64) -> Self

Create an ExtentBuffer from raw bytes at the given logical address.

§Panics

Panics if data is empty.

Source

pub fn new_zeroed(nodesize: u32, logical: u64) -> Self

Create a zeroed ExtentBuffer of nodesize bytes at the given logical address.

Source

pub fn logical(&self) -> u64

Return the logical byte address of this block.

Source

pub fn set_logical(&mut self, logical: u64)

Set the logical byte address of this block.

Source

pub fn nodesize(&self) -> u32

Return the nodesize (length of the buffer).

Source

pub fn as_bytes(&self) -> &[u8]

Return a reference to the raw byte buffer.

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Return a mutable reference to the raw byte buffer.

Source

pub fn as_tree_block(&self) -> TreeBlock

Parse this buffer into a TreeBlock for read-only inspection.

Source

pub fn generation(&self) -> u64

Read the generation field from the header.

Source

pub fn owner(&self) -> u64

Read the owner (tree ID) field from the header.

Source

pub fn nritems(&self) -> u32

Read the nritems field from the header.

Source

pub fn level(&self) -> u8

Read the level field from the header.

Source

pub fn bytenr(&self) -> u64

Read the bytenr field from the header.

Source

pub fn flags(&self) -> u64

Read the flags field from the header.

Source

pub fn fsid(&self) -> Uuid

Read the fsid from the header.

§Panics

Panics if the buffer is shorter than 48 bytes.

Source

pub fn chunk_tree_uuid(&self) -> Uuid

Read the chunk_tree_uuid from the header.

§Panics

Panics if the buffer is shorter than 80 bytes.

Source

pub fn set_generation(&mut self, generation: u64)

Write the generation field.

Source

pub fn set_owner(&mut self, owner: u64)

Write the owner (tree ID) field.

Source

pub fn set_nritems(&mut self, nritems: u32)

Write the nritems field.

Source

pub fn set_level(&mut self, level: u8)

Write the level field.

Source

pub fn set_bytenr(&mut self, bytenr: u64)

Write the bytenr field.

Source

pub fn set_flags(&mut self, flags: u64)

Write the flags field.

Source

pub fn set_fsid(&mut self, fsid: &Uuid)

Write the fsid.

Source

pub fn set_chunk_tree_uuid(&mut self, uuid: &Uuid)

Write the chunk_tree_uuid.

Source

pub fn item_key(&self, slot: usize) -> DiskKey

Read the key of the item at the given slot index in a leaf.

§Panics

Panics if slot is out of bounds.

Source

pub fn item_offset(&self, slot: usize) -> u32

Read the data offset field of the item at the given slot. This offset is relative to byte 101 (immediately after the header).

Source

pub fn item_size(&self, slot: usize) -> u32

Read the data size field of the item at the given slot.

Source

pub fn item_data_offset(&self, slot: usize) -> usize

Return the absolute byte offset within the block where item data starts. The item’s offset field is relative to byte 101 (HEADER_SIZE).

Source

pub fn item_data(&self, slot: usize) -> &[u8]

Return a slice of the item’s data payload.

Source

pub fn item_data_mut(&mut self, slot: usize) -> &mut [u8]

Return a mutable slice of the item’s data payload.

Source

pub fn set_item_key(&mut self, slot: usize, key: &DiskKey)

Write the key for an item at the given slot.

Source

pub fn set_item_offset(&mut self, slot: usize, offset: u32)

Write the data offset for an item at the given slot.

Source

pub fn set_item_size(&mut self, slot: usize, size: u32)

Write the data size for an item at the given slot.

Source

pub fn key_ptr_key(&self, slot: usize) -> DiskKey

Read the key of the key pointer at the given slot in a node.

Source

pub fn key_ptr_blockptr(&self, slot: usize) -> u64

Read the blockptr of the key pointer at the given slot.

Source

pub fn key_ptr_generation(&self, slot: usize) -> u64

Read the generation of the key pointer at the given slot.

Source

pub fn set_key_ptr_key(&mut self, slot: usize, key: &DiskKey)

Write the key for a key pointer at the given slot.

Source

pub fn set_key_ptr_blockptr(&mut self, slot: usize, blockptr: u64)

Write the blockptr for a key pointer at the given slot.

Source

pub fn set_key_ptr_generation(&mut self, slot: usize, generation: u64)

Write the generation for a key pointer at the given slot.

Source

pub fn set_key_ptr( &mut self, slot: usize, key: &DiskKey, blockptr: u64, generation: u64, )

Write a complete key pointer at the given slot.

Source

pub fn leaf_free_space(&self) -> u32

Compute the free space in a leaf block.

Free space is the gap between the end of the item descriptor array and the start of the first item’s data (which grows backward from the end of the block).

Source

pub fn leaf_data_end(&self) -> u32

Return the absolute byte offset of the first (lowest-offset) data byte in the leaf. This is HEADER_SIZE + item[nritems-1].offset (since the last item has the lowest offset, as data grows backward).

For an empty leaf, returns nodesize.

Source

pub fn update_checksum(&mut self, csum_type: ChecksumType)

Recompute the checksum using csum_type and write it into the header.

Source

pub fn copy_within(&mut self, src: Range<usize>, dest: usize)

Copy a range of bytes within this buffer.

Equivalent to memmove: handles overlapping regions correctly.

Source

pub fn zero_range(&mut self, offset: usize, len: usize)

Fill a range with zeros.

Source

pub fn is_leaf(&self) -> bool

Return true if this is a leaf (level == 0).

Source

pub fn is_node(&self) -> bool

Return true if this is an internal node (level > 0).

Source

pub fn max_key_ptrs(&self) -> u32

Maximum number of key pointers that can fit in this node.

Source

pub fn check_leaf(&self) -> Result<(), String>

Validate leaf structural invariants.

Checks that are cheap (O(nritems), no I/O) but verify the fundamental on-disk layout rules:

  • level == 0
  • bytenr == logical
  • Keys are in ascending order
  • Data offsets are in descending order (item 0 highest)
  • Item data regions do not overlap each other
  • Item data regions fit within the block
  • No overlap between item descriptors and item data

Returns Ok(()) if valid, or Err(description) on the first violation found.

Source

pub fn check_node(&self) -> Result<(), String>

Validate internal node structural invariants.

Checks:

  • level > 0
  • bytenr == logical
  • nritems <= max_key_ptrs
  • Key pointers are in ascending order
  • All blockptr values are nonzero

Returns Ok(()) if valid, or Err(description) on the first violation found.

Source

pub fn check(&self) -> Result<(), String>

Validate this block as either a leaf or a node based on its level.

Returns Ok(()) if valid, or Err(description) on violation.

Trait Implementations§

Source§

impl Clone for ExtentBuffer

Source§

fn clone(&self) -> ExtentBuffer

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 ExtentBuffer

Source§

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

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.