Skip to content

Build f3probe and f3brew on macOS - #285

Open
nickclyde wants to merge 2 commits into
AltraMayor:masterfrom
nickclyde:macos-f3probe
Open

Build f3probe and f3brew on macOS#285
nickclyde wants to merge 2 commits into
AltraMayor:masterfrom
nickclyde:macos-f3probe

Conversation

@nickclyde

Copy link
Copy Markdown

This makes f3probe and f3brew build and run natively on macOS, so Mac users no longer need a Linux machine to probe a drive. (The README currently points Mac users at Docker, but Docker Desktop cannot expose the host's block devices to a container, so that route does not actually work on Mac.)

Changes

src/libdevs.c — a __APPLE__ code path replacing the Linux-only interfaces:

  • O_DIRECTfcntl(F_NOCACHE)
  • fsync() + posix_fadvise()F_FULLFSYNC, falling back to fsync(). Neither is supported on every device node: /dev/rdiskN returns ENOTTY for F_FULLFSYNC, which initially made every write "fail" and the drive report as damaged.
  • BLKGETSIZE64/BLKSSZGETDKIOCGETBLOCKCOUNT/DKIOCGETBLOCKSIZE
  • libudev partition detection → reject /dev/[r]diskNsM names by convention, so --destructive on a partition is still caught.
  • USB resets need USBDEVFS_RESET, so only --reset-type=2 is accepted; f3probe already always uses it, and f3brew prints the command to use.

Makefile

  • -ludev only on Linux.
  • make extra / make install-extra build only f3probe and f3brew on Darwin, since f3fix needs libparted.
  • Locate argp-standalone via brew --prefix argp-standalone. The formula is keg-only, so $(brew --prefix)/include/argp.h never existed and the macOS build failed out of the box.

CI — the macOS job now builds the extra targets and runs f3probe and f3brew against a RAM disk created with hdiutil (analogous to the Linux loop-device test).

README — updated the Mac sections accordingly.

Testing

  • macOS 15 / Apple Silicon: make all extra builds cleanly with -Wall -Wextra -pedantic. f3probe reports a 20 MB hdiutil RAM disk as genuine, and correctly identified a counterfeit 1 TB USB drive as limbo with ~108 MB usable (~2.5 min run, --destructive --time-ops). Partition names are rejected before opening the device.
  • Linux: docker build with the repo's Dockerfile still builds and runs f3probe, f3brew, and f3fix.

f3probe and f3brew depended on Linux-only interfaces: O_DIRECT,
posix_fadvise(), the BLKGETSIZE64/BLKSSZGET ioctls, and libudev for
partition detection and USB resets. Add a macOS code path to libdevs.c:

- open the device with F_NOCACHE instead of O_DIRECT;
- flush with F_FULLFSYNC, falling back to fsync() since neither is
  supported on every device node (e.g. /dev/rdiskN returns ENOTTY);
- query geometry with DKIOCGETBLOCKCOUNT and DKIOCGETBLOCKSIZE;
- reject partition names (/dev/[r]diskNsM) by convention, since there
  is no udev to map a partition to its disk;
- only support --reset-type=2 (RT_NONE); f3probe already always uses
  it, and f3brew reports how to pass it.

f3fix still requires libparted, so "make extra" builds only f3probe and
f3brew on Darwin. Link -ludev only on Linux, and locate the keg-only
argp-standalone via its own Homebrew prefix, since it is not linked
into $(brew --prefix) and the previous path never resolved.

Extend the macOS CI job to build the extra targets and to run f3probe
and f3brew against a RAM disk created with hdiutil.
Also note that the Docker installation cannot be used on Mac since
Docker Desktop does not expose the host's block devices to containers.
@AltraMayor

Copy link
Copy Markdown
Owner

Hi @nickclyde,

As you can see at this comment, we may have found someone to spearhead the port of ALL extra tools to macOS. If he chooses to move forward, would you be willing to help the effort in any capacity? I can create a Telegram group to help with group communication. If you're willing to help, please leave a comment on pull request #283 to confirm and indicate in what capacity you can help.

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.

2 participants