]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - e2fsck/e2fsck.h
Many files:
[thirdparty/e2fsprogs.git] / e2fsck / e2fsck.h
CommitLineData
3839e657
TT
1/*
2 * e2fsck.h
3 *
4 * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
5 * redistributed under the terms of the GNU Public License.
6 *
7 */
8
9#include <stdio.h>
10#include <string.h>
11#include <unistd.h>
12#include <stdlib.h>
3839e657
TT
13#include <sys/types.h>
14#include <sys/time.h>
15
50e1e10f 16#ifdef HAVE_LINUX_FS_H
3839e657 17#include <linux/fs.h>
50e1e10f 18#endif
3839e657
TT
19#include <linux/ext2_fs.h>
20
21#include "ext2fs/ext2fs.h"
22
23#ifdef __STDC__
24#define NOARGS void
25#else
26#define NOARGS
27#define const
28#endif
29
30/*
31 * Exit codes used by fsck-type programs
32 */
33#define FSCK_OK 0 /* No errors */
34#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
35#define FSCK_REBOOT 2 /* System should be rebooted */
36#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
37#define FSCK_ERROR 8 /* Operational error */
38#define FSCK_USAGE 16 /* Usage or syntax error */
39#define FSCK_LIBRARY 128 /* Shared library error */
40
f3db3566
TT
41/*
42 * The last ext2fs revision level that this version of e2fsck is able to
43 * support
44 */
1e3472c5 45#define E2FSCK_CURRENT_REV 1
f3db3566 46
3839e657
TT
47/*
48 * The directory information structure; stores directory information
49 * collected in earlier passes, to avoid disk i/o in fetching the
21c84b71 50 * directory information.
3839e657
TT
51 */
52struct dir_info {
53 ino_t ino; /* Inode number */
54 ino_t dotdot; /* Parent according to '..' */
55 ino_t parent; /* Parent according to treewalk */
56};
57
3839e657
TT
58/*
59 * This structure is used for keeping track of how much resources have
60 * been used for a particular pass of e2fsck.
61 */
62struct resource_track {
63 struct timeval time_start;
64 struct timeval user_start;
65 struct timeval system_start;
66 void *brk_start;
67};
68
69/*
1b6bf175 70 * E2fsck options
3839e657 71 */
1b6bf175
TT
72#define E2F_OPT_READONLY 0x0001
73#define E2F_OPT_PREEN 0x0002
74#define E2F_OPT_YES 0x0004
75#define E2F_OPT_NO 0x0008
76#define E2F_OPT_TIME 0x0010
77#define E2F_OPT_TIME2 0x0020
78#define E2F_OPT_CHECKBLOCKS 0x0040
79#define E2F_OPT_DEBUG 0x0080
3839e657 80
1b6bf175
TT
81/*
82 * This is the global e2fsck structure.
83 */
84struct e2fsck_struct {
85 ext2_filsys fs;
86 const char *program_name;
87 const char *filesystem_name;
88 const char *device_name;
89 int options;
90 blk_t use_superblock; /* sb requested by user */
91 blk_t superblock; /* sb used to open fs */
92
93 ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
94 ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
95 ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
96 ext2fs_inode_bitmap inode_bb_map; /* Inodes which are in bad blocks */
97
98 ext2fs_block_bitmap block_found_map; /* Blocks which are in use */
99 ext2fs_block_bitmap block_dup_map; /* Blks referenced more than once */
100 ext2fs_block_bitmap block_illegal_map; /* Meta-data blocks */
101
102 /*
103 * Inode count arrays
104 */
105 ext2_icount_t inode_count;
106 ext2_icount_t inode_link_info;
107
108 /*
109 * Array of flags indicating whether an inode bitmap, block
110 * bitmap, or inode table is invalid
111 */
112 int *invalid_inode_bitmap_flag;
113 int *invalid_block_bitmap_flag;
114 int *invalid_inode_table_flag;
115 int invalid_bitmaps; /* There are invalid bitmaps/itable */
116
117 /*
118 * For pass1_check_directory and pass1_get_blocks
119 */
120 ino_t stashed_ino;
121 struct ext2_inode *stashed_inode;
122
123 /*
124 * Tuning parameters
125 */
126 int process_inode_size;
127 int inode_buffer_blocks;
128
129 /*
130 * For timing purposes
131 */
132 struct resource_track global_rtrack;
133
134 /* File counts */
135 int fs_directory_count;
136 int fs_regular_count;
137 int fs_blockdev_count;
138 int fs_chardev_count;
139 int fs_links_count;
140 int fs_symlinks_count;
141 int fs_fast_symlinks_count;
142 int fs_fifo_count;
143 int fs_total_count;
144 int fs_badblocks_count;
145 int fs_sockets_count;
146 int fs_ind_count;
147 int fs_dind_count;
148 int fs_tind_count;
149 int fs_fragmented;
150};
f3db3566 151
1b6bf175 152typedef struct e2fsck_struct *e2fsck_t;
f3db3566 153
1e3472c5 154/*
1b6bf175 155 * Variables
1e3472c5 156 */
1b6bf175 157extern int restart_e2fsck;
1e3472c5 158
3839e657
TT
159/*
160 * Procedure declarations
161 */
162
1b6bf175
TT
163extern void pass1(e2fsck_t ctx);
164extern void pass1_dupblocks(e2fsck_t ctx, char *block_buf);
165extern void pass2(e2fsck_t ctx);
166extern void pass3(e2fsck_t ctx);
167extern void pass4(e2fsck_t ctx);
168extern void pass5(e2fsck_t ctx);
169
170/* e2fsck.c */
171errcode_t e2fsck_allocate_context(e2fsck_t *ret);
172errcode_t e2fsck_reset_context(e2fsck_t ctx);
173void e2fsck_free_context(e2fsck_t ctx);
3839e657 174
1e3472c5
TT
175/* pass1.c */
176extern errcode_t pass1_check_directory(ext2_filsys fs, ino_t ino);
177extern errcode_t pass1_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks);
178extern errcode_t pass1_read_inode(ext2_filsys fs, ino_t ino,
179 struct ext2_inode *inode);
180extern errcode_t pass1_write_inode(ext2_filsys fs, ino_t ino,
181 struct ext2_inode *inode);
7cf73dcd 182extern int e2fsck_pass1_check_device_inode(struct ext2_inode *inode);
1e3472c5 183
3839e657 184/* badblock.c */
1b6bf175 185extern void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
3839e657 186 int replace_bad_blocks);
1b6bf175 187extern void test_disk(e2fsck_t ctx);
3839e657
TT
188
189/* dirinfo.c */
21c84b71 190extern void add_dir_info(ext2_filsys fs, ino_t ino, ino_t parent);
3839e657
TT
191extern struct dir_info *get_dir_info(ino_t ino);
192extern void free_dir_info(ext2_filsys fs);
193extern int get_num_dirs(ext2_filsys fs);
21c84b71 194extern struct dir_info *dir_info_iter(int *control);
3839e657
TT
195
196/* ehandler.c */
197extern const char *ehandler_operation(const char *op);
198extern void ehandler_init(io_channel channel);
199
1b6bf175
TT
200/* super.c */
201void check_super_block(e2fsck_t ctx);
202
1e3472c5 203/* swapfs.c */
1b6bf175 204void swap_filesys(e2fsck_t ctx);
1e3472c5 205
3839e657
TT
206/* util.c */
207extern void *allocate_memory(int size, const char *description);
1b6bf175 208extern int ask(e2fsck_t ctx, const char * string, int def);
3839e657
TT
209extern int ask_yn(const char * string, int def);
210extern void fatal_error (const char * fmt_string);
1b6bf175
TT
211extern void read_bitmaps(e2fsck_t ctx);
212extern void write_bitmaps(e2fsck_t ctx);
213extern void preenhalt(e2fsck_t ctx);
214extern void print_resource_track(const char *desc,
215 struct resource_track *track);
3839e657
TT
216extern void init_resource_track(struct resource_track *track);
217extern int inode_has_valid_blocks(struct ext2_inode *inode);
f3db3566
TT
218extern void e2fsck_read_inode(ext2_filsys fs, unsigned long ino,
219 struct ext2_inode * inode, const char * proc);
220extern void e2fsck_write_inode(ext2_filsys fs, unsigned long ino,
221 struct ext2_inode * inode, const char * proc);
3839e657
TT
222#ifdef MTRACE
223extern void mtrace_print(char *mesg);
224#endif
1b6bf175 225extern blk_t get_backup_sb(ext2_filsys fs);
3839e657
TT
226
227#define die(str) fatal_error(str)
228
229/*
230 * pass3.c
231 */
1b6bf175 232extern int reconnect_file(e2fsck_t ctx, ino_t inode);