簡體   English   中英

IOKit並獲取唯一ID

[英]IOKit and getting unique ID's

我正在使用:IOServiceGetMatchingServices

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

我正在尋找如何查找有關內部HD的信息,因為上述問題可能會影響USB設備。

我似乎找不到列表或任何能告訴我這一點的東西。

本質上,我正在尋找一種從系統獲取唯一ID的方法。 在Windows上,其他開發人員使用硬盤ID。

任何人都可以闡明這些價值觀嗎?

我相信您要做的是查看設備描述符,看看它是否具有序列號。 由設備提供序列號,如果完全提供,則該序列號可能不是唯一的。 如果設備具有自定義描述符,則其中也可能有用。

請參閱以下有關描述符的內容: 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設備並請求所需的數據。

在命令行上,您可以使用ioreg工具瀏覽IO Kit注冊表。 對於Lion或更舊的版本,您還可以使用Apple的硬件IO工具包中的便捷IORegistryExplorer GUI工具。 (在“山獅”上崩潰)

對於查看內部硬盤驅動器屬性,這是一個不錯的開始:

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函數獲得 通過此函數公開的設備屬性似乎未在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