如何以编程方式确定哪个Mac驱动器是启动驱动器? [英] How do I programmatically determine which Mac drive is the boot drive?

查看:110
本文介绍了如何以编程方式确定哪个Mac驱动器是启动驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关此问题中有关通过IOKit询问已安装驱动器的详细信息.但是,是否可以确定IOIteratorNext()返回的哪些设备是引导驱动器?或者更好的是,是否有一种方法可以只将IOServiceGetMatchingServices()返回的迭代器中的启动驱动器获取?

Great information on interrogating mounted drives via IOKit in this question. But is there a way to determine which of the devices returned by IOIteratorNext() is the boot drive? Or better yet, might there be a way to get just the boot drive in the iterator returned by IOServiceGetMatchingServices()?

推荐答案

引导是通过媒体完成的,而不是设备本身.设备有媒体,媒体有卷.我不相信IOKit中会显示卷.

Booting is done from media, not a device per se. Devices have media, media have volumes. I don't believe that volumes are represented in IOKit.

这可能是使用磁盘仲裁最简单的方法.将DADiskCreateFromVolumePath()CFURL一起用于/.然后调用DADiskCopyDescription()获取描述字典.这将包括卷,介质,设备甚至总线的属性,如果需要,还包括IOKit路径.不过,很有可能您要查找的信息直接在描述字典中.

This is probably easiest using Disk Arbitration. Use DADiskCreateFromVolumePath() with the CFURL for /. Then call DADiskCopyDescription() to get the description dictionary. That will include properties of the volume, the media, the device, and even the bus, including IOKit paths if you need them. There's a good chance the information you're looking for is directly in the description dictionary, though.

Mark Setchell引用的NVRAM信息也可以从IOKit的路径IOService:/AppleACPIPlatformExpert/AppleEFIRuntime/AppleEFINVRAM获得.有一个属性efi-boot-device.它的值是一个属性列表,其中包括服务匹配字典.如您所见,它将查找提供程序类为IOMedia的条目,该条目的UUID属性是某个UUID.

The NVRAM information cited by Mark Setchell is available from IOKit, too, at path IOService:/AppleACPIPlatformExpert/AppleEFIRuntime/AppleEFINVRAM. There's a property efi-boot-device. Its value is a property list including a service matching dictionary. As you can see, it looks for an entry with provider class of IOMedia whose UUID property is a certain UUID.

这篇关于如何以编程方式确定哪个Mac驱动器是启动驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆