tags:

views:

349

answers:

1

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?

+2  A: 

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.

asveikau
This works. `dev_t` is a 32 bit integer, the first 8 bits are the major version and the other 24 are the minor version. Is there a way to make this portable in case `dev_t` is changed to a 64bit integer?
Georg
in <sys/types.h> on my OpenBSD machine, there appear to be macros major() and minor() for this.
asveikau
@ asveikau: Thanks, found them. I could swear that those functions weren't there yesterday when I looked for them.
Georg