Question

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 BSD minor and major numbers from a path?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top