Skip to main content

sys_chunk_array_append

Function sys_chunk_array_append 

Source
pub fn sys_chunk_array_append(
    array: &mut [u8],
    size: &mut u32,
    bg_start: u64,
    chunk_bytes: &[u8],
) -> Result<u32, &'static str>
Expand description

Append a single (disk_key, btrfs_chunk) record to the superblock’s sys_chunk_array byte buffer.

Writes the 17-byte btrfs_disk_key followed by chunk_bytes (already serialized via chunk_item_bytes) starting at offset *size. On success, *size is bumped by the record size and Ok(new_size) is returned. Returns Err if the record would overflow the 2048-byte sys_chunk_array.

bg_start is the chunk’s logical start address; it becomes the offset field of the BTRFS_FIRST_CHUNK_TREE_OBJECTID / CHUNK_ITEM disk key.

§Errors

Returns an error if the record does not fit in the remaining sys_chunk_array space.

§Panics

Panics in debug builds if the new array size cannot be represented in a u32. In practice this never happens because callers cap the buffer at 2048 bytes.