Reputation: 13067
With exactly i mean preserving holes in sparse files and all extended attributes catching situations where the target file system does not support them or not fully (for example different EA lengths)? And on mounted NTFS filesystems it should work with alternate streams too. Preserving as much file attributes as possible.
Need callbacks for progress GUI too. This seems to be difficult an maintenance hell, so i guess there is something already useable like the SHFileOperation on Windows.
I looked at GLIB and they are doing it in the most simple way with open/read/write/close sequence.
Upvotes: 1
Views: 878
Reputation: 479
sendfile doesn't handle sparse files at all, at least on Linux 4.4 and earlier. Starting from Linux 4.5 there is a new system call copy_file_range which hides all the details for you.
For earlier versions, here is my working example of copying file contents with holes, by lseek and SEEK_HOLE. It's different from the implementation in cp, which instead reads everything from source and skip all-zero blocks, thus being to create holes in destination but still wastes time reading holes from the source. However, it's very possible that some file systems don't support SEEK_HOLE even through they already support sparse file, in that case my code would end up creating non-sparse files.
As for extended attributes, you really have to call listxattr and then copy each extended attributes by getxattr/setxattr by yourself.
Nano timestamp can be set by utimensat/futimens*
Upvotes: 1