1

問題が 1 つ発生しました。以下のコード行で bsdName を取得できますが、USB フラッシュ ディスクに 2 つのパーティションがある場合、最後の bsdName しか取得できません。 USBドライブ?実際には、各パーティションのボリューム名を取得したいと思います...よろしくお願いします

CFStringRef bsdName = ( CFStringRef ) IORegistryEntrySearchCFProperty ( usbDevice,
                                                                               kIOServicePlane,
                                                                               CFSTR ( kIOBSDNameKey ),
                                                                               kCFAllocatorDefault,
                                                                               kIORegistryIterateRecursively );
        NSLog(@"bsdName=%@",bsdName);
        volumeName = deviceNameWithMountPath((NSString*)bsdName);
        //find_hid_device(usbDevice);
        NSLog(@"volume Name=%@",volumeName);

        NSString *mediaType = FindWholeMedia(usbDevice);
        NSLog(@"media type = %@",mediaType);

        //CFRelease(bsdName);

        // Done with this USB device; release the reference added by IOIteratorNext
        kr = IOObjectRelease(usbDevice);        
    }
}



NSString *deviceNameWithMountPath(NSString *mountPath)
{
    DASessionRef session = NULL;
    DADiskRef disk = NULL;
    CFDictionaryRef dd = NULL;
    CFTypeRef val = nil;

    session = DASessionCreate(kCFAllocatorDefault);
    if (!session) {
        NSLog(@"Can't create DiskArb session");
        return nil;
    }

//    DASessionScheduleWithRunLoop(session,
//                                 CFRunLoopGetCurrent(),
//                                 kCFRunLoopDefaultMode);
//    
//    DARegisterDiskAppearedCallback(session, NULL, DiskAppeared, NULL);


    disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, [mountPath UTF8String]);
    if (!disk) {
        NSLog(@"DADiskCreateFromBSDName(%s) failed", [mountPath UTF8String]);
        return nil;
    }
    dd = DADiskCopyDescription(disk);
    if (!dd) {
        NSLog(@"DADiskCopyDescription(%s) failed", [mountPath UTF8String]);
        return nil;
    }

    CFDictionaryGetValueIfPresent(dd, (kDADiskDescriptionVolumeNameKey), &val);
    DiskAppeared(disk, NULL);
    CFRelease(disk);
    CFRelease(session); 

    return (NSString *)val;
}
4

0 に答える 0