4

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

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

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]));

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)

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?

Further information:

  • XCode 4.3.2
  • 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 :

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.

P.Chouhan
  • 41
  • 1
  • 3
  • So Question http://stackoverflow.com/questions/2019244/how-to-get-serial-number-from-mac-hard-disks – Deepesh Apr 27 '12 at 09:43
  • Hi elppa, thanks for your answer but the solution in your link is exactly what i have already tried: iterated over all IOUSBDevices - which is a subset of AppleUSBEHCI. I can't find any information about bsd names or partitions if i try this approach. Maybe i'm just missing something. In that case: could you please give me more information? – P.Chouhan Apr 27 '12 at 10:25
  • Note: that is NOT the hard drive serial number. It is the USB serial number, they are two different things. (That is also why you dont see the hard disk name. I.e. because this is simply a USB interface, not hard drive interface). – chacham15 Apr 26 '13 at 23:14

1 Answers1

2

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 )

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/

Rafael Baptista
  • 11,181
  • 5
  • 39
  • 59