title: OSX, usb mass storage discovery
body: <p>I'm trying to discover USB mass storage devices under MAC OSX. I hoped to get the device class, and, on base of that, decide if the device is a mass storage or not. But, for all the usb flash drives I have, I'm getting the device class == 0, which seems to be a composite device. Please, help me to figure out, what am I doing wrong, or, maybe, what is other reliable way to discover USB Mass Storage devices (I need to get PID, VID and mount point). Here is my code:</p>
  
  <pre><code>#import &lt;iostream&gt;
  #import &lt;IOKit/IOkitLib.h&gt;
  #import &lt;IOKit/usb/IOUSBLib.h&gt;
  #import &lt;IOKit/IOCFPlugIn.h&gt;
  #import &lt;IOKit/usb/USBSpec.h&gt;
  #import &lt;CoreFoundation/CoreFoundation.h&gt;
  #import &lt;Foundation/Foundation.h&gt;
  
  int main(int argc, const char * argv[]) {
  CFMutableDictionaryRef matchingDictionary = NULL;
  io_iterator_t foundIterator = 0;
  io_service_t usbDevice;
  matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName);
  IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &amp;foundIterator);
  for(usbDevice = IOIteratorNext(foundIterator); usbDevice; usbDevice = IOIteratorNext(foundIterator))
  {
      IOCFPlugInInterface** plugin = NULL;
      SInt32 theScore=0;
      IOReturn err;
  
      err = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &amp;plugin, &amp;theScore);
      if (err!= 0){
          std::cout&lt;&lt;"error, error code: "&lt;&lt;err_get_code(err) &lt;&lt;std::endl;
      }
      else if (plugin &amp;&amp; *plugin)
      {
          IOUSBDeviceInterface182** usbInterface = NULL;
          (*plugin)-&gt;QueryInterface(plugin, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID182),(LPVOID*)&amp;usbInterface);
          (*plugin)-&gt;Release(plugin);
          if (usbInterface &amp;&amp; *usbInterface)
          {
              UInt8 devClass;
              UInt8 devSubClass;
              UInt16 productId;
              UInt16 vendorID;
  
              //here I'm getting 0 for all my USB flash cards
              (*usbInterface)-&gt;GetDeviceClass(usbInterface,&amp;devClass); 
              (*usbInterface)-&gt;GetDeviceVendor(usbInterface, &amp;vendorID);
              (*usbInterface)-&gt;GetDeviceProduct(usbInterface, &amp;productId);
              (*usbInterface)-&gt;GetDeviceSubClass(usbInterface, &amp;devSubClass);
              std::cout&lt;&lt;"device class: "&lt;&lt;+devClass&lt;&lt;std::endl;
              std::cout&lt;&lt;"device sub class: "&lt;&lt;+devSubClass&lt;&lt;std::endl;
              std::cout&lt;&lt;"vendor ID: "&lt;&lt;vendorID&lt;&lt;std::endl;
              std::cout&lt;&lt;"product ID: "&lt;&lt;productId&lt;&lt;std::endl;
          }
      }
      IOObjectRelease(usbDevice);
  }
  IOObjectRelease(foundIterator);
  return 0;
  </code></pre>
  
  <p>}</p>