Kenny Leung <mailto:[EMAIL PROTECTED]> wrote (Wednesday,
April 9, 2008 11:49 AM -0700):
I am looking for sample code to obtain the UUID. Any pointers are greatly
appreciated!
If you're only running on Leopard, one simply way is to use the
new FSEventsCopyUUIDForDevice() function. I suspect that this
was introduced primarily to make it easier to use file system
events, but it's also a convenient method for just obtaining a
volume's UUID.
// Get the device identifier for the given path
struct statfs stat;
NSString* path = [[pathToAnyItemOnVolume
stringByExpandingTildeInPath] stringByStandardizingPath];
if (statfs([[NSFileManager defaultManager]
fileSystemRepresentationWithPath:path],&stat)!=0)
{
NSLog(@"statfs error %d",errno);
return;
}
dev_t device = stat.f_fsid.val[0];
CFUUIDRef uuid = FSEventsCopyUUIDForDevice(device);
CFStringRef uuidStr = CFUUIDCreateString(uuid);
CFRelease(uuid); // CF copy rule
return ((NSString*)uuidStr);
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]