+ group = ext2fs_group_of_ino(fs, dirent->inode);
+ first_unused_inode = group * fs->super->s_inodes_per_group +
+ 1 + fs->super->s_inodes_per_group -
+ ext2fs_bg_itable_unused(fs, group);
+ cd->pctx.group = group;
+
+ /*
+ * Check if the inode was missed out because
+ * _INODE_UNINIT flag was set or bg_itable_unused was
+ * incorrect. If so, clear the _INODE_UNINIT flag and
+ * restart e2fsck. In the future it would be nice if
+ * we could call a function in pass1.c that checks the
+ * newly visible inodes.
+ */
+ if (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)) {
+ pctx.num = dirent->inode;
+ if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT,
+ &cd->pctx)){
+ ext2fs_bg_flags_clear(fs, group,
+ EXT2_BG_INODE_UNINIT);
+ ext2fs_mark_super_dirty(fs);
+ ctx->flags |= E2F_FLAG_RESTART_LATER;
+ } else {
+ ext2fs_unmark_valid(fs);
+ if (problem == PR_2_BAD_INO)
+ goto next;
+ }
+ } else if (dirent->inode >= first_unused_inode) {
+ pctx.num = dirent->inode;
+ if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){
+ ext2fs_bg_itable_unused_set(fs, group, 0);
+ ext2fs_mark_super_dirty(fs);
+ ctx->flags |= E2F_FLAG_RESTART_LATER;
+ } else {
+ ext2fs_unmark_valid(fs);
+ if (problem == PR_2_BAD_INO)
+ goto next;
+ }
+ }
+
+ /*
+ * Offer to clear unused inodes; if we are going to be
+ * restarting the scan due to bg_itable_unused being
+ * wrong, then don't clear any inodes to avoid zapping
+ * inodes that were skipped during pass1 due to an
+ * incorrect bg_itable_unused; we'll get any real
+ * problems after we restart.
+ */
+ if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
+ !(ext2fs_test_inode_bitmap2(ctx->inode_used_map,
+ dirent->inode)))
+ problem = PR_2_UNUSED_INODE;
+
+ if (problem) {
+ if (fix_problem(ctx, problem, &cd->pctx)) {
+ dirent->inode = 0;
+ dir_modified++;
+ goto next;
+ } else {
+ ext2fs_unmark_valid(fs);
+ if (problem == PR_2_BAD_INO)
+ goto next;
+ }
+ }
+