开发者

Getting OS X Storage Device List Using IOServiceGetMatchingServices

I need to get the list of physical storage devices on an OS X system. IOServiceGetMatchingServices using the kIOStor开发者_StackOverflow社区ageClass key gives me a list of all volumes, not all hardware storage devices. How do I do this?


The question is a little ambiguous (do you want whole drives, partitions, all of the above?), I suggest firing up the IORegistryExplorer utility (comes with XCode) and figuring out which class of device you want. I can tell you that each whole drive normally corresponds to an IOBlockStorageDriver, so maybe that's the class you want to match. It will then have an IOMedia client representing the whole device. It in turn will have a partition scheme client, which has an IOMedia client for each partition, unless it's not partitioned.


To get list of physical storage device you can match for kIOATABlockStorageDeviceClass. Following code obtains iterator for block storage devices.

IOReturn        error       = kIOReturnSuccess;
io_iterator_t   iter        = MACH_PORT_NULL;
error = IOServiceGetMatchingServices (  kIOMasterPortDefault,
                                      IOServiceMatching ( kIOATABlockStorageDeviceClass ),
                                      &iter );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜