获取USB HDD的序列号(Mac OS) [英] Get Serial Number of USB HDD (Mac OS)

查看:292
本文介绍了获取USB HDD的序列号(Mac OS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在stackoverflow.com和google上搜索了答案,但是找不到任何东西.

i've already searched stackoverflow.com and google for an answer but couldn't find anything.

我有一个分区(disk1s1)的bsdName,该分区属于一个外部USB HDD(disk1).

I've got the bsdName of a partition (disk1s1) which belongs to an external USB HDD (disk1).

我需要找出该外部HDD的序列号. 我已经尝试了以下方法(寻找具有bsd名称的服务):

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):

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

存在的问题是:返回的服务类型为IOMedia,其中没有字段USB Serial Number.如果使用DiskArbitration framework(这是IOMedia的缩写),我会遇到相同的问题

The Problem with that is: The service type returned is IOMedia which has no field USB Serial Number. I end up with the same problem if i use DiskArbitrationframework (which is an abstraktion for IOMedia)

因此,我尝试了另一种方法:使所有IOUSBDevice服务在它们上进行迭代,然后仅在该IOUSBDevice上查找bsdName或分区.不幸的是,在IOUSBDevice中没有存储有关任何分区或bsd名称的信息.

So i tried the other way around: Get all IOUSBDeviceservices iterate over them and just look for the bsdName or partitions on that IOUSBDevice. Unfortunately, there is no information stored about any partitions or bsd names in IOUSBDevice.

有人可以帮助我解决这个问题吗?

Can anybody help me with this problem?

更多信息:

  • XCode 4.3.2
  • Mac OS X Lion(10.7.3)

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

Here is the interesting part of the output if i iterate over all IOUSBDevice or 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名称.

As you can see, i get the serial number but i have no possibility to tell which bsd name this device has.

推荐答案

我有一个有关如何在c ++中执行此操作的教程.给定io_service_t,即下面的代码片段中的usbDevice,您将获得bsdName,如下所示:

I have a tutorial on how to do this in c++. Given an io_service_t, that's the usbDevice in the code snippet below, you get the bsdName like this:

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

这是从C ++中获取USB闪存盘序列号的代码,但它可能会根据您的目的进行调整:

This is code to get the serial number off of USB Flash disks in C++, but it can probably be adapted to your purposes:

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

这篇关于获取USB HDD的序列号(Mac OS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆