Get device filesystem path from dev_t on macOS

♀尐吖头ヾ 提交于 2021-02-20 04:03:03

问题


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")?


回答1:


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.




回答2:


find /dev -type b -ls

, And check the output for major/minor == {0x1000,4}


Or: find / -type b -ls if need to search the entire file system.

BTW: there could be more entries, referring to the same {major,minor} combination.



来源:https://stackoverflow.com/questions/54790858/get-device-filesystem-path-from-dev-t-on-macos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!