BLDumpVolumeFinderInfo.c [plain text]
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/param.h>
#include <CoreFoundation/CoreFoundation.h>
#include "bless.h"
#include "bless_private.h"
int BLCreateVolumeInformationDictionary(BLContextPtr context, const char * mountpoint,
CFDictionaryRef *outDict) {
uint32_t finderinfo[8];
int err;
uint32_t i;
uint32_t dirID;
CFMutableDictionaryRef dict = NULL;
CFMutableArrayRef infarray = NULL;
char blesspath[MAXPATHLEN];
err = BLGetVolumeFinderInfo(context, mountpoint, finderinfo);
if(err) {
return 1;
}
infarray = CFArrayCreateMutable(kCFAllocatorDefault,
8,
&kCFTypeArrayCallBacks);
dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 3, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
for(i = 0; i< 8-2; i++) {
CFMutableDictionaryRef word =
CFDictionaryCreateMutable(kCFAllocatorDefault,6, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFTypeRef val;
dirID = finderinfo[i];
blesspath[0] = '\0';
err = BLLookupFileIDOnMount(context, mountpoint, dirID, blesspath);
val = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &dirID);
CFDictionaryAddValue(word, CFSTR("Directory ID"), val);
CFRelease(val); val = NULL;
val = CFStringCreateWithCString(kCFAllocatorDefault, blesspath, kCFStringEncodingUTF8);
CFDictionaryAddValue(word, CFSTR("Path"), val);
CFRelease(val); val = NULL;
if(strlen(blesspath) == 0 || 0 == strcmp(mountpoint, "/")) {
val = CFStringCreateWithCString(kCFAllocatorDefault, blesspath, kCFStringEncodingUTF8);
} else {
val = CFStringCreateWithCString(kCFAllocatorDefault, blesspath+strlen(mountpoint), kCFStringEncodingUTF8);
}
CFDictionaryAddValue(word, CFSTR("Relative Path"), val);
CFRelease(val); val = NULL;
CFArrayAppendValue(infarray, word);
CFRelease(word); word = NULL;
}
CFDictionaryAddValue(dict, CFSTR("Finder Info"),
infarray);
CFRelease(infarray); infarray = NULL;
{
CFNumberRef vsdbref = NULL;
uint64_t vsdb;
vsdb = (*(uint64_t *)&finderinfo[8-2]);
vsdbref = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &vsdb);
CFDictionaryAddValue(dict, CFSTR("VSDB ID"), vsdbref);
CFRelease(vsdbref); vsdbref = NULL;
}
*outDict = dict;
return 0;
}