xref: /aosp_15_r20/external/e2fsprogs/lib/ext2fs/ext2fsP.h (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker  * ext2fsP.h --- private header file for ext2 library
3*6a54128fSAndroid Build Coastguard Worker  *
4*6a54128fSAndroid Build Coastguard Worker  * Copyright (C) 1997 Theodore Ts'o.
5*6a54128fSAndroid Build Coastguard Worker  *
6*6a54128fSAndroid Build Coastguard Worker  * %Begin-Header%
7*6a54128fSAndroid Build Coastguard Worker  * This file may be redistributed under the terms of the GNU Library
8*6a54128fSAndroid Build Coastguard Worker  * General Public License, version 2.
9*6a54128fSAndroid Build Coastguard Worker  * %End-Header%
10*6a54128fSAndroid Build Coastguard Worker  */
11*6a54128fSAndroid Build Coastguard Worker 
12*6a54128fSAndroid Build Coastguard Worker #if HAVE_SYS_STAT_H
13*6a54128fSAndroid Build Coastguard Worker #include <sys/stat.h>
14*6a54128fSAndroid Build Coastguard Worker #endif
15*6a54128fSAndroid Build Coastguard Worker 
16*6a54128fSAndroid Build Coastguard Worker #include "ext2fs.h"
17*6a54128fSAndroid Build Coastguard Worker 
18*6a54128fSAndroid Build Coastguard Worker #define EXT2FS_MAX_NESTED_LINKS  8
19*6a54128fSAndroid Build Coastguard Worker 
ext2fsP_is_disk_device(mode_t mode)20*6a54128fSAndroid Build Coastguard Worker static inline int ext2fsP_is_disk_device(mode_t mode)
21*6a54128fSAndroid Build Coastguard Worker {
22*6a54128fSAndroid Build Coastguard Worker #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
23*6a54128fSAndroid Build Coastguard Worker 	return S_ISBLK(mode) || S_ISCHR(mode);
24*6a54128fSAndroid Build Coastguard Worker #else
25*6a54128fSAndroid Build Coastguard Worker 	return S_ISBLK(mode);
26*6a54128fSAndroid Build Coastguard Worker #endif
27*6a54128fSAndroid Build Coastguard Worker }
28*6a54128fSAndroid Build Coastguard Worker 
29*6a54128fSAndroid Build Coastguard Worker /*
30*6a54128fSAndroid Build Coastguard Worker  * Badblocks list
31*6a54128fSAndroid Build Coastguard Worker  */
32*6a54128fSAndroid Build Coastguard Worker struct ext2_struct_u32_list {
33*6a54128fSAndroid Build Coastguard Worker 	int	magic;
34*6a54128fSAndroid Build Coastguard Worker 	int	num;
35*6a54128fSAndroid Build Coastguard Worker 	int	size;
36*6a54128fSAndroid Build Coastguard Worker 	__u32	*list;
37*6a54128fSAndroid Build Coastguard Worker 	int	badblocks_flags;
38*6a54128fSAndroid Build Coastguard Worker };
39*6a54128fSAndroid Build Coastguard Worker 
40*6a54128fSAndroid Build Coastguard Worker struct ext2_struct_u32_iterate {
41*6a54128fSAndroid Build Coastguard Worker 	int			magic;
42*6a54128fSAndroid Build Coastguard Worker 	ext2_u32_list		bb;
43*6a54128fSAndroid Build Coastguard Worker 	int			ptr;
44*6a54128fSAndroid Build Coastguard Worker };
45*6a54128fSAndroid Build Coastguard Worker 
46*6a54128fSAndroid Build Coastguard Worker 
47*6a54128fSAndroid Build Coastguard Worker /*
48*6a54128fSAndroid Build Coastguard Worker  * Directory block iterator definition
49*6a54128fSAndroid Build Coastguard Worker  */
50*6a54128fSAndroid Build Coastguard Worker struct ext2_struct_dblist {
51*6a54128fSAndroid Build Coastguard Worker 	int			magic;
52*6a54128fSAndroid Build Coastguard Worker 	ext2_filsys		fs;
53*6a54128fSAndroid Build Coastguard Worker 	unsigned long long	size;
54*6a54128fSAndroid Build Coastguard Worker 	unsigned long long	count;
55*6a54128fSAndroid Build Coastguard Worker 	int			sorted;
56*6a54128fSAndroid Build Coastguard Worker 	struct ext2_db_entry2 *	list;
57*6a54128fSAndroid Build Coastguard Worker };
58*6a54128fSAndroid Build Coastguard Worker 
59*6a54128fSAndroid Build Coastguard Worker /*
60*6a54128fSAndroid Build Coastguard Worker  * For directory iterators
61*6a54128fSAndroid Build Coastguard Worker  */
62*6a54128fSAndroid Build Coastguard Worker struct dir_context {
63*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		dir;
64*6a54128fSAndroid Build Coastguard Worker 	int		flags;
65*6a54128fSAndroid Build Coastguard Worker 	char		*buf;
66*6a54128fSAndroid Build Coastguard Worker 	unsigned int	buflen;
67*6a54128fSAndroid Build Coastguard Worker 	int (*func)(ext2_ino_t	dir,
68*6a54128fSAndroid Build Coastguard Worker 		    int	entry,
69*6a54128fSAndroid Build Coastguard Worker 		    struct ext2_dir_entry *dirent,
70*6a54128fSAndroid Build Coastguard Worker 		    int	offset,
71*6a54128fSAndroid Build Coastguard Worker 		    int	blocksize,
72*6a54128fSAndroid Build Coastguard Worker 		    char	*buf,
73*6a54128fSAndroid Build Coastguard Worker 		    void	*priv_data);
74*6a54128fSAndroid Build Coastguard Worker 	void		*priv_data;
75*6a54128fSAndroid Build Coastguard Worker 	errcode_t	errcode;
76*6a54128fSAndroid Build Coastguard Worker };
77*6a54128fSAndroid Build Coastguard Worker 
78*6a54128fSAndroid Build Coastguard Worker /*
79*6a54128fSAndroid Build Coastguard Worker  * Inode cache structure
80*6a54128fSAndroid Build Coastguard Worker  */
81*6a54128fSAndroid Build Coastguard Worker struct ext2_inode_cache {
82*6a54128fSAndroid Build Coastguard Worker 	void *				buffer;
83*6a54128fSAndroid Build Coastguard Worker 	blk64_t				buffer_blk;
84*6a54128fSAndroid Build Coastguard Worker 	int				cache_last;
85*6a54128fSAndroid Build Coastguard Worker 	unsigned int			cache_size;
86*6a54128fSAndroid Build Coastguard Worker 	int				refcount;
87*6a54128fSAndroid Build Coastguard Worker 	struct ext2_inode_cache_ent	*cache;
88*6a54128fSAndroid Build Coastguard Worker };
89*6a54128fSAndroid Build Coastguard Worker 
90*6a54128fSAndroid Build Coastguard Worker struct ext2_inode_cache_ent {
91*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t		ino;
92*6a54128fSAndroid Build Coastguard Worker 	struct ext2_inode	*inode;
93*6a54128fSAndroid Build Coastguard Worker };
94*6a54128fSAndroid Build Coastguard Worker 
95*6a54128fSAndroid Build Coastguard Worker /*
96*6a54128fSAndroid Build Coastguard Worker  * NLS definitions
97*6a54128fSAndroid Build Coastguard Worker  */
98*6a54128fSAndroid Build Coastguard Worker struct ext2fs_nls_table {
99*6a54128fSAndroid Build Coastguard Worker 	int version;
100*6a54128fSAndroid Build Coastguard Worker 	const struct ext2fs_nls_ops *ops;
101*6a54128fSAndroid Build Coastguard Worker };
102*6a54128fSAndroid Build Coastguard Worker 
103*6a54128fSAndroid Build Coastguard Worker struct ext2fs_nls_ops {
104*6a54128fSAndroid Build Coastguard Worker 	int (*casefold)(const struct ext2fs_nls_table *charset,
105*6a54128fSAndroid Build Coastguard Worker 			const unsigned char *str, size_t len,
106*6a54128fSAndroid Build Coastguard Worker 			unsigned char *dest, size_t dlen);
107*6a54128fSAndroid Build Coastguard Worker 	int (*validate)(const struct ext2fs_nls_table *table,
108*6a54128fSAndroid Build Coastguard Worker 			char *s, size_t len, char **pos);
109*6a54128fSAndroid Build Coastguard Worker 	int (*casefold_cmp)(const struct ext2fs_nls_table *table,
110*6a54128fSAndroid Build Coastguard Worker 			    const unsigned char *str1, size_t len1,
111*6a54128fSAndroid Build Coastguard Worker 			    const unsigned char *str2, size_t len2);
112*6a54128fSAndroid Build Coastguard Worker };
113*6a54128fSAndroid Build Coastguard Worker 
114*6a54128fSAndroid Build Coastguard Worker /* Function prototypes */
115*6a54128fSAndroid Build Coastguard Worker 
116*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_process_dir_block(ext2_filsys  	fs,
117*6a54128fSAndroid Build Coastguard Worker 				    blk64_t		*blocknr,
118*6a54128fSAndroid Build Coastguard Worker 				    e2_blkcnt_t		blockcnt,
119*6a54128fSAndroid Build Coastguard Worker 				    blk64_t		ref_block,
120*6a54128fSAndroid Build Coastguard Worker 				    int			ref_offset,
121*6a54128fSAndroid Build Coastguard Worker 				    void		*priv_data);
122*6a54128fSAndroid Build Coastguard Worker 
123*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino);
124*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_inline_data_expand(ext2_filsys fs, ext2_ino_t ino);
125*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_inline_data_dir_iterate(ext2_filsys fs,
126*6a54128fSAndroid Build Coastguard Worker 					  ext2_ino_t ino,
127*6a54128fSAndroid Build Coastguard Worker 					  void *priv_data);
128*6a54128fSAndroid Build Coastguard Worker 
129*6a54128fSAndroid Build Coastguard Worker /* Generic numeric progress meter */
130*6a54128fSAndroid Build Coastguard Worker 
131*6a54128fSAndroid Build Coastguard Worker struct ext2fs_numeric_progress_struct {
132*6a54128fSAndroid Build Coastguard Worker 	__u64		max;
133*6a54128fSAndroid Build Coastguard Worker 	int		log_max;
134*6a54128fSAndroid Build Coastguard Worker 	int		skip_progress;
135*6a54128fSAndroid Build Coastguard Worker };
136*6a54128fSAndroid Build Coastguard Worker 
137*6a54128fSAndroid Build Coastguard Worker /*
138*6a54128fSAndroid Build Coastguard Worker  * progress callback functions
139*6a54128fSAndroid Build Coastguard Worker  */
140*6a54128fSAndroid Build Coastguard Worker struct ext2fs_progress_ops {
141*6a54128fSAndroid Build Coastguard Worker 	void (*init)(ext2_filsys fs,
142*6a54128fSAndroid Build Coastguard Worker 		     struct ext2fs_numeric_progress_struct * progress,
143*6a54128fSAndroid Build Coastguard Worker 		     const char *label, __u64 max);
144*6a54128fSAndroid Build Coastguard Worker 	void (*update)(ext2_filsys fs,
145*6a54128fSAndroid Build Coastguard Worker 		       struct ext2fs_numeric_progress_struct * progress,
146*6a54128fSAndroid Build Coastguard Worker 		       __u64 val);
147*6a54128fSAndroid Build Coastguard Worker 	void (*close)(ext2_filsys fs,
148*6a54128fSAndroid Build Coastguard Worker 		      struct ext2fs_numeric_progress_struct * progress,
149*6a54128fSAndroid Build Coastguard Worker 		      const char *message);
150*6a54128fSAndroid Build Coastguard Worker };
151*6a54128fSAndroid Build Coastguard Worker 
152*6a54128fSAndroid Build Coastguard Worker extern struct ext2fs_progress_ops ext2fs_numeric_progress_ops;
153*6a54128fSAndroid Build Coastguard Worker 
154*6a54128fSAndroid Build Coastguard Worker extern void ext2fs_numeric_progress_init(ext2_filsys fs,
155*6a54128fSAndroid Build Coastguard Worker 					 struct ext2fs_numeric_progress_struct * progress,
156*6a54128fSAndroid Build Coastguard Worker 					 const char *label, __u64 max);
157*6a54128fSAndroid Build Coastguard Worker extern void ext2fs_numeric_progress_update(ext2_filsys fs,
158*6a54128fSAndroid Build Coastguard Worker 					   struct ext2fs_numeric_progress_struct * progress,
159*6a54128fSAndroid Build Coastguard Worker 					   __u64 val);
160*6a54128fSAndroid Build Coastguard Worker extern void ext2fs_numeric_progress_close(ext2_filsys fs,
161*6a54128fSAndroid Build Coastguard Worker 					  struct ext2fs_numeric_progress_struct * progress,
162*6a54128fSAndroid Build Coastguard Worker 					  const char *message);
163*6a54128fSAndroid Build Coastguard Worker 
164*6a54128fSAndroid Build Coastguard Worker /*
165*6a54128fSAndroid Build Coastguard Worker  * 64-bit bitmap support
166*6a54128fSAndroid Build Coastguard Worker  */
167*6a54128fSAndroid Build Coastguard Worker 
168*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
169*6a54128fSAndroid Build Coastguard Worker 					   int type, __u64 start, __u64 end,
170*6a54128fSAndroid Build Coastguard Worker 					   __u64 real_end,
171*6a54128fSAndroid Build Coastguard Worker 					   const char * description,
172*6a54128fSAndroid Build Coastguard Worker 					   ext2fs_generic_bitmap *bmap);
173*6a54128fSAndroid Build Coastguard Worker 
174*6a54128fSAndroid Build Coastguard Worker extern void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
175*6a54128fSAndroid Build Coastguard Worker 
176*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
177*6a54128fSAndroid Build Coastguard Worker 					  ext2fs_generic_bitmap *dest);
178*6a54128fSAndroid Build Coastguard Worker 
179*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
180*6a54128fSAndroid Build Coastguard Worker 					    __u64 new_end,
181*6a54128fSAndroid Build Coastguard Worker 					    __u64 new_real_end);
182*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
183*6a54128fSAndroid Build Coastguard Worker 					       errcode_t neq,
184*6a54128fSAndroid Build Coastguard Worker 					       __u64 end, __u64 *oend);
185*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,
186*6a54128fSAndroid Build Coastguard Worker 				    __u64 arg);
187*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,
188*6a54128fSAndroid Build Coastguard Worker 				      __u64 arg);
189*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,
190*6a54128fSAndroid Build Coastguard Worker 				    __u64 arg);
191*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bitmap,
192*6a54128fSAndroid Build Coastguard Worker 					       __u64 start, unsigned int num,
193*6a54128fSAndroid Build Coastguard Worker 					       void *in);
194*6a54128fSAndroid Build Coastguard Worker extern errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bitmap,
195*6a54128fSAndroid Build Coastguard Worker 					       __u64 start, unsigned int num,
196*6a54128fSAndroid Build Coastguard Worker 					       void *out);
197*6a54128fSAndroid Build Coastguard Worker extern void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap,const char *func);
198*6a54128fSAndroid Build Coastguard Worker 
199*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_mem_is_zero(const char *mem, size_t len);
200*6a54128fSAndroid Build Coastguard Worker 
201*6a54128fSAndroid Build Coastguard Worker extern int ext2fs_file_block_offset_too_big(ext2_filsys fs,
202*6a54128fSAndroid Build Coastguard Worker 					    struct ext2_inode *inode,
203*6a54128fSAndroid Build Coastguard Worker 					    blk64_t offset);
204*6a54128fSAndroid Build Coastguard Worker 
205*6a54128fSAndroid Build Coastguard Worker /* atexit support */
206*6a54128fSAndroid Build Coastguard Worker typedef void (*ext2_exit_fn)(void *);
207*6a54128fSAndroid Build Coastguard Worker errcode_t ext2fs_add_exit_fn(ext2_exit_fn fn, void *data);
208*6a54128fSAndroid Build Coastguard Worker errcode_t ext2fs_remove_exit_fn(ext2_exit_fn fn, void *data);
209*6a54128fSAndroid Build Coastguard Worker 
210*6a54128fSAndroid Build Coastguard Worker #define EXT2FS_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
211