Skip to content

Instantly share code, notes, and snippets.

@smorr
Last active June 5, 2018 17:39
Show Gist options
  • Save smorr/bb5e08b91a159c9e0d599bb3aef67d17 to your computer and use it in GitHub Desktop.
Save smorr/bb5e08b91a159c9e0d599bb3aef67d17 to your computer and use it in GitHub Desktop.
Quick program to fetch the current FSEventUUID for boot device on macOS
#import <Foundation/Foundation.h>
#include <sys/param.h>
#include <sys/mount.h>
// adapted from http://www.cocoabuilder.com/archive/cocoa/203717-looking-for-sample-code-to-read-uuid-from-disk-volume.html
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
struct statfs stat;
NSString* path = [[@"~" stringByExpandingTildeInPath] stringByStandardizingPath];
if (statfs([[NSFileManager defaultManager] fileSystemRepresentationWithPath:path],&stat)!=0)
{
printf("statfs error %d",errno);
return errno;
}
dev_t device = stat.f_fsid.val[0];
CFUUIDRef uuid = FSEventsCopyUUIDForDevice(device);
CFStringRef uuidStr = CFUUIDCreateString(nil,uuid);
CFRelease(uuid); // CF copy rule
printf("%s",CFStringGetCStringPtr(uuidStr, kCFStringEncodingASCII));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment