macOS SDK11/ARM64:statfs64/f_mntonname [英] macOS SDK11 / ARM64: statfs64 / f_mntonname

查看:47
本文介绍了macOS SDK11/ARM64:statfs64/f_mntonname的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用函数 statfs64 通过属性 f_mntonname 从 macOS 上的路径获取挂载点.这在针对 x86_64 架构的 SDK 10.x 构建时工作正常.

但是,在为 arm64(和 SDK 11)构建时,该方法不可用.

我可以使用 statfs 作为后备,这似乎可用,但这对路径长度有限制.

我知道有 NSFileManager-API (attributesOfFileSystemForPath),但不幸的是没有安装路径的属性.

有谁知道如何在新的 SDK/平台上做到这一点?

谢谢和问候,多米尼克

解决方案

statfs64fstatfs64 自 macOS 10.6 起已弃用,以支持版本化符号".

如果您正在为 macOS 10.6 或更高版本构建,只需切换到 statfsfstatfs,并将其添加到源文件的顶部(在包含之前):

#define _DARWIN_USE_64_BIT_INODE

或者添加一个编译器标志,如果更改很多源文件太繁琐:

-D_DARWIN_USE_64_BIT_INODE

对于arm64目标,这个已经设置好了,所以没有作用.
对于 x86_64 目标,这会导致链接器发出对 _statfs$INODE64(等效于 _statfs64)而不是 _statfs 的依赖项.>

如果您的 x86_64 切片确实需要支持 macOS 10.5,那么您将不得不求助于一些预处理:

#define _DARWIN_USE_64_BIT_INODE#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <1060#define STATFS statfs64#define FSTATFS fstatfs64#别的#define STATFS statfs#define FSTATFS fstatfs#万一

如果您需要支持 macOS 10.4 或更低版本,那么无论如何您都不走运,因为那里没有 64 位 inode 支持.

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

解决方案

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.

这篇关于macOS SDK11/ARM64:statfs64/f_mntonname的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆