BLGetRAIDBootDataForDevice.c [plain text]
#include <stdlib.h>
#include <unistd.h>
#include <mach/mach_error.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOKitKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#include "bless.h"
#include "bless_private.h"
#if SUPPORT_RAID
#include <IOKit/storage/RAID/AppleRAIDUserLib.h>
int BLGetRAIDBootDataForDevice(BLContextPtr context, const char * device,
CFTypeRef *bootData)
{
const char *name = NULL;
kern_return_t kret;
mach_port_t ourIOKitPort;
io_service_t service;
io_iterator_t serviter;
CFTypeRef data = NULL;
*bootData = NULL;
if(!device || 0 != strncmp(device, "/dev/", 5)) return 1;
name = device + 5;
if((kret = IOMasterPort(bootstrap_port, &ourIOKitPort)) != KERN_SUCCESS) {
return 2;
}
kret = IOServiceGetMatchingServices(ourIOKitPort,
IOBSDNameMatching(ourIOKitPort,
0, name),
&serviter);
if (kret != KERN_SUCCESS) {
return 3;
}
service = IOIteratorNext(serviter);
if (!service) {
IOObjectRelease(serviter);
return 3;
}
IOObjectRelease(serviter);
data = IORegistryEntrySearchCFProperty( service,
kIOServicePlane,
CFSTR(kIOBootDeviceKey),
kCFAllocatorDefault,
kIORegistryIterateRecursively|
kIORegistryIterateParents);
if(data == NULL) {
IOObjectRelease(service);
return 0;
}
IOObjectRelease(service);
if(CFGetTypeID(data) == CFArrayGetTypeID()) {
} else if(CFGetTypeID(bootData) == CFDictionaryGetTypeID()) {
} else {
contextprintf(context, kBLLogLevelError, "Invalid RAID boot data\n" );
return 3;
}
*bootData = data;
return 0;
}
#endif // SUPPORT_RAID