Пример #1
0
int make_tux3(struct sb *sb)
{
	struct inode *dir = &(struct inode){
		.i_sb = sb,
		.i_mode = S_IFDIR | 0755,
	};
	struct tux_iattr *iattr = &(struct tux_iattr){};
	int err;

	err = clear_other_magic(sb);
	if (err)
		return err;

	trace("create inode table");
	init_btree(itable_btree(sb), sb, no_root, &itable_ops);

	trace("create bitmap");
	sb->bitmap = __tux_create_inode(dir, TUX_BITMAP_INO, iattr, 0);
	if (IS_ERR(sb->bitmap)) {
		err = PTR_ERR(sb->bitmap);
		goto eek;
	}
	assert(sb->bitmap->inum == TUX_BITMAP_INO);
	sb->bitmap->i_size = (sb->volblocks + 7) >> 3;
	/* should this?, tuxtruncate(sb->bitmap, (sb->volblocks + 7) >> 3); */

	trace("reserve superblock");
	/* Always 8K regardless of blocksize */
	int reserve = 1 << (sb->blockbits > 13 ? 0 : 13 - sb->blockbits);
	for (int i = 0; i < reserve; i++) {
		block_t block = balloc_from_range(sb, i, 1, 1);
		if (block == -1)
			goto eek;
		trace("reserve %Lx", (L)block); // error ???
	}

	trace("create version table");
	sb->vtable = __tux_create_inode(dir, TUX_VTABLE_INO, iattr, 0);
	if (IS_ERR(sb->vtable)) {
		err = PTR_ERR(sb->vtable);
		goto eek;
	}
	assert(sb->vtable->inum == TUX_VTABLE_INO);

	trace("create atom dictionary");
	sb->atable = __tux_create_inode(dir, TUX_ATABLE_INO, iattr, 0);
	if (IS_ERR(sb->atable)) {
		err = PTR_ERR(sb->atable);
		goto eek;
	}
	assert(sb->atable->inum == TUX_ATABLE_INO);
	sb->atomref_base = 1 << (40 - sb->blockbits); // see xattr.c
	sb->unatom_base = sb->atomref_base + (1 << (34 - sb->blockbits));
	sb->atomgen = 1; // atom 0 not allowed, means end of atom freelist

	trace("create root directory");
	struct tux_iattr root_iattr = { .mode = S_IFDIR | 0755, };
	sb->rootdir = __tux_create_inode(dir, TUX_ROOTDIR_INO, &root_iattr, 0);
	if (IS_ERR(sb->rootdir)) {
		err = PTR_ERR(sb->rootdir);
		goto eek;
	}
	assert(sb->rootdir->inum == TUX_ROOTDIR_INO);

	if ((err = sync_super(sb)))
		goto eek;

	show_buffers(mapping(sb->bitmap));
	show_buffers(mapping(sb->rootdir));
	show_buffers(sb->volmap->map);
	return 0;
eek:
	if (err)
		warn("eek, %s", strerror(-err));
	iput(sb->bitmap);
	sb->bitmap = NULL;
	return err ? err : -ENOSPC; // just guess
}
Пример #2
0
int make_tux3(struct sb *sb)
{
	int err;

	err = clear_other_magic(sb);
	if (err)
		return err;

	change_begin_atomic(sb);

	trace("create bitmap");
	sb->bitmap = create_internal_inode(sb, TUX_BITMAP_INO, NULL);
	if (IS_ERR(sb->bitmap)) {
		err = PTR_ERR(sb->bitmap);
		goto error_change_end;
	}

	change_end_atomic(sb);

	/* Set fake backend mark to modify backend objects. */
	tux3_start_backend(sb);
	err = reserve_superblock(sb);
	tux3_end_backend();
	if (err)
		goto error;

	change_begin_atomic(sb);
#if 0
	trace("create version table");
	sb->vtable = create_internal_inode(sb, TUX_VTABLE_INO, NULL);
	if (IS_ERR(sb->vtable)) {
		err = PTR_ERR(sb->vtable);
		goto error_change_end;
	}
#endif
	trace("create atom dictionary");
	sb->atable = create_internal_inode(sb, TUX_ATABLE_INO, NULL);
	if (IS_ERR(sb->atable)) {
		err = PTR_ERR(sb->atable);
		goto error_change_end;
	}

	trace("create root directory");
	struct tux_iattr root_iattr = { .mode = S_IFDIR | 0755, };
	sb->rootdir = create_internal_inode(sb, TUX_ROOTDIR_INO, &root_iattr);
	if (IS_ERR(sb->rootdir)) {
		err = PTR_ERR(sb->rootdir);
		goto error_change_end;
	}

	change_end_atomic(sb);

	err = sync_super(sb);
	if (err)
		goto error;

	show_buffers(mapping(sb->bitmap));
	show_buffers(mapping(sb->rootdir));
	show_buffers(sb->volmap->map);

	return 0;

error_change_end:
	change_end_atomic(sb);
error:
	tux3_err(sb, "eek, %s", strerror(-err));
	iput(sb->bitmap);
	sb->bitmap = NULL;

	return err;
}

int tux3_init_mem(void)
{
	return tux3_init_hole_cache();
}

void tux3_exit_mem(void)
{
	tux3_destroy_hole_cache();
}