从macOS上的dev_t获取设备文件系统路径 [英] Get device filesystem path from dev_t on macOS

查看:151
本文介绍了从macOS上的dev_t获取设备文件系统路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在macOS(Darwin)上具有32位整数BSD设备编号dev_t(例如0x1000004),如何获取该设备的相应文件系统路径(例如"/dev/disk1s4")?

If I have a 32-bit integer BSD device number dev_t (e.g. 0x1000004) on macOS (Darwin), how can I get the corresponding filesystem path for this device (e.g. "/dev/disk1s4")?

推荐答案

您必须枚举已挂载的文件系统,并查找与设备ID匹配的文件系统.您可以使用 getfsstat()进行枚举.这将填充 struct statfs 结构.将每个结构的字段 f_fsid.val [0] 与要查找的 dev_t 进行比较.如果它们匹配,则 struct statfs 是您要查找的设备的名称,您可以检查其其他字段以查找所需的信息.特别是,f_mntfromname 是设备路径.

You have to enumerate the mounted file systems and look for one who's device ID matches. You can use getfsstat() for the enumeration. That fills in struct statfs structures. Compare the field f_fsid.val[0] of each structure to the dev_t you're looking for. If they match, then that struct statfs is the one for the device you're looking for and you can examine its other fields for the info you're looking for. In particular, the f_mntfromname is the device path.

这篇关于从macOS上的dev_t获取设备文件系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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