Skip to main content

Crate btrfs_stream

Crate btrfs_stream 

Source
Expand description

§btrfs-stream: btrfs send stream parser and receive operations

This crate handles the btrfs send stream format: a binary TLV protocol used by btrfs send / btrfs receive to serialize and replay filesystem changes between subvolume snapshots.

§Stream parsing (default, platform-independent)

The default feature set provides a zero-copy stream parser that works on any platform:

  • StreamReader reads a btrfs send stream from any impl Read, validates the stream header (magic, protocol version 1-3), and yields StreamCommand values with CRC32C integrity checks on every command.
  • StreamCommand is an enum covering all v1, v2, and v3 command types (subvol, snapshot, write, clone, encoded write, fallocate, enable verity, and so on).
  • Timespec represents timestamps carried in the stream.

§Receive operations (feature receive, Linux-only)

Enable the receive feature to get ReceiveContext, which applies a parsed stream to a mounted btrfs filesystem. It creates subvolumes and snapshots, writes files, clones extents, sets xattrs and permissions, and finalizes received subvolumes with their received UUID. It handles v2 encoded writes with automatic decompression fallback (zlib, zstd, lzo) and v3 fs-verity enablement.

This feature depends on btrfs-uapi for ioctl access and requires CAP_SYS_ADMIN on Linux.

Structs§

ReceiveContext
Applies a parsed btrfs send stream to a mounted btrfs filesystem.
StreamReader
Reads and parses a btrfs send stream.
StreamWriter
TLV-framed encoder for the btrfs send stream. Construct with StreamWriter::new (writes the stream header), then call StreamWriter::write_command for each command. Drop or call StreamWriter::finish to release the inner writer.
Timespec
A timestamp from the send stream (sec + nsec).

Enums§

StreamCommand
A parsed command from the send stream.
StreamError
Errors that can occur while parsing a btrfs send stream.