Perform reflink operation on compatible filesystems (btrfs or xfs).
There are a number of type of links existing on Linux:
Reflinks are a new kind of links found in btrfs and xfs which act similar to hard links, except modifying one of the two files will not change the other, and typically only the changed data will take space on the disk (copy-on-write).
A machine needs to have a compatible OS and filesystem to perform reflinks. Known to work are:
Other OSes have similar features, to be implemented in the future.
DUPLICATE_EXTENTS_TO_FILE
reflink
clonefile
err := reflink.Always("original_file.bin", "snapshot-001.bin")
// or
err := reflink.Auto("source_img.png", "modified_img.png")
reflink.Always
will fail if reflink is not supported or didn't work for any reason, while reflink.Auto
will fallback to a regular file copy.
os.Link
or os.Rename
rather than io.Copy
as we are dealing with filenames.