xref: /aosp_15_r20/external/e2fsprogs/e2fsck/e2fsck.h (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker  * e2fsck.h
3*6a54128fSAndroid Build Coastguard Worker  *
4*6a54128fSAndroid Build Coastguard Worker  * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be
5*6a54128fSAndroid Build Coastguard Worker  * redistributed under the terms of the GNU Public License.
6*6a54128fSAndroid Build Coastguard Worker  *
7*6a54128fSAndroid Build Coastguard Worker  */
8*6a54128fSAndroid Build Coastguard Worker 
9*6a54128fSAndroid Build Coastguard Worker #ifndef _E2FSCK_H
10*6a54128fSAndroid Build Coastguard Worker #define _E2FSCK_H
11*6a54128fSAndroid Build Coastguard Worker 
12*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
13*6a54128fSAndroid Build Coastguard Worker #include <string.h>
14*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_UNISTD_H
15*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
16*6a54128fSAndroid Build Coastguard Worker #endif
17*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
18*6a54128fSAndroid Build Coastguard Worker #include <time.h>
19*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SYS_TYPES_H
20*6a54128fSAndroid Build Coastguard Worker #include <sys/types.h>
21*6a54128fSAndroid Build Coastguard Worker #endif
22*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SYS_TIME_H
23*6a54128fSAndroid Build Coastguard Worker #include <sys/time.h>
24*6a54128fSAndroid Build Coastguard Worker #endif
25*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SETJMP_H
26*6a54128fSAndroid Build Coastguard Worker #include <setjmp.h>
27*6a54128fSAndroid Build Coastguard Worker #endif
28*6a54128fSAndroid Build Coastguard Worker 
29*6a54128fSAndroid Build Coastguard Worker #if EXT2_FLAT_INCLUDES
30*6a54128fSAndroid Build Coastguard Worker #include "ext2_fs.h"
31*6a54128fSAndroid Build Coastguard Worker #include "ext2fs.h"
32*6a54128fSAndroid Build Coastguard Worker #include "blkid.h"
33*6a54128fSAndroid Build Coastguard Worker #else
34*6a54128fSAndroid Build Coastguard Worker #include "ext2fs/ext2_fs.h"
35*6a54128fSAndroid Build Coastguard Worker #include "ext2fs/ext2fs.h"
36*6a54128fSAndroid Build Coastguard Worker #include "blkid/blkid.h"
37*6a54128fSAndroid Build Coastguard Worker #endif
38*6a54128fSAndroid Build Coastguard Worker 
39*6a54128fSAndroid Build Coastguard Worker #include "support/profile.h"
40*6a54128fSAndroid Build Coastguard Worker #include "support/prof_err.h"
41*6a54128fSAndroid Build Coastguard Worker 
42*6a54128fSAndroid Build Coastguard Worker #ifdef ENABLE_NLS
43*6a54128fSAndroid Build Coastguard Worker #include <libintl.h>
44*6a54128fSAndroid Build Coastguard Worker #include <locale.h>
45*6a54128fSAndroid Build Coastguard Worker #define _(a) (gettext (a))
46*6a54128fSAndroid Build Coastguard Worker #ifdef gettext_noop
47*6a54128fSAndroid Build Coastguard Worker #define N_(a) gettext_noop (a)
48*6a54128fSAndroid Build Coastguard Worker #else
49*6a54128fSAndroid Build Coastguard Worker #define N_(a) (a)
50*6a54128fSAndroid Build Coastguard Worker #endif
51*6a54128fSAndroid Build Coastguard Worker #define P_(singular, plural, n) (ngettext (singular, plural, n))
52*6a54128fSAndroid Build Coastguard Worker #ifndef NLS_CAT_NAME
53*6a54128fSAndroid Build Coastguard Worker #define NLS_CAT_NAME "e2fsprogs"
54*6a54128fSAndroid Build Coastguard Worker #endif
55*6a54128fSAndroid Build Coastguard Worker #ifndef LOCALEDIR
56*6a54128fSAndroid Build Coastguard Worker #define LOCALEDIR "/usr/share/locale"
57*6a54128fSAndroid Build Coastguard Worker #endif
58*6a54128fSAndroid Build Coastguard Worker #else
59*6a54128fSAndroid Build Coastguard Worker #define _(a) (a)
60*6a54128fSAndroid Build Coastguard Worker #define N_(a) a
61*6a54128fSAndroid Build Coastguard Worker #define P_(singular, plural, n) ((n) == 1 ? (singular) : (plural))
62*6a54128fSAndroid Build Coastguard Worker #endif
63*6a54128fSAndroid Build Coastguard Worker 
64*6a54128fSAndroid Build Coastguard Worker #ifdef __GNUC__
65*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_ATTR(x) __attribute__(x)
66*6a54128fSAndroid Build Coastguard Worker #else
67*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_ATTR(x)
68*6a54128fSAndroid Build Coastguard Worker #endif
69*6a54128fSAndroid Build Coastguard Worker 
70*6a54128fSAndroid Build Coastguard Worker #include "support/quotaio.h"
71*6a54128fSAndroid Build Coastguard Worker #if __GNUC_PREREQ (4, 6)
72*6a54128fSAndroid Build Coastguard Worker #pragma GCC diagnostic push
73*6a54128fSAndroid Build Coastguard Worker #pragma GCC diagnostic ignored "-Wunused-function"
74*6a54128fSAndroid Build Coastguard Worker #endif
75*6a54128fSAndroid Build Coastguard Worker #include "ext2fs/fast_commit.h"
76*6a54128fSAndroid Build Coastguard Worker #if __GNUC_PREREQ (4, 6)
77*6a54128fSAndroid Build Coastguard Worker #pragma GCC diagnostic pop
78*6a54128fSAndroid Build Coastguard Worker #endif
79*6a54128fSAndroid Build Coastguard Worker 
80*6a54128fSAndroid Build Coastguard Worker /*
81*6a54128fSAndroid Build Coastguard Worker  * Exit codes used by fsck-type programs
82*6a54128fSAndroid Build Coastguard Worker  */
83*6a54128fSAndroid Build Coastguard Worker #define FSCK_OK          0	/* No errors */
84*6a54128fSAndroid Build Coastguard Worker #define FSCK_NONDESTRUCT 1	/* File system errors corrected */
85*6a54128fSAndroid Build Coastguard Worker #define FSCK_REBOOT      2	/* System should be rebooted */
86*6a54128fSAndroid Build Coastguard Worker #define FSCK_UNCORRECTED 4	/* File system errors left uncorrected */
87*6a54128fSAndroid Build Coastguard Worker #define FSCK_ERROR       8	/* Operational error */
88*6a54128fSAndroid Build Coastguard Worker #define FSCK_USAGE       16	/* Usage or syntax error */
89*6a54128fSAndroid Build Coastguard Worker #define FSCK_CANCELED	 32	/* Aborted with a signal or ^C */
90*6a54128fSAndroid Build Coastguard Worker #define FSCK_LIBRARY     128	/* Shared library error */
91*6a54128fSAndroid Build Coastguard Worker 
92*6a54128fSAndroid Build Coastguard Worker /*
93*6a54128fSAndroid Build Coastguard Worker  * The last ext2fs revision level that this version of e2fsck is able to
94*6a54128fSAndroid Build Coastguard Worker  * support
95*6a54128fSAndroid Build Coastguard Worker  */
96*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_CURRENT_REV	1
97*6a54128fSAndroid Build Coastguard Worker 
98*6a54128fSAndroid Build Coastguard Worker /*
99*6a54128fSAndroid Build Coastguard Worker  * The directory information structure; stores directory information
100*6a54128fSAndroid Build Coastguard Worker  * collected in earlier passes, to avoid disk i/o in fetching the
101*6a54128fSAndroid Build Coastguard Worker  * directory information.
102*6a54128fSAndroid Build Coastguard Worker  */
103*6a54128fSAndroid Build Coastguard Worker struct dir_info {
104*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		ino;	/* Inode number */
105*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		dotdot;	/* Parent according to '..' */
106*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		parent; /* Parent according to treewalk */
107*6a54128fSAndroid Build Coastguard Worker };
108*6a54128fSAndroid Build Coastguard Worker 
109*6a54128fSAndroid Build Coastguard Worker 
110*6a54128fSAndroid Build Coastguard Worker /*
111*6a54128fSAndroid Build Coastguard Worker  * The indexed directory information structure; stores information for
112*6a54128fSAndroid Build Coastguard Worker  * directories which contain a hash tree index.
113*6a54128fSAndroid Build Coastguard Worker  */
114*6a54128fSAndroid Build Coastguard Worker struct dx_dir_info {
115*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		ino;		/* Inode number */
116*6a54128fSAndroid Build Coastguard Worker 	short			depth;		/* depth of tree (15 bits) */
117*6a54128fSAndroid Build Coastguard Worker 	__u8			hashversion;
118*6a54128fSAndroid Build Coastguard Worker 	__u8			casefolded_hash:1;
119*6a54128fSAndroid Build Coastguard Worker 	blk_t			numblocks;	/* number of blocks in dir */
120*6a54128fSAndroid Build Coastguard Worker 	struct dx_dirblock_info	*dx_block;	/* Array of size numblocks */
121*6a54128fSAndroid Build Coastguard Worker };
122*6a54128fSAndroid Build Coastguard Worker 
123*6a54128fSAndroid Build Coastguard Worker #define DX_DIRBLOCK_ROOT	1
124*6a54128fSAndroid Build Coastguard Worker #define DX_DIRBLOCK_LEAF	2
125*6a54128fSAndroid Build Coastguard Worker #define DX_DIRBLOCK_NODE	3
126*6a54128fSAndroid Build Coastguard Worker #define DX_DIRBLOCK_CORRUPT	4
127*6a54128fSAndroid Build Coastguard Worker #define DX_DIRBLOCK_CLEARED	8
128*6a54128fSAndroid Build Coastguard Worker 
129*6a54128fSAndroid Build Coastguard Worker struct dx_dirblock_info {
130*6a54128fSAndroid Build Coastguard Worker 	int		type;
131*6a54128fSAndroid Build Coastguard Worker 	int		flags;
132*6a54128fSAndroid Build Coastguard Worker 	blk64_t		phys;
133*6a54128fSAndroid Build Coastguard Worker 	blk64_t		parent;
134*6a54128fSAndroid Build Coastguard Worker 	blk64_t		previous;
135*6a54128fSAndroid Build Coastguard Worker 	ext2_dirhash_t	min_hash;
136*6a54128fSAndroid Build Coastguard Worker 	ext2_dirhash_t	max_hash;
137*6a54128fSAndroid Build Coastguard Worker 	ext2_dirhash_t	node_min_hash;
138*6a54128fSAndroid Build Coastguard Worker 	ext2_dirhash_t	node_max_hash;
139*6a54128fSAndroid Build Coastguard Worker };
140*6a54128fSAndroid Build Coastguard Worker 
141*6a54128fSAndroid Build Coastguard Worker #define DX_FLAG_REFERENCED	1
142*6a54128fSAndroid Build Coastguard Worker #define DX_FLAG_DUP_REF		2
143*6a54128fSAndroid Build Coastguard Worker #define DX_FLAG_FIRST		4
144*6a54128fSAndroid Build Coastguard Worker #define DX_FLAG_LAST		8
145*6a54128fSAndroid Build Coastguard Worker 
146*6a54128fSAndroid Build Coastguard Worker struct encrypted_file_info;
147*6a54128fSAndroid Build Coastguard Worker 
148*6a54128fSAndroid Build Coastguard Worker #define RESOURCE_TRACK
149*6a54128fSAndroid Build Coastguard Worker 
150*6a54128fSAndroid Build Coastguard Worker #ifdef RESOURCE_TRACK
151*6a54128fSAndroid Build Coastguard Worker /*
152*6a54128fSAndroid Build Coastguard Worker  * This structure is used for keeping track of how much resources have
153*6a54128fSAndroid Build Coastguard Worker  * been used for a particular pass of e2fsck.
154*6a54128fSAndroid Build Coastguard Worker  */
155*6a54128fSAndroid Build Coastguard Worker struct resource_track {
156*6a54128fSAndroid Build Coastguard Worker 	struct timeval time_start;
157*6a54128fSAndroid Build Coastguard Worker 	struct timeval user_start;
158*6a54128fSAndroid Build Coastguard Worker 	struct timeval system_start;
159*6a54128fSAndroid Build Coastguard Worker 	void	*brk_start;
160*6a54128fSAndroid Build Coastguard Worker 	unsigned long long bytes_read;
161*6a54128fSAndroid Build Coastguard Worker 	unsigned long long bytes_written;
162*6a54128fSAndroid Build Coastguard Worker };
163*6a54128fSAndroid Build Coastguard Worker #endif
164*6a54128fSAndroid Build Coastguard Worker 
165*6a54128fSAndroid Build Coastguard Worker /*
166*6a54128fSAndroid Build Coastguard Worker  * E2fsck options
167*6a54128fSAndroid Build Coastguard Worker  */
168*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_READONLY	0x0001
169*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_PREEN		0x0002
170*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_YES		0x0004
171*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_NO		0x0008
172*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_TIME		0x0010
173*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_TIME2		0x0020
174*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_CHECKBLOCKS	0x0040
175*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_DEBUG		0x0080
176*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_FORCE		0x0100
177*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_WRITECHECK	0x0200
178*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_COMPRESS_DIRS	0x0400
179*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_FRAGCHECK	0x0800
180*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_JOURNAL_ONLY	0x1000 /* only replay the journal */
181*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_DISCARD		0x2000
182*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_CONVERT_BMAP	0x4000 /* convert blockmap to extent */
183*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_FIXES_ONLY	0x8000 /* skip all optimizations */
184*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_NOOPT_EXTENTS	0x10000 /* don't optimize extents */
185*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_ICOUNT_FULLMAP	0x20000 /* use an array for inode counts */
186*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_UNSHARE_BLOCKS  0x40000
187*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_CLEAR_UNINIT	0x80000 /* Hack to clear the uninit bit */
188*6a54128fSAndroid Build Coastguard Worker #define E2F_OPT_CHECK_ENCODING  0x100000 /* Force verification of encoded filenames */
189*6a54128fSAndroid Build Coastguard Worker 
190*6a54128fSAndroid Build Coastguard Worker /*
191*6a54128fSAndroid Build Coastguard Worker  * E2fsck flags
192*6a54128fSAndroid Build Coastguard Worker  */
193*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_ABORT		0x0001 /* Abort signaled */
194*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_CANCEL		0x0002 /* Cancel signaled */
195*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_SIGNAL_MASK	(E2F_FLAG_ABORT | E2F_FLAG_CANCEL)
196*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_RESTART	0x0004 /* Restart signaled */
197*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_RUN_RETURN	(E2F_FLAG_SIGNAL_MASK | E2F_FLAG_RESTART)
198*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_RESTART_LATER	0x0008 /* Restart after all iterations done */
199*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_SETJMP_OK	0x0010 /* Setjmp valid for abort */
200*6a54128fSAndroid Build Coastguard Worker 
201*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_PROG_BAR	0x0020 /* Progress bar on screen */
202*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_PROG_SUPPRESS	0x0040 /* Progress suspended */
203*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_JOURNAL_INODE	0x0080 /* Create a new ext3 journal inode */
204*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_SB_SPECIFIED	0x0100 /* The superblock was explicitly
205*6a54128fSAndroid Build Coastguard Worker 					* specified by the user */
206*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_RESTARTED	0x0200 /* E2fsck has been restarted */
207*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_RESIZE_INODE	0x0400 /* Request to recreate resize inode */
208*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_GOT_DEVSIZE	0x0800 /* Device size has been fetched */
209*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_EXITING	0x1000 /* E2fsck exiting due to errors */
210*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_TIME_INSANE	0x2000 /* Time is insane */
211*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_PROBLEMS_FIXED	0x4000 /* At least one problem was fixed */
212*6a54128fSAndroid Build Coastguard Worker #define E2F_FLAG_ALLOC_OK	0x8000 /* Can we allocate blocks? */
213*6a54128fSAndroid Build Coastguard Worker 
214*6a54128fSAndroid Build Coastguard Worker #define E2F_RESET_FLAGS (E2F_FLAG_TIME_INSANE | E2F_FLAG_PROBLEMS_FIXED)
215*6a54128fSAndroid Build Coastguard Worker 
216*6a54128fSAndroid Build Coastguard Worker /*
217*6a54128fSAndroid Build Coastguard Worker  * Defines for indicating the e2fsck pass number
218*6a54128fSAndroid Build Coastguard Worker  */
219*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_1	1
220*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_2	2
221*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_3	3
222*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_4	4
223*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_5	5
224*6a54128fSAndroid Build Coastguard Worker #define E2F_PASS_1B	6
225*6a54128fSAndroid Build Coastguard Worker 
226*6a54128fSAndroid Build Coastguard Worker /*
227*6a54128fSAndroid Build Coastguard Worker  * Define the extended attribute refcount structure
228*6a54128fSAndroid Build Coastguard Worker  */
229*6a54128fSAndroid Build Coastguard Worker typedef struct ea_refcount *ext2_refcount_t;
230*6a54128fSAndroid Build Coastguard Worker 
231*6a54128fSAndroid Build Coastguard Worker /*
232*6a54128fSAndroid Build Coastguard Worker  * This is the global e2fsck structure.
233*6a54128fSAndroid Build Coastguard Worker  */
234*6a54128fSAndroid Build Coastguard Worker typedef struct e2fsck_struct *e2fsck_t;
235*6a54128fSAndroid Build Coastguard Worker 
236*6a54128fSAndroid Build Coastguard Worker #define MAX_EXTENT_DEPTH_COUNT 8
237*6a54128fSAndroid Build Coastguard Worker 
238*6a54128fSAndroid Build Coastguard Worker /*
239*6a54128fSAndroid Build Coastguard Worker  * This structure is used to manage the list of extents in a file. Placing
240*6a54128fSAndroid Build Coastguard Worker  * it here since this is used by fast_commit.h.
241*6a54128fSAndroid Build Coastguard Worker  */
242*6a54128fSAndroid Build Coastguard Worker struct extent_list {
243*6a54128fSAndroid Build Coastguard Worker 	blk64_t blocks_freed;
244*6a54128fSAndroid Build Coastguard Worker 	struct ext2fs_extent *extents;
245*6a54128fSAndroid Build Coastguard Worker 	unsigned int count;
246*6a54128fSAndroid Build Coastguard Worker 	unsigned int size;
247*6a54128fSAndroid Build Coastguard Worker 	unsigned int ext_read;
248*6a54128fSAndroid Build Coastguard Worker 	errcode_t retval;
249*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t ino;
250*6a54128fSAndroid Build Coastguard Worker };
251*6a54128fSAndroid Build Coastguard Worker 
252*6a54128fSAndroid Build Coastguard Worker /* State structure for fast commit replay */
253*6a54128fSAndroid Build Coastguard Worker struct e2fsck_fc_replay_state {
254*6a54128fSAndroid Build Coastguard Worker 	struct extent_list fc_extent_list;
255*6a54128fSAndroid Build Coastguard Worker 	int fc_replay_num_tags;
256*6a54128fSAndroid Build Coastguard Worker 	int fc_replay_expected_off;
257*6a54128fSAndroid Build Coastguard Worker 	enum passtype fc_current_pass;
258*6a54128fSAndroid Build Coastguard Worker 	int fc_cur_tag;
259*6a54128fSAndroid Build Coastguard Worker 	unsigned int fc_crc;
260*6a54128fSAndroid Build Coastguard Worker 	__u16 fc_super_state;
261*6a54128fSAndroid Build Coastguard Worker };
262*6a54128fSAndroid Build Coastguard Worker 
263*6a54128fSAndroid Build Coastguard Worker struct e2fsck_struct {
264*6a54128fSAndroid Build Coastguard Worker 	ext2_filsys fs;
265*6a54128fSAndroid Build Coastguard Worker 	const char *program_name;
266*6a54128fSAndroid Build Coastguard Worker 	char *filesystem_name;
267*6a54128fSAndroid Build Coastguard Worker 	char *device_name;
268*6a54128fSAndroid Build Coastguard Worker 	char *io_options;
269*6a54128fSAndroid Build Coastguard Worker 	FILE	*logf;
270*6a54128fSAndroid Build Coastguard Worker 	char	*log_fn;
271*6a54128fSAndroid Build Coastguard Worker 	FILE	*problem_logf;
272*6a54128fSAndroid Build Coastguard Worker 	char	*problem_log_fn;
273*6a54128fSAndroid Build Coastguard Worker 	int	flags;		/* E2fsck internal flags */
274*6a54128fSAndroid Build Coastguard Worker 	int	options;
275*6a54128fSAndroid Build Coastguard Worker 	unsigned blocksize;	/* blocksize */
276*6a54128fSAndroid Build Coastguard Worker 	blk64_t	use_superblock;	/* sb requested by user */
277*6a54128fSAndroid Build Coastguard Worker 	blk64_t	superblock;	/* sb used to open fs */
278*6a54128fSAndroid Build Coastguard Worker 	blk64_t	num_blocks;	/* Total number of blocks */
279*6a54128fSAndroid Build Coastguard Worker 	blk64_t	free_blocks;
280*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t free_inodes;
281*6a54128fSAndroid Build Coastguard Worker 	int	mount_flags;
282*6a54128fSAndroid Build Coastguard Worker 	int	openfs_flags;
283*6a54128fSAndroid Build Coastguard Worker 	blkid_cache blkid;	/* blkid cache */
284*6a54128fSAndroid Build Coastguard Worker 
285*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SETJMP_H
286*6a54128fSAndroid Build Coastguard Worker 	jmp_buf	abort_loc;
287*6a54128fSAndroid Build Coastguard Worker #endif
288*6a54128fSAndroid Build Coastguard Worker 	unsigned long abort_code;
289*6a54128fSAndroid Build Coastguard Worker 
290*6a54128fSAndroid Build Coastguard Worker 	int (*progress)(e2fsck_t ctx, int pass, unsigned long cur,
291*6a54128fSAndroid Build Coastguard Worker 			unsigned long max);
292*6a54128fSAndroid Build Coastguard Worker 
293*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
294*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
295*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
296*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_bb_map; /* Inodes which are in bad blocks */
297*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_imagic_map; /* AFS inodes */
298*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_reg_map; /* Inodes which are regular files*/
299*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inode_casefold_map; /* Inodes which are casefolded */
300*6a54128fSAndroid Build Coastguard Worker 
301*6a54128fSAndroid Build Coastguard Worker 	ext2fs_block_bitmap block_found_map; /* Blocks which are in use */
302*6a54128fSAndroid Build Coastguard Worker 	ext2fs_block_bitmap block_dup_map; /* Blks referenced more than once */
303*6a54128fSAndroid Build Coastguard Worker 	ext2fs_block_bitmap block_ea_map; /* Blocks which are used by EA's */
304*6a54128fSAndroid Build Coastguard Worker 
305*6a54128fSAndroid Build Coastguard Worker 	/*
306*6a54128fSAndroid Build Coastguard Worker 	 * Inode count arrays
307*6a54128fSAndroid Build Coastguard Worker 	 */
308*6a54128fSAndroid Build Coastguard Worker 	ext2_icount_t	inode_count;
309*6a54128fSAndroid Build Coastguard Worker 	ext2_icount_t inode_link_info;
310*6a54128fSAndroid Build Coastguard Worker 
311*6a54128fSAndroid Build Coastguard Worker 	ext2_refcount_t	refcount;
312*6a54128fSAndroid Build Coastguard Worker 	ext2_refcount_t refcount_extra;
313*6a54128fSAndroid Build Coastguard Worker 
314*6a54128fSAndroid Build Coastguard Worker 	/*
315*6a54128fSAndroid Build Coastguard Worker 	 * Quota blocks and inodes to be charged for each ea block.
316*6a54128fSAndroid Build Coastguard Worker 	 */
317*6a54128fSAndroid Build Coastguard Worker 	ext2_refcount_t ea_block_quota_blocks;
318*6a54128fSAndroid Build Coastguard Worker 	ext2_refcount_t ea_block_quota_inodes;
319*6a54128fSAndroid Build Coastguard Worker 
320*6a54128fSAndroid Build Coastguard Worker 	/*
321*6a54128fSAndroid Build Coastguard Worker 	 * ea_inode references from attr entries.
322*6a54128fSAndroid Build Coastguard Worker 	 */
323*6a54128fSAndroid Build Coastguard Worker 	ext2_refcount_t ea_inode_refs;
324*6a54128fSAndroid Build Coastguard Worker 
325*6a54128fSAndroid Build Coastguard Worker 	/*
326*6a54128fSAndroid Build Coastguard Worker 	 * Array of flags indicating whether an inode bitmap, block
327*6a54128fSAndroid Build Coastguard Worker 	 * bitmap, or inode table is invalid
328*6a54128fSAndroid Build Coastguard Worker 	 */
329*6a54128fSAndroid Build Coastguard Worker 	int *invalid_inode_bitmap_flag;
330*6a54128fSAndroid Build Coastguard Worker 	int *invalid_block_bitmap_flag;
331*6a54128fSAndroid Build Coastguard Worker 	int *invalid_inode_table_flag;
332*6a54128fSAndroid Build Coastguard Worker 	int invalid_bitmaps;	/* There are invalid bitmaps/itable */
333*6a54128fSAndroid Build Coastguard Worker 
334*6a54128fSAndroid Build Coastguard Worker 	/*
335*6a54128fSAndroid Build Coastguard Worker 	 * Block buffer
336*6a54128fSAndroid Build Coastguard Worker 	 */
337*6a54128fSAndroid Build Coastguard Worker 	char *block_buf;
338*6a54128fSAndroid Build Coastguard Worker 
339*6a54128fSAndroid Build Coastguard Worker 	/*
340*6a54128fSAndroid Build Coastguard Worker 	 * For pass1_check_directory and pass1_get_blocks
341*6a54128fSAndroid Build Coastguard Worker 	 */
342*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t stashed_ino;
343*6a54128fSAndroid Build Coastguard Worker 	struct ext2_inode *stashed_inode;
344*6a54128fSAndroid Build Coastguard Worker 
345*6a54128fSAndroid Build Coastguard Worker 	/*
346*6a54128fSAndroid Build Coastguard Worker 	 * Location of the lost and found directory
347*6a54128fSAndroid Build Coastguard Worker 	 */
348*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t lost_and_found;
349*6a54128fSAndroid Build Coastguard Worker 	int bad_lost_and_found;
350*6a54128fSAndroid Build Coastguard Worker 
351*6a54128fSAndroid Build Coastguard Worker 	/*
352*6a54128fSAndroid Build Coastguard Worker 	 * Directory information
353*6a54128fSAndroid Build Coastguard Worker 	 */
354*6a54128fSAndroid Build Coastguard Worker 	struct dir_info_db	*dir_info;
355*6a54128fSAndroid Build Coastguard Worker 
356*6a54128fSAndroid Build Coastguard Worker 	/*
357*6a54128fSAndroid Build Coastguard Worker 	 * Indexed directory information
358*6a54128fSAndroid Build Coastguard Worker 	 */
359*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		dx_dir_info_count;
360*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		dx_dir_info_size;
361*6a54128fSAndroid Build Coastguard Worker 	struct dx_dir_info	*dx_dir_info;
362*6a54128fSAndroid Build Coastguard Worker 
363*6a54128fSAndroid Build Coastguard Worker 	/*
364*6a54128fSAndroid Build Coastguard Worker 	 * Directories to hash
365*6a54128fSAndroid Build Coastguard Worker 	 */
366*6a54128fSAndroid Build Coastguard Worker 	ext2_u32_list	dirs_to_hash;
367*6a54128fSAndroid Build Coastguard Worker 
368*6a54128fSAndroid Build Coastguard Worker 	/*
369*6a54128fSAndroid Build Coastguard Worker 	 * Encrypted file information
370*6a54128fSAndroid Build Coastguard Worker 	 */
371*6a54128fSAndroid Build Coastguard Worker 	struct encrypted_file_info *encrypted_files;
372*6a54128fSAndroid Build Coastguard Worker 
373*6a54128fSAndroid Build Coastguard Worker 	/*
374*6a54128fSAndroid Build Coastguard Worker 	 * Tuning parameters
375*6a54128fSAndroid Build Coastguard Worker 	 */
376*6a54128fSAndroid Build Coastguard Worker 	int process_inode_size;
377*6a54128fSAndroid Build Coastguard Worker 	int inode_buffer_blocks;
378*6a54128fSAndroid Build Coastguard Worker 	unsigned int htree_slack_percentage;
379*6a54128fSAndroid Build Coastguard Worker 
380*6a54128fSAndroid Build Coastguard Worker 	/*
381*6a54128fSAndroid Build Coastguard Worker 	 * ext3 journal support
382*6a54128fSAndroid Build Coastguard Worker 	 */
383*6a54128fSAndroid Build Coastguard Worker 	io_channel	journal_io;
384*6a54128fSAndroid Build Coastguard Worker 	char	*journal_name;
385*6a54128fSAndroid Build Coastguard Worker 
386*6a54128fSAndroid Build Coastguard Worker 	/*
387*6a54128fSAndroid Build Coastguard Worker 	 * Ext4 quota support
388*6a54128fSAndroid Build Coastguard Worker 	 */
389*6a54128fSAndroid Build Coastguard Worker 	quota_ctx_t qctx;
390*6a54128fSAndroid Build Coastguard Worker #ifdef RESOURCE_TRACK
391*6a54128fSAndroid Build Coastguard Worker 	/*
392*6a54128fSAndroid Build Coastguard Worker 	 * For timing purposes
393*6a54128fSAndroid Build Coastguard Worker 	 */
394*6a54128fSAndroid Build Coastguard Worker 	struct resource_track	global_rtrack;
395*6a54128fSAndroid Build Coastguard Worker #endif
396*6a54128fSAndroid Build Coastguard Worker 
397*6a54128fSAndroid Build Coastguard Worker 	/*
398*6a54128fSAndroid Build Coastguard Worker 	 * How we display the progress update (for unix)
399*6a54128fSAndroid Build Coastguard Worker 	 */
400*6a54128fSAndroid Build Coastguard Worker 	int progress_fd;
401*6a54128fSAndroid Build Coastguard Worker 	int progress_pos;
402*6a54128fSAndroid Build Coastguard Worker 	int progress_last_percent;
403*6a54128fSAndroid Build Coastguard Worker 	unsigned int progress_last_time;
404*6a54128fSAndroid Build Coastguard Worker 	int interactive;	/* Are we connected directly to a tty? */
405*6a54128fSAndroid Build Coastguard Worker 	char start_meta[2], stop_meta[2];
406*6a54128fSAndroid Build Coastguard Worker 
407*6a54128fSAndroid Build Coastguard Worker 	/* File counts */
408*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_directory_count;
409*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_regular_count;
410*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_blockdev_count;
411*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_chardev_count;
412*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_links_count;
413*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_symlinks_count;
414*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_fast_symlinks_count;
415*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_fifo_count;
416*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_total_count;
417*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_badblocks_count;
418*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_sockets_count;
419*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_ind_count;
420*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_dind_count;
421*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_tind_count;
422*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_fragmented;
423*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_fragmented_dir;
424*6a54128fSAndroid Build Coastguard Worker 	__u32 large_files;
425*6a54128fSAndroid Build Coastguard Worker 	__u32 large_dirs;
426*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_ext_attr_inodes;
427*6a54128fSAndroid Build Coastguard Worker 	__u32 fs_ext_attr_blocks;
428*6a54128fSAndroid Build Coastguard Worker 	__u32 extent_depth_count[MAX_EXTENT_DEPTH_COUNT];
429*6a54128fSAndroid Build Coastguard Worker 
430*6a54128fSAndroid Build Coastguard Worker 	/* misc fields */
431*6a54128fSAndroid Build Coastguard Worker 	time_t now;
432*6a54128fSAndroid Build Coastguard Worker 	time_t time_fudge;	/* For working around buggy init scripts */
433*6a54128fSAndroid Build Coastguard Worker 	int ext_attr_ver;
434*6a54128fSAndroid Build Coastguard Worker 	profile_t	profile;
435*6a54128fSAndroid Build Coastguard Worker 	int blocks_per_page;
436*6a54128fSAndroid Build Coastguard Worker 	ext2_u32_list casefolded_dirs;
437*6a54128fSAndroid Build Coastguard Worker 
438*6a54128fSAndroid Build Coastguard Worker 	/* Reserve blocks for root and l+f re-creation */
439*6a54128fSAndroid Build Coastguard Worker 	blk64_t root_repair_block, lnf_repair_block;
440*6a54128fSAndroid Build Coastguard Worker 
441*6a54128fSAndroid Build Coastguard Worker 	/*
442*6a54128fSAndroid Build Coastguard Worker 	 * For the use of callers of the e2fsck functions; not used by
443*6a54128fSAndroid Build Coastguard Worker 	 * e2fsck functions themselves.
444*6a54128fSAndroid Build Coastguard Worker 	 */
445*6a54128fSAndroid Build Coastguard Worker 	void *priv_data;
446*6a54128fSAndroid Build Coastguard Worker 	ext2fs_block_bitmap block_metadata_map; /* Metadata blocks */
447*6a54128fSAndroid Build Coastguard Worker 
448*6a54128fSAndroid Build Coastguard Worker 	/* How much are we allowed to readahead? */
449*6a54128fSAndroid Build Coastguard Worker 	unsigned long long readahead_kb;
450*6a54128fSAndroid Build Coastguard Worker 
451*6a54128fSAndroid Build Coastguard Worker 	/*
452*6a54128fSAndroid Build Coastguard Worker 	 * Inodes to rebuild extent trees
453*6a54128fSAndroid Build Coastguard Worker 	 */
454*6a54128fSAndroid Build Coastguard Worker 	ext2fs_inode_bitmap inodes_to_rebuild;
455*6a54128fSAndroid Build Coastguard Worker 
456*6a54128fSAndroid Build Coastguard Worker 	/* Undo file */
457*6a54128fSAndroid Build Coastguard Worker 	char *undo_file;
458*6a54128fSAndroid Build Coastguard Worker 
459*6a54128fSAndroid Build Coastguard Worker 	/* Fast commit replay state */
460*6a54128fSAndroid Build Coastguard Worker 	struct e2fsck_fc_replay_state fc_replay_state;
461*6a54128fSAndroid Build Coastguard Worker };
462*6a54128fSAndroid Build Coastguard Worker 
463*6a54128fSAndroid Build Coastguard Worker /* Data structures to evaluate whether an extent tree needs rebuilding. */
464*6a54128fSAndroid Build Coastguard Worker struct extent_tree_level {
465*6a54128fSAndroid Build Coastguard Worker 	unsigned int	num_extents;
466*6a54128fSAndroid Build Coastguard Worker 	unsigned int	max_extents;
467*6a54128fSAndroid Build Coastguard Worker };
468*6a54128fSAndroid Build Coastguard Worker 
469*6a54128fSAndroid Build Coastguard Worker struct extent_tree_info {
470*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t ino;
471*6a54128fSAndroid Build Coastguard Worker 	int force_rebuild;
472*6a54128fSAndroid Build Coastguard Worker 	struct extent_tree_level	ext_info[MAX_EXTENT_DEPTH_COUNT];
473*6a54128fSAndroid Build Coastguard Worker };
474*6a54128fSAndroid Build Coastguard Worker 
475*6a54128fSAndroid Build Coastguard Worker /* Used by the region allocation code */
476*6a54128fSAndroid Build Coastguard Worker typedef __u64 region_addr_t;
477*6a54128fSAndroid Build Coastguard Worker typedef struct region_struct *region_t;
478*6a54128fSAndroid Build Coastguard Worker 
479*6a54128fSAndroid Build Coastguard Worker #ifndef HAVE_STRNLEN
480*6a54128fSAndroid Build Coastguard Worker #define strnlen(str, x) e2fsck_strnlen((str),(x))
481*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_strnlen(const char * s, int count);
482*6a54128fSAndroid Build Coastguard Worker #endif
483*6a54128fSAndroid Build Coastguard Worker 
484*6a54128fSAndroid Build Coastguard Worker /*
485*6a54128fSAndroid Build Coastguard Worker  * Procedure declarations
486*6a54128fSAndroid Build Coastguard Worker  */
487*6a54128fSAndroid Build Coastguard Worker 
488*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass1(e2fsck_t ctx);
489*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf);
490*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass2(e2fsck_t ctx);
491*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass3(e2fsck_t ctx);
492*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass4(e2fsck_t ctx);
493*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_pass5(e2fsck_t ctx);
494*6a54128fSAndroid Build Coastguard Worker 
495*6a54128fSAndroid Build Coastguard Worker /* e2fsck.c */
496*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_allocate_context(e2fsck_t *ret);
497*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_reset_context(e2fsck_t ctx);
498*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_free_context(e2fsck_t ctx);
499*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_run(e2fsck_t ctx);
500*6a54128fSAndroid Build Coastguard Worker 
501*6a54128fSAndroid Build Coastguard Worker 
502*6a54128fSAndroid Build Coastguard Worker /* badblock.c */
503*6a54128fSAndroid Build Coastguard Worker extern void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
504*6a54128fSAndroid Build Coastguard Worker 				 int replace_bad_blocks);
505*6a54128fSAndroid Build Coastguard Worker 
506*6a54128fSAndroid Build Coastguard Worker /* dirinfo.c */
507*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
508*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_free_dir_info(e2fsck_t ctx);
509*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_get_num_dirinfo(e2fsck_t ctx);
510*6a54128fSAndroid Build Coastguard Worker extern struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx);
511*6a54128fSAndroid Build Coastguard Worker extern struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx,
512*6a54128fSAndroid Build Coastguard Worker 					     struct dir_info_iter *);
513*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_dir_info_iter_end(e2fsck_t ctx, struct dir_info_iter *);
514*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_dir_info_set_parent(e2fsck_t ctx, ext2_ino_t ino,
515*6a54128fSAndroid Build Coastguard Worker 				      ext2_ino_t parent);
516*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_dir_info_set_dotdot(e2fsck_t ctx, ext2_ino_t ino,
517*6a54128fSAndroid Build Coastguard Worker 				      ext2_ino_t dotdot);
518*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_dir_info_get_parent(e2fsck_t ctx, ext2_ino_t ino,
519*6a54128fSAndroid Build Coastguard Worker 				      ext2_ino_t *parent);
520*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_dir_info_get_dotdot(e2fsck_t ctx, ext2_ino_t ino,
521*6a54128fSAndroid Build Coastguard Worker 				      ext2_ino_t *dotdot);
522*6a54128fSAndroid Build Coastguard Worker 
523*6a54128fSAndroid Build Coastguard Worker /* dx_dirinfo.c */
524*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino,
525*6a54128fSAndroid Build Coastguard Worker 			      struct ext2_inode *inode, int num_blocks);
526*6a54128fSAndroid Build Coastguard Worker extern struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino);
527*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_free_dx_dir_info(e2fsck_t ctx);
528*6a54128fSAndroid Build Coastguard Worker extern ext2_ino_t e2fsck_get_num_dx_dirinfo(e2fsck_t ctx);
529*6a54128fSAndroid Build Coastguard Worker extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx,
530*6a54128fSAndroid Build Coastguard Worker 						   ext2_ino_t *control);
531*6a54128fSAndroid Build Coastguard Worker 
532*6a54128fSAndroid Build Coastguard Worker /* ea_refcount.c */
533*6a54128fSAndroid Build Coastguard Worker typedef __u64 ea_key_t;
534*6a54128fSAndroid Build Coastguard Worker typedef __u64 ea_value_t;
535*6a54128fSAndroid Build Coastguard Worker 
536*6a54128fSAndroid Build Coastguard Worker extern errcode_t ea_refcount_create(size_t size, ext2_refcount_t *ret);
537*6a54128fSAndroid Build Coastguard Worker extern void ea_refcount_free(ext2_refcount_t refcount);
538*6a54128fSAndroid Build Coastguard Worker extern errcode_t ea_refcount_fetch(ext2_refcount_t refcount, ea_key_t ea_key,
539*6a54128fSAndroid Build Coastguard Worker 				   ea_value_t *ret);
540*6a54128fSAndroid Build Coastguard Worker extern errcode_t ea_refcount_increment(ext2_refcount_t refcount,
541*6a54128fSAndroid Build Coastguard Worker 				       ea_key_t ea_key, ea_value_t *ret);
542*6a54128fSAndroid Build Coastguard Worker extern errcode_t ea_refcount_decrement(ext2_refcount_t refcount,
543*6a54128fSAndroid Build Coastguard Worker 				       ea_key_t ea_key, ea_value_t *ret);
544*6a54128fSAndroid Build Coastguard Worker extern errcode_t ea_refcount_store(ext2_refcount_t refcount, ea_key_t ea_key,
545*6a54128fSAndroid Build Coastguard Worker 				   ea_value_t count);
546*6a54128fSAndroid Build Coastguard Worker extern size_t ext2fs_get_refcount_size(ext2_refcount_t refcount);
547*6a54128fSAndroid Build Coastguard Worker extern void ea_refcount_intr_begin(ext2_refcount_t refcount);
548*6a54128fSAndroid Build Coastguard Worker extern ea_key_t ea_refcount_intr_next(ext2_refcount_t refcount,
549*6a54128fSAndroid Build Coastguard Worker 				      ea_value_t *ret);
550*6a54128fSAndroid Build Coastguard Worker 
551*6a54128fSAndroid Build Coastguard Worker /* ehandler.c */
552*6a54128fSAndroid Build Coastguard Worker extern const char *ehandler_operation(const char *op);
553*6a54128fSAndroid Build Coastguard Worker extern void ehandler_init(io_channel channel);
554*6a54128fSAndroid Build Coastguard Worker 
555*6a54128fSAndroid Build Coastguard Worker /* encrypted_files.c */
556*6a54128fSAndroid Build Coastguard Worker 
557*6a54128fSAndroid Build Coastguard Worker struct problem_context;
558*6a54128fSAndroid Build Coastguard Worker int add_encrypted_file(e2fsck_t ctx, struct problem_context *pctx);
559*6a54128fSAndroid Build Coastguard Worker 
560*6a54128fSAndroid Build Coastguard Worker #define NO_ENCRYPTION_POLICY		((__u32)-1)
561*6a54128fSAndroid Build Coastguard Worker #define CORRUPT_ENCRYPTION_POLICY	((__u32)-2)
562*6a54128fSAndroid Build Coastguard Worker #define UNRECOGNIZED_ENCRYPTION_POLICY	((__u32)-3)
563*6a54128fSAndroid Build Coastguard Worker __u32 find_encryption_policy(e2fsck_t ctx, ext2_ino_t ino);
564*6a54128fSAndroid Build Coastguard Worker 
565*6a54128fSAndroid Build Coastguard Worker void destroy_encryption_policy_map(e2fsck_t ctx);
566*6a54128fSAndroid Build Coastguard Worker void destroy_encrypted_file_info(e2fsck_t ctx);
567*6a54128fSAndroid Build Coastguard Worker 
568*6a54128fSAndroid Build Coastguard Worker /* extents.c */
569*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_rebuild_extents_later(e2fsck_t ctx, ext2_ino_t ino);
570*6a54128fSAndroid Build Coastguard Worker int e2fsck_ino_will_be_rebuilt(e2fsck_t ctx, ext2_ino_t ino);
571*6a54128fSAndroid Build Coastguard Worker void e2fsck_pass1e(e2fsck_t ctx);
572*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_check_rebuild_extents(e2fsck_t ctx, ext2_ino_t ino,
573*6a54128fSAndroid Build Coastguard Worker 				       struct ext2_inode *inode,
574*6a54128fSAndroid Build Coastguard Worker 				       struct problem_context *pctx);
575*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_should_rebuild_extents(e2fsck_t ctx,
576*6a54128fSAndroid Build Coastguard Worker 					struct problem_context *pctx,
577*6a54128fSAndroid Build Coastguard Worker 					struct extent_tree_info *eti,
578*6a54128fSAndroid Build Coastguard Worker 					struct ext2_extent_info *info);
579*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_read_extents(e2fsck_t ctx, struct extent_list *extents);
580*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_rewrite_extent_tree(e2fsck_t ctx,
581*6a54128fSAndroid Build Coastguard Worker 				     struct extent_list *extents);
582*6a54128fSAndroid Build Coastguard Worker 
583*6a54128fSAndroid Build Coastguard Worker /* journal.c */
584*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx);
585*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx);
586*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_move_ext3_journal(e2fsck_t ctx);
587*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_fix_ext3_journal_hint(e2fsck_t ctx);
588*6a54128fSAndroid Build Coastguard Worker 
589*6a54128fSAndroid Build Coastguard Worker /* logfile.c */
590*6a54128fSAndroid Build Coastguard Worker extern void set_up_logging(e2fsck_t ctx);
591*6a54128fSAndroid Build Coastguard Worker 
592*6a54128fSAndroid Build Coastguard Worker /* quota.c */
593*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_hide_quota(e2fsck_t ctx);
594*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_validate_quota_inodes(e2fsck_t ctx);
595*6a54128fSAndroid Build Coastguard Worker 
596*6a54128fSAndroid Build Coastguard Worker /* pass1.c */
597*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_setup_icount(e2fsck_t ctx, const char *icount_name,
598*6a54128fSAndroid Build Coastguard Worker 				     int flags, ext2_icount_t hint,
599*6a54128fSAndroid Build Coastguard Worker 				     ext2_icount_t *ret);
600*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_use_inode_shortcuts(e2fsck_t ctx, int use_shortcuts);
601*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_pass1_check_device_inode(ext2_filsys fs,
602*6a54128fSAndroid Build Coastguard Worker 					   struct ext2_inode *inode);
603*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
604*6a54128fSAndroid Build Coastguard Worker 				      struct ext2_inode *inode, char *buf);
605*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_clear_inode(e2fsck_t ctx, ext2_ino_t ino,
606*6a54128fSAndroid Build Coastguard Worker 			       struct ext2_inode *inode, int restart_flag,
607*6a54128fSAndroid Build Coastguard Worker 			       const char *source);
608*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_intercept_block_allocations(e2fsck_t ctx);
609*6a54128fSAndroid Build Coastguard Worker 
610*6a54128fSAndroid Build Coastguard Worker /* pass2.c */
611*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
612*6a54128fSAndroid Build Coastguard Worker 				    ext2_ino_t ino, char *buf);
613*6a54128fSAndroid Build Coastguard Worker 
614*6a54128fSAndroid Build Coastguard Worker /* pass3.c */
615*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_reconnect_file(e2fsck_t ctx, ext2_ino_t inode);
616*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
617*6a54128fSAndroid Build Coastguard Worker 					 int num, int gauranteed_size);
618*6a54128fSAndroid Build Coastguard Worker extern ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix);
619*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_adjust_inode_count(e2fsck_t ctx, ext2_ino_t ino,
620*6a54128fSAndroid Build Coastguard Worker 					   int adj);
621*6a54128fSAndroid Build Coastguard Worker 
622*6a54128fSAndroid Build Coastguard Worker /* readahead.c */
623*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_SUPER	(0x01)
624*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_GDT	(0x02)
625*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_BBITMAP	(0x04)
626*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_IBITMAP	(0x08)
627*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_ITABLE	(0x10)
628*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_READA_ALL_FLAGS	(0x1F)
629*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_readahead(ext2_filsys fs, int flags, dgrp_t start,
630*6a54128fSAndroid Build Coastguard Worker 			   dgrp_t ngroups);
631*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_RA_DBLIST_IGNORE_BLOCKCNT	(0x01)
632*6a54128fSAndroid Build Coastguard Worker #define E2FSCK_RA_DBLIST_ALL_FLAGS		(0x01)
633*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_readahead_dblist(ext2_filsys fs, int flags,
634*6a54128fSAndroid Build Coastguard Worker 				  ext2_dblist dblist,
635*6a54128fSAndroid Build Coastguard Worker 				  unsigned long long start,
636*6a54128fSAndroid Build Coastguard Worker 				  unsigned long long count);
637*6a54128fSAndroid Build Coastguard Worker int e2fsck_can_readahead(ext2_filsys fs);
638*6a54128fSAndroid Build Coastguard Worker unsigned long long e2fsck_guess_readahead(ext2_filsys fs);
639*6a54128fSAndroid Build Coastguard Worker 
640*6a54128fSAndroid Build Coastguard Worker /* region.c */
641*6a54128fSAndroid Build Coastguard Worker extern region_t region_create(region_addr_t min, region_addr_t max);
642*6a54128fSAndroid Build Coastguard Worker extern void region_free(region_t region);
643*6a54128fSAndroid Build Coastguard Worker extern int region_allocate(region_t region, region_addr_t start, int n);
644*6a54128fSAndroid Build Coastguard Worker 
645*6a54128fSAndroid Build Coastguard Worker /* rehash.c */
646*6a54128fSAndroid Build Coastguard Worker void e2fsck_rehash_dir_later(e2fsck_t ctx, ext2_ino_t ino);
647*6a54128fSAndroid Build Coastguard Worker int e2fsck_dir_will_be_rehashed(e2fsck_t ctx, ext2_ino_t ino);
648*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
649*6a54128fSAndroid Build Coastguard Worker 			    struct problem_context *pctx);
650*6a54128fSAndroid Build Coastguard Worker void e2fsck_rehash_directories(e2fsck_t ctx);
651*6a54128fSAndroid Build Coastguard Worker 
652*6a54128fSAndroid Build Coastguard Worker /* sigcatcher.c */
653*6a54128fSAndroid Build Coastguard Worker void sigcatcher_setup(void);
654*6a54128fSAndroid Build Coastguard Worker 
655*6a54128fSAndroid Build Coastguard Worker /* super.c */
656*6a54128fSAndroid Build Coastguard Worker void check_super_block(e2fsck_t ctx);
657*6a54128fSAndroid Build Coastguard Worker int check_backup_super_block(e2fsck_t ctx);
658*6a54128fSAndroid Build Coastguard Worker void check_resize_inode(e2fsck_t ctx);
659*6a54128fSAndroid Build Coastguard Worker 
660*6a54128fSAndroid Build Coastguard Worker /* util.c */
661*6a54128fSAndroid Build Coastguard Worker extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
662*6a54128fSAndroid Build Coastguard Worker 				    const char *description);
663*6a54128fSAndroid Build Coastguard Worker extern int ask(e2fsck_t ctx, const char * string, int def);
664*6a54128fSAndroid Build Coastguard Worker extern int ask_yn(e2fsck_t ctx, const char * string, int def);
665*6a54128fSAndroid Build Coastguard Worker extern void fatal_error(e2fsck_t ctx, const char * fmt_string);
666*6a54128fSAndroid Build Coastguard Worker extern void log_out(e2fsck_t ctx, const char *fmt, ...)
667*6a54128fSAndroid Build Coastguard Worker 	E2FSCK_ATTR((format(printf, 2, 3)));
668*6a54128fSAndroid Build Coastguard Worker extern void log_err(e2fsck_t ctx, const char *fmt, ...)
669*6a54128fSAndroid Build Coastguard Worker 	E2FSCK_ATTR((format(printf, 2, 3)));
670*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_read_bitmaps(e2fsck_t ctx);
671*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_write_bitmaps(e2fsck_t ctx);
672*6a54128fSAndroid Build Coastguard Worker extern void preenhalt(e2fsck_t ctx);
673*6a54128fSAndroid Build Coastguard Worker extern char *string_copy(e2fsck_t ctx, const char *str, size_t len);
674*6a54128fSAndroid Build Coastguard Worker extern int fs_proc_check(const char *fs_name);
675*6a54128fSAndroid Build Coastguard Worker extern int check_for_modules(const char *fs_name);
676*6a54128fSAndroid Build Coastguard Worker #ifdef RESOURCE_TRACK
677*6a54128fSAndroid Build Coastguard Worker extern void print_resource_track(e2fsck_t ctx,
678*6a54128fSAndroid Build Coastguard Worker 				 const char *desc,
679*6a54128fSAndroid Build Coastguard Worker 				 struct resource_track *track,
680*6a54128fSAndroid Build Coastguard Worker 				 io_channel channel);
681*6a54128fSAndroid Build Coastguard Worker extern void init_resource_track(struct resource_track *track,
682*6a54128fSAndroid Build Coastguard Worker 				io_channel channel);
683*6a54128fSAndroid Build Coastguard Worker #else
684*6a54128fSAndroid Build Coastguard Worker #define print_resource_track(ctx, desc, track, channel) do { } while (0)
685*6a54128fSAndroid Build Coastguard Worker #define init_resource_track(track, channel) do { } while (0)
686*6a54128fSAndroid Build Coastguard Worker #endif
687*6a54128fSAndroid Build Coastguard Worker extern int inode_has_valid_blocks(struct ext2_inode *inode);
688*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
689*6a54128fSAndroid Build Coastguard Worker 			      struct ext2_inode * inode, const char * proc);
690*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_read_inode_full(e2fsck_t ctx, unsigned long ino,
691*6a54128fSAndroid Build Coastguard Worker 				   struct ext2_inode *inode,
692*6a54128fSAndroid Build Coastguard Worker 				   const int bufsize, const char *proc);
693*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
694*6a54128fSAndroid Build Coastguard Worker 			       struct ext2_inode * inode, const char * proc);
695*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
696*6a54128fSAndroid Build Coastguard Worker                                struct ext2_inode * inode, int bufsize,
697*6a54128fSAndroid Build Coastguard Worker                                const char *proc);
698*6a54128fSAndroid Build Coastguard Worker #ifdef MTRACE
699*6a54128fSAndroid Build Coastguard Worker extern void mtrace_print(char *mesg);
700*6a54128fSAndroid Build Coastguard Worker #endif
701*6a54128fSAndroid Build Coastguard Worker extern blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
702*6a54128fSAndroid Build Coastguard Worker 			   const char *name, io_manager manager);
703*6a54128fSAndroid Build Coastguard Worker extern int ext2_file_type(unsigned int mode);
704*6a54128fSAndroid Build Coastguard Worker extern int write_all(int fd, char *buf, size_t count);
705*6a54128fSAndroid Build Coastguard Worker void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...)
706*6a54128fSAndroid Build Coastguard Worker 	E2FSCK_ATTR((format(printf, 2, 3)));
707*6a54128fSAndroid Build Coastguard Worker errcode_t e2fsck_mmp_update(ext2_filsys fs);
708*6a54128fSAndroid Build Coastguard Worker 
709*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_set_bitmap_type(ext2_filsys fs,
710*6a54128fSAndroid Build Coastguard Worker 				   unsigned int default_type,
711*6a54128fSAndroid Build Coastguard Worker 				   const char *profile_name,
712*6a54128fSAndroid Build Coastguard Worker 				   unsigned int *old_type);
713*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_allocate_inode_bitmap(ext2_filsys fs,
714*6a54128fSAndroid Build Coastguard Worker 					      const char *descr,
715*6a54128fSAndroid Build Coastguard Worker 					      int default_type,
716*6a54128fSAndroid Build Coastguard Worker 					      const char *profile_name,
717*6a54128fSAndroid Build Coastguard Worker 					      ext2fs_inode_bitmap *ret);
718*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_allocate_block_bitmap(ext2_filsys fs,
719*6a54128fSAndroid Build Coastguard Worker 					      const char *descr,
720*6a54128fSAndroid Build Coastguard Worker 					      int default_type,
721*6a54128fSAndroid Build Coastguard Worker 					      const char *profile_name,
722*6a54128fSAndroid Build Coastguard Worker 					      ext2fs_block_bitmap *ret);
723*6a54128fSAndroid Build Coastguard Worker extern errcode_t e2fsck_allocate_subcluster_bitmap(ext2_filsys fs,
724*6a54128fSAndroid Build Coastguard Worker 						   const char *descr,
725*6a54128fSAndroid Build Coastguard Worker 						   int default_type,
726*6a54128fSAndroid Build Coastguard Worker 						   const char *profile_name,
727*6a54128fSAndroid Build Coastguard Worker 						   ext2fs_block_bitmap *ret);
728*6a54128fSAndroid Build Coastguard Worker unsigned long long get_memory_size(void);
729*6a54128fSAndroid Build Coastguard Worker 
730*6a54128fSAndroid Build Coastguard Worker /* unix.c */
731*6a54128fSAndroid Build Coastguard Worker extern void e2fsck_clear_progbar(e2fsck_t ctx);
732*6a54128fSAndroid Build Coastguard Worker extern int e2fsck_simple_progress(e2fsck_t ctx, const char *label,
733*6a54128fSAndroid Build Coastguard Worker 				  float percent, unsigned int dpynum);
734*6a54128fSAndroid Build Coastguard Worker 
735*6a54128fSAndroid Build Coastguard Worker #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
736*6a54128fSAndroid Build Coastguard Worker 
737*6a54128fSAndroid Build Coastguard Worker #endif /* _E2FSCK_H */
738