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