- Some notes and sample programs I wrote when playing around with APFS
make
will build three programs,modify
,clone
, andswap
modify
changes the first 26 bytes of a fileclone
uses the new COW copy APIswap
atomically swaps two filesclone
andswap
won't work on non-APFS Volumes
- (Needs macOS >=10.12)
alias apfs="diskutil apfs -IHaveBeenWarnedThatAPFSIsPreReleaseAndThatIMayLoseData"
is convenient to have
- Imports APFS Physical stores
- Exports APFS Volumes
- Named by a particular physical store
- Called the container reference disk
- (Only supports 1:1 mapping between physical stores and volumes for now)
diskutil apfs -IHaveBeenWarnedThatAPFSIsPreReleaseAndThatIMayLoseData
- Aliased by
apfs
on my laptop
apfs createContainer diskXsY
apfs list
shows global APFS state- One container, one physical store
apfs addVolume diskXsY APFS MyVolume
- Space-sharing by default
- Space-sharing volumes will share storage of underlying container
- May result in surprising out-of-space errors
apfs addVolume diskXsY APFS MyFixedVolume 10g
- Fixed-size volume
- Can't grow beyond original size
- Guaranteed to have as much space as originally allocated
dd if=/dev/random of=bigfile bs=1m count=512
clone bigfile bigfile.2
du -ch .
reports 1GB of data,apfs list
reports ~512M of usage!
for i in $(seq 500); do clone bigfile "bigfile.tmp.${i}"; done;
- 251G vs ~512M!!
- Change first block
modify bigfile
- Space doesn't increase much, most blocks unchanged
- Prepend to file
vim bigfile
, insert character- Space increases a ton, all blocks after edit have been modified
- New atomic swap operation
swap bigfile bigfile.tmp.2
- Claimed to be atomic by Apple
- Copy-on-write
- Clone operation creates file with references to old blocks
- Only create copy of a block when it's modified
- Saves space when performing lots of copies
- Very different from hard link
- Modifying hard-linked file changes original
- Modifying COWed file creates copy, original stays same
- Snapshotting and Revisioning?
- Doesn't seem to be available yet
- No mention of either in man pages
- Encryption
- Lots of encryption / privacy features
- Fast erase: Give
eff
option toapfs addVolume
- Not really encryption
- How might it be implemented?
- Doesn't work yet as far as I can tell
- Per volume, per file, encryption
- Apple Documentation
- WWDC Presentation
- APFS on Wikipedia
man diskutil
man hdiutil
man copyfile
man renamex_ap