Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的程序/dev/rdisk0从输入中读取设备路径,然后查找IOKit具有 BSD 名称的磁盘disk0。为此,我必须/dev/r从路径中删除。
/dev/rdisk0
IOKit
disk0
/dev/r
硬编码这条路径可能会在未来版本的 Mac OS X 中中断。因此我想到了另一种方式:我可以匹配IOService使用设备的 BSD 主要和次要版本。
IOService
这是我的问题:是否可以从路径中提取 BSD 次要编号和主要编号?
是的。使用stat系统调用。struct stat您正在寻找的成员是st_dev,我相信这是移位后的主要和次要的 OR。
stat
struct stat
st_dev