Currently std::fs::copy is using std::io::copy to copy files - it reads the file content into the memory, and then write it to the output file. std::fs::copy or (edit: it tries copy_file_range(2) first and has already benefited from the file cloning feature) std::io::copy can benefit from the file cloning feature in Btrfs and XFS by using FICLONE (and fallbacking to read-write loop if the filesystem does not support it).
I think is easy to use FICLONE in std::fs::copy, but it's less general (it requires file paths). std::io::copy is more general, but some additional methods may be needed to be added to std::io::Read and std::io::Write in order to use FICLONE.
libuv's support for FICLONE: libuv/libuv#1491
The ioctl_ficlonerange(2) man page: https://www.man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html
Currently
std::fs::copyisusing(edit: it triesstd::io::copyto copy files - it reads the file content into the memory, and then write it to the output file.std::fs::copyorcopy_file_range(2)first and has already benefited from the file cloning feature)std::io::copycan benefit from the file cloning feature in Btrfs and XFS by usingFICLONE(and fallbacking to read-write loop if the filesystem does not support it).I think is easy to use
FICLONEinstd::fs::copy, but it's less general (it requires file paths).std::io::copyis more general, but some additional methods may be needed to be added tostd::io::Readandstd::io::Writein order to useFICLONE.libuv's support for
FICLONE: libuv/libuv#1491The
ioctl_ficlonerange(2)man page: https://www.man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html