macosxcode12mount-pointapple-m1

macOS SDK11 / ARM64: statfs64 / f_mntonname


I am using the function statfs64 to obtain the mount point from a path on macOS via property f_mntonname. This works fine when building against the SDK 10.x for the architecture x86_64.

However, when building for arm64 (and SDK 11), the method is not available.

I can use statfs as fallback which seems to be available, but this has limits to the path length.

I know there is the NSFileManager-API (attributesOfFileSystemForPath), but unfortunately there is no property for the mount path.

Does anyone know how to to this on the new SDK/Platform?

Thank you and regards, Dominik


Solution

  • statfs64 and fstatfs64 have been deprecated since macOS 10.6 in favour of "versioned symbols".

    If you're building for macOS 10.6 or higher, simply switch to statfs and fstatfs, and add this at the top of your source files (before the includes):

    #define _DARWIN_USE_64_BIT_INODE
    

    Or add a compiler flag, if changing many source files is too tedious:

    -D_DARWIN_USE_64_BIT_INODE
    

    For arm64 targets, this is already set, so it has no effect.
    For x86_64 targets, this causes the linker to emit a dependency on _statfs$INODE64 (which is equivalent to _statfs64) rather than _statfs.

    If your x86_64 slice does indeed need to support macOS 10.5, then you'll have to resort to some preprocessing:

    #define _DARWIN_USE_64_BIT_INODE
    #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060
        #define STATFS statfs64
        #define FSTATFS fstatfs64
    #else
        #define STATFS statfs
        #define FSTATFS fstatfs
    #endif
    

    And if you need to support macOS 10.4 or lower, you're out of luck anyway because there is no 64-bit inode support back there.