Skip to content

Conversation

@lkraider
Copy link

This PR introduces a comprehensive refactoring for multi-platform support, with code for native macOS partitioning support, while maintaining full Linux compatibility. The changes include:

Key Changes

  • New Filesystem Layout:

Platform specific code tree:

src/platform
├── darwin   # macOS-specific implementations
│   ├── block_device.c     # Disk I/O using Disk Arbitration
│   ├── usb_reset.c        # USB specific handling (stubs for now)
│   ├── partition
│   │   └── partition.c    # diskutil-based partitioning
│   └── platform_compat.c  # Posix compatibility shims
│
├── linux
│   ├── block_device.c
│   ├── usb_reset.c
│   ├── partition
│   │   └── partition.c
│   ├── platform_compat.c
│   └── private
│       └── linux_private.h
│
│  # BSD platform stubs for now
├── freebsd
│   └── platform_compat.c
├── openbsd
│   └── platform_compat.c
│
│   # Common platform headers
└── private
    ├── block_device_private.h
    └── usb_reset_private.h

Platform independent code tree:

src
├── f3
│   ├── f3read.c
│   ├── f3write.c
│   │ 
│   └── lib
│       ├── libflow.c
│       └── utils.c
│ 
└── f3-extra
    ├── f3brew.c
    ├── f3fix.c
    ├── f3probe.c
    │ 
    └── lib
        ├── file_device.c
        ├── libdevs.c
        ├── libprobe.c
        ├── libutils.c
        ├── perf_device.c
        └── safe_device.c
  • Platform Detection: Enhanced Makefile for multi-platform support
  • macOS Native Build: Framework linking with DiskArbitration and CoreFoundation

Implementation Notes

  • Uses diskutil for partition management (replaces parted)
  • Implements block device I/O with proper caching behavior
  • Provides compatibility shims for Linux-specific functions
  • Maintains clean separation between Linux, macOS code paths
  • Adds clear extension points support for new platforms to be added

Testing

  • Added test-macos-f3fix.sh for f3fix partition testing
  • Ensured Linux build remains unaffected

Limitations

  • USB reset functionality is stubbed (will probably require USBDriverKit and private frameworks, maybe)

lkraider added 20 commits April 30, 2025 16:24
Launches diskutil process to perform the actual partition changes.
Apply tabs (display size 8) and comments styling.

Also refactor darwin/block_device.c map_partition_to_disk
with a cleaner implementation.
Simplify and cleanup the Makefile a bit.
Good reference on dependency files generation:
https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
Mixing feature macros when linking could be an issue.
If we want to keep _XOPEN_SOURCE=600 we should update the Makefile
with rules per target.
Rework the compilation to build the correct objects for each target.
@AltraMayor
Copy link
Owner

Hi @lkraider,

I'm so sorry, but I don't have large blocks of time to review large pull requests like this one. I don't want to diminish your work; it's my life that's too busy.

Can you break your pull request into small ones so I can review them in short opportunities that I have?

Thank you for the effort you've put into this pull request.

@lkraider
Copy link
Author

lkraider commented Sep 9, 2025

Hi, no problem, I understand. The functionality code is mostly in the src/platform/darwin folder.

This patch contains a restructuring for the purpose of multi-platform support, but doesn't change the current supported platform functionality.

I could try and create a PR with only the darwin function and minimal existing code restructuring.
Do you have a preference on how the platform-specific code should be added to the current project?

@AltraMayor
Copy link
Owner

I don't have an overall understanding of your pull request, so I'm unable to advise you on how to break it. I recommend breaking into as many pull requests as possible, so reviews are not daunting. Please don't issue all pull requests simultaneously, since things should get clearer as we review the pull requests.

I appreciate your willingness to work this out. I hope this grows into a rewarding collaboration for both of us.

@lkraider
Copy link
Author

lkraider commented Sep 10, 2025

Moving to #246

@lkraider lkraider closed this Sep 10, 2025
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