static int rawFileRead()

in hfs/rawfile.c [163:216]


static int rawFileRead(io_func* io,off_t location, size_t size, void *buffer) {
	RawFile* rawFile;
	Volume* volume;
	Extent* extent;

	size_t blockSize;
	off_t fileLoc;
	off_t locationInBlock;
	size_t possible;

	rawFile = (RawFile*) io->data;
	volume = rawFile->volume;
	blockSize = volume->volumeHeader->blockSize;

	if(!rawFile->extents)
		return FALSE;

	extent = rawFile->extents;
	fileLoc = 0;

	locationInBlock = location;
	while(TRUE) {
		fileLoc += extent->blockCount * blockSize;
		if(fileLoc <= location) {
			locationInBlock -= extent->blockCount * blockSize;
			extent = extent->next;
			if(extent == NULL)
				break;
		} else {
			break;
		}
	}

	while(size > 0) {
		if(extent == NULL)
			return FALSE;

		possible = extent->blockCount * blockSize - locationInBlock;

		if(size > possible) {
			ASSERT(READ(volume->image, extent->startBlock * blockSize + locationInBlock, possible, buffer), "READ");
			size -= possible;
			buffer = (void*)(((size_t)buffer) + possible);
			extent = extent->next;
		} else {
			ASSERT(READ(volume->image, extent->startBlock * blockSize + locationInBlock, size, buffer), "READ");
			break;
		}

		locationInBlock = 0;
	}

	return TRUE;
}