btrfs-fuse
A userspace FUSE driver for btrfs.
This crate is experimental and should not be used for anything you care about. It should be functional, and being read-only it should not corrupt your data.
btrfs-fuse lets you mount a btrfs image file or block device read-only
without kernel btrfs support. All filesystem semantics live in
btrfs-fs; this crate is the thin fuser::Filesystem adapter on top
(inode translation, Stat → FileAttr mapping, mount glue).
If you want to embed a btrfs reader in your own code without going
through FUSE, depend on btrfs-fs directly.
Part of the btrfsutils project.
What's implemented
- Mount a single btrfs image or block device read-only
- Multi-subvolume traversal (auto-follow on subvolume crossings,
..walksROOT_BACKREFfor subvol roots) --subvol PATH/--subvolid IDto mount a specific subvolume as the FUSE rootinit(negotiatesFUSE_DO_READDIRPLUS,FUSE_AUTO_INVAL_DATA, splice flags),forget(eager cache eviction),lookup,getattr,readdir,readdirplus,read,readlink,listxattr,getxattr,statfs,lseek(SEEK_HOLE/SEEK_DATA), andioctl- Inline extents, regular extents, preallocated extents (read as zeros), sparse holes
- zlib, zstd, and lzo decompression (btrfs per-sector LZO framing)
- Symlinks, hardlinks, xattrs, regular files, directories
- 8 btrfs ioctls:
FS_INFO,GET_FEATURES,GET_SUBVOL_INFO,DEV_INFO,INO_LOOKUP,TREE_SEARCH(v1, fixed 4 KiB),GET_SUBVOL_ROOTREF, andTREE_SEARCH_V2(returnsENOPROTOOPTsobtrfs-uapi::tree_search_autofalls back to v1 transparently) - Tunable cache sizes via
--cache-tree-blocks N,--cache-inodes N,--cache-extent-maps N - Kernel
default_permissionsmount option enabled by default (matches kernel btrfs semantics); opt out with--no-default-permissionsfor image-inspection scenarios
What's not yet implemented
- Any write operation
- Variable-size ioctls that need
FUSE_IOCTL_RETRY(INO_PATHS,LOGICAL_INO_V2,SPACE_INFO,ENCODED_READ) — blocked at the kernel boundary: Linux'sfuse_do_ioctlonly honours retry replies for ioctls issued withFUSE_IOCTL_UNRESTRICTED, which standardioctl(2)callers never set BTRFS_IOC_SEND(kernel ioctl path); usebtrfs send --offline IMAGEfrombtrfs-clito generate send streams from images- RAID1/10/5/6 redundancy handling on degraded devices
--foreground=falsedaemonize path (-fforeground works)statfsinode counts (reported as 0)
Usage
As a binary
# Install from source
# Mount an image or block device
# With debug logging
RUST_LOG=btrfs_fuse=debug
# Mount a specific subvolume as the FUSE root
# Tune caches for a memory-constrained host
# Allow reading files whose stored UIDs don't match the local mounter
The mount is always read-only. Pass --allow-other to let other users
on the system see the mount.
As a btrfs subcommand
When btrfs-cli is built with the opt-in fuse feature, the same
mount is available as btrfs fuse:
Same flags, same behaviour. The standalone binary stays for
mount.fuse.btrfs / /etc/fstab integrations that expect a
dedicated executable.
As a library
BtrfsFuse is a fuser::Filesystem impl ready to hand to
fuser::mount2. It carries no inherent operation methods — those live
on btrfs_fs::Filesystem, which is what you should
depend on for embedding.
Testing
Read-path integration tests live in the btrfs-fs crate (the FUSE
adapter has no filesystem logic to test on its own). Run them with:
Requires mkfs.btrfs (from btrfs-progs) on $PATH.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.