Apple File System (APFS) Check if file is a clone on Terminal (shell)

3.2k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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. >:)

1
On

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