My program reads device paths like /dev/rdisk0
from input and then it looks in IOKit
for a disk with the BSD name disk0
. For this I have to remove /dev/r
from the path.
Hard coding this path can break in future versions of Mac OS X. Therefore I though of another way: I could match the IOService
using the BSD Major and Minor version of the device.
Here's my question: Is it possible to extract the B开发者_Python百科SD minor and major numbers from a path?
Yes. Use the stat
syscall. The member of struct stat
you are looking for is st_dev
, which I believe is an OR of major and minor after a bit shift.
精彩评论