DriveRescueSwift: Native macOS Raw Disk Recovery & HFS+ Forensics
When an external hard drive develops bad sectors, macOS automatically locks the device behind background fsck_hfs retries that can freeze Finder and hang I/O. Here is how we built a native Swift 6 & SwiftUI recovery engine to bypass OS locks and rescue failing drives.
Core Systems Architecture
- Swift 6 Strict Concurrency: Modular architecture split into
DriveRescueCore,DriveRescueCLI, and the nativeDriveRescueSwiftmacOS 14+ app. - Direct
/dev/rdisk*Hardware Access: Bypasses kernel block-cache overhead using page-aligned memory buffers (AlignedBuffer). - Automatic
fsckLock Hygiene: Terminates competing backgroundfsck_hfsandfsck_apfsprocesses and unlocks raw node permissions via native macOS authorization. - Unmounted HFS+ Forensics: Inspects Sector 2 (Primary Volume Header) and the Alternate Volume Header without mounting damaged partitions.
- Timeout-Guarded Sector Reads: Enforces strict per-read timeouts (6.0s default) so drive firmware error-recovery loops never freeze the UI.
Why Failing Drives Hang macOS
Whenever a failing USB or Thunderbolt hard drive is plugged into macOS, the operating system immediately attempts to mount its partitions and runs fsck_hfs or fsck_apfs in the background. If the drive has physical media degradation or corrupted B-tree catalog headers, the drive's internal firmware enters aggressive read-retry loops while the kernel holds an exclusive lock on the block device.
Standard file managers and naive copy tools stall indefinitely under these conditions. DriveRescueSwift solves this by taking direct control of the hardware node lifecycle before any read begins.
Direct Raw Sector I/O & HFS+ Header Inspection
Instead of relying on mounted filesystem paths, DriveRescueCore interfaces directly with macOS DiskArbitration (DiskArbitrationBridge) to enumerate BSD devices (e.g., /dev/disk4s2) and their unbuffered character counterparts (/dev/rdisk4s2).
- Sector 2 Probing:
HFSPlusVolumeInspectorreads offset 1024 bytes directly from the raw disk to validate theH+orHXsignature, block size, catalog file length, and journal state without triggering a mount. - Alternate Volume Header Fallback: If the primary header is damaged, the inspector automatically probes
totalSectors - 2at the end of the partition to verify backup metadata. - Signature File Carving: When filesystem tables are beyond repair,
SignatureProfilescans raw sector alignments for known file headers and footers (such as SQLite3 databases and PNG media).
Three-Tier Salvage Pipeline
Inside the SwiftUI workspace, engineers can choose between three salvage strategies depending on drive health:
- Adaptive DMA Cloner: Uses
AlignedBufferraw reads with deterministic timeout guards, logging unresponsive LBAs and skipping forward cleanly to maximize healthy data throughput. - GNU ddrescue Bridge: Orchestrates multi-pass sector scraping with persistent mapfiles for drives that require iterative bad-sector trimming.
- Direct File Copy (rsync): Performs resilient directory synchronization when a partition remains partially mountable in read-only mode.
Built for Sovereign Hardware Recovery
Engineered in Swift 6 with Strict Concurrency to give macOS users direct, non-blocking access to failing storage hardware without relying on opaque third-party utilities.