我刚刚遇到一个问题,我可以通过以下代码行获取bsdName,但是如果USB闪存盘中有两个分区,那么我只能获取最后一个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;
}