2017-06-27 41 views
1

因此,我有一個USB大容量存儲設備,它將兩個磁盤暴露給macOS。 我得到檢測用https://stackoverflow.com/users/1412808/rafael-baptista的文章第一個: https://oroboro.com/usb-serial-number-osx/獲取所有USB大容量存儲設備的列表

但是,使用代碼我不能得到第二個:

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

我會很感激的是我可以有任何指針或信息在這裏做得更好。

謝謝。

+0

你的'usbDevice'句柄來自哪裏?當然,這是這個問題的關鍵。 – pmdj

+0

它來自usbDevice = IOIteratorNext(iterator),它是檢測到新匹配設備時獲得的迭代器。我不認爲它是一個問題。 – GregJaskiewicz

+0

那麼,你是否在迭代多個usbDevices?這部分工作嗎? – pmdj

回答

1

是的。順便說一句,我找到了解決辦法。我正在使用磁盤仲裁來發現新驅動器。

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,其中將包括設備ID(或名稱)和VendorID!