Expand description
§btrfs-uapi: typed Rust wrappers around the btrfs kernel interface
This crate provides typed, safe access to the btrfs kernel interface. Kernel communication uses two mechanisms:
- ioctls for most operations (balance, scrub, subvolume management, …)
- sysfs under
/sys/fs/btrfs/<uuid>/for status that the kernel does not expose via ioctl (quota state, commit statistics, scrub speed limits)
§Safety
All unsafe code is confined to the raw module, which contains
bindgen-generated types from the kernel UAPI headers (btrfs.h and
btrfs_tree.h) and nix ioctl macro declarations for every BTRFS_IOC_*
call.
Every other module wraps raw into a public API that is entirely safe,
exposes no kernel types, and uses idiomatic Rust types throughout:
BorrowedFd, Uuid, bitflags, SystemTime, CString, and so on.
§Usage
Every function that issues an ioctl takes a BorrowedFd
open on any file within the target btrfs filesystem. Functions in sysfs
instead take a uuid::Uuid, which can be obtained from
filesystem::filesystem_info.
Most ioctl-based operations require CAP_SYS_ADMIN.
§Portability
btrfs is Linux-only; this crate does not support other operating systems.
Some ioctls used here were introduced in relatively recent kernel versions;
this crate targets modern kernels (5.x and later) and does not attempt to
detect or work around missing ioctls on older kernels. It is only tested
on amd64, but all architectures supported by the kernel (and Rust) should
work.
Modules§
- balance
- Balance operations: redistributing data and metadata across devices
- blkdev
- Block device ioctls: BLKGETSIZE64, BLKDISCARD
- chunk
- Per-device physical allocation data from the chunk tree
- defrag
- File defragmentation: rewriting fragmented extents into contiguous runs
- device
- Device management: adding, removing, querying, and extent layout
- fiemap
- Physical extent layout of files via
FS_IOC_FIEMAP - filesystem
- Filesystem-level operations: metadata, sync, label, and resize
- inode
- Inode and path resolution: mapping between inodes, logical addresses, and paths
- quota
- Quota and qgroup management: enabling quotas and tracking disk usage
- raw
- Raw bindgen output and ioctl declarations for the btrfs UAPI
- replace
- Device replacement: replacing a device with another while the filesystem is online
- scrub
- Data integrity scrubbing: verifying and repairing filesystem checksums
- send_
receive - Send and receive: generating and applying btrfs send streams
- space
- Block group space usage: how much space each chunk type allocates and uses
- subvolume
- Subvolume and snapshot management: creating, deleting, and querying subvolumes
- sysfs
- Sysfs interface: reading filesystem and device state from
/sys/fs/btrfs/ - tree_
search - Generic B-tree search: walking any internal btrfs tree via
BTRFS_IOC_TREE_SEARCH
Macros§
- field_
size - Return the size in bytes of a single field within a struct.