Skip to main content

Module tree_search

Module tree_search 

Source
Expand description

The kernel’s tree search ioctl lets userspace read any internal btrfs tree (chunk, root, quota, …) by specifying a key range. Items are returned in batches; tree_search advances the cursor automatically and calls a closure once per item until the range is exhausted.

§Byte order

SearchHeader fields (objectid, offset, type) are in host byte order: the kernel fills them in through the ioctl layer. The data slice passed to the callback contains the raw on-disk item payload, which is little-endian; callers must use u64::from_le_bytes and friends when interpreting it.

§Ioctl version

This module provides two variants:

  • tree_search uses BTRFS_IOC_TREE_SEARCH (v1) with its fixed 3992-byte result buffer. Sufficient for all item types used by this crate.
  • tree_search_v2 uses BTRFS_IOC_TREE_SEARCH_V2 with a caller-chosen buffer size. Useful when items may be larger than what v1 can return in a single batch.

Structs§

SearchHeader
Metadata returned for each item found by tree_search.
SearchKey
Parameters specifying which items to return from a tree search.

Functions§

tree_search
Walk every item in the tree that falls within key, calling f once for each one.
tree_search_v2
Like tree_search but uses BTRFS_IOC_TREE_SEARCH_V2 with a larger result buffer.