Whamcloud - gitweb
Fixes necessary for e2fsprogs to work using the diet libc.
[tools/e2fsprogs.git] / e2fsck / pass5.c
index 9dcb7fd..e5964e6 100644 (file)
@@ -38,19 +38,23 @@ void e2fsck_pass5(e2fsck_t ctx)
        if (!(ctx->options & E2F_OPT_PREEN))
                fix_problem(ctx, PR_5_PASS_HEADER, &pctx);
 
-       read_bitmaps(ctx);
+       if (ctx->progress)
+               if ((ctx->progress)(ctx, 5, 0, ctx->fs->group_desc_count*2))
+                       return;
+
+       e2fsck_read_bitmaps(ctx);
 
        check_block_bitmaps(ctx);
-       if (ctx->flags & E2F_FLAG_ABORT)
+       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                return;
        check_inode_bitmaps(ctx);
-       if (ctx->flags & E2F_FLAG_ABORT)
+       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                return;
        check_inode_end(ctx);
-       if (ctx->flags & E2F_FLAG_ABORT)
+       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                return;
        check_block_end(ctx);
-       if (ctx->flags & E2F_FLAG_ABORT)
+       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                return;
 
        ext2fs_free_inode_bitmap(ctx->inode_used_map);
@@ -61,8 +65,10 @@ void e2fsck_pass5(e2fsck_t ctx)
        ctx->block_found_map = 0;
 
 #ifdef RESOURCE_TRACK
-       if (ctx->options & E2F_OPT_TIME2)
-               print_resource_track("Pass 5", &rtrack);
+       if (ctx->options & E2F_OPT_TIME2) {
+               e2fsck_clear_progbar(ctx);
+               print_resource_track(_("Pass 5"), &rtrack);
+       }
 #endif
 }
 
@@ -77,12 +83,12 @@ static void check_block_bitmaps(e2fsck_t ctx)
        int     group_free = 0;
        int     actual, bitmap;
        struct problem_context  pctx;
-       int     problem, fixit;
+       int     problem, fixit, had_problem;
        errcode_t       retval;
        
        clear_problem_context(&pctx);
-       free_array = allocate_memory(fs->group_desc_count * sizeof(int),
-                                    "free block count array");
+       free_array = (int *) e2fsck_allocate_memory(ctx,
+           fs->group_desc_count * sizeof(int), "free block count array");
 
        if ((fs->super->s_first_data_block <
             ext2fs_get_block_bitmap_start(ctx->block_found_map)) ||
@@ -114,7 +120,8 @@ static void check_block_bitmaps(e2fsck_t ctx)
                return;
        }
                       
-redo_counts:                  
+redo_counts:
+       had_problem = 0;
        for (i = fs->super->s_first_data_block;
             i < fs->super->s_blocks_count;
             i++) {
@@ -137,6 +144,8 @@ redo_counts:
                }
                pctx.blk = i;
                fix_problem(ctx, problem, &pctx);
+               ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
+               had_problem++;
                
        do_counts:
                if (!bitmap) {
@@ -150,14 +159,28 @@ redo_counts:
                        group ++;
                        blocks = 0;
                        group_free = 0;
+                       if (ctx->progress)
+                               if ((ctx->progress)(ctx, 5, group,
+                                                   fs->group_desc_count*2))
+                                       return;
                }
        }
-       fixit = end_problem_latch(ctx,  PR_LATCH_BBITMAP);
+       if (had_problem)
+               fixit = end_problem_latch(ctx,  PR_LATCH_BBITMAP);
+       else
+               fixit = -1;
+       ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
+       
        if (fixit == 1) {
                ext2fs_free_block_bitmap(fs->block_map);
                retval = ext2fs_copy_bitmap(ctx->block_found_map,
                                                  &fs->block_map);
-               /* XXX check retval --- should never fail! */
+               if (retval) {
+                       clear_problem_context(&pctx);
+                       fix_problem(ctx, PR_5_COPY_BBITMAP_ERROR, &pctx);
+                       ctx->flags |= E2F_FLAG_ABORT;
+                       return;
+               }
                ext2fs_set_bitmap_padding(fs->block_map);
                ext2fs_mark_bb_dirty(fs);
                
@@ -200,7 +223,7 @@ redo_counts:
 static void check_inode_bitmaps(e2fsck_t ctx)
 {
        ext2_filsys fs = ctx->fs;
-       ino_t   i;
+       ext2_ino_t      i;
        int     free_inodes = 0;
        int     group_free = 0;
        int     dirs_count = 0;
@@ -211,14 +234,14 @@ static void check_inode_bitmaps(e2fsck_t ctx)
        int     actual, bitmap;
        errcode_t       retval;
        struct problem_context  pctx;
-       int     problem, fixit;
+       int     problem, fixit, had_problem;
        
        clear_problem_context(&pctx);
-       free_array = allocate_memory(fs->group_desc_count * sizeof(int),
-                                    "free inode count array");
+       free_array = (int *) e2fsck_allocate_memory(ctx,
+           fs->group_desc_count * sizeof(int), "free inode count array");
                                     
-       dir_array = allocate_memory(fs->group_desc_count * sizeof(int),
-                                   "directory count array");
+       dir_array = (int *) e2fsck_allocate_memory(ctx,
+          fs->group_desc_count * sizeof(int), "directory count array");
                                     
        if ((1 < ext2fs_get_inode_bitmap_start(ctx->inode_used_map)) ||
            (fs->super->s_inodes_count > 
@@ -248,6 +271,7 @@ static void check_inode_bitmaps(e2fsck_t ctx)
        }
 
 redo_counts:
+       had_problem = 0;
        for (i = 1; i <= fs->super->s_inodes_count; i++) {
                actual = ext2fs_fast_test_inode_bitmap(ctx->inode_used_map, i);
                bitmap = ext2fs_fast_test_inode_bitmap(fs->inode_map, i);
@@ -268,6 +292,8 @@ redo_counts:
                }
                pctx.ino = i;
                fix_problem(ctx, problem, &pctx);
+               ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
+               had_problem++;
                
 do_counts:
                if (!bitmap) {
@@ -286,14 +312,29 @@ do_counts:
                        inodes = 0;
                        group_free = 0;
                        dirs_count = 0;
+                       if (ctx->progress)
+                               if ((ctx->progress)(ctx, 5,
+                                           group + fs->group_desc_count,
+                                           fs->group_desc_count*2))
+                                       return;
                }
        }
-       fixit = end_problem_latch(ctx, PR_LATCH_IBITMAP);
+       if (had_problem)
+               fixit = end_problem_latch(ctx, PR_LATCH_IBITMAP);
+       else
+               fixit = -1;
+       ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
+       
        if (fixit == 1) {
                ext2fs_free_inode_bitmap(fs->inode_map);
                retval = ext2fs_copy_bitmap(ctx->inode_used_map,
                                                  &fs->inode_map);
-               /* XXX check retval --- should never fail! */
+               if (retval) {
+                       clear_problem_context(&pctx);
+                       fix_problem(ctx, PR_5_COPY_IBITMAP_ERROR, &pctx);
+                       ctx->flags |= E2F_FLAG_ABORT;
+                       return;
+               }
                ext2fs_set_bitmap_padding(fs->inode_map);
                ext2fs_mark_ib_dirty(fs);
 
@@ -351,7 +392,7 @@ do_counts:
 static void check_inode_end(e2fsck_t ctx)
 {
        ext2_filsys fs = ctx->fs;
-       ino_t   end, save_inodes_count, i;
+       ext2_ino_t      end, save_inodes_count, i;
        struct problem_context  pctx;
 
        clear_problem_context(&pctx);
@@ -415,7 +456,7 @@ static void check_block_end(e2fsck_t ctx)
        for (i = save_blocks_count + 1; i <= end; i++) {
                if (!ext2fs_test_block_bitmap(fs->block_map, i)) {
                        if (fix_problem(ctx, PR_5_BLOCK_BMAP_PADDING, &pctx)) {
-                               for (i = save_blocks_count + 1; i < end; i++)
+                               for (i = save_blocks_count + 1; i <= end; i++)
                                        ext2fs_mark_block_bitmap(fs->block_map,
                                                                 i);
                                ext2fs_mark_bb_dirty(fs);