Skip to content

Port f3probe, f3brew, and f3fix to macOS - #283

Open
sbrunner-atx wants to merge 1 commit into
AltraMayor:masterfrom
sbrunner-atx:macos-port
Open

Port f3probe, f3brew, and f3fix to macOS#283
sbrunner-atx wants to merge 1 commit into
AltraMayor:masterfrom
sbrunner-atx:macos-port

Conversation

@sbrunner-atx

Copy link
Copy Markdown

What

Ports the three extra tools - f3probe, f3brew, and f3fix - to macOS, as invited by #8 and requested in #135.

How

The probing algorithm (libprobe.c) is already platform-independent; only the device-access layer needed work. All changes are behind APPLE guards:

  • open() with F_NOCACHE replaces O_DIRECT (plus _DARWIN_C_SOURCE so Darwin extensions remain visible under _POSIX_C_SOURCE)
  • DKIOCGETBLOCKCOUNT / DKIOCGETBLOCKSIZE replace BLKGETSIZE64 / BLKSSZGET
  • whole-disk detection by device-name convention (/dev/rdiskN vs /dev/rdiskNsM) replaces the udev devtype check
  • manual USB reset (used only by f3brew; f3probe uses RT_NONE) polls the device node instead of using a udev monitor
  • software USB reset reports EOPNOTSUPP on macOS

f3fix on macOS is a new libparted-free backend (f3fix_darwin.c) that writes the MBR directly - fixing a fake drive only ever needs a single MBR partition ending at the last good sector from f3probe. MBR only for now; GPT support could follow if there is demand.

Validation

On macOS 26.5 (Intel, MacBookPro16,1), clang + brew argp-standalone:

  • make extra builds all three tools with no warnings
  • f3probe --debug-unit-test: SUMMARY: Perfect!
  • Real hardware (SanDisk Ultra 128 GB USB 3.0, genuine):
$ sudo ./build/f3probe --destructive --time-ops /dev/rdisk7
Good news: The device /dev/rdisk7 is the real thing
Device geometry:
         *Usable* size: 114.60 GB (240328704 blocks)
        Announced size: 114.60 GB (240328704 blocks)
Probe time: 1 min 36 s

The Linux build is unchanged: gcc on Ubuntu compiles all targets with no new warnings, and the Linux code path is untouched.

Notes

  • Happy to add a macos-latest job to the GitHub Actions workflow in a follow-up commit so the port cannot regress.
  • Disclosure: developed with AI assistance (Claude); reviewed, built, and hardware-validated by the author.

The probing algorithm (libprobe.c) is platform-independent; only the
device-access layer in libdevs.c was Linux-specific. This commit adds
an __APPLE__ backend:

- open() with F_NOCACHE replaces O_DIRECT (with _DARWIN_C_SOURCE so
  the Darwin extensions stay visible despite _POSIX_C_SOURCE)
- DKIOCGETBLOCKCOUNT/DKIOCGETBLOCKSIZE replace BLKGETSIZE64/BLKSSZGET
- whole-disk detection by device-name convention (/dev/rdiskN vs
  /dev/rdiskNsM) replaces the udev devtype check
- manual USB reset (used by f3brew only; f3probe uses RT_NONE) is
  implemented by polling the device node instead of a udev monitor
- software USB reset (USBDEVFS_RESET) reports EOPNOTSUPP on macOS
- posix_fadvise(DONTNEED) is skipped; F_NOCACHE already bypasses the
  page cache

f3fix on macOS is a new libparted-free backend (f3fix_darwin.c) that
writes the MBR directly: fixing a fake drive only ever needs a single
MBR partition ending at the last good sector reported by f3probe.
MBR only for now; GPT is unnecessary for this use case.

The Linux build is unchanged: all __APPLE__ additions are guarded and
the Linux path compiles the same objects with no new warnings.

Tested on macOS 26.5 (Intel, MacBookPro16,1): make extra builds all
three tools with clang and brew argp-standalone, and
f3probe --debug-unit-test reports Perfect.

Closes AltraMayor#8. Closes AltraMayor#135.
@sbrunner-atx

Copy link
Copy Markdown
Author

For anyone who wants to try this on macOS without building manually, I have published a Homebrew tap pinned to this PR branch:

brew tap sbrunner-atx/f3
brew install sbrunner-atx/f3/f3-macos

Tap: https://github.com/sbrunner-atx/homebrew-f3 (README includes macOS usage notes: raw whole-disk device, unmount first, sudo). I will retire the tap once this is merged and the official formula picks up make extra.

Full f3probe hardware-validation transcript (genuine SanDisk Ultra 128 GB, macOS 26.5 Intel) available on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant