使用 IOServiceGetMatchingServices 获取 OS X 存储设备列表

发布于 2024-10-04 08:59:57 字数 115 浏览 0 评论 0原文

我需要获取 OS X 系统上的物理存储设备列表。使用 kIOStorageClass 键的 IOServiceGetMatchingServices 为我提供了所有卷的列表,而不是所有硬件存储设备的列表。我该怎么做?

I need to get the list of physical storage devices on an OS X system. IOServiceGetMatchingServices using the kIOStorageClass key gives me a list of all volumes, not all hardware storage devices. How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亽野灬性zι浪 2024-10-11 08:59:57

问题有点模棱两可(您想要整个驱动器、分区、以上所有内容吗?),我建议启动 IORegistryExplorer 实用程序(随 XCode 一起提供)并找出您想要哪种类型的设备。我可以告诉您,每个整个驱动器通常对应一个IOBlockStorageDriver,所以也许这就是您想要匹配的类。然后它将有一个代表整个设备的 IOMedia 客户端。反过来,它会有一个分区方案客户端,每个分区都有一个 IOMedia 客户端,除非它没有分区。

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.

那片花海 2024-10-11 08:59:57

要获取物理存储设备列表,您可以匹配 kIOATABlockStorageDeviceClass。以下代码获取块存储设备的迭代器。

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

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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文