Exemplo n.º 1
0
status_t
Volume::Initialize(const char* name)
{
	fName = strdup(name);
	if (fName == NULL)
		return B_NO_MEMORY;

	status_t error = fBlockAllocator->Initialize();
	if (error != B_OK)
		return error;

	// create the root directory
	error = CreateDirectory(S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH,
		fRootDirectory);
	if (error != B_OK)
		return error;

	error = fRootDirectory->Flush();
	if (error != B_OK)
		return error;

	// write the super block
	Block block;
	if (!block.GetZero(this, kCheckSumFSSuperBlockOffset / B_PAGE_SIZE))
		return B_ERROR;

	SuperBlock* superBlock = (SuperBlock*)block.Data();
	superBlock->Initialize(this);

	block.Put();

	return block_cache_sync(fBlockCache);
}
Exemplo n.º 2
0
status_t
DirEntryTree::_InsertEntrySplitBlock(int32 level, LevelInfo& info,
	size_t needed, Transaction& transaction, Block& newBlock,
	int32& _splitIndex)
{
	int32 splitIndex = info.entryBlock.FindSplitIndex(info.index,
		needed);

	FUNCTION("level: %" B_PRId32 ", size needed: %" B_PRIuSIZE ", split index: "
		"%" B_PRId32 "/%" B_PRId32 "\n", level, needed, splitIndex,
		info.entryBlock.EntryCount());

	// allocate a new block
	AllocatedBlock allocatedBlock(
		fDirectory->GetVolume()->GetBlockAllocator(), transaction);

	status_t error = allocatedBlock.Allocate(fDirectory->BlockIndex());
	if (error != B_OK)
		RETURN_ERROR(error);
	fDirectory->SetSize(fDirectory->Size() + B_PAGE_SIZE);

	if (!newBlock.GetZero(fDirectory->GetVolume(), allocatedBlock.Index(),
			transaction)) {
		RETURN_ERROR(B_ERROR);
	}

	allocatedBlock.Detach();

	// split the old block
	DirEntryBlock newEntryBlock(
		(checksumfs_dir_entry_block*)newBlock.Data(), B_PAGE_SIZE);
ASSERT(newEntryBlock.Check());
	info.entryBlock.SplitBlock(splitIndex, newEntryBlock);

	PRINT("  -> new block: %" B_PRIu64 "\n", newBlock.Index());

	_splitIndex = splitIndex;
	return B_OK;
}