34

With macOS High Sierra a new file system is available: APFS.

This file system supports clone operations for files: No data duplication on storage.

cp command has a flag (-c) that enables cloning in Terminal (shell).

But I didn't find a way to identify theses cloned files after.

Somebody knows how to identify cloned files with a shell command, or a flag in a existent command, like ls?

Dyorgio
  • 1,114
  • 13
  • 23
  • This is something I'm looking for, too. I thought there'd be some indication in the file info box but there is none. Not even via the `mdls` command. If you find an answer, don't forget to update your post. – user41997 Sep 26 '17 at 19:59
  • have you tried `stat -x file` ? – nbari Oct 03 '17 at 18:04
  • Yes @nbari, output is the same as a regular file, just inode value change... I tried to looking for read inode raw information, and extract clone flag, bug no luck yet. – Dyorgio Oct 04 '17 at 16:15
  • @Dyorgio, can you try `xattr -l file`? I don't have APFS system to test as of yet – Tarun Lalwani Oct 05 '17 at 13:31
  • @TarunLalwani, no diff on output: diff <(xattr -l data-clone.iso) <(xattr -l data-copy.iso) results on no diff. Running in only one I could see com.apple.metadata:kMDItemDownloadedDate com.apple.metadata:kMDItemWhereFroms and com.apple.quarantine values – Dyorgio Oct 05 '17 at 13:51
  • 1
    Can you try `mdls ` ? – Tarun Lalwani Oct 05 '17 at 14:49
  • Note: this is not even remotely a programming question and should therefor not be here, but instead asked on [Superuser](https://superuser.com/). – Mike Lischke Nov 27 '17 at 09:39
  • 4
    The closest I came was to [APFS reference](https://developer.apple.com/support/downloads/Apple-File-System-Reference.pdf) which lists `j_inode_flags` which has the property `INODE_WAS_CLONED`. Unfortunately I can't find a high-level (e.g. ObjC) function to query this info. – Tim Jan 03 '20 at 10:01

2 Answers2

7

After 3 years and 2 months... I received a lot of points because of this question here on stackoverflow.

So yesterday I decided to revisit this topic :).

Using fcntl and F_LOG2PHYS is possible to check if files are using same physical blocks or not.

So I made an utility using this idea and put it on github (https://github.com/dyorgio/apfs-clone-checker).

It is only the first release guys, but I hope that the community can improve it.

Now maybe a good tool to remove duplicated files using clone APFS feature can be born. >:)

Dyorgio
  • 1,114
  • 13
  • 23
-2

The command you have used, is not a feature of APFS-Filesystem. The CP -c command calls a function named "clonefile" which is part of bsd since 2015 (s. Man-Page)

http://www.manpagez.com/man/2/clonefile/

So if you clone a file for example, you can change attributes from Original and the Clone can have diffrent Attributs.

I think, the Feature, you are searching for is build in per Copy and Write. You can see the different, if you make a clone with Time Machine.

A have not found a commando per Terminal today, to show this differences, but the clonefile command therefore is not the right function.

The only Known-Way today to Show changed Attributes in Clones is Apple Time Machine Backup Solution.

It`s a Snapshot Solution. Something about this, in this Apple Dev Support-Case:

https://forums.developer.apple.com/thread/81171

Spindizzy
  • 7,244
  • 1
  • 19
  • 33
  • Thank you for reply, it included some technical information on this topic, however I asked the question precisely because use of clonefile function, there is no another problem to solve here, the only acceptable solution is a Mac OS X terminal command. – Dyorgio Oct 22 '17 at 20:07