简体   繁体   English

IOKit并获取唯一ID

[英]IOKit and getting unique ID's

I am using: IOServiceGetMatchingServices 我正在使用:IOServiceGetMatchingServices

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

I am looking for how I find out information about the internal HD as the above will prob USB device. 我正在寻找如何查找有关内部HD的信息,因为上述问题可能会影响USB设备。

I cannot seem to find a list or anything that would tell me this. 我似乎找不到列表或任何能告诉我这一点的东西。

Essentially I am looking for a way to get a unique ID from the system. 本质上,我正在寻找一种从系统获取唯一ID的方法。 On Windows the other developer uses the hard disk id. 在Windows上,其他开发人员使用硬盘ID。

Can anyone shed some light on these values? 任何人都可以阐明这些价值观吗?

I believe what you want to do is to look at the device descriptor and see if it has a serial number. 我相信您要做的是查看设备描述符,看看它是否具有序列号。 It is up to the device to supply a serial number, and it's possible that the number may not be unique if it is provided at all. 由设备提供序列号,如果完全提供,则该序列号可能不是唯一的。 If the device has a custom descriptor, there may be useful in there too. 如果设备具有自定义描述符,则其中也可能有用。

See the following on descriptors: http://www.beyondlogic.org/usbnutshell/usb5.shtml 请参阅以下有关描述符的内容: http : //www.beyondlogic.org/usbnutshell/usb5.shtml

There appears to be a property to get the serial number on the HID Device wrapper class: 在HID设备包装器类上似乎有一个用于获取序列号的属性:

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

If that doesn't work, there should be a way to get direct access to the USB device and request the data you need. 如果这不起作用,则应该有一种方法可以直接访问USB设备并请求所需的数据。

On the command line, you can use the ioreg tool to explore the IO Kit registry. 在命令行上,您可以使用ioreg工具浏览IO Kit注册表。 For Lion or Older, you can also use the convenient IORegistryExplorer GUI tool from Apple's Hardware IO Tools package. 对于Lion或更旧的版本,您还可以使用Apple的硬件IO工具包中的便捷IORegistryExplorer GUI工具。 (it crashes on Mountain Lion) (在“山狮”上崩溃)

For looking at internal hard drive properties, this is a pretty good start: 对于查看内部硬盘驱动器属性,这是一个不错的开始:

ioreg -irc IOAHCIBlockStorageDevice -w 0

Which on my MacBook Air yields: 在我的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>

You can get at these properties programmatically via the IOKit user library as you've already discovered for USB. 您可以通过IOKit用户库以编程方式获得这些属性,就像您已经发现的USB一样。

At a somewhat higher level, some of the information is also available via the Disk Arbitration Framework, via the DADiskCopyDescription function . 从某种程度上讲,某些信息也可以通过磁盘仲裁框架,通过DADiskCopyDescription函数获得 The device properties exposed via this function don't seem to be documented outside the DADisk.h header file, but they're fairly self-explanatory, eg: 通过此函数公开的设备属性似乎未在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     ) */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM