Problem Statement:
Can anyone suggest why in very few mac systems storage device don’t have “IOUSBMassStorageDriverNub” in the “IORegistry”? And in this case which “IOServiceMatching” should be used for storage devices?
Description:
“IOUSBMassStorageDriverNub” is missing in the “IORegistry” of few mac systems (~3—4 out of millions) for Storage devices. As expected storage device appears under “IOUSBDevice” in the “IORegistry” but My intention is to entertain only storage devices not any other peripheral devices like “USB host”, “Key board”, “Mouse”, etc…
In order to receive “IOServiceMatchingCallback“ for newly added storage device into the system, I am using the below code snippet:
void MyClass::registerNotificationsForUSBStorageDevices()
{
CFMutableDictionaryRef matchingDict;
kern_return_t kr;
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
IONotificationPortRef notifyPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopSourceRef runLoopSource = IONotificationPortGetRunLoopSource(notifyPort);
matchingDict = IOServiceMatching("IOUSBMassStorageDriverNub");
matchingDict = (CFMutableDictionaryRef) CFRetain(matchingDict);
kr = IOServiceAddMatchingNotification(notifyPort, kIOFirstMatchNotification, matchingDict,
(IOServiceMatchingCallback)USBStorageDeviceAddedCallback, NULL, &usbDeviceAddedNotification);
//For already connected devices
USBStorageDeviceAddedCallback (NULL, usbDeviceAddedNotification);
CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopDefaultMode);
return;
}