【问题标题】:Get Serial Number of USB HDD (Mac OS)获取 USB 硬盘的序列号 (Mac OS)
【发布时间】:2012-08-11 01:41:26
【问题描述】:

我已经在 stackoverflow.com 和谷歌上搜索了答案,但没有找到任何答案。

我得到了属于外部 USB 硬盘 (disk1) 的分区 (disk1s1) 的 bsdName。

我需要找出那个外置硬盘的序列号。 我已经尝试了以下方法(寻找具有 bsd 名称的服务):

io_service_t io_service = IOServiceGetMatchingService(kIOMasterPortDefault,IOBSDNameMatching(kIOMasterPortDefault, 0, [@"disk1" cStringUsingEncoding:NSUTF8StringEncoding]));

问题在于:返回的服务类型是IOMedia,它没有字段USB Serial Number。如果我使用DiskArbitrationframework(这是IOMedia 的抽象),我最终会遇到同样的问题

所以我尝试了另一种方法:让所有IOUSBDeviceservices 对其进行迭代,然后在IOUSBDevice 上查找bsdName 或分区。不幸的是,IOUSBDevice 中没有存储有关任何分区或 bsd 名称的信息。

谁能帮我解决这个问题?

更多信息:

  • XCode 4.3.2
  • Mac OS X Lion (10.7.3)

编辑: 如果我遍历所有 IOUSBDevice 或 AppleUSBEHCI io_services,这是输出中有趣的部分:

Child props: {
"Bus Power Available" = 250;
"Device Speed" = 2;
IOCFPlugInTypes =     {
    "9dc7b780-9ec0-11d4-a54f-000a27052861" = "IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle";
};
IOGeneralInterest = "IOCommand is not serializable";
IOUserClientClass = IOUSBDeviceUserClientV2;
"Low Power Displayed" = 0;
PortNum = 3;
"Requested Power" = 250;
"USB Address" = 6;
"USB Product Name" = "Mass Storage Device";
"USB Serial Number" = 09021000000000003740385375;
"USB Vendor Name" = JetFlash;
bDeviceClass = 0;
bDeviceProtocol = 0;
bDeviceSubClass = 0;
bMaxPacketSize0 = 64;
bNumConfigurations = 1;
bcdDevice = 2560;
iManufacturer = 1;
iProduct = 2;
iSerialNumber = 3;
idProduct = 4096;
idVendor = 34148;
kHasMSCInterface = 1;
locationID = "-99418112";
sessionID = 209792844564562;
uid = "USB:85641000003740385375";

}

如你所见,我得到了序列号,但我无法确定该设备的 bsd 名称。

【问题讨论】:

  • 您好 elppa,感谢您的回答,但您链接中的解决方案正是我已经尝试过的:迭代所有 IOUSBDevices - 这是 AppleUSBEHCI 的一个子集。如果我尝试这种方法,我找不到任何关于 bsd 名称或分区的信息。也许我只是错过了一些东西。在那种情况下:你能给我更多的信息吗?
  • 注意:这不是硬盘序列号。这是USB序列号,它们是两个不同的东西。 (这也是为什么你看不到硬盘名称的原因。即因为这只是一个USB接口,而不是硬盘接口)。

标签: objective-c xcode macos usb


【解决方案1】:

我有一个关于如何在 c++ 中执行此操作的教程。给定一个 io_service_t,即下面代码 sn-p 中的 usbDevice,你会得到这样的 bsdName:

     bsdName = ( CFStringRef ) IORegistryEntrySearchCFProperty( 
        usbDevice,
        kIOServicePlane,
        CFSTR( kIOBSDNameKey ),
        kCFAllocatorDefault,
        kIORegistryIterateRecursively )

这是在 C++ 中获取 USB 闪存盘序列号的代码,但它可能适合您的目的:

http://oroboro.com/usb-serial-number-osx/

【讨论】:

  • 别忘了加#import <IOKit/IOBSD.h>
猜你喜欢
  • 2011-01-02
  • 1970-01-01
  • 2011-05-04
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 2016-06-10
相关资源
最近更新 更多