Function reflink_copy::reflink
source · pub fn reflink(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()>Expand description
Copies a file using COW semantics.
For compatibility reasons with macos, the target file will be created using OpenOptions::create_new.
If you want to overwrite existing files, make sure you manually delete the target file first
if it exists.
match reflink_copy::reflink("src.txt", "dest.txt") {
Ok(()) => println!("file has been reflinked"),
Err(e) => println!("error while reflinking: {:?}", e)
}Implementation details per platform
Linux / Android
Uses ioctl_ficlone. Supported file systems include btrfs and XFS (and maybe more in the future).
NOTE that it generates a temporary file and is not atomic.
OS X / ios
Uses clonefile library function. This is supported on OS X Version >=10.12 and iOS version >= 10.0
This will work on APFS partitions (which means most desktop systems are capable).
Windows
Uses ioctl FSCTL_DUPLICATE_EXTENTS_TO_FILE.
Only supports ReFS on Windows Server. Important note: The windows implementation is currently untested and probably buggy. Contributions/testers with access to a Windows Server welcome.
NOTE that it generates a temporary file and is not atomic.