Expand description
Wrapper-aware HFS+ defrag clone.
Classic Mac OS 8.x/9.x volumes store an HFS+ volume embedded inside an
HFS wrapper: the outer Apple_HFS partition is itself a classic HFS
volume whose MDB has drEmbedSigWord == 0x482B/0x4858, with
drEmbedExtent pointing at a contiguous range of outer allocation
blocks that hold a real HFS+ volume. Mac OS 8.1+ reads the MDB, jumps
straight to the inner HFS+, and mounts it; pre-8.1 systems mount the
outer HFS and see a “Where_have_all_my_files_gone?” read-me file.
stream_defragmented_hfsplus
only handles flat HFS+ (no wrapper). stream_wrapped_defragmented_hfsplus
in this module wraps that with the surrounding HFS shell:
+---- new wrapper partition ----+
| boot blocks (verbatim) |
| primary MDB (patched) |
| volume bitmap (patched) |
| wrapper alloc blocks 0..S-1 | (verbatim from source — holds the
| ("read-me" file + B-trees) | wrapper's catalog/extents, untouched)
| embedded extent (S..S+N-1) | ← stream_defragmented_hfsplus output
| = new flat HFS+ volume |
| alt MDB (patched mirror) |
| reserved last sector |
+-------------------------------+where S = drEmbedExtent.startBlock (unchanged from source) and N = ceil(target_inner_size / drAlBlkSiz) (smaller than the source’s
embedded extent). drNmAlBlks shrinks to S + N and the wrapper’s
internal catalog/extents B-trees are preserved byte-for-byte because
their allocation blocks all lie in [0..S) and stay at the same
source byte offsets.
Structs§
- Wrapped
Clone Plan - Plan for emitting a shrunken wrapped HFS+ volume. All sizes are bytes unless noted.
- Wrapped
HfsPlus Info - Fields parsed from the outer HFS wrapper MDB that the clone pipeline needs to rebuild the wrapper around a shrunken inner volume.
Enums§
Functions§
- detect_
wrapped_ hfsplus - Probe the wrapper MDB at
partition_offset + 1024and return the parsed wrapper info iff it’s a classic HFS volume with an embedded HFS+/HFSX. ReturnsNonefor any other layout (flat HFS+, native HFS, non-HFS, parse errors). - detect_
wrapped_ hfsplus_ at - Same as
detect_wrapped_hfsplusbut reads the MDB sector via positioned I/O (std::os::unix::fs::FileExt::read_aton Unix, [std::os::windows::fs::FileExt::seek_read] on Windows). Use this from any context that shares the underlying file descriptor across threads —try_clone()on Unix usesdup(), which shares the kernel-level seek offset, so concurrentseek + readcallers can clobber each other and return the wrong partition’s MDB. Positioned reads carry the offset in the syscall itself and don’t touch the shared cursor, so they’re safe under any amount of fd sharing. - plan_
wrapped_ clone - Build a
WrappedClonePlansized for a shrunken inner HFS+ volume. - stream_
wrapped_ defragmented_ hfsplus - Stream a shrunken wrapped HFS+ volume to
dst. Single-pass; no seeks required on the writer.