How can I copy a file using copy on write using C++ over a file in a BTRFS filesystem from C++ code on a Linux system that is assumed to support it? Is the solution generic to all Unix systems?
CoW is not included at all in any part of the C++ standard for filesystems. It is not present either in the documentation of Linux, and is not POSIX standard either.
In fact, even if the GNU cp utility can handle copy on write, it may not always be performed since it require an argument, namely --reflink=true
to force its usage
As such, using CoW will very likely need to use low level primitives for which apparently no documentation for Linux or more broadly POSIX have been prepared.