以编程方式检索OS X磁盘分区UUID(Programmatically retrieve an OS X disk partition UUID)

编程入门 行业动态 更新时间:2024-10-28 16:19:17
以编程方式检索OS X磁盘分区UUID(Programmatically retrieve an OS X disk partition UUID)

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

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.

最满意答案

您可以使用磁盘仲裁框架( Apple参考 )。 Chris Suter在这篇博客中也有一个很好的总结。

您可以使用kDADiskDescriptionMediaUUIDKey获取UUID。 Aaron Burghardt在这个邮件列表线程中描述得很好。 以下是该链接的引用:

获得DADisk后,使用DADiskCopyDescription获取属性字典,您可以在其中找到带有密钥kDADiskDescriptionMediaUUIDKey的UUID(有关其他密钥的信息,请参阅DADisk.h)。 请注意,DADisk是IOMedia对象周围的包装,描述字典直接对应于IOMedia对象中的属性。 此外,CFShow()对于将描述字典打印到控制台很有用。

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.

更多推荐

本文发布于:2023-04-27 11:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327071.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:磁盘分区   方式   OS   UUID   partition

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!