void do_init_filesys(int argc, char **argv)
{
	struct ext2_super_block param;
	errcode_t	retval;
	int		err;

	if (common_args_process(argc, argv, 3, 3, "initialize",
				"<device> <blocksize>", CHECK_FS_NOTOPEN))
		return;

	memset(&param, 0, sizeof(struct ext2_super_block));
	param.s_blocks_count = parse_ulong(argv[2], argv[0],
					   "blocks count", &err);
	if (err)
		return;
	retval = ext2fs_initialize(argv[1], 0, &param,
				   unix_io_manager, &current_fs);
	if (retval) {
		com_err(argv[1], retval, "while initializing filesystem");
		current_fs = NULL;
		return;
	}
	root = cwd = EXT2_ROOT_INO;
	return;
}
Example #2
0
static void setup_filesystem(const char *name,
			     unsigned int blocks, unsigned int inodes,
			     unsigned int type, int flags)
{
	struct ext2_super_block param;
	errcode_t retval;

	memset(&param, 0, sizeof(param));
	ext2fs_blocks_count_set(&param, blocks);
	param.s_inodes_count = inodes;

	retval = ext2fs_initialize("test fs", flags, &param,
				   test_io_manager, &test_fs);

	if (retval) {
		com_err(name, retval, "while initializing filesystem");
		return;
	}
	test_fs->default_bitmap_type = type;
	ext2fs_free_block_bitmap(test_fs->block_map);
	test_fs->block_map = 0;
	ext2fs_free_inode_bitmap(test_fs->inode_map);
	test_fs->inode_map = 0;
	retval = ext2fs_allocate_block_bitmap(test_fs, "block bitmap",
					      &test_fs->block_map);
	if (retval) {
		com_err(name, retval, "while allocating block bitmap");
		goto errout;
	}
	retval = ext2fs_allocate_inode_bitmap(test_fs, "inode bitmap",
					      &test_fs->inode_map);
	if (retval) {
		com_err(name, retval, "while allocating inode bitmap");
		goto errout;
	}
	return;

errout:
	ext2fs_close_free(&test_fs);
}
Example #3
0
/*
 * Setup the variables for doing the inode scan test.
 */
static void setup(void)
{
	errcode_t	retval;
	struct ext2_super_block param;

	initialize_ext2_error_table();

	memset(&param, 0, sizeof(param));
	ext2fs_blocks_count_set(&param, 12000);

	retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, &param,
				   test_io_manager, &test_fs);
	if (retval) {
		com_err("setup", retval,
			"while initializing filesystem");
		exit(1);
	}
	retval = ext2fs_allocate_tables(test_fs);
	if (retval) {
		com_err("setup", retval,
			"while allocating tables for test filesystem");
		exit(1);
	}
}
Example #4
0
int main(int argc, char **argv)
{
	int		retval;
	int		sci_idx;
	int		c;
	char		*request = 0;
	int		exit_status = 0;
	char		*cmd_file = 0;
	struct ext2_super_block param;

	initialize_ext2_error_table();

	/*
	 * Create a sample filesystem structure
	 */
	memset(&param, 0, sizeof(struct ext2_super_block));
	ext2fs_blocks_count_set(&param, 80000);
	param.s_inodes_count = 20000;
	retval = ext2fs_initialize("/dev/null", 0, &param,
				   unix_io_manager, &test_fs);
	if (retval) {
		com_err("/dev/null", retval, "while setting up test fs");
		exit(1);
	}

	while ((c = getopt (argc, argv, "wR:f:")) != EOF) {
		switch (c) {
		case 'R':
			request = optarg;
			break;
		case 'f':
			cmd_file = optarg;
			break;
		default:
			com_err(argv[0], 0, "Usage: test_icount "
				"[-R request] [-f cmd_file]");
			exit(1);
		}
	}
	sci_idx = ss_create_invocation("test_icount", "0.0", (char *) NULL,
				       &test_cmds, &retval);
	if (retval) {
		ss_perror(sci_idx, retval, "creating invocation");
		exit(1);
	}

	(void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval);
	if (retval) {
		ss_perror(sci_idx, retval, "adding standard requests");
		exit (1);
	}
	if (request) {
		retval = 0;
		retval = ss_execute_line(sci_idx, request);
		if (retval) {
			ss_perror(sci_idx, retval, request);
			exit_status++;
		}
	} else if (cmd_file) {
		exit_status = source_file(cmd_file, sci_idx);
	} else {
		ss_listen(sci_idx);
	}

	return(exit_status);
}
Example #5
0
int main(int argc, char *argv[])
{
    ext2_filsys		fs;
    struct ext2_super_block param;
    errcode_t		retval;
    int			i;

    /* setup */
    initialize_ext2_error_table();

    memset(&param, 0, sizeof(param));
    ext2fs_blocks_count_set(&param, 32768);
    param.s_inodes_count = 100;

    param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_INLINE_DATA;
    param.s_rev_level = EXT2_DYNAMIC_REV;
    param.s_inode_size = 256;

    retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, &param,
                               test_io_manager, &fs);
    if (retval) {
        com_err("setup", retval,
                "while initializing filesystem");
        exit(1);
    }

    retval = ext2fs_allocate_tables(fs);
    if (retval) {
        com_err("setup", retval,
                "while allocating tables for test filesysmte");
        exit(1);
    }

    /* initialize inode cache */
    if (!fs->icache) {
        struct ext2_inode inode;
        ext2_ino_t first_ino = EXT2_FIRST_INO(fs->super);
        int i;

        /* we just want to init inode cache.  So ignore error */
        ext2fs_create_inode_cache(fs, 16);
        if (!fs->icache) {
            fprintf(stderr,
                    "tst_inline_data: init inode cache failed\n");
            exit(1);
        }

        /* setup inode cache */
        for (i = 0; i < fs->icache->cache_size; i++)
            fs->icache->cache[i].ino = first_ino++;
    }

    /* test */
    if (file_test(fs)) {
        fprintf(stderr, "tst_inline_data(FILE): FAILED\n");
        return 1;
    }
    printf("tst_inline_data(FILE): OK\n");

    if (dir_test(fs)) {
        fprintf(stderr, "tst_inline_data(DIR): FAILED\n");
        return 1;
    }
    printf("tst_inline_data(DIR): OK\n");

    return 0;
}
Example #6
0
int main(int argc, char **argv)
{
	struct ext2_super_block param;
	errcode_t		retval;
	ext2_filsys		fs;
	int			i;
	__u16 csum1, csum2, csum_known = 0xd3a4;

	memset(&param, 0, sizeof(param));
	param.s_blocks_count = 32768;

	retval = ext2fs_initialize("test fs", 0, &param,
				   test_io_manager, &fs);
	if (retval) {
		com_err("setup", retval,
			"While initializing filesystem");
		exit(1);
	}
	memcpy(fs->super->s_uuid, sb_uuid, 16);
	fs->super->s_feature_ro_compat = EXT4_FEATURE_RO_COMPAT_GDT_CSUM;

	for (i=0; i < fs->group_desc_count; i++) {
		fs->group_desc[i].bg_block_bitmap = 124;
		fs->group_desc[i].bg_inode_bitmap = 125;
		fs->group_desc[i].bg_inode_table = 126;
		fs->group_desc[i].bg_free_blocks_count = 31119;
		fs->group_desc[i].bg_free_inodes_count = 15701;
		fs->group_desc[i].bg_used_dirs_count = 2;
		fs->group_desc[i].bg_flags = 0;
	};

	csum1 = ext2fs_group_desc_csum(fs, 0);
	print_csum("csum0000", fs, 0);

	if (csum1 != csum_known) {
		printf("checksum for group 0 should be %04x\n", csum_known);
		exit(1);
	}
	csum2 = ext2fs_group_desc_csum(fs, 1);
	print_csum("csum0001", fs, 1);
	if (csum1 == csum2) {
		printf("checksums for different groups shouldn't match\n");
		exit(1);
	}
	csum2 = ext2fs_group_desc_csum(fs, 2);
	print_csum("csumffff", fs, 2);
	if (csum1 == csum2) {
		printf("checksums for different groups shouldn't match\n");
		exit(1);
	}
	fs->group_desc[0].bg_checksum = csum1;
	csum2 = ext2fs_group_desc_csum(fs, 0);
	print_csum("csum_set", fs, 0);
	if (csum1 != csum2) {
		printf("checksums should not depend on checksum field\n");
		exit(1);
	}
	if (!ext2fs_group_desc_csum_verify(fs, 0)) {
		printf("checksums should verify against gd_checksum\n");
		exit(1);
	}
	memset(fs->super->s_uuid, 0x30, sizeof(fs->super->s_uuid));
	print_csum("new_uuid", fs, 0);
	if (ext2fs_group_desc_csum_verify(fs, 0) != 0) {
		printf("checksums for different filesystems shouldn't match\n");
		exit(1);
	}
	csum1 = fs->group_desc[0].bg_checksum = ext2fs_group_desc_csum(fs, 0);
	print_csum("csum_new", fs, 0);
	fs->group_desc[0].bg_free_blocks_count = 1;
	csum2 = ext2fs_group_desc_csum(fs, 0);
	print_csum("csum_blk", fs, 0);
	if (csum1 == csum2) {
		printf("checksums for different data shouldn't match\n");
		exit(1);
	}

	return 0;
}
Example #7
0
/*
 * Setup the variables for doing the inode scan test.
 */
static void setup(void)
{
	errcode_t	retval;
	int		i;
	struct ext2_super_block param;

	initialize_ext2_error_table();

	memset(&param, 0, sizeof(param));
	param.s_blocks_count = 12000;


	test_io_cb_read_blk = test_read_blk;

	retval = ext2fs_initialize("test fs", 0, &param,
				   test_io_manager, &test_fs);
	if (retval) {
		com_err("setup", retval,
			"While initializing filesystem");
		exit(1);
	}
	retval = ext2fs_allocate_tables(test_fs);
	if (retval) {
		com_err("setup", retval,
			"While allocating tables for test filesystem");
		exit(1);
	}
	retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
					      &bad_block_map);
	if (retval) {
		com_err("setup", retval,
			"While allocating bad_block bitmap");
		exit(1);
	}
	retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
					      &touched_map);
	if (retval) {
		com_err("setup", retval,
			"While allocating touched block bitmap");
		exit(1);
	}
	retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
					      &bad_inode_map);
	if (retval) {
		com_err("setup", retval,
			"While allocating bad inode bitmap");
		exit(1);
	}

	retval = ext2fs_badblocks_list_create(&test_badblocks, 5);
	if (retval) {
		com_err("setup", retval, "while creating badblocks list");
		exit(1);
	}
	for (i=0; test_vec[i]; i++) {
		retval = ext2fs_badblocks_list_add(test_badblocks, test_vec[i]);
		if (retval) {
			com_err("setup", retval,
				"while adding test vector %d", i);
			exit(1);
		}
		ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]);
	}
	test_fs->badblocks = test_badblocks;
}