Exemplo n.º 1
0
long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length)
{
    const char *filePath;
    BVRef bvr;

    if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
        return -1;

    if (bvr->fs_readfile == NULL)
        return -1;

    return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
}
Exemplo n.º 2
0
long GetFileBlock(const char *fileSpec, unsigned long long *firstBlock)
{
    const char * filePath;
    BVRef        bvr;

    // Resolve the boot volume from the file spec.

    if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
        printf("Boot volume for '%s' is bogus\n", fileSpec);
        return -1;
    }

    return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock);
}
Exemplo n.º 3
0
long GetFSUUID(char *spec, char *uuidStr)
{
    BVRef      bvr;
    long       rval = -1;
    const char *devSpec;

    if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL)
        return -1;

    if(bvr->fs_getuuid)
        rval = bvr->fs_getuuid(bvr, uuidStr);

    return rval;
}
Exemplo n.º 4
0
long LoadThinFatFile(const char *fileSpec, void **binary)
{
    const char       *filePath;
    FSReadFile readFile;
    BVRef      bvr;
    unsigned long    length, length2;
  
    // Resolve the boot volume from the file spec.

    if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
        return -1;
  
    *binary = (void *)kLoadAddr;
  
    // Read file into load buffer. The data in the load buffer will be
    // overwritten by the next LoadFile() call.

    gFSLoadAddress = (void *) LOAD_ADDR;

    readFile = bvr->fs_readfile;
  
    if (readFile != NULL) {
        // Read the first 4096 bytes (fat header)
        length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000);
        if (length > 0) {
            if (ThinFatFile(binary, &length) == 0) {
				if (length == 0)
					return 0;
                // We found a fat binary; read only the thin part
                length = readFile(bvr, (char *)filePath,
                                  (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length);
                *binary = (void *)kLoadAddr;
            } else {
                // Not a fat binary; read the rest of the file
                length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0);
                if (length2 == -1) return -1;
                length += length2;
            }
        }
    } else {
        length = bvr->fs_loadfile(bvr, (char *)filePath);
        if (length > 0) {
            ThinFatFile(binary, &length);
        }
    }
  
    return length;
}
Exemplo n.º 5
0
static int open_bvr(BVRef bvr, const char *filePath, int flags)
{
	struct iob	*io;
	int		fdesc;
	int		i;

	if (bvr == NULL) {
		return -1;
	}

	fdesc = GetFreeFd();
	io = &iob[fdesc];
	bzero(io, sizeof(*io));

	// Mark the descriptor as taken.
	io->i_flgs = F_ALLOC;

	// Find the next available memory block in the download buffer.
	io->i_buf = (char *) LOAD_ADDR;
	for (i = 0; i < NFILES; i++) {
		if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) {
			continue;
		}
		io->i_buf = max(iob[i].i_filesize + iob[i].i_buf, io->i_buf);
	}

	// Load entire file into memory. Unnecessary open() calls must be avoided.
	gFSLoadAddress = io->i_buf;
	io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
	if (io->i_filesize < 0) {
		close(fdesc);
		return -1;
	}
	return fdesc;
}
Exemplo n.º 6
0
Arquivo: disk.c Projeto: aosm/boot
void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, BOOL verbose )
{
    unsigned char type = (unsigned char) bvr->part_type;
    const char * name = getNameForValue( fdiskTypes, type );
    char *p;

    if (name == NULL)
        name = bvr->type_name;

    p = str;
    if ( name && verbose ) {
        sprintf( str, "hd(%d,%d) ",
                 BIOS_DEV_UNIT(bvr), bvr->part_no);
        for (; strMaxLen > 0 && *p != '\0'; p++, strMaxLen--);
    } else {
        *p = '\0';
    }
    bvr->description(bvr, p, strMaxLen);
    if (*p == '\0') {
        const char * name = getNameForValue( fdiskTypes, type );
        if (name == NULL) {
            name = bvr->type_name;
        }
        if (name == NULL) {
            sprintf(p, "TYPE %02x", type);
        } else {
            strncpy(p, name, strMaxLen);
        }
    }
}
Exemplo n.º 7
0
long GetDirEntry(const char * dirSpec, long * dirIndex, const char ** name, 
                 long * flags, long * time)
{
    const char * dirPath;
    BVRef        bvr;

    // Resolve the boot volume from the dir spec.

    if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL)
        return -1;

    // Return 0 on success, or -1 if there are no additional entries.

    return bvr->fs_getdirentry( bvr,
                /* dirPath */   (char *)dirPath,
                /* dirIndex */  dirIndex,
                /* dirEntry */  (char **)name, flags, time, 0, 0 );
}
Exemplo n.º 8
0
long LoadVolumeFile(BVRef bvr, const char *filePath)
{
    long         fileSize;

    // Read file into load buffer. The data in the load buffer will be
    // overwritten by the next LoadFile() call.

    gFSLoadAddress = (void *) LOAD_ADDR;

    fileSize = bvr->fs_loadfile(bvr, (char *)filePath);

    // Return the size of the file, or -1 if load failed.

    return fileSize;
}