What really happens when you duplicate a file on iOS?

By

ios apfs clones storage file providers
Hidden storage.
Photo: Josh Coleman/Unsplash

How much space do duplicate files take up on your iPad? In theory, they use no extra storage. Thanks to the design of the Apple File System (APFS) used on iOS and macOS, duplicating a file doesn’t actually create a copy. It just creates a reference that points to the original file on the disk.

But what about File Providers, and iCloud, and all that stuff? I decided to take a deep dive and find out if you can really make a zillion copies of a file with no penalty. The results were, to say the least, confusing.

Duplicates are free

APFS has a feature called APFS Cloning. The clearest explanation I have found comes from Mike Bombich, developer of Mac backup app Carbon Copy Cloner. I’ll paste it here for you to read:

APFS cloning allows the user to instantly create copies of files on the same volume without consuming extra storage space. When cloning a file, the file system doesn’t create copies of the data, rather it creates a second reference to the file that can be modified independently of the first file.

The two files will share storage on the disk for portions of the files that remain identical, but changes to either file will be written to different parts of the disk. APFS file cloning only works when you make copies of a file on the same volume (e.g. duplicate a file or folder in the Finder).

This was written about APFS on the Mac, but should also apply to iOS. For example, if you make 10 copies of a 1GB file, then it still takes up only 1GB. The other “copies” are just references to that original file. If you modify one of those references, however, it will turn into an actual duplicate file. So far, so straightforward.

Do file providers work the same way?

But what if your apps use File Providers? Do these count as separate volumes? Does this means that iOS will make a real copy when moving files to and from these locations?

First, though, what’s a File Provider? Take a look at the Files app. On the left side is a column showing Locations:

Those "locations" on the left are File Providers.
Those “locations” on the left are File Providers.
Photo: Cult of Mac

Those are File Providers. Some provide access to cloud storage (like Dropbox), but some are local. Third-party apps like Kymatica’s AudioShare and Readdle’s Documents use a File Provider to open up their in-app storage to any other app that wants it. So, my question is, are File Provers counted as separate storage volumes, or as part of the main volume?

No good data

iMazing agrees almost exactly with the iPad's own data, but iTunes tells a different story.
iMazing agrees almost exactly with the iPad’s own data, but iTunes tells a different story.
Photo: Cult of Mac

The problem with sleuthing this out on iOS is that it’s hard to get a trustworthy number for the actual amount of storage used. I decided to take numbers from three sources: iTunes and iMazing on a connected Mac, plus the storage report from the iPad itself. I noted the numbers, then I made seven copies of the same 1.54GB file. The file — a download of drum machine samples — was in Readdle’s Documents app, and I moved it into AudioShare’s storage area using the Files app.

Here’s how the three sources reported the storage before the copy operation. All sizes in GB, and the numbers in brackets were calculated by me, using 512GB as the total drive size:

  • iTunes: (173.06 used) 338.94 free
  • iPad: 148.3 used (363.7 free)
  • iMazing: 241.48 used, 270GB free

Not a good start. Those numbers are nowhere near each other. Still, perhaps they will agree on the difference in storage space in the before/after test.

Before and after

I copied the same file seven times, from Documents’ file provider to the AudioShare file provider. The copy took a few moments. It seems that it would be impossible to copy almost 10GB of data in such a short time. From this information alone, I guessed that these copies were in fact APFS clones. But what did the numbers say?

  • iTunes: (173.14 used), 338.86 free
  • iPad: 159.1 used, (352.9 free)
  • iMazing: 252.3 used, 259.7 free

So, the differences in used space are as follows:

  • iTunes: 0.08 GB
  • iPad: 10.8 GB
  • iMazing: 10.82 GB

Here we go! This is much more useful information. Seven copies of that 1.54 GB file totals 10.78 GB. Both the iPad’s native storage tool, and iMazing, report this amount of extra used space. But iTunes says that no extra storage has been used. That’s weird. Maybe we can find more information?

App storage

The individual apps report the changes in storage.
The individual apps report the changes in storage.
Photo: Cult of Mac

Here we can see the storage measurements for Documents and for AudioShare. Documents stays the same, as you’d expect — we’re copying from it. AudioShare shows an increase of 10.78GB. That’s the exact size of those seven copied files. What’s going on?

Well, it’s possible that iTunes is either wrong or right. If it’s correct, then the iPad’s reporting is wrong. There’s not much more to say on this, without more information. But how about one more test? Let’s copy a file to the iPad’s own On My iPad folder, and then copy that file a bunch of times to another folder. We’ll ignore File Providers entirely for this test, then compare our results from both tests.

Test 2: plain old file copies

I removed the copies we made in the first test, emptied the iPad’s trash, emptied AudioShare’s own trash, and moved the test file to the iPad’s download folder. (Interestingly, the files I deleted out of AudioShare’s File Provider did not show up in the Files’ app’s own Recently Deleted section, aka the iPad’s trash).

Then I synced with iTunes, and hit reload on iMazing. The method used to run the test was exactly the same as the previous test, only I first copied the file to another folder in the On My iPad section, and then used the Duplicate command to create a total of seven copies.

This time I’ll spare you the actual measurements, and just present the conclusions, i.e the before/after difference in storage used:

  • iTunes: 0.74 GB
  • iPad: 10.8 GB
  • iMazing: 10.79 GB

In short, these are pretty much identical to the first set of results. Copies between File Provider silos give the same result as file copies in the iPad’s “native” storage area.

APFS is magic

Apple’s own APFS spec says that files duplicated on the same volume are clones, not copies. In both our tests, the result was the same: iTunes reported no increase in used storage, while the iPad and iMazing agreed that those files did in fact take up more space.

In which case, one conclusion is that iTunes is right, because it agrees with Apple’s own APFS description. And if that’s the case, then moving files in and out of File Providers is just the same as moving them around in the same folder.

If you know more about how this works, please let me know, either in the comments, or via Twitter/microblog/email.

Newsletters

Daily round-ups or a weekly refresher, straight from Cult of Mac to your inbox.

  • The Weekender

    The week's best Apple news, reviews and how-tos from Cult of Mac, every Saturday morning. Our readers say: "Thank you guys for always posting cool stuff" -- Vaughn Nevins. "Very informative" -- Kenly Xavier.