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