Beispiel #1
0
status_t
Inode::EnableFileCache()
{
	TRACE("Inode::EnableFileCache()\n");

	if (fCached)
		return B_OK;
	if (fCache != NULL) {
		fCached = true;
		return B_OK;
	}

	TRACE("Inode::EnableFileCache(): Creating file cache: %ld, %lld, %lld\n",
		fVolume->ID(), ID(), Size());
	fCache = file_cache_create(fVolume->ID(), ID(), Size());
	fMap = file_map_create(fVolume->ID(), ID(), Size());

	if (fCache == NULL) {
		ERROR("Inode::EnableFileCache(): Failed to create file cache\n");
		fCached = false;
		return B_ERROR;
	}

	fCached = true;
	TRACE("Inode::EnableFileCache(): Done\n");

	return B_OK;
}
Beispiel #2
0
status_t
Inode::CreateFileCache()
{
	TRACE("Inode::CreateFileCache()\n");

	if (fCache != NULL)
		return B_OK;

	TRACE("Inode::CreateFileCache(): Creating file cache: %" B_PRIu32 ", %"
		B_PRIdINO ", %" B_PRIdOFF "\n", fVolume->ID(), ID(), Size());

	fCache = file_cache_create(fVolume->ID(), ID(), Size());
	if (fCache == NULL) {
		ERROR("Inode::CreateFileCache(): Failed to create file cache\n");
		return B_ERROR;
	}

	fMap = file_map_create(fVolume->ID(), ID(), Size());
	if (fMap == NULL) {
		ERROR("Inode::CreateFileCache(): Failed to create file map\n");
		file_cache_delete(fCache);
		fCache = NULL;
		return B_ERROR;
	}

	TRACE("Inode::CreateFileCache(): Done\n");

	return B_OK;
}
Beispiel #3
0
/** Get an inode from an Ext2 filesystem.
 * @note		Node creation/lookup are protected by the mount lock,
 *			meaning this function does not need to lock.
 * @param mount		Mount to read from.
 * @param num		Inode number to read.
 * @param inodep	Where to store pointer to inode structure.
 * @return		Status code describing result of the operation. */
status_t ext2_inode_get(ext2_mount_t *mount, uint32_t num, ext2_inode_t **inodep) {
	ext2_inode_t *inode = NULL;
	size_t group, bytes;
	offset_t offset;
	status_t ret;

	/* Get the group descriptor table containing the inode. */
	group = (num - 1) / mount->inodes_per_group;
	if(group >= mount->block_groups) {
		dprintf("ext2: group number %zu is invalid on mount %p\n", group, mount);
		return STATUS_CORRUPT_FS;
	}

	/* Get the offset of the inode in the group's inode table. */
	offset = ((num - 1) % mount->inodes_per_group) * mount->inode_size;

	/* Create a structure to store details of the inode in memory. */
	inode = kmalloc(sizeof(ext2_inode_t), MM_WAIT);
	mutex_init(&inode->lock, "ext2_inode_lock", MUTEX_RECURSIVE);
	inode->mount = mount;
	inode->num = num;
	inode->disk_size = MIN(mount->inode_size, sizeof(ext2_disk_inode_t));
	inode->disk_offset = ((offset_t)le32_to_cpu(mount->group_tbl[group].bg_inode_table) * mount->block_size) + offset;

	/* Read it in. */
	ret = device_read(mount->device, &inode->disk, inode->disk_size, inode->disk_offset, &bytes);
	if(ret != STATUS_SUCCESS) {
		dprintf("ext2: error occurred while reading inode %" PRIu32 " (%d)\n", num, ret);
		kfree(inode);
		return ret;
	} else if(bytes != inode->disk_size) {
		kfree(inode);
		return STATUS_CORRUPT_FS;
	}

	/* Work out the size of the node data. Regular files can be larger than
	 * 4GB - the high 32-bits of the file size are stored in i_dir_acl. */
	inode->size = le32_to_cpu(inode->disk.i_size);
	if(le16_to_cpu(inode->disk.i_mode) & EXT2_S_IFREG) {
		inode->size |= ((uint64_t)le32_to_cpu(inode->disk.i_dir_acl)) << 32;
	}

	/* Create the various caches. */
	inode->map = file_map_create(mount->block_size, &ext2_file_map_ops, inode);
	inode->cache = vm_cache_create(inode->size, &file_map_vm_cache_ops, inode->map);
	inode->entries = entry_cache_create(&ext2_entry_cache_ops, inode);

	dprintf("ext2: read inode %" PRIu32 " from %" PRIu64 " (group: %zu, block: %zu)\n",
		num, inode->disk_offset, group,
		le32_to_cpu(mount->group_tbl[group].bg_inode_table));
	*inodep = inode;
	return STATUS_SUCCESS;
}
Beispiel #4
0
void
storeDirConfigure(void)
{
    SwapDir *SD;
    int i;
    Config.Swap.maxSize = 0;
    for (i = 0; i < Config.cacheSwap.n_configured; i++) {
	SD = &Config.cacheSwap.swapDirs[i];;
	Config.Swap.maxSize += SD->max_size;
	if (NULL == SD->map)
	    SD->map = file_map_create();
    }
}
Beispiel #5
0
Inode::Inode(Volume* volume, ino_t id)
	:
	fVolume(volume),
	fID(id),
	fCache(NULL),
	fMap(NULL)
{
	rw_lock_init(&fLock, "btrfs inode");

	fInitStatus = UpdateNodeFromDisk();
	if (fInitStatus == B_OK) {
		if (!IsDirectory() && !IsSymLink()) {
			fCache = file_cache_create(fVolume->ID(), ID(), Size());
			fMap = file_map_create(fVolume->ID(), ID(), Size());
		}
	}
}