2 * pass5.c --- check block and inode bitmaps against on-disk bitmaps
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
15 #include <sys/types.h>
17 #include <sys/ioctl.h>
24 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
26 static void check_block_bitmaps(e2fsck_t ctx);
27 static void check_inode_bitmaps(e2fsck_t ctx);
28 static void check_inode_end(e2fsck_t ctx);
29 static void check_block_end(e2fsck_t ctx);
31 void e2fsck_pass5(e2fsck_t ctx)
34 struct resource_track rtrack;
36 struct problem_context pctx;
39 mtrace_print("Pass 5");
42 init_resource_track(&rtrack, ctx->fs->io);
43 clear_problem_context(&pctx);
45 if (!(ctx->options & E2F_OPT_PREEN))
46 fix_problem(ctx, PR_5_PASS_HEADER, &pctx);
49 if ((ctx->progress)(ctx, 5, 0, ctx->fs->group_desc_count*2))
52 e2fsck_read_bitmaps(ctx);
54 check_block_bitmaps(ctx);
55 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
57 check_inode_bitmaps(ctx);
58 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
61 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
64 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
67 ext2fs_free_inode_bitmap(ctx->inode_used_map);
68 ctx->inode_used_map = 0;
69 ext2fs_free_inode_bitmap(ctx->inode_dir_map);
70 ctx->inode_dir_map = 0;
71 ext2fs_free_block_bitmap(ctx->block_found_map);
72 ctx->block_found_map = 0;
74 print_resource_track(ctx, _("Pass 5"), &rtrack, ctx->fs->io);
77 static void e2fsck_discard_blocks(e2fsck_t ctx, blk64_t start,
80 ext2_filsys fs = ctx->fs;
83 * If the filesystem has changed it means that there was an corruption
84 * which should be repaired, but in some cases just one e2fsck run is
85 * not enough to fix the problem, hence it is not safe to run discard
88 if (ext2fs_test_changed(fs))
89 ctx->options &= ~E2F_OPT_DISCARD;
91 if (!(ctx->options & E2F_OPT_NO) &&
92 (ctx->options & E2F_OPT_DISCARD) &&
93 (io_channel_discard(fs->io, start, count)))
94 ctx->options &= ~E2F_OPT_DISCARD;
98 * This will try to discard number 'count' inodes starting at
99 * inode number 'start' within the 'group'. Note that 'start'
100 * is 1-based, it means that we need to adjust it by -1 in this
101 * function to compute right offset in the particular inode table.
103 static void e2fsck_discard_inodes(e2fsck_t ctx, int group,
104 int start, int count)
106 ext2_filsys fs = ctx->fs;
111 * Sanity check for 'start'
113 if ((start < 1) || (start > EXT2_INODES_PER_GROUP(fs->super))) {
114 printf("PROGRAMMING ERROR: Got start %d outside of group %d!"
115 " Disabling discard\n",
117 ctx->options &= ~E2F_OPT_DISCARD;
120 if ((ctx->options & E2F_OPT_NO) || !(ctx->options & E2F_OPT_DISCARD))
124 * Start is inode number within the group which starts
125 * counting from 1, so we need to adjust it.
130 * We can discard only blocks containing only unused
131 * inodes in the table.
133 blk = DIV_ROUND_UP(start,
134 EXT2_INODES_PER_BLOCK(fs->super));
135 count -= (blk * EXT2_INODES_PER_BLOCK(fs->super) - start);
136 blk += ext2fs_inode_table_loc(fs, group);
137 num = count / EXT2_INODES_PER_BLOCK(fs->super);
140 e2fsck_discard_blocks(ctx, blk, num);
143 #define NO_BLK ((blk64_t) -1)
145 static void print_bitmap_problem(e2fsck_t ctx, int problem,
146 struct problem_context *pctx)
149 case PR_5_BLOCK_UNUSED:
150 if (pctx->blk == pctx->blk2)
153 problem = PR_5_BLOCK_RANGE_UNUSED;
155 case PR_5_BLOCK_USED:
156 if (pctx->blk == pctx->blk2)
159 problem = PR_5_BLOCK_RANGE_USED;
161 case PR_5_INODE_UNUSED:
162 if (pctx->ino == pctx->ino2)
165 problem = PR_5_INODE_RANGE_UNUSED;
167 case PR_5_INODE_USED:
168 if (pctx->ino == pctx->ino2)
171 problem = PR_5_INODE_RANGE_USED;
174 fix_problem(ctx, problem, pctx);
175 pctx->blk = pctx->blk2 = NO_BLK;
176 pctx->ino = pctx->ino2 = 0;
179 /* Just to be more succint */
180 #define B2C(x) EXT2FS_B2C(fs, (x))
181 #define EQ_CLSTR(x, y) (B2C(x) == B2C(y))
182 #define LE_CLSTR(x, y) (B2C(x) <= B2C(y))
183 #define GE_CLSTR(x, y) (B2C(x) >= B2C(y))
185 static void check_block_bitmaps(e2fsck_t ctx)
187 ext2_filsys fs = ctx->fs;
192 blk64_t free_blocks = 0;
193 blk64_t first_free = ext2fs_blocks_count(fs->super);
196 struct problem_context pctx;
197 int problem, save_problem, fixit, had_problem;
201 int old_desc_blocks = 0;
205 blk64_t super_blk, old_desc_blk, new_desc_blk;
206 io_manager manager = ctx->fs->io->manager;
208 clear_problem_context(&pctx);
209 free_array = (int *) e2fsck_allocate_memory(ctx,
210 fs->group_desc_count * sizeof(int), "free block count array");
212 if ((B2C(fs->super->s_first_data_block) <
213 ext2fs_get_block_bitmap_start2(ctx->block_found_map)) ||
214 (B2C(ext2fs_blocks_count(fs->super)-1) >
215 ext2fs_get_block_bitmap_end2(ctx->block_found_map))) {
217 pctx.blk = B2C(fs->super->s_first_data_block);
218 pctx.blk2 = B2C(ext2fs_blocks_count(fs->super) - 1);
219 pctx.ino = ext2fs_get_block_bitmap_start2(ctx->block_found_map);
220 pctx.ino2 = ext2fs_get_block_bitmap_end2(ctx->block_found_map);
221 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
223 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
227 if ((B2C(fs->super->s_first_data_block) <
228 ext2fs_get_block_bitmap_start2(fs->block_map)) ||
229 (B2C(ext2fs_blocks_count(fs->super)-1) >
230 ext2fs_get_block_bitmap_end2(fs->block_map))) {
232 pctx.blk = B2C(fs->super->s_first_data_block);
233 pctx.blk2 = B2C(ext2fs_blocks_count(fs->super) - 1);
234 pctx.ino = ext2fs_get_block_bitmap_start2(fs->block_map);
235 pctx.ino2 = ext2fs_get_block_bitmap_end2(fs->block_map);
236 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
238 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
242 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
243 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
247 pctx.blk = pctx.blk2 = NO_BLK;
249 (ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT)))
251 for (i = B2C(fs->super->s_first_data_block);
252 i < ext2fs_blocks_count(fs->super);
253 i += EXT2FS_CLUSTER_RATIO(fs)) {
254 actual = ext2fs_fast_test_block_bitmap2(ctx->block_found_map, i);
257 if ((B2C(i) - B2C(fs->super->s_first_data_block)) %
258 fs->super->s_clusters_per_group == 0) {
262 ext2fs_super_and_bgd_loc2(fs, group, &super_blk,
263 &old_desc_blk, &new_desc_blk, 0);
265 if (fs->super->s_feature_incompat &
266 EXT2_FEATURE_INCOMPAT_META_BG)
268 fs->super->s_first_meta_bg;
270 old_desc_blocks = fs->desc_blocks +
271 fs->super->s_reserved_gdt_blocks;
274 cmp_block = fs->super->s_clusters_per_group;
275 if (group == (int)fs->group_desc_count - 1)
276 cmp_block = EXT2FS_NUM_B2C(fs,
277 ext2fs_group_blocks_count(fs, group));
281 if (EQ_CLSTR(i, super_blk) ||
282 (old_desc_blk && old_desc_blocks &&
283 GE_CLSTR(i, old_desc_blk) &&
284 LE_CLSTR(i, old_desc_blk + old_desc_blocks-1)) ||
285 (new_desc_blk && EQ_CLSTR(i, new_desc_blk)) ||
286 EQ_CLSTR(i, ext2fs_block_bitmap_loc(fs, group)) ||
287 EQ_CLSTR(i, ext2fs_inode_bitmap_loc(fs, group)) ||
288 (GE_CLSTR(i, ext2fs_inode_table_loc(fs, group)) &&
289 LE_CLSTR(i, (ext2fs_inode_table_loc(fs, group) +
290 fs->inode_blocks_per_group - 1)))) {
292 actual = (actual != 0);
295 } else if ((EXT2FS_B2C(fs, i) - count -
296 EXT2FS_B2C(fs, fs->super->s_first_data_block)) %
297 fs->super->s_clusters_per_group == 0) {
299 * When the compare data blocks in block bitmap
300 * are 0, count the free block,
301 * skip the current block group.
303 if (ext2fs_test_block_bitmap_range2(
304 ctx->block_found_map,
308 * -1 means to skip the current block
311 blocks = fs->super->s_clusters_per_group - 1;
312 group_free = cmp_block;
313 free_blocks += cmp_block;
315 * The current block group's last block
318 i += EXT2FS_C2B(fs, cmp_block - 1);
323 } else if (redo_flag)
326 bitmap = ext2fs_fast_test_block_bitmap2(fs->block_map, i);
328 if (!actual == !bitmap)
331 if (!actual && bitmap) {
333 * Block not used, but marked in use in the bitmap.
335 problem = PR_5_BLOCK_UNUSED;
338 * Block used, but not marked in use in the bitmap.
340 problem = PR_5_BLOCK_USED;
343 struct problem_context pctx2;
346 if (fix_problem(ctx, PR_5_BLOCK_UNINIT,&pctx2)){
347 ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
352 if (pctx.blk == NO_BLK) {
353 pctx.blk = pctx.blk2 = i;
354 save_problem = problem;
356 if ((problem == save_problem) &&
360 print_bitmap_problem(ctx, save_problem, &pctx);
361 pctx.blk = pctx.blk2 = i;
362 save_problem = problem;
365 ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
369 * If there a problem we should turn off the discard so we
370 * do not compromise the filesystem.
372 ctx->options &= ~E2F_OPT_DISCARD;
375 if (!bitmap && (!skip_group || csum_flag)) {
382 e2fsck_discard_blocks(ctx, first_free,
384 first_free = ext2fs_blocks_count(fs->super);
387 if ((blocks == fs->super->s_clusters_per_group) ||
388 (EXT2FS_B2C(fs, i) ==
389 EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1))) {
391 * If the last block of this group is free, then we can
392 * discard it as well.
394 if (!bitmap && i >= first_free)
395 e2fsck_discard_blocks(ctx, first_free,
396 (i - first_free) + 1);
397 first_free = ext2fs_blocks_count(fs->super);
399 free_array[group] = group_free;
405 if ((ctx->progress)(ctx, 5, group,
406 fs->group_desc_count*2))
409 (i != ext2fs_blocks_count(fs->super)-1) &&
410 ext2fs_bg_flags_test(fs, group,
411 EXT2_BG_BLOCK_UNINIT))
415 if (pctx.blk != NO_BLK)
416 print_bitmap_problem(ctx, save_problem, &pctx);
418 fixit = end_problem_latch(ctx, PR_LATCH_BBITMAP);
421 ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
424 ext2fs_free_block_bitmap(fs->block_map);
425 retval = ext2fs_copy_bitmap(ctx->block_found_map,
428 clear_problem_context(&pctx);
429 fix_problem(ctx, PR_5_COPY_BBITMAP_ERROR, &pctx);
430 ctx->flags |= E2F_FLAG_ABORT;
433 ext2fs_set_bitmap_padding(fs->block_map);
434 ext2fs_mark_bb_dirty(fs);
436 /* Redo the counts */
437 blocks = 0; free_blocks = 0; group_free = 0; group = 0;
438 memset(free_array, 0, fs->group_desc_count * sizeof(int));
441 } else if (fixit == 0)
442 ext2fs_unmark_valid(fs);
444 for (i = 0; i < fs->group_desc_count; i++) {
445 if (free_array[i] != ext2fs_bg_free_blocks_count(fs, i)) {
447 pctx.blk = ext2fs_bg_free_blocks_count(fs, i);
448 pctx.blk2 = free_array[i];
450 if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT_GROUP,
452 ext2fs_bg_free_blocks_count_set(fs, i, free_array[i]);
453 ext2fs_mark_super_dirty(fs);
455 ext2fs_unmark_valid(fs);
458 free_blocks = EXT2FS_C2B(fs, free_blocks);
459 if (free_blocks != ext2fs_free_blocks_count(fs->super)) {
461 pctx.blk = ext2fs_free_blocks_count(fs->super);
462 pctx.blk2 = free_blocks;
464 if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT, &pctx)) {
465 ext2fs_free_blocks_count_set(fs->super, free_blocks);
466 ext2fs_mark_super_dirty(fs);
468 ext2fs_unmark_valid(fs);
471 ext2fs_free_mem(&free_array);
474 static void check_inode_bitmaps(e2fsck_t ctx)
476 ext2_filsys fs = ctx->fs;
478 unsigned int free_inodes = 0;
482 unsigned int inodes = 0;
487 struct problem_context pctx;
488 int problem, save_problem, fixit, had_problem;
492 io_manager manager = ctx->fs->io->manager;
493 int first_free = fs->super->s_inodes_per_group + 1;
495 clear_problem_context(&pctx);
496 free_array = (int *) e2fsck_allocate_memory(ctx,
497 fs->group_desc_count * sizeof(int), "free inode count array");
499 dir_array = (int *) e2fsck_allocate_memory(ctx,
500 fs->group_desc_count * sizeof(int), "directory count array");
502 if ((1 < ext2fs_get_inode_bitmap_start2(ctx->inode_used_map)) ||
503 (fs->super->s_inodes_count >
504 ext2fs_get_inode_bitmap_end2(ctx->inode_used_map))) {
507 pctx.blk2 = fs->super->s_inodes_count;
508 pctx.ino = ext2fs_get_inode_bitmap_start2(ctx->inode_used_map);
509 pctx.ino2 = ext2fs_get_inode_bitmap_end2(ctx->inode_used_map);
510 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
512 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
515 if ((1 < ext2fs_get_inode_bitmap_start2(fs->inode_map)) ||
516 (fs->super->s_inodes_count >
517 ext2fs_get_inode_bitmap_end2(fs->inode_map))) {
520 pctx.blk2 = fs->super->s_inodes_count;
521 pctx.ino = ext2fs_get_inode_bitmap_start2(fs->inode_map);
522 pctx.ino2 = ext2fs_get_inode_bitmap_end2(fs->inode_map);
523 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
525 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
529 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
530 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
534 pctx.ino = pctx.ino2 = 0;
536 (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)))
539 /* Protect loop from wrap-around if inodes_count is maxed */
540 for (i = 1; i <= fs->super->s_inodes_count && i > 0; i++) {
543 i % fs->super->s_inodes_per_group == 1) {
545 * Current inode is the first inode
546 * in the current block group.
548 if (ext2fs_test_inode_bitmap_range(
549 ctx->inode_used_map, i,
550 fs->super->s_inodes_per_group)) {
552 * When the compared inodes in inodes bitmap
553 * are 0, count the free inode,
554 * skip the current block group.
557 inodes = fs->super->s_inodes_per_group - 1;
559 free_inodes += inodes;
566 actual = ext2fs_fast_test_inode_bitmap2(ctx->inode_used_map, i);
569 else if (!skip_group)
570 bitmap = ext2fs_fast_test_inode_bitmap2(fs->inode_map, i);
571 if (!actual == !bitmap)
574 if (!actual && bitmap) {
576 * Inode wasn't used, but marked in bitmap
578 problem = PR_5_INODE_UNUSED;
579 } else /* if (actual && !bitmap) */ {
581 * Inode used, but not in bitmap
583 problem = PR_5_INODE_USED;
585 /* We should never hit this, because it means that
586 * inodes were marked in use that weren't noticed
587 * in pass1 or pass 2. It is easier to fix the problem
588 * than to kill e2fsck and leave the user stuck. */
590 struct problem_context pctx2;
593 if (fix_problem(ctx, PR_5_INODE_UNINIT,&pctx2)){
594 ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
600 pctx.ino = pctx.ino2 = i;
601 save_problem = problem;
603 if ((problem == save_problem) &&
607 print_bitmap_problem(ctx, save_problem, &pctx);
608 pctx.ino = pctx.ino2 = i;
609 save_problem = problem;
612 ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
615 * If there a problem we should turn off the discard so we
616 * do not compromise the filesystem.
618 ctx->options &= ~E2F_OPT_DISCARD;
623 if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, i))
625 if (inodes > first_free) {
626 e2fsck_discard_inodes(ctx, group, first_free,
627 inodes - first_free);
628 first_free = fs->super->s_inodes_per_group + 1;
630 } else if (!skip_group || csum_flag) {
633 if (first_free > inodes)
637 if ((inodes == fs->super->s_inodes_per_group) ||
638 (i == fs->super->s_inodes_count)) {
640 * If the last inode is free, we can discard it as well.
642 if (!bitmap && inodes >= first_free)
643 e2fsck_discard_inodes(ctx, group, first_free,
644 inodes - first_free + 1);
646 * If discard zeroes data and the group inode table
647 * was not zeroed yet, set itable as zeroed
649 if ((ctx->options & E2F_OPT_DISCARD) &&
650 io_channel_discard_zeroes_data(fs->io) &&
651 !(ext2fs_bg_flags_test(fs, group,
652 EXT2_BG_INODE_ZEROED))) {
653 ext2fs_bg_flags_set(fs, group,
654 EXT2_BG_INODE_ZEROED);
655 ext2fs_group_desc_csum_set(fs, group);
658 first_free = fs->super->s_inodes_per_group + 1;
659 free_array[group] = group_free;
660 dir_array[group] = dirs_count;
667 if ((ctx->progress)(ctx, 5,
668 group + fs->group_desc_count,
669 fs->group_desc_count*2))
672 (i != fs->super->s_inodes_count) &&
673 (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)
679 print_bitmap_problem(ctx, save_problem, &pctx);
682 fixit = end_problem_latch(ctx, PR_LATCH_IBITMAP);
685 ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
688 ext2fs_free_inode_bitmap(fs->inode_map);
689 retval = ext2fs_copy_bitmap(ctx->inode_used_map,
692 clear_problem_context(&pctx);
693 fix_problem(ctx, PR_5_COPY_IBITMAP_ERROR, &pctx);
694 ctx->flags |= E2F_FLAG_ABORT;
697 ext2fs_set_bitmap_padding(fs->inode_map);
698 ext2fs_mark_ib_dirty(fs);
701 inodes = 0; free_inodes = 0; group_free = 0;
702 dirs_count = 0; group = 0;
703 memset(free_array, 0, fs->group_desc_count * sizeof(int));
704 memset(dir_array, 0, fs->group_desc_count * sizeof(int));
707 } else if (fixit == 0)
708 ext2fs_unmark_valid(fs);
710 for (i = 0; i < fs->group_desc_count; i++) {
711 if (free_array[i] != ext2fs_bg_free_inodes_count(fs, i)) {
713 pctx.ino = ext2fs_bg_free_inodes_count(fs, i);
714 pctx.ino2 = free_array[i];
715 if (fix_problem(ctx, PR_5_FREE_INODE_COUNT_GROUP,
717 ext2fs_bg_free_inodes_count_set(fs, i, free_array[i]);
718 ext2fs_mark_super_dirty(fs);
720 ext2fs_unmark_valid(fs);
722 if (dir_array[i] != ext2fs_bg_used_dirs_count(fs, i)) {
724 pctx.ino = ext2fs_bg_used_dirs_count(fs, i);
725 pctx.ino2 = dir_array[i];
727 if (fix_problem(ctx, PR_5_FREE_DIR_COUNT_GROUP,
729 ext2fs_bg_used_dirs_count_set(fs, i, dir_array[i]);
730 ext2fs_mark_super_dirty(fs);
732 ext2fs_unmark_valid(fs);
735 if (free_inodes != fs->super->s_free_inodes_count) {
737 pctx.ino = fs->super->s_free_inodes_count;
738 pctx.ino2 = free_inodes;
740 if (fix_problem(ctx, PR_5_FREE_INODE_COUNT, &pctx)) {
741 fs->super->s_free_inodes_count = free_inodes;
742 ext2fs_mark_super_dirty(fs);
744 ext2fs_unmark_valid(fs);
747 ext2fs_free_mem(&free_array);
748 ext2fs_free_mem(&dir_array);
751 static void check_inode_end(e2fsck_t ctx)
753 ext2_filsys fs = ctx->fs;
754 ext2_ino_t end, save_inodes_count, i;
755 struct problem_context pctx;
757 clear_problem_context(&pctx);
759 end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
760 pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end,
764 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
765 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
768 if (save_inodes_count == end)
771 /* protect loop from wrap-around if end is maxed */
772 for (i = save_inodes_count + 1; i <= end && i > save_inodes_count; i++) {
773 if (!ext2fs_test_inode_bitmap(fs->inode_map, i)) {
774 if (fix_problem(ctx, PR_5_INODE_BMAP_PADDING, &pctx)) {
775 for (; i <= end; i++)
776 ext2fs_mark_inode_bitmap(fs->inode_map,
778 ext2fs_mark_ib_dirty(fs);
780 ext2fs_unmark_valid(fs);
785 pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map,
786 save_inodes_count, 0);
789 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
790 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
795 static void check_block_end(e2fsck_t ctx)
797 ext2_filsys fs = ctx->fs;
798 blk64_t end, save_blocks_count, i;
799 struct problem_context pctx;
801 clear_problem_context(&pctx);
803 end = ext2fs_get_block_bitmap_start2(fs->block_map) +
804 ((blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * fs->group_desc_count) - 1;
805 pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map, end,
809 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
810 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
813 if (save_blocks_count == end)
816 /* Protect loop from wrap-around if end is maxed */
817 for (i = save_blocks_count + 1; i <= end && i > save_blocks_count; i++) {
818 if (!ext2fs_test_block_bitmap2(fs->block_map,
819 EXT2FS_C2B(fs, i))) {
820 if (fix_problem(ctx, PR_5_BLOCK_BMAP_PADDING, &pctx)) {
821 for (; i <= end; i++)
822 ext2fs_mark_block_bitmap2(fs->block_map,
824 ext2fs_mark_bb_dirty(fs);
826 ext2fs_unmark_valid(fs);
831 pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map,
832 save_blocks_count, 0);
835 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
836 ctx->flags |= E2F_FLAG_ABORT; /* fatal */