• 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 };
108 
109 /* Function prototypes */
110 
111 extern int ext2fs_process_dir_block(ext2_filsys  	fs,
112 				    blk64_t		*blocknr,
113 				    e2_blkcnt_t		blockcnt,
114 				    blk64_t		ref_block,
115 				    int			ref_offset,
116 				    void		*priv_data);
117 
118 extern errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino);
119 extern errcode_t ext2fs_inline_data_expand(ext2_filsys fs, ext2_ino_t ino);
120 extern int ext2fs_inline_data_dir_iterate(ext2_filsys fs,
121 					  ext2_ino_t ino,
122 					  void *priv_data);
123 
124 /* Generic numeric progress meter */
125 
126 struct ext2fs_numeric_progress_struct {
127 	__u64		max;
128 	int		log_max;
129 	int		skip_progress;
130 };
131 
132 /*
133  * progress callback functions
134  */
135 struct ext2fs_progress_ops {
136 	void (*init)(ext2_filsys fs,
137 		     struct ext2fs_numeric_progress_struct * progress,
138 		     const char *label, __u64 max);
139 	void (*update)(ext2_filsys fs,
140 		       struct ext2fs_numeric_progress_struct * progress,
141 		       __u64 val);
142 	void (*close)(ext2_filsys fs,
143 		      struct ext2fs_numeric_progress_struct * progress,
144 		      const char *message);
145 };
146 
147 extern struct ext2fs_progress_ops ext2fs_numeric_progress_ops;
148 
149 extern void ext2fs_numeric_progress_init(ext2_filsys fs,
150 					 struct ext2fs_numeric_progress_struct * progress,
151 					 const char *label, __u64 max);
152 extern void ext2fs_numeric_progress_update(ext2_filsys fs,
153 					   struct ext2fs_numeric_progress_struct * progress,
154 					   __u64 val);
155 extern void ext2fs_numeric_progress_close(ext2_filsys fs,
156 					  struct ext2fs_numeric_progress_struct * progress,
157 					  const char *message);
158 
159 /*
160  * 64-bit bitmap support
161  */
162 
163 extern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
164 					   int type, __u64 start, __u64 end,
165 					   __u64 real_end,
166 					   const char * description,
167 					   ext2fs_generic_bitmap *bmap);
168 
169 extern void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
170 
171 extern errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
172 					  ext2fs_generic_bitmap *dest);
173 
174 extern errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
175 					    __u64 new_end,
176 					    __u64 new_real_end);
177 extern errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
178 					       errcode_t neq,
179 					       __u64 end, __u64 *oend);
180 extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,
181 				    __u64 arg);
182 extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,
183 				      __u64 arg);
184 extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,
185 				    __u64 arg);
186 extern errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bitmap,
187 					       __u64 start, unsigned int num,
188 					       void *in);
189 extern errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bitmap,
190 					       __u64 start, unsigned int num,
191 					       void *out);
192 extern void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap,const char *func);
193 
194 extern int ext2fs_mem_is_zero(const char *mem, size_t len);
195 
196 extern int ext2fs_file_block_offset_too_big(ext2_filsys fs,
197 					    struct ext2_inode *inode,
198 					    blk64_t offset);
199 
200 /* atexit support */
201 typedef void (*ext2_exit_fn)(void *);
202 errcode_t ext2fs_add_exit_fn(ext2_exit_fn fn, void *data);
203 errcode_t ext2fs_remove_exit_fn(ext2_exit_fn fn, void *data);
204 
205 #define EXT2FS_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)]))
206