2 * e2fsck.c - a consistency checker for the new extended file system.
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
18 * This function allocates an e2fsck context
20 errcode_t e2fsck_allocate_context(e2fsck_t *ret)
25 retval = ext2fs_get_mem(sizeof(struct e2fsck_struct),
30 memset(context, 0, sizeof(struct e2fsck_struct));
32 context->process_inode_size = 256;
39 * This function resets an e2fsck context; it is called when e2fsck
40 * needs to be restarted.
42 errcode_t e2fsck_reset_context(e2fsck_t ctx)
45 if (ctx->inode_used_map) {
46 ext2fs_free_inode_bitmap(ctx->inode_used_map);
47 ctx->inode_used_map = 0;
49 if (ctx->inode_dir_map) {
50 ext2fs_free_inode_bitmap(ctx->inode_dir_map);
51 ctx->inode_dir_map = 0;
53 if (ctx->block_found_map) {
54 ext2fs_free_block_bitmap(ctx->block_found_map);
55 ctx->block_found_map = 0;
57 if (ctx->inode_link_info) {
58 ext2fs_free_icount(ctx->inode_link_info);
59 ctx->inode_link_info = 0;
61 if (ctx->fs && ctx->fs->dblist) {
62 ext2fs_free_dblist(ctx->fs->dblist);
65 e2fsck_free_dir_info(ctx);
66 if (ctx->block_dup_map) {
67 ext2fs_free_block_bitmap(ctx->block_dup_map);
68 ctx->block_dup_map = 0;
70 if (ctx->inode_bb_map) {
71 ext2fs_free_inode_bitmap(ctx->inode_bb_map);
72 ctx->inode_bb_map = 0;
74 if (ctx->inode_bad_map) {
75 ext2fs_free_inode_bitmap(ctx->inode_bad_map);
76 ctx->inode_bad_map = 0;
80 * Clear the array of invalid meta-data flags
82 if (ctx->invalid_inode_bitmap_flag) {
83 ext2fs_free_mem((void **) &ctx->invalid_inode_bitmap_flag);
84 ctx->invalid_inode_bitmap_flag = 0;
86 if (ctx->invalid_block_bitmap_flag) {
87 ext2fs_free_mem((void **) &ctx->invalid_block_bitmap_flag);
88 ctx->invalid_block_bitmap_flag = 0;
90 if (ctx->invalid_inode_table_flag) {
91 ext2fs_free_mem((void **) &ctx->invalid_inode_table_flag);
92 ctx->invalid_inode_table_flag = 0;
95 /* Clear statistic counters */
96 ctx->fs_directory_count = 0;
97 ctx->fs_regular_count = 0;
98 ctx->fs_blockdev_count = 0;
99 ctx->fs_chardev_count = 0;
100 ctx->fs_links_count = 0;
101 ctx->fs_symlinks_count = 0;
102 ctx->fs_fast_symlinks_count = 0;
103 ctx->fs_fifo_count = 0;
104 ctx->fs_total_count = 0;
105 ctx->fs_badblocks_count = 0;
106 ctx->fs_sockets_count = 0;
107 ctx->fs_ind_count = 0;
108 ctx->fs_dind_count = 0;
109 ctx->fs_tind_count = 0;
110 ctx->fs_fragmented = 0;
111 ctx->large_files = 0;
113 /* Reset the superblock to the user's requested value */
114 ctx->superblock = ctx->use_superblock;
119 void e2fsck_free_context(e2fsck_t ctx)
124 e2fsck_reset_context(ctx);
126 ext2fs_free_mem((void **) &ctx);
130 * This function runs through the e2fsck passes and calls them all,
131 * returning restart, abort, or cancel as necessary...
133 typedef void (*pass_t)(e2fsck_t ctx);
135 pass_t e2fsck_passes[] = {
136 e2fsck_pass1, e2fsck_pass2, e2fsck_pass3, e2fsck_pass4,
139 #define E2F_FLAG_RUN_RETURN (E2F_FLAG_SIGNAL_MASK|E2F_FLAG_RESTART)
141 int e2fsck_run(e2fsck_t ctx)
147 if (setjmp(ctx->abort_loc))
148 return (ctx->flags & E2F_FLAG_RUN_RETURN);
149 ctx->flags |= E2F_FLAG_SETJMP_OK;
152 for (i=0; (e2fsck_pass = e2fsck_passes[i]); i++) {
153 if (ctx->flags & E2F_FLAG_RUN_RETURN)
157 (void) (ctx->progress)(ctx, 0, 0, 0);
159 ctx->flags &= ~E2F_FLAG_SETJMP_OK;
161 if (ctx->flags & E2F_FLAG_RUN_RETURN)
162 return (ctx->flags & E2F_FLAG_RUN_RETURN);