summaryrefslogtreecommitdiff
path: root/e2fsck/pass3.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-12-12 15:39:14 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-12-12 15:39:14 -0500
commit2d3df8dc7f5f6970e77ed741e35c88408741a136 (patch)
tree230904720af345de15eaf7a6feb179fc7c12834f /e2fsck/pass3.c
parent1b977a0fad7be60d444228b5802683ff6b78baf2 (diff)
parent299cc61755f72311df002cc99dae13f469e0a198 (diff)
downloade2fsprogs-2d3df8dc7f5f6970e77ed741e35c88408741a136.tar.gz
Merge branch 'maint' into next
Conflicts: lib/ext2fs/newdir.c
Diffstat (limited to 'e2fsck/pass3.c')
-rw-r--r--e2fsck/pass3.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c
index fbaadcfc..dc9d7c19 100644
--- a/e2fsck/pass3.c
+++ b/e2fsck/pass3.c
@@ -53,7 +53,7 @@ static ext2fs_inode_bitmap inode_done_map = 0;
void e2fsck_pass3(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
- struct dir_info_iter *iter;
+ struct dir_info_iter *iter = NULL;
#ifdef RESOURCE_TRACK
struct resource_track rtrack;
#endif
@@ -108,7 +108,6 @@ void e2fsck_pass3(e2fsck_t ctx)
if (check_directory(ctx, dir->ino, &pctx))
goto abort_exit;
}
- e2fsck_dir_info_iter_end(ctx, iter);
/*
* Force the creation of /lost+found if not present
@@ -123,6 +122,8 @@ void e2fsck_pass3(e2fsck_t ctx)
e2fsck_rehash_directories(ctx);
abort_exit:
+ if (iter)
+ e2fsck_dir_info_iter_end(ctx, iter);
e2fsck_free_dir_info(ctx);
if (inode_loop_detect) {
ext2fs_free_inode_bitmap(inode_loop_detect);
@@ -757,6 +758,27 @@ static int expand_dir_proc(ext2_filsys fs,
return BLOCK_CHANGED;
}
+/*
+ * Ensure that all blocks are marked in the block_found_map, since it's
+ * possible that the library allocated an extent node block or a block map
+ * block during the directory rebuilding; these new allocations are not
+ * captured in block_found_map. This is bad since we could later use
+ * block_found_map to allocate more blocks.
+ */
+static int find_new_blocks_proc(ext2_filsys fs,
+ blk64_t *blocknr,
+ e2_blkcnt_t blockcnt,
+ blk64_t ref_block EXT2FS_ATTR((unused)),
+ int ref_offset EXT2FS_ATTR((unused)),
+ void *priv_data)
+{
+ struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
+ e2fsck_t ctx = es->ctx;
+
+ ext2fs_mark_block_bitmap2(ctx->block_found_map, *blocknr);
+ return 0;
+}
+
errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
int num, int guaranteed_size)
{
@@ -764,7 +786,7 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
errcode_t retval;
struct expand_dir_struct es;
struct ext2_inode inode;
- blk64_t sz;
+ blk64_t sz, before, after;
if (!(fs->flags & EXT2_FLAG_RW))
return EXT2_ET_RO_FILSYS;
@@ -787,11 +809,27 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
es.ctx = ctx;
es.dir = dir;
+ before = ext2fs_free_blocks_count(fs->super);
retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
0, expand_dir_proc, &es);
if (es.err)
return es.err;
+ after = ext2fs_free_blocks_count(fs->super);
+
+ /*
+ * If the free block count has dropped by more than the blocks we
+ * allocated ourselves, then we must've allocated some extent/map
+ * blocks. Therefore, we must iterate this dir's blocks again to
+ * ensure that all newly allocated blocks are captured in
+ * block_found_map.
+ */
+ if ((before - after) > es.newblocks) {
+ retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY,
+ 0, find_new_blocks_proc, &es);
+ if (es.err)
+ return es.err;
+ }
/*
* Update the size and block count fields in the inode.