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
impl ExtentBuffer
Sourcepub fn from_raw(data: Vec<u8>, logical: u64) -> Self
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.
Sourcepub fn new_zeroed(nodesize: u32, logical: u64) -> Self
pub fn new_zeroed(nodesize: u32, logical: u64) -> Self
Create a zeroed ExtentBuffer of nodesize bytes at the given logical address.
Sourcepub fn set_logical(&mut self, logical: u64)
pub fn set_logical(&mut self, logical: u64)
Set the logical byte address of this block.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Return a mutable reference to the raw byte buffer.
Sourcepub fn as_tree_block(&self) -> TreeBlock
pub fn as_tree_block(&self) -> TreeBlock
Parse this buffer into a TreeBlock for read-only inspection.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Read the generation field from the header.
Sourcepub fn chunk_tree_uuid(&self) -> Uuid
pub fn chunk_tree_uuid(&self) -> Uuid
Sourcepub fn set_generation(&mut self, generation: u64)
pub fn set_generation(&mut self, generation: u64)
Write the generation field.
Sourcepub fn set_nritems(&mut self, nritems: u32)
pub fn set_nritems(&mut self, nritems: u32)
Write the nritems field.
Sourcepub fn set_bytenr(&mut self, bytenr: u64)
pub fn set_bytenr(&mut self, bytenr: u64)
Write the bytenr field.
Sourcepub fn set_chunk_tree_uuid(&mut self, uuid: &Uuid)
pub fn set_chunk_tree_uuid(&mut self, uuid: &Uuid)
Write the chunk_tree_uuid.
Sourcepub fn item_key(&self, slot: usize) -> DiskKey
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.
Sourcepub fn item_offset(&self, slot: usize) -> u32
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).
Sourcepub fn item_size(&self, slot: usize) -> u32
pub fn item_size(&self, slot: usize) -> u32
Read the data size field of the item at the given slot.
Sourcepub fn item_data_offset(&self, slot: usize) -> usize
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).
Sourcepub fn item_data_mut(&mut self, slot: usize) -> &mut [u8] ⓘ
pub fn item_data_mut(&mut self, slot: usize) -> &mut [u8] ⓘ
Return a mutable slice of the item’s data payload.
Sourcepub fn set_item_key(&mut self, slot: usize, key: &DiskKey)
pub fn set_item_key(&mut self, slot: usize, key: &DiskKey)
Write the key for an item at the given slot.
Sourcepub fn set_item_offset(&mut self, slot: usize, offset: u32)
pub fn set_item_offset(&mut self, slot: usize, offset: u32)
Write the data offset for an item at the given slot.
Sourcepub fn set_item_size(&mut self, slot: usize, size: u32)
pub fn set_item_size(&mut self, slot: usize, size: u32)
Write the data size for an item at the given slot.
Sourcepub fn key_ptr_key(&self, slot: usize) -> DiskKey
pub fn key_ptr_key(&self, slot: usize) -> DiskKey
Read the key of the key pointer at the given slot in a node.
Sourcepub fn key_ptr_blockptr(&self, slot: usize) -> u64
pub fn key_ptr_blockptr(&self, slot: usize) -> u64
Read the blockptr of the key pointer at the given slot.
Sourcepub fn key_ptr_generation(&self, slot: usize) -> u64
pub fn key_ptr_generation(&self, slot: usize) -> u64
Read the generation of the key pointer at the given slot.
Sourcepub fn set_key_ptr_key(&mut self, slot: usize, key: &DiskKey)
pub fn set_key_ptr_key(&mut self, slot: usize, key: &DiskKey)
Write the key for a key pointer at the given slot.
Sourcepub fn set_key_ptr_blockptr(&mut self, slot: usize, blockptr: u64)
pub fn set_key_ptr_blockptr(&mut self, slot: usize, blockptr: u64)
Write the blockptr for a key pointer at the given slot.
Sourcepub fn set_key_ptr_generation(&mut self, slot: usize, generation: u64)
pub fn set_key_ptr_generation(&mut self, slot: usize, generation: u64)
Write the generation for a key pointer at the given slot.
Sourcepub fn set_key_ptr(
&mut self,
slot: usize,
key: &DiskKey,
blockptr: u64,
generation: u64,
)
pub fn set_key_ptr( &mut self, slot: usize, key: &DiskKey, blockptr: u64, generation: u64, )
Write a complete key pointer at the given slot.
Sourcepub fn leaf_free_space(&self) -> u32
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).
Sourcepub fn leaf_data_end(&self) -> u32
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.
Sourcepub fn update_checksum(&mut self, csum_type: ChecksumType)
pub fn update_checksum(&mut self, csum_type: ChecksumType)
Recompute the checksum using csum_type and write it into the header.
Sourcepub fn copy_within(&mut self, src: Range<usize>, dest: usize)
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.
Sourcepub fn zero_range(&mut self, offset: usize, len: usize)
pub fn zero_range(&mut self, offset: usize, len: usize)
Fill a range with zeros.
Sourcepub fn max_key_ptrs(&self) -> u32
pub fn max_key_ptrs(&self) -> u32
Maximum number of key pointers that can fit in this node.
Sourcepub fn check_leaf(&self) -> Result<(), String>
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 == 0bytenr == 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.
Sourcepub fn check_node(&self) -> Result<(), String>
pub fn check_node(&self) -> Result<(), String>
Validate internal node structural invariants.
Checks:
level > 0bytenr == logicalnritems <= max_key_ptrs- Key pointers are in ascending order
- All
blockptrvalues are nonzero
Returns Ok(()) if valid, or Err(description) on the first
violation found.
Trait Implementations§
Source§impl Clone for ExtentBuffer
impl Clone for ExtentBuffer
Source§fn clone(&self) -> ExtentBuffer
fn clone(&self) -> ExtentBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more