19 #include <sys/resource.h>
20 #include <sys/param.h>
21 #include <sys/mount.h>
22 #include <sys/ioctl.h>
27 #include "ext2fs/kernel-list.h"
28 #include <sys/types.h>
29 #include <linux/types.h>
33 * Now pull in the real linux/jfs.h definitions.
35 #include "ext2fs/kernel-jbd.h"
41 #include "ext2fs/ext2_fs.h"
42 #include "blkid/blkid.h"
43 #include "ext2fs/ext2_ext_attr.h"
44 #include "uuid/uuid.h"
49 #define read_a_char() getch()
58 * The last ext2fs revision level that this version of e2fsck is able to
61 #define E2FSCK_CURRENT_REV 1
63 /* Used by the region allocation code */
64 typedef __u32 region_addr_t;
65 typedef struct region_struct *region_t;
67 struct dx_dirblock_info {
72 ext2_dirhash_t min_hash;
73 ext2_dirhash_t max_hash;
74 ext2_dirhash_t node_min_hash;
75 ext2_dirhash_t node_max_hash;
79 These defines are used in the type field of dx_dirblock_info
82 #define DX_DIRBLOCK_ROOT 1
83 #define DX_DIRBLOCK_LEAF 2
84 #define DX_DIRBLOCK_NODE 3
85 #define DX_DIRBLOCK_CORRUPT 4
86 #define DX_DIRBLOCK_CLEARED 8
90 The following defines are used in the 'flags' field of a dx_dirblock_info
92 #define DX_FLAG_REFERENCED 1
93 #define DX_FLAG_DUP_REF 2
94 #define DX_FLAG_FIRST 4
95 #define DX_FLAG_LAST 8
99 * This structure is used for keeping track of how much resources have
100 * been used for a particular pass of e2fsck.
102 struct resource_track {
103 struct timeval time_start;
104 struct timeval user_start;
105 struct timeval system_start;
113 #define E2F_OPT_READONLY 0x0001
114 #define E2F_OPT_PREEN 0x0002
115 #define E2F_OPT_YES 0x0004
116 #define E2F_OPT_NO 0x0008
117 #define E2F_OPT_TIME 0x0010
118 #define E2F_OPT_TIME2 0x0020
119 #define E2F_OPT_CHECKBLOCKS 0x0040
120 #define E2F_OPT_DEBUG 0x0080
121 #define E2F_OPT_FORCE 0x0100
122 #define E2F_OPT_WRITECHECK 0x0200
123 #define E2F_OPT_COMPRESS_DIRS 0x0400
128 #define E2F_FLAG_ABORT 0x0001 /* Abort signaled */
129 #define E2F_FLAG_CANCEL 0x0002 /* Cancel signaled */
130 #define E2F_FLAG_SIGNAL_MASK 0x0003
131 #define E2F_FLAG_RESTART 0x0004 /* Restart signaled */
133 #define E2F_FLAG_SETJMP_OK 0x0010 /* Setjmp valid for abort */
135 #define E2F_FLAG_PROG_BAR 0x0020 /* Progress bar on screen */
136 #define E2F_FLAG_PROG_SUPPRESS 0x0040 /* Progress suspended */
137 #define E2F_FLAG_JOURNAL_INODE 0x0080 /* Create a new ext3 journal inode */
138 #define E2F_FLAG_SB_SPECIFIED 0x0100 /* The superblock was explicitly
139 * specified by the user */
140 #define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */
141 #define E2F_FLAG_RESIZE_INODE 0x0400 /* Request to recreate resize inode */
144 * Defines for indicating the e2fsck pass number
151 #define E2F_PASS_1B 6
153 /*Don't know where these come from*/
157 #define KERN_DEBUG ""
158 #define cpu_to_be32(n) htonl(n)
159 #define be32_to_cpu(n) ntohl(n)
163 * The directory information structure; stores directory information
164 * collected in earlier passes, to avoid disk i/o in fetching the
165 * directory information.
168 ext2_ino_t ino; /* Inode number */
169 ext2_ino_t dotdot; /* Parent according to '..' */
170 ext2_ino_t parent; /* Parent according to treewalk */
176 * The indexed directory information structure; stores information for
177 * directories which contain a hash tree index.
180 ext2_ino_t ino; /* Inode number */
181 int numblocks; /* number of blocks */
183 short depth; /* depth of tree */
184 struct dx_dirblock_info *dx_block; /* Array of size numblocks */
188 * Define the extended attribute refcount structure
190 typedef struct ea_refcount *ext2_refcount_t;
192 struct e2fsck_struct {
194 const char *program_name;
195 char *filesystem_name;
198 int flags; /* E2fsck internal flags */
200 blk_t use_superblock; /* sb requested by user */
201 blk_t superblock; /* sb used to open fs */
202 int blocksize; /* blocksize */
203 blk_t num_blocks; /* Total number of blocks */
205 blkid_cache blkid; /* blkid cache */
209 unsigned long abort_code;
211 int (*progress)(e2fsck_t ctx, int pass, unsigned long cur,
214 ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
215 ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
216 ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
217 ext2fs_inode_bitmap inode_bb_map; /* Inodes which are in bad blocks */
218 ext2fs_inode_bitmap inode_imagic_map; /* AFS inodes */
219 ext2fs_inode_bitmap inode_reg_map; /* Inodes which are regular files*/
221 ext2fs_block_bitmap block_found_map; /* Blocks which are in use */
222 ext2fs_block_bitmap block_dup_map; /* Blks referenced more than once */
223 ext2fs_block_bitmap block_ea_map; /* Blocks which are used by EA's */
228 ext2_icount_t inode_count;
229 ext2_icount_t inode_link_info;
231 ext2_refcount_t refcount;
232 ext2_refcount_t refcount_extra;
235 * Array of flags indicating whether an inode bitmap, block
236 * bitmap, or inode table is invalid
238 int *invalid_inode_bitmap_flag;
239 int *invalid_block_bitmap_flag;
240 int *invalid_inode_table_flag;
241 int invalid_bitmaps; /* There are invalid bitmaps/itable */
249 * For pass1_check_directory and pass1_get_blocks
251 ext2_ino_t stashed_ino;
252 struct ext2_inode *stashed_inode;
255 * Location of the lost and found directory
257 ext2_ino_t lost_and_found;
258 int bad_lost_and_found;
261 * Directory information
265 struct dir_info *dir_info;
268 * Indexed directory information
270 int dx_dir_info_count;
271 int dx_dir_info_size;
272 struct dx_dir_info *dx_dir_info;
275 * Directories to hash
277 ext2_u32_list dirs_to_hash;
282 int process_inode_size;
283 int inode_buffer_blocks;
286 * ext3 journal support
288 io_channel journal_io;
291 #ifdef RESOURCE_TRACK
293 * For timing purposes
295 struct resource_track global_rtrack;
299 * How we display the progress update (for unix)
303 int progress_last_percent;
304 unsigned int progress_last_time;
305 int interactive; /* Are we connected directly to a tty? */
306 char start_meta[2], stop_meta[2];
309 int fs_directory_count;
310 int fs_regular_count;
311 int fs_blockdev_count;
312 int fs_chardev_count;
314 int fs_symlinks_count;
315 int fs_fast_symlinks_count;
318 int fs_badblocks_count;
319 int fs_sockets_count;
325 int fs_ext_attr_inodes;
326 int fs_ext_attr_blocks;
331 * For the use of callers of the e2fsck functions; not used by
332 * e2fsck functions themselves.
339 static inline int tid_gt(tid_t x, tid_t y)
341 int difference = (x - y);
342 return (difference > 0);
345 static inline int tid_geq(tid_t x, tid_t y)
347 int difference = (x - y);
348 return (difference >= 0);