On linux, we have the call

int ioctl(int, FICLONERANGE, struct file_clone_range *);

to "reflink" files. APFS also supports COW and thus a similar system call should exist. However, the clonefile API can only clone whole files, not blocks within the file.

Is there something similar to the ioctl call?

1 Answer 1


No, macOS does not currently have an API that allows you to clone only a range. You can use clonefile()/clonefileat()/fclonefileat() to clone a full file. After you have cloned the file, you can make changes to the clones ofcourse.

  • So basically, if files A and B share a block C, then I can deduplicate by creating a file with content C, clone C twice, and add the additional contents of A and B to each of the clones, and finally removing C?
    – Ma Joad
    Jan 26 at 18:05
  • Well, that would be a bit of a roundabout way of doing it, but I suppose so, yes. In simpler terms, if A and B share a block C - then make a copy of A, modify it to be like B and delete B.
    – jksoegaard
    Jan 27 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .