You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
apfsck: "Allocation zone: invalid range" on macOS containers of 8 GiB or more #24
apfsck stops with Allocation zone: invalid range. on every APFS container of 8 GiB or more that macOS 27.0.1 creates, even an empty one right after formatting. A 4 GiB one is fine. To reproduce:
# macOS
mkfile -n 8g zones.img
diskutil image attach --noMount zones.img # comes up as diskN
diskutil eraseDisk APFS Test GPT diskN
diskutil eject diskN
# Linux, apfsck from master (1bd1c1c)
losetup -P -f --show zones.img # /dev/loop0; p1 is the EFI partition
apfsck -cw /dev/loop0p2
Allocation zone: invalid range.
fsck_apfs has no complaints about the same image.
On these containers the space manager's datazone has four zones, with ids 1 to 4. macOS only sets a zone's boundaries the first time it allocates from it, and until then they are 0..0. On the fresh 8 GiB container zone 1 is already placed and zones 2 to 4 are still 0..0. I also walked the checkpoints of a 1.5 TiB container that I filled with files: all four zones were 0..0 at xid 1, zone 1 got boundaries at xid 3, zones 2 and 4 at xid 6, and zone 3 never did. check_alloc_zone_sanity() requires start < end for every zone that has an id, so the unplaced ones fail. Since APFS_SM_ALLOCZONE_INVALID_END_BOUNDARY is 0, I'm guessing a zero end is how macOS marks a zone that hasn't been placed yet.
Unrelated to the error, but in case it's useful: the boundaries look like block numbers rather than byte offsets. Each placed zone covers one 32768-block bitmap chunk, and the data macOS writes there starts at the zone's first block. The alignment checks still pass for them.
I have a fix on my fork that skips the range checks when both boundaries are zero and keeps the id and overlap checks: logicalangel@2c0f7ba. It was written with an LLM, and I know from linux-apfs/linux-apfs-rw#132 that you'd rather write fixes yourself, so feel free to ignore it. I'm happy to test whatever you come up with on more macOS images.
Activity
Allow allocation zones ending in address 0
eafer commentedon Nov 13, 2026
Thanks again. Weirdly I can't reproduce this with my macos vm, so when you can let me know if this patch solves the problem for you.