简体   繁体   English

获取USB HDD的序列号(Mac OS)

[英]Get Serial Number of USB HDD (Mac OS)

i've already searched stackoverflow.com and google for an answer but couldn't find anything. 我已经搜索了stackoverflow.com和谷歌的答案,但找不到任何东西。

I've got the bsdName of a partition (disk1s1) which belongs to an external USB HDD (disk1). 我有一个属于外部USB HDD(disk1)的分区(disk1s1)的bsdName。

I need to find out the serial number of that external HDD. 我需要找出外部硬盘的序列号。 I already tried the following (look for a service with the bsd Name): 我已经尝试过以下内容(使用bsd名称查找服务):

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

The Problem with that is: The service type returned is IOMedia which has no field USB Serial Number . 问题是:返回的服务类型是IOMedia ,它没有字段USB Serial Number I end up with the same problem if i use DiskArbitration framework (which is an abstraktion for IOMedia ) 如果我使用DiskArbitration框架(这是IOMedia一个abstraktion),我最终会DiskArbitration同样的问题

So i tried the other way around: Get all IOUSBDevice services iterate over them and just look for the bsdName or partitions on that IOUSBDevice . 所以,我想周围的其他方法:获取所有IOUSBDevice服务遍历他们只需按一下该bsdName或分区IOUSBDevice Unfortunately, there is no information stored about any partitions or bsd names in IOUSBDevice . 不幸的是, IOUSBDevice没有关于任何分区或bsd名称的IOUSBDevice

Can anybody help me with this problem? 任何人都可以帮我解决这个问题吗?

Further information: 更多的信息:

  • XCode 4.3.2 XCode 4.3.2
  • Mac OS X Lion (10.7.3) Mac OS X Lion(10.7.3)

EDIT: Here is the interesting part of the output if i iterate over all IOUSBDevice or AppleUSBEHCI io_services : 编辑:如果我迭代所有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";

} }

As you can see, i get the serial number but i have no possibility to tell which bsd name this device has. 如你所见,我得到序列号,但我无法分辨出这个设备有哪个bsd名称。

I have a tutorial on how to do this in c++. 我有一个关于如何在c ++中执行此操作的教程。 Given an io_service_t, that's the usbDevice in the code snippet below, you get the bsdName like this: 给定一个io_service_t,这是下面代码片段中的usbDevice,你得到的bsdName如下:

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

This is code to get the serial number off of USB Flash disks in C++, but it can probably be adapted to your purposes: 这是用C ++获取USB闪存盘的序列号的代码,但它可能适合您的目的:

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

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

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