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_DISCARD) &&
92 (io_channel_discard(fs->io, start, count)))
93 ctx->options &= ~E2F_OPT_DISCARD;
97 * This will try to discard number 'count' inodes starting at
98 * inode number 'start' within the 'group'. Note that 'start'
99 * is 1-based, it means that we need to adjust it by -1 in this
100 * function to compute right offset in the particular inode table.
102 static void e2fsck_discard_inodes(e2fsck_t ctx, dgrp_t group,
103 ext2_ino_t start, int count)
105 ext2_filsys fs = ctx->fs;
109 * Sanity check for 'start'
111 if ((start < 1) || (start > EXT2_INODES_PER_GROUP(fs->super))) {
112 printf("PROGRAMMING ERROR: Got start %d outside of group %d!"
113 " Disabling discard\n",
115 ctx->options &= ~E2F_OPT_DISCARD;
119 * Do not attempt to discard if E2F_OPT_DISCARD is not set. And also
120 * skip the discard on this group if discard does not zero data.
121 * The reason is that if the inode table is not zeroed discard would
122 * no help us since we need to zero it anyway, or if the inode table
123 * is zeroed then the read after discard would not be deterministic
124 * anyway and we would not be able to assume that this inode table
125 * was zeroed anymore so we would have to zero it again, which does
126 * not really make sense.
128 if (!(ctx->options & E2F_OPT_DISCARD) ||
129 !io_channel_discard_zeroes_data(fs->io))
133 * Start is inode number within the group which starts
134 * counting from 1, so we need to adjust it.
139 * We can discard only blocks containing only unused
140 * inodes in the table.
142 blk = DIV_ROUND_UP(start,
143 EXT2_INODES_PER_BLOCK(fs->super));
144 count -= (blk * EXT2_INODES_PER_BLOCK(fs->super) - start);
145 blk += ext2fs_inode_table_loc(fs, group);
146 num = count / EXT2_INODES_PER_BLOCK(fs->super);
149 e2fsck_discard_blocks(ctx, blk, num);
152 #define NO_BLK ((blk64_t) -1)
154 static void print_bitmap_problem(e2fsck_t ctx, problem_t problem,
155 struct problem_context *pctx)
158 case PR_5_BLOCK_UNUSED:
159 if (pctx->blk == pctx->blk2)
162 problem = PR_5_BLOCK_RANGE_UNUSED;
164 case PR_5_BLOCK_USED:
165 if (pctx->blk == pctx->blk2)
168 problem = PR_5_BLOCK_RANGE_USED;
170 case PR_5_INODE_UNUSED:
171 if (pctx->ino == pctx->ino2)
174 problem = PR_5_INODE_RANGE_UNUSED;
176 case PR_5_INODE_USED:
177 if (pctx->ino == pctx->ino2)
180 problem = PR_5_INODE_RANGE_USED;
183 fix_problem(ctx, problem, pctx);
184 pctx->blk = pctx->blk2 = NO_BLK;
185 pctx->ino = pctx->ino2 = 0;
188 /* Just to be more succint */
189 #define B2C(x) EXT2FS_B2C(fs, (x))
190 #define EQ_CLSTR(x, y) (B2C(x) == B2C(y))
191 #define LE_CLSTR(x, y) (B2C(x) <= B2C(y))
192 #define GE_CLSTR(x, y) (B2C(x) >= B2C(y))
194 static void check_block_bitmaps(e2fsck_t ctx)
196 ext2_filsys fs = ctx->fs;
198 unsigned int *free_array;
200 unsigned int blocks = 0;
201 blk64_t free_blocks = 0;
202 blk64_t first_free = ext2fs_blocks_count(fs->super);
203 unsigned int group_free = 0;
205 struct problem_context pctx;
206 problem_t problem, save_problem;
207 int fixit, had_problem;
209 int old_desc_blocks = 0;
213 blk64_t super_blk, old_desc_blk, new_desc_blk;
214 char *actual_buf, *bitmap_buf;
216 actual_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize,
217 "actual bitmap buffer");
218 bitmap_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize,
219 "bitmap block buffer");
221 clear_problem_context(&pctx);
222 free_array = (unsigned int *) e2fsck_allocate_memory(ctx,
223 fs->group_desc_count * sizeof(unsigned int), "free block count array");
225 if ((B2C(fs->super->s_first_data_block) <
226 ext2fs_get_block_bitmap_start2(ctx->block_found_map)) ||
227 (B2C(ext2fs_blocks_count(fs->super)-1) >
228 ext2fs_get_block_bitmap_end2(ctx->block_found_map))) {
230 pctx.blk = B2C(fs->super->s_first_data_block);
231 pctx.blk2 = B2C(ext2fs_blocks_count(fs->super) - 1);
232 pctx.ino = ext2fs_get_block_bitmap_start2(ctx->block_found_map);
233 pctx.ino2 = ext2fs_get_block_bitmap_end2(ctx->block_found_map);
234 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
236 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
240 if ((B2C(fs->super->s_first_data_block) <
241 ext2fs_get_block_bitmap_start2(fs->block_map)) ||
242 (B2C(ext2fs_blocks_count(fs->super)-1) >
243 ext2fs_get_block_bitmap_end2(fs->block_map))) {
245 pctx.blk = B2C(fs->super->s_first_data_block);
246 pctx.blk2 = B2C(ext2fs_blocks_count(fs->super) - 1);
247 pctx.ino = ext2fs_get_block_bitmap_start2(fs->block_map);
248 pctx.ino2 = ext2fs_get_block_bitmap_end2(fs->block_map);
249 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
251 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
258 pctx.blk = pctx.blk2 = NO_BLK;
259 for (i = B2C(fs->super->s_first_data_block);
260 i < ext2fs_blocks_count(fs->super);
261 i += EXT2FS_CLUSTER_RATIO(fs)) {
262 int first_block_in_bg = (B2C(i) -
263 B2C(fs->super->s_first_data_block)) %
264 fs->super->s_clusters_per_group == 0;
265 int n, nbytes = fs->super->s_clusters_per_group / 8;
267 actual = ext2fs_fast_test_block_bitmap2(ctx->block_found_map, i);
270 * Try to optimize pass5 by extracting a bitmap block
271 * as expected from what we have on disk, and then
272 * comparing the two. If they are identical, then
273 * update the free block counts and go on to the next
274 * block group. This is much faster than doing the
275 * individual bit-by-bit comparison. The one downside
276 * is that this doesn't work if we are asking e2fsck
277 * to do a discard operation.
279 if (!first_block_in_bg ||
280 (group == (int)fs->group_desc_count - 1) ||
281 (ctx->options & E2F_OPT_DISCARD))
284 retval = ext2fs_get_block_bitmap_range2(ctx->block_found_map,
285 B2C(i), fs->super->s_clusters_per_group,
289 retval = ext2fs_get_block_bitmap_range2(fs->block_map,
290 B2C(i), fs->super->s_clusters_per_group,
294 if (memcmp(actual_buf, bitmap_buf, nbytes) != 0)
296 n = ext2fs_bitcount(actual_buf, nbytes);
297 group_free = fs->super->s_clusters_per_group - n;
298 free_blocks += group_free;
299 i += EXT2FS_C2B(fs, fs->super->s_clusters_per_group - 1);
306 bitmap = ext2fs_fast_test_block_bitmap2(fs->block_map, i);
308 if (!actual == !bitmap)
311 if (!actual && bitmap) {
313 * Block not used, but marked in use in the bitmap.
315 problem = PR_5_BLOCK_UNUSED;
318 * Block used, but not marked in use in the bitmap.
320 problem = PR_5_BLOCK_USED;
322 if (ext2fs_bg_flags_test(fs, group,
323 EXT2_BG_BLOCK_UNINIT)) {
324 struct problem_context pctx2;
327 if (fix_problem(ctx, PR_5_BLOCK_UNINIT,
329 ext2fs_bg_flags_clear(fs, group,
330 EXT2_BG_BLOCK_UNINIT);
333 if (pctx.blk == NO_BLK) {
334 pctx.blk = pctx.blk2 = i;
335 save_problem = problem;
337 if ((problem == save_problem) &&
338 (pctx.blk2 == i - EXT2FS_CLUSTER_RATIO(fs)))
339 pctx.blk2 += EXT2FS_CLUSTER_RATIO(fs);
341 print_bitmap_problem(ctx, save_problem, &pctx);
342 pctx.blk = pctx.blk2 = i;
343 save_problem = problem;
346 ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
350 * If there a problem we should turn off the discard so we
351 * do not compromise the filesystem.
353 ctx->options &= ~E2F_OPT_DISCARD;
361 } else if (i > first_free) {
362 e2fsck_discard_blocks(ctx, first_free,
364 first_free = ext2fs_blocks_count(fs->super);
367 if ((blocks == fs->super->s_clusters_per_group) ||
368 (EXT2FS_B2C(fs, i) ==
369 EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1))) {
371 * If the last block of this group is free, then we can
372 * discard it as well.
374 if (!bitmap && i >= first_free)
375 e2fsck_discard_blocks(ctx, first_free,
376 (i - first_free) + 1);
378 first_free = ext2fs_blocks_count(fs->super);
380 free_array[group] = group_free;
385 if ((ctx->progress)(ctx, 5, group,
386 fs->group_desc_count*2))
390 if (pctx.blk != NO_BLK)
391 print_bitmap_problem(ctx, save_problem, &pctx);
393 fixit = end_problem_latch(ctx, PR_LATCH_BBITMAP);
396 ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
399 ext2fs_free_block_bitmap(fs->block_map);
400 retval = ext2fs_copy_bitmap(ctx->block_found_map,
403 clear_problem_context(&pctx);
404 fix_problem(ctx, PR_5_COPY_BBITMAP_ERROR, &pctx);
405 ctx->flags |= E2F_FLAG_ABORT;
408 ext2fs_set_bitmap_padding(fs->block_map);
409 ext2fs_mark_bb_dirty(fs);
411 /* Redo the counts */
412 blocks = 0; free_blocks = 0; group_free = 0; group = 0;
413 memset(free_array, 0, fs->group_desc_count * sizeof(int));
416 } else if (fixit == 0)
417 ext2fs_unmark_valid(fs);
419 for (g = 0; g < fs->group_desc_count; g++) {
420 if (free_array[g] != ext2fs_bg_free_blocks_count(fs, g)) {
422 pctx.blk = ext2fs_bg_free_blocks_count(fs, g);
423 pctx.blk2 = free_array[g];
425 if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT_GROUP,
427 ext2fs_bg_free_blocks_count_set(fs, g, free_array[g]);
428 ext2fs_mark_super_dirty(fs);
430 ext2fs_unmark_valid(fs);
433 free_blocks = EXT2FS_C2B(fs, free_blocks);
434 if (free_blocks != ext2fs_free_blocks_count(fs->super)) {
436 pctx.blk = ext2fs_free_blocks_count(fs->super);
437 pctx.blk2 = free_blocks;
439 if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT, &pctx)) {
440 ext2fs_free_blocks_count_set(fs->super, free_blocks);
441 ext2fs_mark_super_dirty(fs);
445 ext2fs_free_mem(&free_array);
446 ext2fs_free_mem(&actual_buf);
447 ext2fs_free_mem(&bitmap_buf);
450 static void check_inode_bitmaps(e2fsck_t ctx)
452 ext2_filsys fs = ctx->fs;
454 unsigned int free_inodes = 0;
458 unsigned int inodes = 0;
459 ext2_ino_t *free_array;
460 ext2_ino_t *dir_array;
463 struct problem_context pctx;
464 problem_t problem, save_problem;
465 int fixit, had_problem;
469 ext2_ino_t first_free = fs->super->s_inodes_per_group + 1;
471 clear_problem_context(&pctx);
472 free_array = (ext2_ino_t *) e2fsck_allocate_memory(ctx,
473 fs->group_desc_count * sizeof(ext2_ino_t), "free inode count array");
475 dir_array = (ext2_ino_t *) e2fsck_allocate_memory(ctx,
476 fs->group_desc_count * sizeof(ext2_ino_t), "directory count array");
478 if ((1 < ext2fs_get_inode_bitmap_start2(ctx->inode_used_map)) ||
479 (fs->super->s_inodes_count >
480 ext2fs_get_inode_bitmap_end2(ctx->inode_used_map))) {
483 pctx.blk2 = fs->super->s_inodes_count;
484 pctx.ino = ext2fs_get_inode_bitmap_start2(ctx->inode_used_map);
485 pctx.ino2 = ext2fs_get_inode_bitmap_end2(ctx->inode_used_map);
486 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
488 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
491 if ((1 < ext2fs_get_inode_bitmap_start2(fs->inode_map)) ||
492 (fs->super->s_inodes_count >
493 ext2fs_get_inode_bitmap_end2(fs->inode_map))) {
496 pctx.blk2 = fs->super->s_inodes_count;
497 pctx.ino = ext2fs_get_inode_bitmap_start2(fs->inode_map);
498 pctx.ino2 = ext2fs_get_inode_bitmap_end2(fs->inode_map);
499 fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
501 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
505 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
506 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
510 pctx.ino = pctx.ino2 = 0;
512 (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)))
515 /* Protect loop from wrap-around if inodes_count is maxed */
516 for (i = 1; i <= fs->super->s_inodes_count && i > 0; i++) {
519 i % fs->super->s_inodes_per_group == 1) {
521 * Current inode is the first inode
522 * in the current block group.
524 if (ext2fs_test_inode_bitmap_range(
525 ctx->inode_used_map, i,
526 fs->super->s_inodes_per_group)) {
528 * When the compared inodes in inodes bitmap
529 * are 0, count the free inode,
530 * skip the current block group.
533 inodes = fs->super->s_inodes_per_group - 1;
535 free_inodes += inodes;
542 actual = ext2fs_fast_test_inode_bitmap2(ctx->inode_used_map, i);
545 else if (!skip_group)
546 bitmap = ext2fs_fast_test_inode_bitmap2(fs->inode_map, i);
547 if (!actual == !bitmap)
550 if (!actual && bitmap) {
552 * Inode wasn't used, but marked in bitmap
554 problem = PR_5_INODE_UNUSED;
555 } else /* if (actual && !bitmap) */ {
557 * Inode used, but not in bitmap
559 problem = PR_5_INODE_USED;
561 /* We should never hit this, because it means that
562 * inodes were marked in use that weren't noticed
563 * in pass1 or pass 2. It is easier to fix the problem
564 * than to kill e2fsck and leave the user stuck. */
566 struct problem_context pctx2;
569 if (fix_problem(ctx, PR_5_INODE_UNINIT,&pctx2)){
570 ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
576 pctx.ino = pctx.ino2 = i;
577 save_problem = problem;
579 if ((problem == save_problem) &&
583 print_bitmap_problem(ctx, save_problem, &pctx);
584 pctx.ino = pctx.ino2 = i;
585 save_problem = problem;
588 ctx->flags |= E2F_FLAG_PROG_SUPPRESS;
591 * If there a problem we should turn off the discard so we
592 * do not compromise the filesystem.
594 ctx->options &= ~E2F_OPT_DISCARD;
599 if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, i))
601 if (inodes > first_free) {
602 e2fsck_discard_inodes(ctx, group, first_free,
603 inodes - first_free);
604 first_free = fs->super->s_inodes_per_group + 1;
609 if (first_free > inodes)
613 if ((inodes == fs->super->s_inodes_per_group) ||
614 (i == fs->super->s_inodes_count)) {
616 * If the last inode is free, we can discard it as well.
618 if (!bitmap && inodes >= first_free)
619 e2fsck_discard_inodes(ctx, group, first_free,
620 inodes - first_free + 1);
622 * If discard zeroes data and the group inode table
623 * was not zeroed yet, set itable as zeroed
625 if ((ctx->options & E2F_OPT_DISCARD) &&
626 io_channel_discard_zeroes_data(fs->io) &&
627 !(ext2fs_bg_flags_test(fs, group,
628 EXT2_BG_INODE_ZEROED))) {
629 ext2fs_bg_flags_set(fs, group,
630 EXT2_BG_INODE_ZEROED);
631 ext2fs_group_desc_csum_set(fs, group);
634 first_free = fs->super->s_inodes_per_group + 1;
635 free_array[group] = group_free;
636 dir_array[group] = dirs_count;
643 if ((ctx->progress)(ctx, 5,
644 group + fs->group_desc_count,
645 fs->group_desc_count*2))
648 (i != fs->super->s_inodes_count) &&
649 (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)
655 print_bitmap_problem(ctx, save_problem, &pctx);
658 fixit = end_problem_latch(ctx, PR_LATCH_IBITMAP);
661 ctx->flags &= ~E2F_FLAG_PROG_SUPPRESS;
664 ext2fs_free_inode_bitmap(fs->inode_map);
665 retval = ext2fs_copy_bitmap(ctx->inode_used_map,
668 clear_problem_context(&pctx);
669 fix_problem(ctx, PR_5_COPY_IBITMAP_ERROR, &pctx);
670 ctx->flags |= E2F_FLAG_ABORT;
673 ext2fs_set_bitmap_padding(fs->inode_map);
674 ext2fs_mark_ib_dirty(fs);
677 inodes = 0; free_inodes = 0; group_free = 0;
678 dirs_count = 0; group = 0;
679 memset(free_array, 0, fs->group_desc_count * sizeof(int));
680 memset(dir_array, 0, fs->group_desc_count * sizeof(int));
683 } else if (fixit == 0)
684 ext2fs_unmark_valid(fs);
686 for (i = 0; i < fs->group_desc_count; i++) {
687 if (free_array[i] != ext2fs_bg_free_inodes_count(fs, i)) {
689 pctx.ino = ext2fs_bg_free_inodes_count(fs, i);
690 pctx.ino2 = free_array[i];
691 if (fix_problem(ctx, PR_5_FREE_INODE_COUNT_GROUP,
693 ext2fs_bg_free_inodes_count_set(fs, i, free_array[i]);
694 ext2fs_mark_super_dirty(fs);
696 ext2fs_unmark_valid(fs);
698 if (dir_array[i] != ext2fs_bg_used_dirs_count(fs, i)) {
700 pctx.ino = ext2fs_bg_used_dirs_count(fs, i);
701 pctx.ino2 = dir_array[i];
703 if (fix_problem(ctx, PR_5_FREE_DIR_COUNT_GROUP,
705 ext2fs_bg_used_dirs_count_set(fs, i, dir_array[i]);
706 ext2fs_mark_super_dirty(fs);
708 ext2fs_unmark_valid(fs);
711 if (free_inodes != fs->super->s_free_inodes_count) {
713 pctx.ino = fs->super->s_free_inodes_count;
714 pctx.ino2 = free_inodes;
716 if (fix_problem(ctx, PR_5_FREE_INODE_COUNT, &pctx)) {
717 fs->super->s_free_inodes_count = free_inodes;
718 ext2fs_mark_super_dirty(fs);
722 ext2fs_free_mem(&free_array);
723 ext2fs_free_mem(&dir_array);
726 static void check_inode_end(e2fsck_t ctx)
728 ext2_filsys fs = ctx->fs;
729 ext2_ino_t end, save_inodes_count, i;
730 struct problem_context pctx;
732 clear_problem_context(&pctx);
734 end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
735 pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end,
739 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
740 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
743 if (save_inodes_count == end)
746 /* protect loop from wrap-around if end is maxed */
747 for (i = save_inodes_count + 1; i <= end && i > save_inodes_count; i++) {
748 if (!ext2fs_test_inode_bitmap(fs->inode_map, i)) {
749 if (fix_problem(ctx, PR_5_INODE_BMAP_PADDING, &pctx)) {
750 for (; i <= end; i++)
751 ext2fs_mark_inode_bitmap(fs->inode_map,
753 ext2fs_mark_ib_dirty(fs);
755 ext2fs_unmark_valid(fs);
760 pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map,
761 save_inodes_count, 0);
764 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
765 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
770 static void check_block_end(e2fsck_t ctx)
772 ext2_filsys fs = ctx->fs;
773 blk64_t end, save_blocks_count, i;
774 struct problem_context pctx;
776 clear_problem_context(&pctx);
778 end = ext2fs_get_block_bitmap_start2(fs->block_map) +
779 ((blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * fs->group_desc_count) - 1;
780 pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map, end,
784 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
785 ctx->flags |= E2F_FLAG_ABORT; /* fatal */
788 if (save_blocks_count == end)
791 /* Protect loop from wrap-around if end is maxed */
792 for (i = save_blocks_count + 1; i <= end && i > save_blocks_count; i++) {
793 if (!ext2fs_test_block_bitmap2(fs->block_map,
794 EXT2FS_C2B(fs, i))) {
795 if (fix_problem(ctx, PR_5_BLOCK_BMAP_PADDING, &pctx)) {
796 for (; i <= end; i++)
797 ext2fs_mark_block_bitmap2(fs->block_map,
799 ext2fs_mark_bb_dirty(fs);
801 ext2fs_unmark_valid(fs);
806 pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map,
807 save_blocks_count, 0);
810 fix_problem(ctx, PR_5_FUDGE_BITMAP_ERROR, &pctx);
811 ctx->flags |= E2F_FLAG_ABORT; /* fatal */