获取所有 USB 大容量存储设备的列表

Get list of all USB Mass Storage devices

所以我有一个 USB 大容量存储设备,它向 macOS 公开了两个磁盘。 我使用 https://whosebug.com/users/1412808/rafael-baptista 的文章检测到第一个: https://oroboro.com/usb-serial-number-osx/

但是,我无法使用代码获得第二个:

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 ) {
....

对于我可以在这里做得更好的任何指示或信息,我将不胜感激。

谢谢。

是的。顺便说一句,我找到了解决办法。我正在使用磁盘仲裁来发现新驱动器。

  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 将包含 IOPath,IOPath 将包含设备 ID(或名称)和 VendorID!