Exemple #1
0
int run_test(int flags, int size, char *dir, struct test_program *prog)
{
	errcode_t	retval;
	ext2_icount_t	icount;
	struct test_program *pc;
	__u16		result;
	int		problem = 0;

	if (dir) {
		retval = ext2fs_create_icount_tdb(test_fs, dir,
						  flags, &icount);
		if (retval) {
			com_err("run_test", retval,
				"while creating icount using tdb");
			exit(1);
		}
	} else {
		retval = ext2fs_create_icount2(test_fs, flags, size, 0,
					       &icount);
		if (retval) {
			com_err("run_test", retval, "while creating icount");
			exit(1);
		}
	}
	for (pc = prog; pc->cmd != EXIT; pc++) {
		switch (pc->cmd) {
		case FETCH:
			printf("icount_fetch(%u) = ", pc->ino);
			break;
		case STORE:
			retval = ext2fs_icount_store(icount, pc->ino, pc->arg);
			if (retval) {
				com_err("run_test", retval,
					"while calling icount_store");
				exit(1);
			}
			printf("icount_store(%u, %u) = ", pc->ino, pc->arg);
			break;
		case INCREMENT:
			retval = ext2fs_icount_increment(icount, pc->ino, 0);
			if (retval) {
				com_err("run_test", retval,
					"while calling icount_increment");
				exit(1);
			}
			printf("icount_increment(%u) = ", pc->ino);
			break;
		case DECREMENT:
			retval = ext2fs_icount_decrement(icount, pc->ino, 0);
			if (retval) {
				com_err("run_test", retval,
					"while calling icount_decrement");
				exit(1);
			}
			printf("icount_decrement(%u) = ", pc->ino);
			break;
		}
		retval = ext2fs_icount_fetch(icount, pc->ino, &result);
		if (retval) {
			com_err("run_test", retval,
				"while calling icount_fetch");
			exit(1);
		}
		printf("%u (%s)\n", result, (result == pc->expected) ?
		       "OK" : "NOT OK");
		if (result != pc->expected)
			problem++;
	}
	printf("icount size is %u\n", ext2fs_get_icount_size(icount));
	retval = ext2fs_icount_validate(icount, stdout);
	if (retval) {
		com_err("run_test", retval, "while calling icount_validate");
		exit(1);
	}
	ext2fs_free_icount(icount);
	return problem;
}
Exemple #2
0
void e2fsck_pass2(e2fsck_t ctx)
{
	struct ext2_super_block *sb = ctx->fs->super;
	struct problem_context	pctx;
	ext2_filsys 		fs = ctx->fs;
	char			*buf;
#ifdef RESOURCE_TRACK
	struct resource_track	rtrack;
#endif
	struct check_dir_struct cd;
	struct dx_dir_info	*dx_dir;
	struct dx_dirblock_info	*dx_db, *dx_parent;
	unsigned int		save_type;
	int			b;
	int			i, depth;
	problem_t		code;
	int			bad_dir;

	init_resource_track(&rtrack, ctx->fs->io);
	clear_problem_context(&cd.pctx);

#ifdef MTRACE
	mtrace_print("Pass 2");
#endif

	if (!(ctx->options & E2F_OPT_PREEN))
		fix_problem(ctx, PR_2_PASS_HEADER, &cd.pctx);

	e2fsck_setup_tdb_icount(ctx, EXT2_ICOUNT_OPT_INCREMENT,
				&ctx->inode_count);
	if (ctx->inode_count)
		cd.pctx.errcode = 0;
	else {
		e2fsck_set_bitmap_type(fs, EXT2FS_BMAP64_RBTREE,
				       "inode_count", &save_type);
		cd.pctx.errcode = ext2fs_create_icount2(fs,
						EXT2_ICOUNT_OPT_INCREMENT,
						0, ctx->inode_link_info,
						&ctx->inode_count);
		fs->default_bitmap_type = save_type;
	}
	if (cd.pctx.errcode) {
		fix_problem(ctx, PR_2_ALLOCATE_ICOUNT, &cd.pctx);
		ctx->flags |= E2F_FLAG_ABORT;
		return;
	}
	buf = (char *) e2fsck_allocate_memory(ctx, 2*fs->blocksize,
					      "directory scan buffer");

	/*
	 * Set up the parent pointer for the root directory, if
	 * present.  (If the root directory is not present, we will
	 * create it in pass 3.)
	 */
	(void) e2fsck_dir_info_set_parent(ctx, EXT2_ROOT_INO, EXT2_ROOT_INO);

	cd.buf = buf;
	cd.ctx = ctx;
	cd.count = 1;
	cd.max = ext2fs_dblist_count2(fs->dblist);

	if (ctx->progress)
		(void) (ctx->progress)(ctx, 2, 0, cd.max);

	if (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX)
		ext2fs_dblist_sort2(fs->dblist, special_dir_block_cmp);

	cd.pctx.errcode = ext2fs_dblist_iterate2(fs->dblist, check_dir_block,
						 &cd);
	if (ctx->flags & E2F_FLAG_SIGNAL_MASK || ctx->flags & E2F_FLAG_RESTART)
		return;

	if (ctx->flags & E2F_FLAG_RESTART_LATER) {
		ctx->flags |= E2F_FLAG_RESTART;
		return;
	}

	if (cd.pctx.errcode) {
		fix_problem(ctx, PR_2_DBLIST_ITERATE, &cd.pctx);
		ctx->flags |= E2F_FLAG_ABORT;
		return;
	}

#ifdef ENABLE_HTREE
	for (i=0; (dx_dir = e2fsck_dx_dir_info_iter(ctx, &i)) != 0;) {
		if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
			return;
		if (dx_dir->numblocks == 0)
			continue;
		clear_problem_context(&pctx);
		bad_dir = 0;
		pctx.dir = dx_dir->ino;
		dx_db = dx_dir->dx_block;
		if (dx_db->flags & DX_FLAG_REFERENCED)
			dx_db->flags |= DX_FLAG_DUP_REF;
		else
			dx_db->flags |= DX_FLAG_REFERENCED;
		/*
		 * Find all of the first and last leaf blocks, and
		 * update their parent's min and max hash values
		 */
		for (b=0, dx_db = dx_dir->dx_block;
		     b < dx_dir->numblocks;
		     b++, dx_db++) {
			if ((dx_db->type != DX_DIRBLOCK_LEAF) ||
			    !(dx_db->flags & (DX_FLAG_FIRST | DX_FLAG_LAST)))
				continue;
			dx_parent = &dx_dir->dx_block[dx_db->parent];
			/*
			 * XXX Make sure dx_parent->min_hash > dx_db->min_hash
			 */
			if (dx_db->flags & DX_FLAG_FIRST)
				dx_parent->min_hash = dx_db->min_hash;
			/*
			 * XXX Make sure dx_parent->max_hash < dx_db->max_hash
			 */
			if (dx_db->flags & DX_FLAG_LAST)
				dx_parent->max_hash = dx_db->max_hash;
		}

		for (b=0, dx_db = dx_dir->dx_block;
		     b < dx_dir->numblocks;
		     b++, dx_db++) {
			pctx.blkcount = b;
			pctx.group = dx_db->parent;
			code = 0;
			if (!(dx_db->flags & DX_FLAG_FIRST) &&
			    (dx_db->min_hash < dx_db->node_min_hash)) {
				pctx.blk = dx_db->min_hash;
				pctx.blk2 = dx_db->node_min_hash;
				code = PR_2_HTREE_MIN_HASH;
				fix_problem(ctx, code, &pctx);
				bad_dir++;
			}
			if (dx_db->type == DX_DIRBLOCK_LEAF) {
				depth = htree_depth(dx_dir, dx_db);
				if (depth != dx_dir->depth) {
					pctx.num = dx_dir->depth;
					code = PR_2_HTREE_BAD_DEPTH;
					fix_problem(ctx, code, &pctx);
					bad_dir++;
				}
			}
			/*
			 * This test doesn't apply for the root block
			 * at block #0
			 */
			if (b &&
			    (dx_db->max_hash > dx_db->node_max_hash)) {
				pctx.blk = dx_db->max_hash;
				pctx.blk2 = dx_db->node_max_hash;
				code = PR_2_HTREE_MAX_HASH;
				fix_problem(ctx, code, &pctx);
				bad_dir++;
			}
			if (!(dx_db->flags & DX_FLAG_REFERENCED)) {
				code = PR_2_HTREE_NOTREF;
				fix_problem(ctx, code, &pctx);
				bad_dir++;
			} else if (dx_db->flags & DX_FLAG_DUP_REF) {
				code = PR_2_HTREE_DUPREF;
				fix_problem(ctx, code, &pctx);
				bad_dir++;
			}
		}
		if (bad_dir && fix_problem(ctx, PR_2_HTREE_CLEAR, &pctx)) {
			clear_htree(ctx, dx_dir->ino);
			dx_dir->numblocks = 0;
		}
	}
	e2fsck_free_dx_dir_info(ctx);
#endif
	ext2fs_free_mem(&buf);
	ext2fs_free_dblist(fs->dblist);

	if (ctx->inode_bad_map) {
		ext2fs_free_inode_bitmap(ctx->inode_bad_map);
		ctx->inode_bad_map = 0;
	}
	if (ctx->inode_reg_map) {
		ext2fs_free_inode_bitmap(ctx->inode_reg_map);
		ctx->inode_reg_map = 0;
	}

	clear_problem_context(&pctx);
	if (ctx->large_files) {
		if (!(sb->s_feature_ro_compat &
		      EXT2_FEATURE_RO_COMPAT_LARGE_FILE) &&
		    fix_problem(ctx, PR_2_FEATURE_LARGE_FILES, &pctx)) {
			sb->s_feature_ro_compat |=
				EXT2_FEATURE_RO_COMPAT_LARGE_FILE;
			fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
			ext2fs_mark_super_dirty(fs);
		}
		if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
		    fix_problem(ctx, PR_1_FS_REV_LEVEL, &pctx)) {
			ext2fs_update_dynamic_rev(fs);
			ext2fs_mark_super_dirty(fs);
		}
	}

	print_resource_track(ctx, _("Pass 2"), &rtrack, fs->io);
}
Exemple #3
0
errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
			       unsigned int size,
			       ext2_icount_t *ret)
{
	return ext2fs_create_icount2(fs, flags, size, 0, ret);
}
Exemple #4
0
void e2fsck_pass2(e2fsck_t ctx)
{
    struct ext2_super_block *sb = ctx->fs->super;
    struct problem_context	pctx;
    ext2_filsys 		fs = ctx->fs;
    char			*buf;
#ifdef RESOURCE_TRACK
    struct resource_track	rtrack;
#endif
    struct dir_info 	*dir;
    struct check_dir_struct cd;

#ifdef RESOURCE_TRACK
    init_resource_track(&rtrack);
#endif

    clear_problem_context(&cd.pctx);

#ifdef MTRACE
    mtrace_print("Pass 2");
#endif

    if (!(ctx->options & E2F_OPT_PREEN))
        fix_problem(ctx, PR_2_PASS_HEADER, &cd.pctx);

    cd.pctx.errcode = ext2fs_create_icount2(fs, EXT2_ICOUNT_OPT_INCREMENT,
                                            0, ctx->inode_link_info,
                                            &ctx->inode_count);
    if (cd.pctx.errcode) {
        fix_problem(ctx, PR_2_ALLOCATE_ICOUNT, &cd.pctx);
        ctx->flags |= E2F_FLAG_ABORT;
        return;
    }
    buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize,
                                          "directory scan buffer");

    /*
     * Set up the parent pointer for the root directory, if
     * present.  (If the root directory is not present, we will
     * create it in pass 3.)
     */
    dir = e2fsck_get_dir_info(ctx, EXT2_ROOT_INO);
    if (dir)
        dir->parent = EXT2_ROOT_INO;

    cd.buf = buf;
    cd.ctx = ctx;
    cd.count = 1;
    cd.max = ext2fs_dblist_count(fs->dblist);

    if (ctx->progress)
        (void) (ctx->progress)(ctx, 2, 0, cd.max);

    cd.pctx.errcode = ext2fs_dblist_iterate(fs->dblist, check_dir_block,
                                            &cd);
    if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
        return;
    if (cd.pctx.errcode) {
        fix_problem(ctx, PR_2_DBLIST_ITERATE, &cd.pctx);
        ctx->flags |= E2F_FLAG_ABORT;
        return;
    }

    ext2fs_free_mem((void **) &buf);
    ext2fs_free_dblist(fs->dblist);

    if (ctx->inode_bad_map) {
        ext2fs_free_inode_bitmap(ctx->inode_bad_map);
        ctx->inode_bad_map = 0;
    }
    if (ctx->inode_reg_map) {
        ext2fs_free_inode_bitmap(ctx->inode_reg_map);
        ctx->inode_reg_map = 0;
    }

    clear_problem_context(&pctx);
    if (ctx->large_files) {
        if (!(sb->s_feature_ro_compat &
                EXT2_FEATURE_RO_COMPAT_LARGE_FILE) &&
                fix_problem(ctx, PR_2_FEATURE_LARGE_FILES, &pctx)) {
            sb->s_feature_ro_compat |=
                EXT2_FEATURE_RO_COMPAT_LARGE_FILE;
            ext2fs_mark_super_dirty(fs);
        }
        if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
                fix_problem(ctx, PR_1_FS_REV_LEVEL, &pctx)) {
            ext2fs_update_dynamic_rev(fs);
            ext2fs_mark_super_dirty(fs);
        }
    } else if (!ctx->large_files &&
               (sb->s_feature_ro_compat &
                EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) {
        if (fs->flags & EXT2_FLAG_RW) {
            sb->s_feature_ro_compat &=
                ~EXT2_FEATURE_RO_COMPAT_LARGE_FILE;
            ext2fs_mark_super_dirty(fs);
        }
    }

#ifdef RESOURCE_TRACK
    if (ctx->options & E2F_OPT_TIME2) {
        e2fsck_clear_progbar(ctx);
        print_resource_track("Pass 2", &rtrack);
    }
#endif
}