以编程方式检索OS X磁盘分区UUID [英] Programmatically retrieve an OS X disk partition UUID

查看:118
本文介绍了以编程方式检索OS X磁盘分区UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分区路径.如何在不使用终端命令的情况下以编程方式检索该分区的UUID?一个例子会更有帮助.

解决方案

您可以使用磁盘仲裁框架(博客上也有一个很好的摘要. >

您可以使用kDADiskDescriptionMediaUUIDKey来获取UUID.亚伦·伯格哈特(Aaron Burghardt)在此邮件列表 thread 中对此进行了很好的描述.这是该链接的引文:

一旦有了DADisk,请使用DADiskCopyDescription来获取属性字典,在该字典中 使用密钥kDADiskDescriptionMediaUUIDKey查找UUID(有关其他密钥,请参见DADisk.h). 兴趣).注意,DADisk是IOMedia对象和描述字典的包装器 直接对应于IOMedia对象中的属性.另外,CFShow()可用于打印 描述字典到控制台.

I have a path to a partition. How can I retrieve UUID of that partition programatically without using terminal commands? An example will be more helpful.

解决方案

You can use the Disk Arbitration framework (Apple reference). There is also a good summary at this blog by Chris Suter.

You can get the UUID by using the kDADiskDescriptionMediaUUIDKey. Aaron Burghardt described it well in this mailing list thread. Here is a quote from that link:

Once you have the DADisk, use DADiskCopyDescription to get a dictionary of properties, in which you will find the UUID with the key kDADiskDescriptionMediaUUIDKey (see DADisk.h for other keys that may be of interest). Note, a DADisk is a wrapper around an IOMedia object and the description dictionary corresponds directly to the properties in the IOMedia object. Also, CFShow() is useful for printing the description dictionary to the console.

这篇关于以编程方式检索OS X磁盘分区UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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