IOKit并获得唯一ID

时间:2013-03-04 21:46:34

标签: c++ macos iokit

我正在使用:IOServiceGetMatchingServices

kr = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceNameMatching("AppleUSBEHCI"), &io_objects);

我正在寻找如何找到有关内部HD的信息,因为上面会探讨USB设备。

我似乎无法找到列表或任何可以告诉我这一点的内容。

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

任何人都可以对这些价值观有所了解吗?

2 个答案:

答案 0 :(得分:1)

我相信你想要做的是查看设备描述符并查看它是否有序列号。设备需要提供序列号,如果提供该号码,则该号码可能不是唯一的。如果设备有自定义描述符,那么也可能有用。

请参阅以下有关描述符: 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 :(得分:0)

在命令行上,您可以使用ioreg工具来浏览IO Kit注册表。对于Lion或Older,您还可以使用Apple的Hardware IO Tools软件包中方便的IORegistryExplorer GUI工具。 (它在Mountain Lion上崩溃了)

要查看内部硬盘驱动器属性,这是一个非常好的开始:

ioreg -irc IOAHCIBlockStorageDevice -w 0

我MacBook Air上的产量:

+-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头文件之外记录,但它们是相当不言自明的,例如:

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     ) */