Build f3probe and f3brew on macOS - #285
Open
nickclyde wants to merge 2 commits into
Open
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes
f3probeandf3brewbuild 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_DIRECT→fcntl(F_NOCACHE)fsync()+posix_fadvise()→F_FULLFSYNC, falling back tofsync(). Neither is supported on every device node:/dev/rdiskNreturnsENOTTYforF_FULLFSYNC, which initially made every write "fail" and the drive report as damaged.BLKGETSIZE64/BLKSSZGET→DKIOCGETBLOCKCOUNT/DKIOCGETBLOCKSIZE/dev/[r]diskNsMnames by convention, so--destructiveon a partition is still caught.USBDEVFS_RESET, so only--reset-type=2is accepted;f3probealready always uses it, andf3brewprints the command to use.Makefile-ludevonly on Linux.make extra/make install-extrabuild onlyf3probeandf3brewon Darwin, sincef3fixneeds libparted.brew --prefix argp-standalone. The formula is keg-only, so$(brew --prefix)/include/argp.hnever existed and the macOS build failed out of the box.CI — the macOS job now builds the extra targets and runs
f3probeandf3brewagainst a RAM disk created withhdiutil(analogous to the Linux loop-device test).README — updated the Mac sections accordingly.
Testing
make all extrabuilds cleanly with-Wall -Wextra -pedantic.f3probereports a 20 MBhdiutilRAM disk as genuine, and correctly identified a counterfeit 1 TB USB drive aslimbowith ~108 MB usable (~2.5 min run,--destructive --time-ops). Partition names are rejected before opening the device.docker buildwith the repo's Dockerfile still builds and runsf3probe,f3brew, andf3fix.