Expand description
Sparse-aware fast copy with reflink fallback.
Two-tier strategy that preserves sparseness on every supported platform:
-
Reflink (zero-copy COW). Tries
clonefile(2)on macOS andioctl(FICLONE)on Linux viareflink-copy. Succeeds instantly on APFS, btrfs, XFS (withreflink=1), and bcachefs. ReturnsEOPNOTSUPP(or similar) on ext4 and other non-COW filesystems. -
Sparse-aware copy. POSIX
SEEK_DATA/SEEK_HOLEwalk of the source’s allocation map, withcopy_file_range(2)on Linux for in-kernel zero-copy of data extents. The destination isftruncated to the source size up front so unallocated regions stay holes.
Never falls back to a naive byte-for-byte copy — that would densify a 4 GiB sparse file with a few MB of data into 4 GiB on disk, which is the exact failure mode this module exists to prevent.
See planning/microsandbox/implementation/snapshots.md for the
full design and tradeoffs.
Functions§
- fast_
copy - Copy
srctodst, preserving sparseness. Returns the apparent size of the destination in bytes. - sparse_
copy - Sparse-aware copy via
SEEK_DATA/SEEK_HOLEand per-extent copy.