apfs-extent-xray

command
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

apfs-extent-xray

Zero-CGo, zero-sudo APFS physical extent inspector and sparse hole puncher built with x/apfs.

What It Demonstrates

  • Physical Extent Inspection (apfs.Extents / F_LOG2PHYS_EXT) & Sharing (apfs.SharedExtentBytes): Creates a 2 MiB file, clones it via apfs.CloneFile, and proves 100% of physical disk blocks are shared.
  • Copy-on-Write Extent Divergence: Mutates a single 4 KiB page at offset 0x100000, syncs, and renders an ASCII extent map showing the exact diverged physical extent (16 KiB on Apple Silicon's 16 KiB VM pages) while surrounding extents remain shared.
  • Sparse Hole Punching (apfs.PunchHole / F_PUNCHHOLE): Punches a 1 MiB sparse hole in the clone, compares st_blocks before vs after (2048 KiB -> 1024 KiB on disk), and verifies the punched range reads back as zeros while logical file size remains 2 MiB.

Usage

CGO_ENABLED=0 go run ./examples/kernel/apfs-extent-xray

Measured Output (Apple M4 Max, CGO_ENABLED=0)

apfs-extent-xray (temp=/var/folders/kj/qbc32fzd2pv6ngnsysy8vpmw0000gn/T/apfs-extent-xray-3098367313)

[1] After apfs.CloneFile (before mutation)
    orig [0]: logical 0x000000..0x200000 (2048 KiB) -> phys 0x057b48639000  [SHARED]
    clone[0]: logical 0x000000..0x200000 (2048 KiB) -> phys 0x057b48639000  [SHARED]
    shared physical bytes: 2097152 / 2097152 (100.0%)
    extent map (64x32KiB): [================================================================]  (= shared, D diverged, . hole)

[2] After mutating 4 KiB page at logical offset 0x100000
    clone[0]: logical 0x000000..0x100000 (1024 KiB) -> phys 0x057b48639000  [SHARED]
    clone[1]: logical 0x100000..0x104000 (  16 KiB) -> phys 0x058912a57000  [DIVERGED]
    clone[2]: logical 0x104000..0x200000 (1008 KiB) -> phys 0x057b4873d000  [SHARED]
    shared physical bytes: 2080768 / 2097152 (99.2%), diverged: 16 KiB
    extent map (64x32KiB): [================================D===============================]  (= shared, D diverged, . hole)

[3] After apfs.PunchHole [0x0, +1024 KiB)
    clone[0]: logical 0x100000..0x104000 (  16 KiB) -> phys 0x058912a57000  [DIVERGED]
    clone[1]: logical 0x104000..0x200000 (1008 KiB) -> phys 0x057b4873d000  [SHARED]
    st_blocks: 4096 (2048 KiB) -> 2048 (1024 KiB) on disk
    logical size unchanged: 2048 KiB; punched range reads all zeros: true
    extent map (64x32KiB): [................................D===============================]  (= shared, D diverged, . hole)

Documentation

Rendered for darwin/amd64

Overview

Command apfs-extent-xray demonstrates APFS physical extent inspection (F_LOG2PHYS_EXT), copy-on-write divergence after a single-page mutation, and sparse hole punching (F_PUNCHHOLE) using x/apfs with zero cgo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL