APFS (Apple File System) details

Thanks to a colleague, I became aware of APFS' capability of duplicating files as snapshots (i.e. without the snapshot "copy" occupying any space until one of the two "copies" being changed). This is a great capability.


Can anyone point me to a technical document about APFS, explaining more of the technical details ?


I do have some questions though:


1) Duplicating files: I am using the Finder's Command-D shortcut as well as the "Duplicate" right click. But it looks like a Command-C/Command-V combination has the same effect. Also dragging a file with Option. All seem to create file snapshots. Is this correct ?


Corollary question: is there a way to force a real full copy ?


2) Identifying snapshots: Is there a way to see which of the "copies" are snapshots and which one is the "original" copy ? The Finder Get Info command does not show any difference.


Corollary: Get Info on a directory containing a file and its N snapshots shows the total occupied size as N+1 times the original file. That makes it difficult to see actual disk space use ...


3) Operating system interface: I observe that

cp file1 file2 

creates a full copy. But I also saw that when using the -c option, I get a "clone":

cp -c file1 file2 

Is this using the APFS snapshot mechanism too ?


4) Updating files: What happens when I update any of the snapshots (or the original file). Say I only update one block of one of the file. Is this generating a full copy of the file ? Or just the modified blocks ?





MacBook Pro 13", macOS 10.13

Posted on Jan 15, 2020 3:14 AM

Reply

Similar questions

5 replies

Jan 18, 2020 2:43 AM in response to etresoft

I guess I mis-used the term “snapshot”. I’m not sure what the proper term is to designate the sort of shallow copies APFS does when I duplicate or copy a file or a directory.


Meanwhile I found a number of technical sources that all confirm my understanding:

  • command-c/command-v as well as option-copy or the command line `cp -c` all create clones.
  • the shallow copies are block-level. This makes it ideal for taking snapshots of container data structures like VMs or virtual drives
  • the one question I found no answer for is the easy determination of disk space usage. Get Info as well as `du` report clones as if they occupied the full space. But then I don’t see how it would be possible to not do that (Unix hard links behave the same way)


All in all, the cloning facility is great. I started using it to take clones of my virtual box VMs instead of virtual box snapshots



Jan 18, 2020 12:40 PM in response to agodfrin

agodfrin wrote:

• the one question I found no answer for is the easy determination of disk space usage. Get Info as well as `du` report clones as if they occupied the full space. But then I don’t see how it would be possible to not do that (Unix hard links behave the same way)

In theory, it might be possible for a low-level tool to look at all of the blocks of a file and report that the file is "84% cloned", for example. But even that wouldn't tell you how many other clones exist.


However, the file system does keep track of the total number of blocks in use. Therefore, it knows how much space is used on a drive and how much is still free. But this is where it gets really tricky. In most places, the operating system will not tell you how much free storage you have. Instead, it will report how much "available" storage you have. This "available" space is your free storage space plus your "purgeable" storage space. This "purgeable" space is supposedly the space that could be made free if you really needed it. But it is the operating system that decides how badly you really need it. It is common for people to run out of free storage space and have various parts of the operating system complain that there is no storage space left. Then, when these people go looking, the operating system tells them they have 90 GB of storage "available". As you might expect, this leads to confusion.


If you use Disk Utility, it will report the true "free" space on the drive. But if you use the Finder, it may only report "available" space.


Often, it is those APFS snapshots that are what causes a large discrepancy between "available" and "free" space. A snapshot may hold on to cloned file system blocks that have been long since deleted. The blocks are not freed until the snapshot is deleted.

Jan 17, 2020 6:27 PM in response to agodfrin

Hello agodfrin,


I want to help you find the answers you need. Check out this page which offers more information about APFS: Disk Utility User Guide Feel free to let me know if you have any questions about the information on this page.


For full details on shortcuts offered on your Mac, look here: Mac keyboard shortcuts

For full details on screenshots, look here: How to take a screenshot on your Mac

For full details on local snapshots, look here: About Time Machine local snapshots


Please let me know if you have any questions about the information on these links.


Cheers!

Jan 17, 2020 7:07 PM in response to agodfrin

  1. No. Snapshots are a filesystem operation. Time Machine creates them and some 3rd party disk utilities can create them. What you are talking about is the copy-on-write feature. You can avoid copy-on-write if you really want to.
  2. Again, APFS snapshots are a very specific thing that is something else. You are just talking about low-level filesystem blocks. There is no way for the end-user to look at file system blocks. You would have to do into very low-level programming, deeper than just normal programming. But you are correct that this feature can make storage space a tricky, if not impossible thing to calculate.
  3. Again, this is the answer to your question 1. You can use this terminal copy command to create a clone of a file instead of a true copy. No snapshots.
  4. It depends. In theory, if you only modify a single block that is shared by more than one file, you only need to write a new block for the new file. All of the old files will still use their old blocks. Your new file will also use the old blocks except for the one new block. In practice, it depends. In many cases, the operating system will write out an entirely new file and just delete the old one altogether. This helps avoid disk fragmentation, which can be a problem with APFS when used on mechanical hard drives. Each app that is writing data could do it differently, or use multiple methods.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

APFS (Apple File System) details

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.