Hey everyone. In my app, I need a way to uniquely identify USB drives. Right now, I’m doing it by UUID, and I’m getting it with this code:
+ (NSUUID *)uuidForDeviceName:(NSString *)name {
DADiskRef disk = NULL;
CFDictionaryRef descDict;
DASessionRef session = DASessionCreate(NULL);
if (session) {
const char *mountPoint = [name
cStringUsingEncoding:NSASCIIStringEncoding];
CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL,
(const UInt8 *)mountPoint, strlen(mountPoint), TRUE);
disk = DADiskCreateFromVolumePath(NULL, session, url);
if (disk) {
descDict = DADiskCopyDescription(disk);
if (descDict) {
CFTypeRef value =
(CFTypeRef)CFDictionaryGetValue(descDict,
CFSTR("DAVolumeUUID"));
CFStringRef strValue =
CFStringCreateWithFormat(NULL, NULL,
CFSTR("%@"), value);
//NSLog(@"%@", strValue);
CFRelease(descDict);
NSUUID *uuid = [[NSUUID alloc]
initWithUUIDString:CFBridgingRelease(strValue)];
//SBLogObject([uuid UUIDString]);
return uuid;
} else {
NSLog(@"Sorry, no Disk Arbitration
description.");
}
CFRelease(disk);
} else {
NSLog(@"Sorry, no Disk Arbitration disk.");
}
} else {
NSLog(@"Sorry, no Disk Arbitration session.");
}
return nil;
}
Unfortunately, there is a problem. It only seems to work with HFS+ drives. It
cannot get the UUID of a FAT 32-formatted drive, which is what my problem
typically requires.
Is there any supported way to get the UUID of a FAT-formatted drive? Or another
method which can uniquely identify USBs of all major filesystem types?
Thanks in advance to anyone who helps.
— SevenBits
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
