Reputation: 496
So I have a USB Mass Storage device, which exposes two disks to the macOS. I get detect the first one using https://stackoverflow.com/users/1412808/rafael-baptista 's article: https://oroboro.com/usb-serial-number-osx/
However, I cannot get the second one using code:
io_registry_entry_t child;
io_iterator_t child_iterator = MACH_PORT_NULL;
kern_return_t kr;
kr = IORegistryEntryCreateIterator(usbDevice,
kIOServicePlane,
kIORegistryIterateRecursively,
&child_iterator);
if (kr != kIOReturnSuccess) {
return;
}
while ((child = IOIteratorNext(child_iterator)) != MACH_PORT_NULL) {
CFStringRef bsdName = NULL;
bsdName = ( CFStringRef ) IORegistryEntrySearchCFProperty(child, kIOServicePlane, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, kIORegistryIterateRecursively );
if ( bsdName ) {
....
I'd appreciate any pointers or information of what I could have done better here.
Thanks.
Upvotes: 1
Views: 785
Reputation: 496
yes. Btw, I found a solution to this. I'm using disk arbitration to discover new drives.
CFDictionaryRef dict = DADiskCopyDescription(disk);
NSDictionary *diskDictionary = (__bridge NSDictionary *)dict;
NSURL *mountPointURL = diskDictionary[(__bridge NSString *)kDADiskDescriptionVolumePathKey];
NSString *deviceMountPath = [mountPointURL path];
NSString *deviceDiskPath = diskDictionary[(__bridge NSString *)kDADiskDescriptionDevicePathKey];
deviceDiskPath will include IOPath, which will include device ID (or name) and VendorID !
Upvotes: 2