When I copy a file using reflink option, e.g.,

cp --reflink foo bar

how and what stage in execution of cp determines if the underneath file system supports COW. I tried looking into coreutils/src/cp.c but couldn't find the specific system call/ ioctl or any other method which determines COW capability and accordingly proceeds for cp execution / reports error:

cp: failed to clone 'bar' from 'foo': Bad address

In short, I am looking for how resolution of --reflink=auto option happens.


The code calls a function called clone_file if the reflink option is set to “always” or “auto”, and falls back to copying if reflink is “always” (and goes directly to copying if reflink is off). clone_file calls the BTRFS_IOC_CLONE ioctl. So there's no testing whether the system supports copy-on-write, it just attempts the BTRFS method.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.