Last Week on My Mac: Attack of the Clones

As the seventh birthday of APFS draws closer, this is an appropriate time to reflect on its impact on macOS, what we see, and how we work. Although Time Machine now relies on snapshots, both those made hourly to the volumes it’s backing up, and for its backups, until you need to use them it’s easy to forget the changes brought in those backups. As for clone files, we’re almost unaware of them, and of how they have changed macOS.

As we can’t readily see which files have been cloned, it’s natural to assume that most of the files we work with haven’t been cloned, unless you have duplicated them yourself in the Finder. Here’s a little experiment to try using my free app Precize, to demonstrate how common clone files have become. Precize is one of the few ways that you can see whether a file has, at some stage, been cloned. If you know of another way of doing so, by all means use that instead.

Open TextEdit and create a new document. Type or paste in a few words or a paragraph, save that document and close it. Then open it using Precize (or your substitute).

clone1

Make a note of that file’s inode number, the last number given in its volfs path at the top. Here it’s 1262686, and the Clone checkbox isn’t ticked.

Now, open that file again in TextEdit, add some more text to it, save it, and close it. As TextEdit is one of the many apps that uses the macOS version system, that should save another version of that file into the hidden database at the root of the volume on which your document is stored. Inspect your document a second time using Precize.

clone2

There have now been several changes, those you’d expect such as its sizes increasing, but check its inode number, and you’ll see that has changed, here to 1262713. The Clone checkbox is now ticked, indicating that file has been cloned, although you didn’t duplicate or even copy it yourself.

Now check some other files written by apps that save versions, like Preview, Pages, Numbers, source code edited in Xcode, or the King of text editors BBEdit. Files saved just once won’t be clones, but those saved again will be. Some other apps, like GraphicConverter, don’t make clones, but save each document afresh as a new file, without any cloning taking place.

Why that file’s inode number changes and it becomes a clone isn’t, perhaps, obvious. Some apps that save documents, including BBEdit, don’t change the inode number of a file in the same way, but it’s most probable that TextEdit is performing a Safe Save, where the changed file is written out to a new file, and that’s then used to replace the original. While cloning could be a part of that, it also appears to be related to the macOS version system. Unfortunately, Apple’s programming guide for this hasn’t been updated since 2012, so there’s no clear account of how this works in recent macOS with APFS and clone files.

When it was first introduced in OS X 10.7 Lion, in 2011, the hidden database of saved file versions on each volume stored data for each version in chunks, in its .cs ChunkStorage folder. Of course, HFS+ doesn’t support clone files, so that was probably the most efficient storage available at the time. When the version system was later updated to make best use of APFS volumes, Apple seems to have adopted cloning as a means of creating saved versions.

This might work by cloning the document file when a new version is to be made, for example when the user saves that document, or an app auto-saves it. One of the two cloned files is then added to the version database, and stored somewhere buried deep inside the hidden .DocumentRevisions-V100 folder at the top level of the same volume.

Unless you’re one of the few users who has blocked the macOS version system by creating your own .DocumentRevisions-V100 item at the root level of each of the volumes containing documents, those version clones are there for the asking. At least they are until a document is in iCloud Drive and is evicted from local storage, when its stored versions will be removed, if your Mac is running Sonoma 14.4.

The macOS version system may be old, coming up to 13 later this year, but it has moved with the times, although it’s currently in urgent need of repair. As for clone files, they’re all around us, just not easy to see.