You can see what system calls are done by cp --reflink=always notes.txt notes.txt.backup
with strace
.
So if you run strace cp --reflink=always notes.txt notes.txt.backup
you can find this in the output:
openat(AT_FDCWD, "notes.txt", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=760, ...}) = 0
openat(AT_FDCWD, "notes.txt.backup", O_WRONLY|O_TRUNC) = 4
fstat(4, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
ioctl(4, BTRFS_IOC_CLONE or FICLONE, 3) = 0
That ioctl
call is the CoW magic that creates an explicit CoW copy of a file.
You can read man ioctl_ficlone