Lines Matching refs:ctx
44 static void check_root(e2fsck_t ctx);
45 static int check_directory(e2fsck_t ctx, ext2_ino_t ino,
47 static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
52 void e2fsck_pass3(e2fsck_t ctx)
54 ext2_filsys fs = ctx->fs;
63 init_resource_track(&rtrack, ctx->fs->io);
70 if (!(ctx->options & E2F_OPT_PREEN))
71 fix_problem(ctx, PR_3_PASS_HEADER, &pctx);
80 fix_problem(ctx, PR_3_ALLOCATE_IBITMAP_ERROR, &pctx);
81 ctx->flags |= E2F_FLAG_ABORT;
84 print_resource_track(ctx, _("Peak memory"), &ctx->global_rtrack, NULL);
86 check_root(ctx);
87 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
92 maxdirs = e2fsck_get_num_dirinfo(ctx);
95 if (ctx->progress)
96 if ((ctx->progress)(ctx, 3, 0, maxdirs))
99 iter = e2fsck_dir_info_iter_begin(ctx);
100 while ((dir = e2fsck_dir_info_iter(ctx, iter)) != 0) {
101 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
103 if (ctx->progress && (ctx->progress)(ctx, 3, count++, maxdirs))
105 if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, dir->ino))
106 if (check_directory(ctx, dir->ino, &pctx))
109 e2fsck_dir_info_iter_end(ctx, iter);
114 if ((ctx->flags & E2F_OPT_READONLY) == 0)
115 e2fsck_get_lost_and_found(ctx, 1);
121 e2fsck_rehash_directories(ctx);
124 e2fsck_free_dir_info(ctx);
134 print_resource_track(ctx, _("Pass 3"), &rtrack, ctx->fs->io);
141 static void check_root(e2fsck_t ctx)
143 ext2_filsys fs = ctx->fs;
151 if (ext2fs_test_inode_bitmap(ctx->inode_used_map, EXT2_ROOT_INO)) {
157 if (!(ext2fs_test_inode_bitmap(ctx->inode_dir_map,
159 fix_problem(ctx, PR_3_ROOT_NOT_DIR_ABORT, &pctx);
160 ctx->flags |= E2F_FLAG_ABORT;
165 if (!fix_problem(ctx, PR_3_NO_ROOT_INODE, &pctx)) {
166 fix_problem(ctx, PR_3_NO_ROOT_INODE_ABORT, &pctx);
167 ctx->flags |= E2F_FLAG_ABORT;
171 e2fsck_read_bitmaps(ctx);
176 pctx.errcode = ext2fs_new_block(fs, 0, ctx->block_found_map, &blk);
179 fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
180 ctx->flags |= E2F_FLAG_ABORT;
183 ext2fs_mark_block_bitmap(ctx->block_found_map, blk);
194 fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
195 ctx->flags |= E2F_FLAG_ABORT;
202 fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
203 ctx->flags |= E2F_FLAG_ABORT;
214 inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now;
225 fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
226 ctx->flags |= E2F_FLAG_ABORT;
233 e2fsck_add_dir_info(ctx, EXT2_ROOT_INO, EXT2_ROOT_INO);
234 ext2fs_icount_store(ctx->inode_count, EXT2_ROOT_INO, 2);
235 ext2fs_icount_store(ctx->inode_link_info, EXT2_ROOT_INO, 2);
237 ext2fs_mark_inode_bitmap(ctx->inode_used_map, EXT2_ROOT_INO);
238 ext2fs_mark_inode_bitmap(ctx->inode_dir_map, EXT2_ROOT_INO);
259 static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
262 ext2_filsys fs = ctx->fs;
280 if (e2fsck_dir_info_get_parent(ctx, ino, &parent)) {
281 fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
295 if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) {
296 if (e2fsck_reconnect_file(ctx, pctx->ino))
299 fix_dotdot(ctx, pctx->ino,
300 ctx->lost_and_found);
301 parent = ctx->lost_and_found;
323 fix_problem(ctx,
325 ctx->flags |= E2F_FLAG_ABORT;
338 if (e2fsck_dir_info_get_dotdot(ctx, dir, &pctx->ino2) ||
339 e2fsck_dir_info_get_parent(ctx, dir, &pctx->dir)) {
340 fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
344 if (fix_problem(ctx, PR_3_BAD_DOT_DOT, pctx))
345 fix_dotdot(ctx, dir, pctx->dir);
354 ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
356 ext2_filsys fs = ctx->fs;
365 if (ctx->lost_and_found)
366 return ctx->lost_and_found;
375 if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, ino)) {
376 ctx->lost_and_found = ino;
384 if (!fix_problem(ctx, PR_3_LPF_NOTDIR, &pctx))
391 fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
394 (void) e2fsck_dir_info_set_parent(ctx, ino, 0);
395 e2fsck_adjust_inode_count(ctx, ino, -1);
398 fix_problem(ctx, PR_3_ERR_FIND_LPF, &pctx);
400 if (!fix_problem(ctx, PR_3_NO_LF_DIR, 0))
407 e2fsck_read_bitmaps(ctx);
412 retval = ext2fs_new_block(fs, 0, ctx->block_found_map, &blk);
415 fix_problem(ctx, PR_3_ERR_LPF_NEW_BLOCK, &pctx);
418 ext2fs_mark_block_bitmap(ctx->block_found_map, blk);
425 ctx->inode_used_map, &ino);
428 fix_problem(ctx, PR_3_ERR_LPF_NEW_INODE, &pctx);
431 ext2fs_mark_inode_bitmap(ctx->inode_used_map, ino);
432 ext2fs_mark_inode_bitmap(ctx->inode_dir_map, ino);
441 fix_problem(ctx, PR_3_ERR_LPF_NEW_DIR_BLOCK, &pctx);
449 fix_problem(ctx, PR_3_ERR_LPF_WRITE_BLOCK, &pctx);
459 inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now;
470 fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
479 fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
486 e2fsck_add_dir_info(ctx, ino, EXT2_ROOT_INO);
487 e2fsck_adjust_inode_count(ctx, EXT2_ROOT_INO, 1);
488 ext2fs_icount_store(ctx->inode_count, ino, 2);
489 ext2fs_icount_store(ctx->inode_link_info, ino, 2);
490 ctx->lost_and_found = ino;
500 int e2fsck_reconnect_file(e2fsck_t ctx, ext2_ino_t ino)
502 ext2_filsys fs = ctx->fs;
512 if (!ctx->bad_lost_and_found && !ctx->lost_and_found) {
513 if (e2fsck_get_lost_and_found(ctx, 1) == 0)
514 ctx->bad_lost_and_found++;
516 if (ctx->bad_lost_and_found) {
517 fix_problem(ctx, PR_3_NO_LPF, &pctx);
524 retval = ext2fs_link(fs, ctx->lost_and_found, name, ino, file_type);
526 if (!fix_problem(ctx, PR_3_EXPAND_LF_DIR, &pctx))
528 retval = e2fsck_expand_directory(ctx, ctx->lost_and_found,
532 fix_problem(ctx, PR_3_CANT_EXPAND_LPF, &pctx);
535 retval = ext2fs_link(fs, ctx->lost_and_found, name,
540 fix_problem(ctx, PR_3_CANT_RECONNECT, &pctx);
543 e2fsck_adjust_inode_count(ctx, ino, 1);
551 errcode_t e2fsck_adjust_inode_count(e2fsck_t ctx, ext2_ino_t ino, int adj)
553 ext2_filsys fs = ctx->fs;
570 ext2fs_icount_increment(ctx->inode_count, ino, 0);
573 ext2fs_icount_increment(ctx->inode_link_info, ino, 0);
576 ext2fs_icount_decrement(ctx->inode_count, ino, 0);
579 ext2fs_icount_decrement(ctx->inode_link_info, ino, 0);
597 e2fsck_t ctx;
617 retval = e2fsck_adjust_inode_count(fp->ctx, dirent->inode, -1);
620 fix_problem(fp->ctx, PR_3_ADJUST_INODE, &pctx);
622 retval = e2fsck_adjust_inode_count(fp->ctx, fp->parent, 1);
625 fix_problem(fp->ctx, PR_3_ADJUST_INODE, &pctx);
628 if (fp->ctx->fs->super->s_feature_incompat &
639 static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
641 ext2_filsys fs = ctx->fs;
649 fp.ctx = ctx;
661 fix_problem(ctx, retval ? PR_3_FIX_PARENT_ERR :
665 (void) e2fsck_dir_info_set_dotdot(ctx, ino, parent);
666 if (e2fsck_dir_info_set_parent(ctx, ino, ctx->lost_and_found))
667 fix_problem(ctx, PR_3_NO_DIRINFO, &pctx);
683 e2fsck_t ctx;
698 e2fsck_t ctx;
700 ctx = es->ctx;
711 retval = ext2fs_new_block(fs, last_blk, ctx->block_found_map,
740 ext2fs_mark_block_bitmap(ctx->block_found_map, new_blk);
750 errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
753 ext2_filsys fs = ctx->fs;
765 e2fsck_read_bitmaps(ctx);
776 es.ctx = ctx;
794 e2fsck_write_inode(ctx, dir, &inode, "expand_directory");