4

cp --reflink=auto shows following output for MacOS:

cp: illegal option -- -

Is copy-on-write or deduplication supported for HFS? How can I COW huge files with HFS?

4 Answers 4

5

Apple's new APFS filesystem supports copy-on-write; CoW is automatically enabled in Finder copy operations where available, and when using cp -c on the command line.

Unfortunately, cp -c is equivalent to cp --reflink=always (not auto), and will fail when copy-on-write is not possible with

cp: somefile: clonefile failed: Operation not supported

I'm not aware of a way to get auto behavior. You could make a shell script or function with automatic fallback a la

cpclone() { cp -c "$@" || cp "$@"; }

but it'll be difficult to make it entirely reliable for all edge cases.

2
  • Seems to work for me. How do you check the copy is actually a reflink? Sep 3, 2019 at 0:43
  • 1
    @JorgeOrpinel The easiest, cross-platform way is to time it: just copy a 512M file. Reflink happens at the extent level, so there should be no expectation for knowing it from, say, reading the inode. I am not aware of any command-line interface to the physical extent on APFS. Nov 23, 2019 at 7:09
4

Updated November 2021: This answer has been rendered obsolete by oncoming coreutils changes. reflink=auto has been the default since 25725f9 (coreutils 9.0). APFS cloning is committed in the tree as 5e36c0c and should appear in coreutils 9.1.


Original posting November 2019: I wrote a patch (mailing list) for GNU coreutils that enables --reflink for macOS > 10.12. Yes, --reflink=auto will work, at least according to my time measurements.

Here are two ways to use it:

  • clone the git repository, run ./bootstrap, and then the usual ./configure -C and make -j12 install.
  • Apply the patch (rebased for 8.31) to another version of coreutils to skip the painful bootstrapping.

You can grab a bunch of possible parameters to use from the homebrew formula. Since the change is only useful for cp and mv only, you can opt to only replace these two binaries. (mv with reflink is useful for submodules.)


There is an associated patch that enables reflink=auto by default for cp and install too. If you keep forgetting about adding the option or want faster ginstall in your Makefiles, try it.

1

Unfortunately the --reflink=auto option wasn't available in MacOS just yet. HFS also does not natively support CoW (Copy on Write).

Perhaps in future such support will be added - likely when ZFS becomes natively available or another native filesystem adds support.

I suggest referring to the man page to get the options that are currently available to you: man cp


NOTE:

In MacOS, most commands (including cp) only support short options, not long options. Thus, if there were an equivalent, it would be a single character only. Example would be -L or --dereference available in GNU coreutils' version of cp. In MacOS, only -L is available.

0
1

uutils is a GNU coreutils clone written in Rust and supports reflink copies on macOS' APFS via the same syntax as GNU coreutils does on Linux.

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.