119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * pass5.c --- check block and inode bitmaps against on-disk bitmaps
33984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt *
419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project *
619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * %Begin-Header%
719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * This file may be redistributed under the terms of the GNU Public
819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * License.
919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * %End-Header%
103984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt *
1119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
1219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include "e2fsck.h"
1419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include "problem.h"
1519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_block_bitmaps(e2fsck_t ctx);
1719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_inode_bitmaps(e2fsck_t ctx);
1819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_inode_end(e2fsck_t ctx);
1919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_block_end(e2fsck_t ctx);
2019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
2119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectvoid e2fsck_pass5(e2fsck_t ctx)
2219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
2319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#ifdef RESOURCE_TRACK
2419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct resource_track	rtrack;
2519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#endif
2619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct problem_context	pctx;
273984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
2819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#ifdef MTRACE
2919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	mtrace_print("Pass 5");
3019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#endif
3119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
323984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	init_resource_track(&rtrack, ctx->fs->io);
3319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	clear_problem_context(&pctx);
3419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (!(ctx->options & E2F_OPT_PREEN))
3619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_PASS_HEADER, &pctx);
3719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (ctx->progress)
3919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if ((ctx->progress)(ctx, 5, 0, ctx->fs->group_desc_count*2))
4019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			return;
4119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
4219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	e2fsck_read_bitmaps(ctx);
4319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
4419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	check_block_bitmaps(ctx);
4519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
4619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
4719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	check_inode_bitmaps(ctx);
4819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
4919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
5019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	check_inode_end(ctx);
5119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
5219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
5319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	check_block_end(ctx);
5419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
5519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
5619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
5719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_inode_bitmap(ctx->inode_used_map);
5819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ctx->inode_used_map = 0;
5919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_inode_bitmap(ctx->inode_dir_map);
6019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ctx->inode_dir_map = 0;
6119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_block_bitmap(ctx->block_found_map);
6219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ctx->block_found_map = 0;
6319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
643984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	print_resource_track(ctx, _("Pass 5"), &rtrack, ctx->fs->io);
6519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
6619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
6719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define NO_BLK ((blk_t) -1)
6819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
6919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void print_bitmap_problem(e2fsck_t ctx, int problem,
7019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    struct problem_context *pctx)
7119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
7219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	switch (problem) {
7319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	case PR_5_BLOCK_UNUSED:
7419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx->blk == pctx->blk2)
7519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx->blk2 = 0;
7619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		else
7719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_BLOCK_RANGE_UNUSED;
7819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		break;
7919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	case PR_5_BLOCK_USED:
8019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx->blk == pctx->blk2)
8119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx->blk2 = 0;
8219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		else
8319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_BLOCK_RANGE_USED;
8419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		break;
8519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	case PR_5_INODE_UNUSED:
8619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx->ino == pctx->ino2)
8719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx->ino2 = 0;
8819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		else
8919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_INODE_RANGE_UNUSED;
9019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		break;
9119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	case PR_5_INODE_USED:
9219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx->ino == pctx->ino2)
9319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx->ino2 = 0;
9419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		else
9519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_INODE_RANGE_USED;
9619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		break;
9719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
9819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	fix_problem(ctx, problem, pctx);
9919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx->blk = pctx->blk2 = NO_BLK;
10019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx->ino = pctx->ino2 = 0;
10119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
10219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
10319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_block_bitmaps(e2fsck_t ctx)
10419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
10519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_filsys fs = ctx->fs;
1063984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	blk_t	i;
10719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int	*free_array;
10819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int	group = 0;
1093984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	blk_t	blocks = 0;
1103984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	blk_t	free_blocks = 0;
11119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int	group_free = 0;
11219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int	actual, bitmap;
11319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct problem_context	pctx;
11419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int	problem, save_problem, fixit, had_problem;
11519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t	retval;
1163984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	int		csum_flag;
11719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		skip_group = 0;
11819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
11919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	clear_problem_context(&pctx);
12019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	free_array = (int *) e2fsck_allocate_memory(ctx,
12119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    fs->group_desc_count * sizeof(int), "free block count array");
12219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
12319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if ((fs->super->s_first_data_block <
12419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_block_bitmap_start(ctx->block_found_map)) ||
12519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    (fs->super->s_blocks_count-1 >
12619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_block_bitmap_end(ctx->block_found_map))) {
12719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 1;
12819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk = fs->super->s_first_data_block;
12919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk2 = fs->super->s_blocks_count -1;
13019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino = ext2fs_get_block_bitmap_start(ctx->block_found_map);
13119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino2 = ext2fs_get_block_bitmap_end(ctx->block_found_map);
13219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
13319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
13419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
13519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto errout;
13619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
13719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
13819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if ((fs->super->s_first_data_block <
13919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_block_bitmap_start(fs->block_map)) ||
14019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    (fs->super->s_blocks_count-1 >
14119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_block_bitmap_end(fs->block_map))) {
14219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 2;
14319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk = fs->super->s_first_data_block;
14419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk2 = fs->super->s_blocks_count -1;
14519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino = ext2fs_get_block_bitmap_start(fs->block_map);
14619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino2 = ext2fs_get_block_bitmap_end(fs->block_map);
14719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
14819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
14919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
15019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto errout;
15119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
15219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1533984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
1543984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					       EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
15519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectredo_counts:
15619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	had_problem = 0;
15719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	save_problem = 0;
15819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.blk = pctx.blk2 = NO_BLK;
1593984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	if (csum_flag &&
1603984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	    (fs->group_desc[group].bg_flags & EXT2_BG_BLOCK_UNINIT))
16119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		skip_group++;
16219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = fs->super->s_first_data_block;
16319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     i < fs->super->s_blocks_count;
16419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     i++) {
16519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		actual = ext2fs_fast_test_block_bitmap(ctx->block_found_map, i);
16619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
16719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (skip_group) {
1683984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			blk_t	super_blk, old_desc_blk, new_desc_blk;
1693984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			int	old_desc_blocks;
1703984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
1713984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			ext2fs_super_and_bgd_loc(fs, group, &super_blk,
1723984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					 &old_desc_blk, &new_desc_blk, 0);
1733984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
1743984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (fs->super->s_feature_incompat &
1753984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			    EXT2_FEATURE_INCOMPAT_META_BG)
1763984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				old_desc_blocks = fs->super->s_first_meta_bg;
1773984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			else
1783984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				old_desc_blocks = fs->desc_blocks +
1793984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					fs->super->s_reserved_gdt_blocks;
1803984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
1813984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			bitmap = 0;
1823984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (i == super_blk)
18319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				bitmap = 1;
1843984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (old_desc_blk && old_desc_blocks &&
1853984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			    (i >= old_desc_blk) &&
1863984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			    (i < old_desc_blk + old_desc_blocks))
1873984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				bitmap = 1;
1883984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (new_desc_blk &&
1893984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			    (i == new_desc_blk))
1903984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				bitmap = 1;
1913984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (i == fs->group_desc[group].bg_block_bitmap)
19219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				bitmap = 1;
19319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			else if (i == fs->group_desc[group].bg_inode_bitmap)
19419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				bitmap = 1;
19519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			else if (i >= fs->group_desc[group].bg_inode_table &&
19619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				 (i < fs->group_desc[group].bg_inode_table
19719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				  + fs->inode_blocks_per_group))
19819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				bitmap = 1;
19919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			actual = (actual != 0);
20019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else
20119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			bitmap = ext2fs_fast_test_block_bitmap(fs->block_map, i);
20219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
20319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (actual == bitmap)
20419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			goto do_counts;
20519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
20619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (!actual && bitmap) {
20719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			/*
20819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 * Block not used, but marked in use in the bitmap.
20919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 */
21019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_BLOCK_UNUSED;
21119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else {
21219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			/*
21319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 * Block used, but not marked in use in the bitmap.
21419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 */
21519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_BLOCK_USED;
2163984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
2173984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (skip_group) {
2183984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				struct problem_context pctx2;
2193984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				pctx2.blk = i;
2203984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				pctx2.group = group;
2213984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				if (fix_problem(ctx, PR_5_BLOCK_UNINIT,&pctx2)){
2223984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					fs->group_desc[group].bg_flags &=
2233984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt						~EXT2_BG_BLOCK_UNINIT;
2243984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					skip_group = 0;
2253984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				}
2263984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			}
22719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
22819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx.blk == NO_BLK) {
22919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.blk = pctx.blk2 = i;
23019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			save_problem = problem;
23119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else {
23219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if ((problem == save_problem) &&
23319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (pctx.blk2 == i-1))
23419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				pctx.blk2++;
23519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			else {
23619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				print_bitmap_problem(ctx, save_problem, &pctx);
23719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				pctx.blk = pctx.blk2 = i;
23819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				save_problem = problem;
23919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			}
24019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
24119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
24219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		had_problem++;
24319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
24419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	do_counts:
2453984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt		if (!bitmap && (!skip_group || csum_flag)) {
24619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group_free++;
24719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			free_blocks++;
24819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
24919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		blocks ++;
25019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if ((blocks == fs->super->s_blocks_per_group) ||
25119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		    (i == fs->super->s_blocks_count-1)) {
25219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			free_array[group] = group_free;
25319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group ++;
25419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			blocks = 0;
25519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group_free = 0;
25619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			skip_group = 0;
25719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (ctx->progress)
25819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				if ((ctx->progress)(ctx, 5, group,
25919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						    fs->group_desc_count*2))
26019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					goto errout;
2613984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (csum_flag &&
26219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (i != fs->super->s_blocks_count-1) &&
26319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (fs->group_desc[group].bg_flags &
26419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			     EXT2_BG_BLOCK_UNINIT))
26519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				skip_group++;
26619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
26719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
26819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.blk != NO_BLK)
26919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		print_bitmap_problem(ctx, save_problem, &pctx);
27019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (had_problem)
27119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fixit = end_problem_latch(ctx, PR_LATCH_BBITMAP);
27219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	else
27319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fixit = -1;
27419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
27519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
27619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (fixit == 1) {
27719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_free_block_bitmap(fs->block_map);
27819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		retval = ext2fs_copy_bitmap(ctx->block_found_map,
27919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						  &fs->block_map);
28019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (retval) {
28119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			clear_problem_context(&pctx);
28219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			fix_problem(ctx, PR_5_COPY_BBITMAP_ERROR, &pctx);
28319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ctx->flags |= E2F_FLAG_ABORT;
28419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			goto errout;
28519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
28619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_set_bitmap_padding(fs->block_map);
28719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_mark_bb_dirty(fs);
28819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
28919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		/* Redo the counts */
29019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		blocks = 0; free_blocks = 0; group_free = 0; group = 0;
29119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		memset(free_array, 0, fs->group_desc_count * sizeof(int));
29219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto redo_counts;
29319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	} else if (fixit == 0)
29419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_unmark_valid(fs);
29519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
29619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = 0; i < fs->group_desc_count; i++) {
29719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (free_array[i] != fs->group_desc[i].bg_free_blocks_count) {
29819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.group = i;
29919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.blk = fs->group_desc[i].bg_free_blocks_count;
30019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.blk2 = free_array[i];
30119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
30219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT_GROUP,
30319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					&pctx)) {
30419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				fs->group_desc[i].bg_free_blocks_count =
30519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					free_array[i];
30619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_mark_super_dirty(fs);
30719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			} else
30819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_unmark_valid(fs);
30919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
31019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
31119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (free_blocks != fs->super->s_free_blocks_count) {
31219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.group = 0;
31319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk = fs->super->s_free_blocks_count;
31419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk2 = free_blocks;
31519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
31619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT, &pctx)) {
31719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			fs->super->s_free_blocks_count = free_blocks;
31819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ext2fs_mark_super_dirty(fs);
31919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else
32019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ext2fs_unmark_valid(fs);
32119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
32219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecterrout:
32319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_mem(&free_array);
32419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
32519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
32619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_inode_bitmaps(e2fsck_t ctx)
32719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
32819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_filsys fs = ctx->fs;
32919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_ino_t	i;
33019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	unsigned int	free_inodes = 0;
33119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		group_free = 0;
33219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		dirs_count = 0;
33319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		group = 0;
33419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	unsigned int	inodes = 0;
33519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		*free_array;
33619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		*dir_array;
33719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		actual, bitmap;
33819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t	retval;
33919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct problem_context	pctx;
34019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		problem, save_problem, fixit, had_problem;
3413984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	int		csum_flag;
34219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		skip_group = 0;
34319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
34419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	clear_problem_context(&pctx);
34519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	free_array = (int *) e2fsck_allocate_memory(ctx,
34619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    fs->group_desc_count * sizeof(int), "free inode count array");
34719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
34819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	dir_array = (int *) e2fsck_allocate_memory(ctx,
34919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	   fs->group_desc_count * sizeof(int), "directory count array");
35019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
35119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if ((1 < ext2fs_get_inode_bitmap_start(ctx->inode_used_map)) ||
35219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    (fs->super->s_inodes_count >
35319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_inode_bitmap_end(ctx->inode_used_map))) {
35419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 3;
35519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk = 1;
35619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk2 = fs->super->s_inodes_count;
35719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino = ext2fs_get_inode_bitmap_start(ctx->inode_used_map);
35819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino2 = ext2fs_get_inode_bitmap_end(ctx->inode_used_map);
35919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
36019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
36119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
36219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto errout;
36319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
36419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if ((1 < ext2fs_get_inode_bitmap_start(fs->inode_map)) ||
36519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	    (fs->super->s_inodes_count >
36619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	     ext2fs_get_inode_bitmap_end(fs->inode_map))) {
36719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 4;
36819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk = 1;
36919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.blk2 = fs->super->s_inodes_count;
37019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino = ext2fs_get_inode_bitmap_start(fs->inode_map);
37119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino2 = ext2fs_get_inode_bitmap_end(fs->inode_map);
37219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
37319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
37419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
37519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto errout;
37619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
37719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3783984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
3793984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					       EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
38019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectredo_counts:
38119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	had_problem = 0;
38219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	save_problem = 0;
38319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.ino = pctx.ino2 = 0;
3843984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	if (csum_flag &&
3853984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	    (fs->group_desc[group].bg_flags & EXT2_BG_INODE_UNINIT))
38619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		skip_group++;
38719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
38819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	/* Protect loop from wrap-around if inodes_count is maxed */
38919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = 1; i <= fs->super->s_inodes_count && i > 0; i++) {
39019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		actual = ext2fs_fast_test_inode_bitmap(ctx->inode_used_map, i);
39119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (skip_group)
39219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			bitmap = 0;
39319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		else
39419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			bitmap = ext2fs_fast_test_inode_bitmap(fs->inode_map, i);
39519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (actual == bitmap)
39619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			goto do_counts;
39719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
39819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (!actual && bitmap) {
39919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			/*
40019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 * Inode wasn't used, but marked in bitmap
40119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 */
40219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_INODE_UNUSED;
40319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else /* if (actual && !bitmap) */ {
40419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			/*
40519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 * Inode used, but not in bitmap
40619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			 */
40719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			problem = PR_5_INODE_USED;
4083984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
4093984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			/* We should never hit this, because it means that
4103984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			 * inodes were marked in use that weren't noticed
4113984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			 * in pass1 or pass 2. It is easier to fix the problem
4123984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			 * than to kill e2fsck and leave the user stuck. */
4133984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (skip_group) {
4143984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				struct problem_context pctx2;
4153984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				pctx2.blk = i;
4163984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				pctx2.group = group;
4173984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				if (fix_problem(ctx, PR_5_INODE_UNINIT,&pctx2)){
4183984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					fs->group_desc[group].bg_flags &=
4193984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt						~EXT2_BG_INODE_UNINIT;
4203984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					skip_group = 0;
4213984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				}
4223984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			}
42319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
42419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (pctx.ino == 0) {
42519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.ino = pctx.ino2 = i;
42619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			save_problem = problem;
42719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else {
42819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if ((problem == save_problem) &&
42919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (pctx.ino2 == i-1))
43019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				pctx.ino2++;
43119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			else {
43219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				print_bitmap_problem(ctx, save_problem, &pctx);
43319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				pctx.ino = pctx.ino2 = i;
43419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				save_problem = problem;
43519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			}
43619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
43719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
43819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		had_problem++;
43919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
44019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectdo_counts:
44119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (bitmap) {
44219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, i))
44319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				dirs_count++;
4443984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt		} else if (!skip_group || csum_flag) {
44519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group_free++;
44619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			free_inodes++;
44719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
44819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		inodes++;
44919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if ((inodes == fs->super->s_inodes_per_group) ||
45019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		    (i == fs->super->s_inodes_count)) {
45119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			free_array[group] = group_free;
45219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			dir_array[group] = dirs_count;
45319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group ++;
45419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			inodes = 0;
45519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			skip_group = 0;
45619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			group_free = 0;
45719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			dirs_count = 0;
45819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (ctx->progress)
45919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				if ((ctx->progress)(ctx, 5,
46019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					    group + fs->group_desc_count,
46119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					    fs->group_desc_count*2))
46219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					goto errout;
4633984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt			if (csum_flag &&
46419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (i != fs->super->s_inodes_count) &&
46519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			    (fs->group_desc[group].bg_flags &
46619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			     EXT2_BG_INODE_UNINIT))
46719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				skip_group++;
46819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
46919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
47019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.ino)
47119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		print_bitmap_problem(ctx, save_problem, &pctx);
47219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
47319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (had_problem)
47419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fixit = end_problem_latch(ctx, PR_LATCH_IBITMAP);
47519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	else
47619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fixit = -1;
47719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
47819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
47919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (fixit == 1) {
48019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_free_inode_bitmap(fs->inode_map);
48119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		retval = ext2fs_copy_bitmap(ctx->inode_used_map,
48219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						  &fs->inode_map);
48319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (retval) {
48419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			clear_problem_context(&pctx);
48519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			fix_problem(ctx, PR_5_COPY_IBITMAP_ERROR, &pctx);
48619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ctx->flags |= E2F_FLAG_ABORT;
48719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			goto errout;
48819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
48919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_set_bitmap_padding(fs->inode_map);
49019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_mark_ib_dirty(fs);
49119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
49219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		/* redo counts */
49319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		inodes = 0; free_inodes = 0; group_free = 0;
49419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		dirs_count = 0; group = 0;
49519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		memset(free_array, 0, fs->group_desc_count * sizeof(int));
49619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		memset(dir_array, 0, fs->group_desc_count * sizeof(int));
49719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		goto redo_counts;
49819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	} else if (fixit == 0)
49919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ext2fs_unmark_valid(fs);
50019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
50119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = 0; i < fs->group_desc_count; i++) {
50219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (free_array[i] != fs->group_desc[i].bg_free_inodes_count) {
50319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.group = i;
50419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.ino = fs->group_desc[i].bg_free_inodes_count;
50519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.ino2 = free_array[i];
50619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (fix_problem(ctx, PR_5_FREE_INODE_COUNT_GROUP,
50719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					&pctx)) {
50819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				fs->group_desc[i].bg_free_inodes_count =
50919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					free_array[i];
51019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_mark_super_dirty(fs);
51119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			} else
51219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_unmark_valid(fs);
51319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
51419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (dir_array[i] != fs->group_desc[i].bg_used_dirs_count) {
51519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.group = i;
51619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.ino = fs->group_desc[i].bg_used_dirs_count;
51719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			pctx.ino2 = dir_array[i];
51819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
51919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (fix_problem(ctx, PR_5_FREE_DIR_COUNT_GROUP,
52019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					&pctx)) {
52119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				fs->group_desc[i].bg_used_dirs_count =
52219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					dir_array[i];
52319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_mark_super_dirty(fs);
52419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			} else
52519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_unmark_valid(fs);
52619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
52719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
52819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (free_inodes != fs->super->s_free_inodes_count) {
52919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.group = -1;
53019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino = fs->super->s_free_inodes_count;
53119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.ino2 = free_inodes;
53219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
53319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (fix_problem(ctx, PR_5_FREE_INODE_COUNT, &pctx)) {
53419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			fs->super->s_free_inodes_count = free_inodes;
53519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ext2fs_mark_super_dirty(fs);
53619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		} else
53719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			ext2fs_unmark_valid(fs);
53819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
53919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecterrout:
54019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_mem(&free_array);
54119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2fs_free_mem(&dir_array);
54219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
54319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
54419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_inode_end(e2fsck_t ctx)
54519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
54619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_filsys fs = ctx->fs;
54719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_ino_t	end, save_inodes_count, i;
54819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct problem_context	pctx;
54919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
55019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	clear_problem_context(&pctx);
55119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
55219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
55319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end,
55419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						     &save_inodes_count);
55519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.errcode) {
55619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 1;
55719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
55819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
55919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
56019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
56119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (save_inodes_count == end)
56219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
56319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
5643984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	/* protect loop from wrap-around if end is maxed */
56519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = save_inodes_count + 1; i <= end && i > save_inodes_count; i++) {
56619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (!ext2fs_test_inode_bitmap(fs->inode_map, i)) {
56719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (fix_problem(ctx, PR_5_INODE_BMAP_PADDING, &pctx)) {
5683984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				for (; i <= end; i++)
56919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					ext2fs_mark_inode_bitmap(fs->inode_map,
57019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project								 i);
57119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_mark_ib_dirty(fs);
57219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			} else
57319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_unmark_valid(fs);
57419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			break;
57519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
57619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
57719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
57819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map,
57919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						     save_inodes_count, 0);
58019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.errcode) {
58119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 2;
58219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
58319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
58419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
58519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
58619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
58719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
58819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic void check_block_end(e2fsck_t ctx)
58919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
59019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	ext2_filsys fs = ctx->fs;
59119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	blk_t	end, save_blocks_count, i;
59219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct problem_context	pctx;
59319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
59419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	clear_problem_context(&pctx);
59519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
5963984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	end = ext2fs_get_block_bitmap_start(fs->block_map) +
59719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		(EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count) - 1;
59819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.errcode = ext2fs_fudge_block_bitmap_end(fs->block_map, end,
59919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						     &save_blocks_count);
60019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.errcode) {
60119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 3;
60219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
60319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
60419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
60519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
60619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (save_blocks_count == end)
60719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
60819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
6093984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	/* Protect loop from wrap-around if end is maxed */
61019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (i = save_blocks_count + 1; i <= end && i > save_blocks_count; i++) {
61119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (!ext2fs_test_block_bitmap(fs->block_map, i)) {
61219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			if (fix_problem(ctx, PR_5_BLOCK_BMAP_PADDING, &pctx)) {
6133984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				for (; i <= end; i++)
61419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					ext2fs_mark_block_bitmap(fs->block_map,
61519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project								 i);
61619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_mark_bb_dirty(fs);
61719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			} else
61819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				ext2fs_unmark_valid(fs);
61919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			break;
62019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
62119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
62219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
62319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	pctx.errcode = ext2fs_fudge_block_bitmap_end(fs->block_map,
62419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project						     save_blocks_count, 0);
62519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (pctx.errcode) {
62619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		pctx.num = 4;
62719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
62819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		ctx->flags |= E2F_FLAG_ABORT; /* fatal */
62919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return;
63019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
63119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
63219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
63319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
63419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
635