Re: looking for sample code to read UUID from a disk volume.
Re: looking for sample code to read UUID from a disk volume.
- Subject: Re: looking for sample code to read UUID from a disk volume.
- From: James Bucanek <email@hidden>
- Date: Wed, 9 Apr 2008 12:20:44 -0700
Kenny Leung <mailto:email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden