Created
December 14, 2019 22:58
-
-
Save dnicolson/19f70c235a0e9172be38571f4c3ffd0f to your computer and use it in GitHub Desktop.
Get the volume UUID (DAVolumeUUID)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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