首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOKit和获取唯一ID

IOKit和获取唯一ID
EN

Stack Overflow用户
提问于 2013-03-05 05:46:34
回答 2查看 2.3K关注 0票数 2

我正在使用: IOServiceGetMatchingServices

代码语言:javascript
复制
kr = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceNameMatching("AppleUSBEHCI"), &io_objects);

我正在寻找我如何找到有关内部硬盘的信息,因为以上将探测USB设备。

我似乎找不到一个列表或任何可以告诉我这一点的东西。

本质上,我正在寻找一种从系统中获得唯一ID的方法。在Windows上,其他开发人员使用硬盘id。

有人能解释一下这些价值观吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-05 06:29:12

在命令行上,您可以使用ioreg工具浏览IO工具包注册表。对于Lion或更早的版本,您还可以使用苹果硬件IO工具包中方便的IORegistryExplorer图形用户界面工具。(它在Mountain Lion上坠毁)

对于查看内部硬盘驱动器属性,这是一个很好的开始:

代码语言:javascript
复制
ioreg -irc IOAHCIBlockStorageDevice -w 0

在我的MacBook Air上产生了以下结果:

代码语言:javascript
复制
+-o IOAHCIBlockStorageDevice  <class IORegistryEntry:IOService:IOBlockStorageDevice:IOAHCIBlockStorageDevice, id 0x100000216, registered, matched, active, busy 0 (472 ms), retain 7>
  | {
  |   "IOCFPlugInTypes" = {"24514B7A-2804-11D6-8A02-003065704866"="SMARTLib.plugin"}
  |   "device-type" = "Generic"
  |   "IOStorageFeatures" = {"Unmap"=Yes}
  |   "Device Characteristics" = {"Logical Block Size"=512,"Product Name"="APPLE SSD TS256C                        ","Medium Type"="Solid State","Physical Block Size"=512,"SATA Features"=23,"Serial Number"="        X06S10H7THRZ","Product Revision Level"="CJAA0201"}
  |   "Protocol Characteristics" = {"Physical Interconnect"="SATA","Physical Interconnect Location"="Internal"}
  |   "SMART Capable" = Yes
  |   "IOMinimumSegmentAlignmentByteCount" = 4
  | }
  | 
  +-o IOBlockStorageDriver  <class IORegistryEntry:IOService:IOStorage:IOBlockStorageDriver, id 0x100000219, registered, matched, active, busy 0 (471 ms), retain 8>
    +-o APPLE SSD TS256C Media  <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x10000021a, registered, matched, active, busy 0 (471 ms), retain 11>
      +-o IOMediaBSDClient  <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x10000021b, registered, matched, active, busy 0 (0 ms), retain 6>
      +-o IOGUIDPartitionScheme  <class IORegistryEntry:IOService:IOStorage:IOPartitionScheme:IOGUIDPartitionScheme, id 0x10000021d, !registered, !matched, active, busy 0 (3 ms), retain 8>
        +-o EFI system partition@1  <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x100000263, registered, matched, active, busy 0 (0 ms), retain 9>
        | +-o IOMediaBSDClient  <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x100000266, registered, matched, active, busy 0 (0 ms), retain 6>
        +-o Customer@2  <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x100000264, registered, matched, active, busy 0 (2 ms), retain 11>
        | +-o IOMediaBSDClient  <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x100000267, registered, matched, active, busy 0 (0 ms), retain 7>
        +-o Recovery HD@3  <class IORegistryEntry:IOService:IOStorage:IOMedia, id 0x100000265, registered, matched, active, busy 0 (3 ms), retain 9>
          +-o IOMediaBSDClient  <class IORegistryEntry:IOService:IOMediaBSDClient, id 0x100000268, registered, matched, active, busy 0 (0 ms), retain 6>

您可以通过IOKit用户库以编程方式获取这些属性,正如您已经在USB中发现的那样。

在更高的层次上,一些信息也可以通过磁盘仲裁框架,通过DADiskCopyDescription function获得。通过此函数公开的设备属性似乎没有记录在DADisk.h头文件之外,但它们是不言而喻的,例如:

代码语言:javascript
复制
extern const CFStringRef kDADiskDescriptionDeviceGUIDKey;      /* ( CFData       ) */
extern const CFStringRef kDADiskDescriptionDeviceInternalKey;  /* ( CFBoolean    ) */
extern const CFStringRef kDADiskDescriptionDeviceModelKey;     /* ( CFString     ) */
extern const CFStringRef kDADiskDescriptionDevicePathKey;      /* ( CFString     ) */
extern const CFStringRef kDADiskDescriptionDeviceProtocolKey;  /* ( CFString     ) */
extern const CFStringRef kDADiskDescriptionDeviceRevisionKey;  /* ( CFString     ) */
extern const CFStringRef kDADiskDescriptionDeviceUnitKey;      /* ( CFNumber     ) */
extern const CFStringRef kDADiskDescriptionDeviceVendorKey;    /* ( CFString     ) */
票数 0
EN

Stack Overflow用户

发布于 2013-03-05 05:59:51

我相信您想要做的是查看设备描述符,看看它是否有序列号。由设备提供序列号,如果提供了序列号,则该序列号可能不是唯一的。如果设备有一个自定义描述符,那么其中也可能有用处。

有关描述符,请参阅以下内容:http://www.beyondlogic.org/usbnutshell/usb5.shtml

似乎有一个属性可以获取HID设备包装类上的序列号:

https://developer.apple.com/library/mac/#documentation/IOKit/Reference/IOHIDBase_header_reference/Reference/reference.html#//apple_ref/doc/uid/TP40012400

如果这不起作用,应该有一种方法可以直接访问USB设备并请求所需的数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15211748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档