Whamcloud - gitweb
e2fsck: perform implied cluster allocations when filling a directory hole
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 26 Jul 2014 00:33:57 +0000 (17:33 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 26 Jul 2014 20:07:17 +0000 (16:07 -0400)
If we're filling a directory hole, we need to perform an implied
cluster allocation to satisfy the bigalloc rule of mapping only one
pblk to a logical cluster.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass2.c

index 2f57af6..8fcb4ac 100644 (file)
@@ -1412,7 +1412,7 @@ static int allocate_dir_block(e2fsck_t ctx,
                              struct problem_context *pctx)
 {
        ext2_filsys fs = ctx->fs;
-       blk64_t                 blk;
+       blk64_t                 blk = 0;
        char                    *block;
        struct ext2_inode       inode;
 
@@ -1428,11 +1428,17 @@ static int allocate_dir_block(e2fsck_t ctx,
        /*
         * First, find a free block
         */
-       pctx->errcode = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
-       if (pctx->errcode) {
-               pctx->str = "ext2fs_new_block";
-               fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx);
-               return 1;
+       e2fsck_read_inode(ctx, db->ino, &inode, "allocate_dir_block");
+       pctx->errcode = ext2fs_map_cluster_block(fs, db->ino, &inode,
+                                                db->blockcnt, &blk);
+       if (pctx->errcode || blk == 0) {
+               pctx->errcode = ext2fs_new_block2(fs, 0,
+                                                 ctx->block_found_map, &blk);
+               if (pctx->errcode) {
+                       pctx->str = "ext2fs_new_block";
+                       fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx);
+                       return 1;
+               }
        }
        ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
        ext2fs_mark_block_bitmap2(fs->block_map, blk);
@@ -1464,7 +1470,6 @@ static int allocate_dir_block(e2fsck_t ctx,
        /*
         * Update the inode block count
         */
-       e2fsck_read_inode(ctx, db->ino, &inode, "allocate_dir_block");
        ext2fs_iblk_add_blocks(fs, &inode, 1);
        if (EXT2_I_SIZE(&inode) < (db->blockcnt+1) * fs->blocksize) {
                pctx->errcode = ext2fs_inode_size_set(fs, &inode,