How do I get the Hard Drive serial number of a USB drive on OS X?

c, c++, macos

Solution

What you are basically asking is "How do I directly communicate with a hard drive over USB?"

The answer is: It depends on the USB controller. Not all controllers support your request.

The following conditions must exist:

- The USB bridge must support ATA pass-through (if ATA)

- SCSI must be supported on the host OS

- The OS must provide a SCSI pass-through API (Yes on Windows and Linux, No on MacOS X)

Another factor arises: Some controllers support drive manufacturer-independent passthroughs, but some support different commands based on the hard drive they are controlling. This also depends on whether the attached drive is PATA, SATA/SAS, or SCSI.

Examples of controllers that support at least one of the above include Sunplus SPIF215/6, SPIF225/6; JMicron JM20329, JM20335-39; and Cypress CY7C68300B/C (AT2LP), CY7C68310 (ISD-300LP).

Wish I had happier news for you.

Problem

I have looked at `DADiskCopyDescription` and enumerating `IOUSBDevice` from IOKit and neither provide me with the serial number of the USB hard drive. The latter provides a USB Serial number which is not equivalent to its hard drive serial number. How do I get that (in c/c++, NOT via the shell)?

Original source