Exemplo n.º 1
0
status_t
Volume::_Init(uint64 totalBlocks)
{
	fTotalBlocks = totalBlocks;
	if (fTotalBlocks * B_PAGE_SIZE < kCheckSumFSMinSize)
		RETURN_ERROR(B_BAD_VALUE);

	// create a block cache
	fBlockCache = block_cache_create(fFD, fTotalBlocks, B_PAGE_SIZE,
		IsReadOnly());
	if (fBlockCache == NULL)
		RETURN_ERROR(B_NO_MEMORY);

	// create the block allocator
	fBlockAllocator = new(std::nothrow) BlockAllocator(this);
	if (fBlockAllocator == NULL)
		RETURN_ERROR(B_NO_MEMORY);

	return B_OK;
}
Exemplo n.º 2
0
Arquivo: vm.c Projeto: Metaxal/racket
static MMU *mmu_create(NewGC *gc) {
  MMU *mmu = ofm_malloc_zero(sizeof(MMU));
  mmu->gc = gc;

#if !( defined(_WIN32) || defined(OSKIT) )
#ifdef USE_BLOCK_CACHE
  mmu->block_cache = block_cache_create(mmu);
#else
  /* initialization of page_range */
  mmu->page_range = page_range_create();

  /* initialization of alloc_cache */
  mmu->alloc_caches[0] = alloc_cache_create();
  mmu->alloc_caches[1] = alloc_cache_create();
#endif

  mmu->os_pagesize = getpagesize();
#else
  mmu->os_pagesize = APAGE_SIZE;
#endif
  
  return mmu;
}
Exemplo n.º 3
0
void*
DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize)
{
	return fBlockCache = block_cache_create(fDevice, numBlocks, blockSize,
		IsReadOnly());
}
Exemplo n.º 4
0
status_t
ISOMount(const char *path, uint32 flags, iso9660_volume **_newVolume,
	bool allowJoliet)
{
	// path: 		path to device (eg, /dev/disk/scsi/030/raw)
	// partition:	partition number on device ????
	// flags:		currently unused

	// determine if it is an ISO volume.
	char buffer[ISO_PVD_SIZE];
	bool done = false;
	bool isISO = false;
	off_t offset = 0x8000;
	ssize_t retval;
	partition_info partitionInfo;
	int deviceBlockSize, multiplier;
	iso9660_volume *volume;

	(void)flags;

	TRACE(("ISOMount - ENTER\n"));

	volume = (iso9660_volume *)calloc(sizeof(iso9660_volume), 1);
	if (volume == NULL) {
		TRACE(("ISOMount - mem error \n"));
		return B_NO_MEMORY;
	}

	memset(&partitionInfo, 0, sizeof(partition_info));

	/* open and lock the device */
	volume->fdOfSession = open(path, O_RDONLY);

	/* try to open the raw device to get access to the other sessions as well */
	if (volume->fdOfSession >= 0) {
		if (ioctl(volume->fdOfSession, B_GET_PARTITION_INFO, &partitionInfo) < 0) {
			TRACE(("B_GET_PARTITION_INFO: ioctl returned error\n"));
			strcpy(partitionInfo.device, path);
		}
		TRACE(("ISOMount: open device/file \"%s\"\n", partitionInfo.device));

		volume->fd = open(partitionInfo.device, O_RDONLY);
	}

	if (volume->fdOfSession < 0 || volume->fd < 0) {
		close(volume->fd);
		close(volume->fdOfSession);

		TRACE(("ISO9660 ERROR - Unable to open <%s>\n", path));
		free(volume);
		return B_BAD_VALUE;
	}

	deviceBlockSize = get_device_block_size(volume->fdOfSession);
	if (deviceBlockSize < 0)  {
		TRACE(("ISO9660 ERROR - device block size is 0\n"));
		close(volume->fd);
		close(volume->fdOfSession);

		free(volume);
		return B_BAD_VALUE;
	}

	volume->joliet_level = 0;
	while (!done && offset < 0x10000) {
		retval = read_pos(volume->fdOfSession, offset, (void*)buffer,
			ISO_PVD_SIZE);
		if (retval < ISO_PVD_SIZE) {
			isISO = false;
			break;
		}

		if (strncmp(buffer + 1, kISO9660IDString, 5) == 0) {
			if (*buffer == 0x01 && !isISO) {
				// ISO_VD_PRIMARY
				off_t maxBlocks;

				TRACE(("ISOMount: Is an ISO9660 volume, initting rec\n"));

				InitVolDesc(volume, buffer);
				strncpy(volume->devicePath,path,127);
				volume->id = ISO_ROOTNODE_ID;
				TRACE(("ISO9660: volume->blockSize = %d\n", volume->logicalBlkSize[FS_DATA_FORMAT]));

				multiplier = deviceBlockSize / volume->logicalBlkSize[FS_DATA_FORMAT];
				TRACE(("ISOMount: block size multiplier is %d\n", multiplier));

				// if the session is on a real device, size != 0
				if (partitionInfo.size != 0) {
					maxBlocks = (partitionInfo.size + partitionInfo.offset)
						/ volume->logicalBlkSize[FS_DATA_FORMAT];
				} else
					maxBlocks = volume->volSpaceSize[FS_DATA_FORMAT];

				/* Initialize access to the cache so that we can do cached i/o */
				TRACE(("ISO9660: cache init: dev %d, max blocks %Ld\n", volume->fd, maxBlocks));
				volume->fBlockCache = block_cache_create(volume->fd, maxBlocks,
					volume->logicalBlkSize[FS_DATA_FORMAT], true);
				isISO = true;
			} else if (*buffer == 0x02 && isISO && allowJoliet) {
				// ISO_VD_SUPPLEMENTARY

				// JOLIET extension
				// test escape sequence for level of UCS-2 characterset
			    if (buffer[88] == 0x25 && buffer[89] == 0x2f) {
					switch (buffer[90]) {
						case 0x40: volume->joliet_level = 1; break;
						case 0x43: volume->joliet_level = 2; break;
						case 0x45: volume->joliet_level = 3; break;
					}

					TRACE(("ISO9660 Extensions: Microsoft Joliet Level %d\n", volume->joliet_level));

					// Because Joliet-stuff starts at other sector,
					// update root directory record.
					if (volume->joliet_level > 0) {
						InitNode(volume, &volume->rootDirRec, &buffer[156],
							NULL);
					}
				}
			} else if (*(unsigned char *)buffer == 0xff) {
				// ISO_VD_END
				done = true;
			} else
				TRACE(("found header %d\n",*buffer));
		}
		offset += 0x800;
	}

	if (!isISO) {
		// It isn't an ISO disk.
		close(volume->fdOfSession);
		close(volume->fd);
		free(volume);

		TRACE(("ISOMount: Not an ISO9660 volume!\n"));
		return B_BAD_VALUE;
	}

	TRACE(("ISOMount - EXIT, returning %p\n", volume));
	*_newVolume = volume;
	return B_OK;
}