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

2

37

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?

Cristacristabel answered 26/9, 2017 at 4:16 Comment(8)
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.Tiaratibbetts
have you tried stat -x file ?Ligulate
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.Cristacristabel
@Dyorgio, can you try xattr -l file? I don't have APFS system to test as of yetNapalm
@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 valuesCristacristabel
Can you try mdls <filename> ?Napalm
Note: this is not even remotely a programming question and should therefor not be here, but instead asked on Superuser.Huberman
The closest I came was to APFS reference 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.Ecru
C
12

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

Cristacristabel answered 10/12, 2020 at 19:29 Comment(0)
C
-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

Consuelaconsuelo answered 20/10, 2017 at 8:26 Comment(1)
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.Cristacristabel

© 2022 - 2024 — McMap. All rights reserved.