BLGetBootBlockData.c [plain text]
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <string.h>
#include "compatCarbon.h"
#include "bless.h"
#define SYSTEM "\pSystem"
static int getBootBlocksFromFSSpec(FSSpec systemFile, unsigned char bootBlocks[]) {
SInt16 fRefNum;
Handle bbH;
int err = 0;
bzero(bootBlocks, 1024);
fRefNum = _BLFSpOpenResFile(&systemFile, fsRdPerm);
if (fRefNum == -1) {
return 3;
}
bbH = _BLGet1Resource('boot', 1);
if (!bbH) {
return 4;
}
_BLDetachResource(bbH);
memcpy(bootBlocks, *bbH, 1024);
_BLDisposeHandle(bbH);
_BLCloseResFile(fRefNum);
return err;
}
int BLGetBootBlocksFromFolder(BLContext context, unsigned char mountpoint[], u_int32_t dir9, unsigned char bootBlocks[]) {
FSSpec spec, systemFile;
int err;
err = _BLNativePathNameToFSSpec(mountpoint, &spec, 0);
if(err) {
return 1;
}
err = _BLFSMakeFSSpec(spec.vRefNum, dir9, SYSTEM , &systemFile);
if(err) {
return 2;
}
err = getBootBlocksFromFSSpec(systemFile, bootBlocks);
if(err) {
return err;
}
return 0;
}
int BLGetBootBlocksFromFile(BLContext context, unsigned char file[], unsigned char bootBlocks[]) {
FSSpec spec;
int err;
err = _BLNativePathNameToFSSpec(file, &spec, 0);
if(err) {
return 1;
}
err = getBootBlocksFromFSSpec(spec, bootBlocks);
if(err) {
return err;
}
return 0;
}
int BLGetBootBlocksFromDataForkFile(BLContext context, unsigned char file[], unsigned char bootBlocks[]) {
int fd;
int err;
fd = open(file, O_RDONLY, 0);
if(fd == -1) {
return 1;
}
err = read(fd, bootBlocks, 1024);
if(err != 1024) {
close(fd);
return 2;
}
close(fd);
return 0;
}