Skip to content

Instantly share code, notes, and snippets.

@dnicolson
Created December 14, 2019 22:58
Show Gist options
  • Save dnicolson/19f70c235a0e9172be38571f4c3ffd0f to your computer and use it in GitHub Desktop.
Save dnicolson/19f70c235a0e9172be38571f4c3ffd0f to your computer and use it in GitHub Desktop.
Get the volume UUID (DAVolumeUUID)
// clang -framework DiskArbitration -framework Carbon disk.c -o disk
#include <Carbon/Carbon.h>
void printUUID()
{
DADiskRef disk;
CFDictionaryRef descDict;
DASessionRef session = DASessionCreate(NULL);
const char* mountPoint = "/";
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);
printf("%s\n", CFStringGetCStringPtr(strValue, kCFStringEncodingMacRoman));
CFRelease(strValue);
CFRelease(descDict);
}
CFRelease(disk);
}
CFRelease(url);
CFRelease(session);
}
int main()
{
printUUID();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment