My filesystem (FS) (ZFS specifically) supports copy-on-write (COW), i.e. a copy (if done right) is a very cheap constant operation, and does not actually copy the underlying content. The content is copied only once I write/modify the new file.
Actually, I just found out, ZFS-on-Linux actually has not implemented that for userspace yet (right?). But e.g. BTRFS or XFS has. (See here, here, here, here.)
For the (GNU) cp
utility, you would pass --reflink=always
option
(see here.)
cp
calls ioctl (dest_fd, FICLONE, src_fd)
(see here, here).
How would I get this behavior (if possible) in Python?
I assume that "zero-copy" (e.g. here via os.sendfile
) would not result in such behavior, right? Because looking at shutil
s _fastcopy_sendfile
implementation (here), it is still a loop around os.sendfile
using some custom byte count (supposed to be the block size, max(os.fstat(infd).st_size, 2 ** 23)
). Or would it?
The COW, is this on a file level, or block level?
If possible, I want this to be generic and cross-platform as well, although my question here is somewhat Linux focused.
A related question specifically about Mac seems to be this.
The MacOSX cp
has the -c
option to clone a file.