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), &context);
29 memset(context, 0, sizeof(struct e2fsck_struct));
31 context->process_inode_size = 256;
32 context->ext_attr_ver = 2;
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 ctx->lost_and_found = 0;
46 ctx->bad_lost_and_found = 0;
47 if (ctx->inode_used_map) {
48 ext2fs_free_inode_bitmap(ctx->inode_used_map);
49 ctx->inode_used_map = 0;
51 if (ctx->inode_dir_map) {
52 ext2fs_free_inode_bitmap(ctx->inode_dir_map);
53 ctx->inode_dir_map = 0;
55 if (ctx->inode_reg_map) {
56 ext2fs_free_inode_bitmap(ctx->inode_reg_map);
57 ctx->inode_reg_map = 0;
59 if (ctx->block_found_map) {
60 ext2fs_free_block_bitmap(ctx->block_found_map);
61 ctx->block_found_map = 0;
63 if (ctx->inode_link_info) {
64 ext2fs_free_icount(ctx->inode_link_info);
65 ctx->inode_link_info = 0;
67 if (ctx->journal_io) {
68 if (ctx->fs && ctx->fs->io != ctx->journal_io)
69 io_channel_close(ctx->journal_io);
72 if (ctx->fs && ctx->fs->dblist) {
73 ext2fs_free_dblist(ctx->fs->dblist);
76 e2fsck_free_dir_info(ctx);
78 e2fsck_free_dx_dir_info(ctx);
81 ea_refcount_free(ctx->refcount);
84 if (ctx->refcount_extra) {
85 ea_refcount_free(ctx->refcount_extra);
86 ctx->refcount_extra = 0;
88 if (ctx->block_dup_map) {
89 ext2fs_free_block_bitmap(ctx->block_dup_map);
90 ctx->block_dup_map = 0;
92 if (ctx->block_ea_map) {
93 ext2fs_free_block_bitmap(ctx->block_ea_map);
94 ctx->block_ea_map = 0;
96 if (ctx->inode_bb_map) {
97 ext2fs_free_inode_bitmap(ctx->inode_bb_map);
98 ctx->inode_bb_map = 0;
100 if (ctx->inode_bad_map) {
101 ext2fs_free_inode_bitmap(ctx->inode_bad_map);
102 ctx->inode_bad_map = 0;
104 if (ctx->inode_imagic_map) {
105 ext2fs_free_inode_bitmap(ctx->inode_imagic_map);
106 ctx->inode_imagic_map = 0;
108 if (ctx->dirs_to_hash) {
109 ext2fs_u32_list_free(ctx->dirs_to_hash);
110 ctx->dirs_to_hash = 0;
114 * Clear the array of invalid meta-data flags
116 if (ctx->invalid_inode_bitmap_flag) {
117 ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag);
118 ctx->invalid_inode_bitmap_flag = 0;
120 if (ctx->invalid_block_bitmap_flag) {
121 ext2fs_free_mem(&ctx->invalid_block_bitmap_flag);
122 ctx->invalid_block_bitmap_flag = 0;
124 if (ctx->invalid_inode_table_flag) {
125 ext2fs_free_mem(&ctx->invalid_inode_table_flag);
126 ctx->invalid_inode_table_flag = 0;
129 /* Clear statistic counters */
130 ctx->fs_directory_count = 0;
131 ctx->fs_regular_count = 0;
132 ctx->fs_blockdev_count = 0;
133 ctx->fs_chardev_count = 0;
134 ctx->fs_links_count = 0;
135 ctx->fs_symlinks_count = 0;
136 ctx->fs_fast_symlinks_count = 0;
137 ctx->fs_fifo_count = 0;
138 ctx->fs_total_count = 0;
139 ctx->fs_badblocks_count = 0;
140 ctx->fs_sockets_count = 0;
141 ctx->fs_ind_count = 0;
142 ctx->fs_dind_count = 0;
143 ctx->fs_tind_count = 0;
144 ctx->fs_fragmented = 0;
145 ctx->large_files = 0;
147 /* Reset the superblock to the user's requested value */
148 ctx->superblock = ctx->use_superblock;
153 void e2fsck_free_context(e2fsck_t ctx)
158 e2fsck_reset_context(ctx);
160 blkid_put_cache(ctx->blkid);
162 ext2fs_free_mem(&ctx);
166 * This function runs through the e2fsck passes and calls them all,
167 * returning restart, abort, or cancel as necessary...
169 typedef void (*pass_t)(e2fsck_t ctx);
171 pass_t e2fsck_passes[] = {
172 e2fsck_pass1, e2fsck_pass2, e2fsck_pass3, e2fsck_pass4,
175 #define E2F_FLAG_RUN_RETURN (E2F_FLAG_SIGNAL_MASK|E2F_FLAG_RESTART)
177 int e2fsck_run(e2fsck_t ctx)
183 if (setjmp(ctx->abort_loc)) {
184 ctx->flags &= ~E2F_FLAG_SETJMP_OK;
185 return (ctx->flags & E2F_FLAG_RUN_RETURN);
187 ctx->flags |= E2F_FLAG_SETJMP_OK;
190 for (i=0; (e2fsck_pass = e2fsck_passes[i]); i++) {
191 if (ctx->flags & E2F_FLAG_RUN_RETURN)
195 (void) (ctx->progress)(ctx, 0, 0, 0);
197 ctx->flags &= ~E2F_FLAG_SETJMP_OK;
199 if (ctx->flags & E2F_FLAG_RUN_RETURN)
200 return (ctx->flags & E2F_FLAG_RUN_RETURN);