问题
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