1/*
2 *  setbootuuid.c
3 *  AppleFileSystemDriver
4 *
5 *  Created by Shantonu Sen on 9/14/07.
6 *  Copyright 2007 Apple Inc. All rights reserved.
7 *
8 */
9
10#include <stdio.h>
11#include <stdarg.h>
12#include <stdlib.h>
13#include <IOKit/IOKitLib.h>
14#include <CoreFoundation/CoreFoundation.h>
15#include <mach/mach_error.h>
16#include <err.h>
17
18void usage(void);
19
20int main(int argc, char *argv[]) {
21
22    CFStringRef uuidstr;
23    CFUUIDRef uuid;
24    io_service_t ioresources = IO_OBJECT_NULL;
25    kern_return_t kret;
26
27    if (argc != 2) {
28        usage();
29    }
30
31    uuidstr = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8);
32    uuid = CFUUIDCreateFromString(kCFAllocatorDefault, uuidstr);
33    if (!uuid) {
34        errx(1, "Invalid UUID string %s", argv[1]);
35    }
36
37    CFRelease(uuid);
38
39    ioresources = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOResourcesClass));
40    if (ioresources == IO_OBJECT_NULL) {
41        errx(1, "Can't find IOResources");
42    }
43
44    kret = IORegistryEntrySetCFProperty(ioresources, CFSTR("boot-uuid"), uuidstr);
45    if (kret) {
46        errx(1, "Can't set boot-uuid: %d %s", kret, mach_error_string(kret));
47    }
48
49    IOObjectRelease(ioresources);
50
51    CFRelease(uuidstr);
52
53    return 0;
54}
55
56void usage(void)
57{
58    fprintf(stderr, "Usage: %s 92DEB3E6-96DE-44CD-BE4F-152A4A4A2365\n", getprogname());
59    exit(1);
60}
61