]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
1 | /* |
2 | * ext2fs.h --- ext2fs | |
3 | * | |
19c78dc0 TT |
4 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. |
5 | * | |
6 | * %Begin-Header% | |
7 | * This file may be redistributed under the terms of the GNU Public | |
8 | * License. | |
9 | * %End-Header% | |
3839e657 TT |
10 | */ |
11 | ||
19c78dc0 TT |
12 | /* |
13 | * Non-GNU C compilers won't necessarily understand inline | |
14 | */ | |
15 | #ifndef __GNUC__ | |
16 | #define NO_INLINE_FUNCS | |
17 | #endif | |
18 | ||
3839e657 TT |
19 | /* |
20 | * Where the master copy of the superblock is located, and how big | |
21 | * superblocks are supposed to be. We define SUPERBLOCK_SIZE because | |
22 | * the size of the superblock structure is not necessarily trustworthy | |
23 | * (some versions have the padding set up so that the superblock is | |
24 | * 1032 bytes long). | |
25 | */ | |
26 | #define SUPERBLOCK_OFFSET 1024 | |
27 | #define SUPERBLOCK_SIZE 1024 | |
28 | ||
f3db3566 TT |
29 | /* |
30 | * The last ext2fs revision level that this version of the library is | |
31 | * able to support. | |
32 | */ | |
33 | #define EXT2_LIB_CURRENT_REV 0 | |
34 | ||
1e3472c5 | 35 | #include <sys/types.h> |
50e1e10f TT |
36 | #include <linux/types.h> |
37 | ||
38 | typedef __u32 blk_t; | |
3839e657 TT |
39 | typedef unsigned int dgrp_t; |
40 | ||
41 | #include "et/com_err.h" | |
42 | #include "ext2fs/io.h" | |
43 | #include "ext2fs/ext2_err.h" | |
44 | ||
f3db3566 TT |
45 | typedef struct struct_ext2_filsys *ext2_filsys; |
46 | ||
1e3472c5 TT |
47 | struct ext2fs_struct_generic_bitmap { |
48 | int magic; | |
49 | ext2_filsys fs; | |
50 | __u32 start, end; | |
51 | __u32 real_end; | |
52 | char * description; | |
53 | char * bitmap; | |
54 | errcode_t base_error_code; | |
55 | __u32 reserved[7]; | |
f3db3566 TT |
56 | }; |
57 | ||
1e3472c5 TT |
58 | #define EXT2FS_MARK_ERROR 0 |
59 | #define EXT2FS_UNMARK_ERROR 1 | |
60 | #define EXT2FS_TEST_ERROR 2 | |
f3db3566 | 61 | |
1e3472c5 | 62 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap; |
1e3472c5 | 63 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap; |
1e3472c5 | 64 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap; |
f3db3566 | 65 | |
7f88b043 TT |
66 | #ifdef EXT2_DYNAMIC_REV |
67 | #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) | |
68 | #else | |
69 | #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO | |
70 | #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) | |
71 | #endif | |
72 | ||
19c78dc0 TT |
73 | /* |
74 | * badblocks list definitions | |
75 | */ | |
76 | ||
77 | typedef struct ext2_struct_badblocks_list *ext2_badblocks_list; | |
78 | typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate; | |
79 | ||
80 | /* old */ | |
81 | typedef struct ext2_struct_badblocks_list *badblocks_list; | |
82 | typedef struct ext2_struct_badblocks_iterate *badblocks_iterate; | |
83 | ||
84 | #define BADBLOCKS_FLAG_DIRTY 1 | |
85 | ||
86 | /* | |
87 | * ext2_dblist structure and abstractions (see dblist.c) | |
88 | */ | |
89 | struct ext2_db_entry { | |
90 | ino_t ino; | |
91 | blk_t blk; | |
92 | int blockcnt; | |
93 | }; | |
94 | ||
95 | typedef struct ext2_struct_dblist *ext2_dblist; | |
96 | ||
97 | #define DBLIST_ABORT 1 | |
98 | ||
3839e657 TT |
99 | /* |
100 | * Flags for the ext2_filsys structure | |
101 | */ | |
102 | ||
19c78dc0 TT |
103 | #define EXT2_FLAG_RW 0x01 |
104 | #define EXT2_FLAG_CHANGED 0x02 | |
105 | #define EXT2_FLAG_DIRTY 0x04 | |
106 | #define EXT2_FLAG_VALID 0x08 | |
107 | #define EXT2_FLAG_IB_DIRTY 0x10 | |
108 | #define EXT2_FLAG_BB_DIRTY 0x20 | |
5c576477 TT |
109 | #define EXT2_FLAG_SWAP_BYTES 0x40 |
110 | #define EXT2_FLAG_SWAP_BYTES_READ 0x80 | |
111 | #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100 | |
112 | #define EXT2_FLAG_MASTER_SB_ONLY 0x200 | |
19c78dc0 | 113 | #define EXT2_FLAG_FORCE 0x400 |
3839e657 | 114 | |
7f88b043 TT |
115 | /* |
116 | * Special flag in the ext2 inode i_flag field that means that this is | |
117 | * a new inode. (So that ext2_write_inode() can clear extra fields.) | |
118 | */ | |
119 | #define EXT2_NEW_INODE_FL 0x80000000 | |
120 | ||
3839e657 | 121 | struct struct_ext2_filsys { |
f3db3566 | 122 | int magic; |
3839e657 TT |
123 | io_channel io; |
124 | int flags; | |
125 | char * device_name; | |
126 | struct ext2_super_block * super; | |
127 | int blocksize; | |
128 | int fragsize; | |
129 | unsigned long group_desc_count; | |
130 | unsigned long desc_blocks; | |
131 | struct ext2_group_desc * group_desc; | |
132 | int inode_blocks_per_group; | |
f3db3566 TT |
133 | ext2fs_inode_bitmap inode_map; |
134 | ext2fs_block_bitmap block_map; | |
3839e657 TT |
135 | errcode_t (*get_blocks)(ext2_filsys fs, ino_t ino, blk_t *blocks); |
136 | errcode_t (*check_directory)(ext2_filsys fs, ino_t ino); | |
137 | errcode_t (*write_bitmaps)(ext2_filsys fs); | |
1e3472c5 TT |
138 | errcode_t (*read_inode)(ext2_filsys fs, ino_t ino, |
139 | struct ext2_inode *inode); | |
140 | errcode_t (*write_inode)(ext2_filsys fs, ino_t ino, | |
141 | struct ext2_inode *inode); | |
19c78dc0 TT |
142 | badblocks_list badblocks; |
143 | ext2_dblist dblist; | |
a29f4d30 | 144 | __u32 stride; /* for mke2fs */ |
19c78dc0 TT |
145 | /* |
146 | * Reserved for future expansion | |
147 | */ | |
a29f4d30 | 148 | __u32 reserved[11]; |
3839e657 TT |
149 | |
150 | /* | |
a29f4d30 | 151 | * Reserved for the use of the calling application. |
3839e657 | 152 | */ |
a29f4d30 TT |
153 | void * private; |
154 | ||
155 | /* | |
156 | * Inode cache | |
157 | */ | |
158 | struct ext2_inode_cache *icache; | |
3839e657 TT |
159 | }; |
160 | ||
f3db3566 TT |
161 | #include "ext2fs/bitops.h" |
162 | ||
3839e657 TT |
163 | /* |
164 | * Return flags for the block iterator functions | |
165 | */ | |
166 | #define BLOCK_CHANGED 1 | |
167 | #define BLOCK_ABORT 2 | |
168 | #define BLOCK_ERROR 4 | |
169 | ||
170 | /* | |
171 | * Block interate flags | |
50e1e10f TT |
172 | * |
173 | * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator | |
174 | * function should be called on blocks where the block number is zero. | |
175 | * This is used by ext2fs_expand_dir() to be able to add a new block | |
176 | * to an inode. It can also be used for programs that want to be able | |
177 | * to deal with files that contain "holes". | |
178 | * | |
179 | * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the | |
180 | * indirect, doubly indirect, etc. blocks should be called after all | |
181 | * of the blocks containined in the indirect blocks are processed. | |
182 | * This is useful if you are going to be deallocating blocks from an | |
183 | * inode. | |
1e3472c5 TT |
184 | * |
185 | * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be | |
186 | * called for data blocks only. | |
3839e657 TT |
187 | */ |
188 | #define BLOCK_FLAG_APPEND 1 | |
50e1e10f | 189 | #define BLOCK_FLAG_HOLE 1 |
3839e657 | 190 | #define BLOCK_FLAG_DEPTH_TRAVERSE 2 |
1e3472c5 TT |
191 | #define BLOCK_FLAG_DATA_ONLY 4 |
192 | ||
193 | /* | |
194 | * Magic "block count" return values for the block iterator function. | |
195 | */ | |
196 | #define BLOCK_COUNT_IND (-1) | |
197 | #define BLOCK_COUNT_DIND (-2) | |
198 | #define BLOCK_COUNT_TIND (-3) | |
199 | #define BLOCK_COUNT_TRANSLATOR (-4) | |
3839e657 | 200 | |
1e1da29f TT |
201 | /* |
202 | * Flags for ext2fs_move_blocks | |
203 | */ | |
204 | #define EXT2_BMOVE_GET_DBLIST 0x0001 | |
36f21439 | 205 | #define EXT2_BMOVE_DEBUG 0x0002 |
1e1da29f | 206 | |
3839e657 TT |
207 | /* |
208 | * Return flags for the directory iterator functions | |
209 | */ | |
210 | #define DIRENT_CHANGED 1 | |
211 | #define DIRENT_ABORT 2 | |
212 | #define DIRENT_ERROR 3 | |
213 | ||
214 | /* | |
215 | * Directory iterator flags | |
216 | */ | |
217 | ||
218 | #define DIRENT_FLAG_INCLUDE_EMPTY 1 | |
219 | ||
19c78dc0 TT |
220 | |
221 | #define DIRENT_DOT_FILE 1 | |
222 | #define DIRENT_DOT_DOT_FILE 2 | |
223 | #define DIRENT_OTHER_FILE 3 | |
224 | ||
3839e657 TT |
225 | /* |
226 | * Inode scan definitions | |
227 | */ | |
f3db3566 TT |
228 | typedef struct ext2_struct_inode_scan *ext2_inode_scan; |
229 | ||
19c78dc0 TT |
230 | /* |
231 | * ext2fs_scan flags | |
232 | */ | |
233 | #define EXT2_SF_CHK_BADBLOCKS 0x0001 | |
234 | #define EXT2_SF_BAD_INODE_BLK 0x0002 | |
235 | #define EXT2_SF_BAD_EXTRA_BYTES 0x0004 | |
236 | #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008 | |
3839e657 | 237 | |
50e1e10f TT |
238 | /* |
239 | * ext2fs_check_if_mounted flags | |
240 | */ | |
241 | #define EXT2_MF_MOUNTED 1 | |
242 | #define EXT2_MF_ISROOT 2 | |
19c78dc0 | 243 | #define EXT2_MF_READONLY 4 |
50e1e10f TT |
244 | |
245 | /* | |
246 | * Ext2/linux mode flags. We define them here so that we don't need | |
247 | * to depend on the OS's sys/stat.h, since we may be compiling on a | |
248 | * non-Linux system. | |
249 | */ | |
250 | #define LINUX_S_IFMT 00170000 | |
251 | #define LINUX_S_IFSOCK 0140000 | |
252 | #define LINUX_S_IFLNK 0120000 | |
253 | #define LINUX_S_IFREG 0100000 | |
254 | #define LINUX_S_IFBLK 0060000 | |
255 | #define LINUX_S_IFDIR 0040000 | |
256 | #define LINUX_S_IFCHR 0020000 | |
257 | #define LINUX_S_IFIFO 0010000 | |
258 | #define LINUX_S_ISUID 0004000 | |
259 | #define LINUX_S_ISGID 0002000 | |
260 | #define LINUX_S_ISVTX 0001000 | |
261 | ||
1e3472c5 TT |
262 | #define LINUX_S_IRWXU 00700 |
263 | #define LINUX_S_IRUSR 00400 | |
264 | #define LINUX_S_IWUSR 00200 | |
265 | #define LINUX_S_IXUSR 00100 | |
266 | ||
267 | #define LINUX_S_IRWXG 00070 | |
268 | #define LINUX_S_IRGRP 00040 | |
269 | #define LINUX_S_IWGRP 00020 | |
270 | #define LINUX_S_IXGRP 00010 | |
271 | ||
272 | #define LINUX_S_IRWXO 00007 | |
273 | #define LINUX_S_IROTH 00004 | |
274 | #define LINUX_S_IWOTH 00002 | |
275 | #define LINUX_S_IXOTH 00001 | |
276 | ||
50e1e10f TT |
277 | #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK) |
278 | #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG) | |
279 | #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR) | |
280 | #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR) | |
281 | #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK) | |
282 | #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO) | |
283 | #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK) | |
284 | ||
19c78dc0 TT |
285 | /* |
286 | * ext2_icount_t abstraction | |
287 | */ | |
288 | #define EXT2_ICOUNT_OPT_INCREMENT 0x01 | |
289 | ||
290 | typedef struct ext2_icount *ext2_icount_t; | |
291 | ||
f3db3566 TT |
292 | /* |
293 | * For checking structure magic numbers... | |
294 | */ | |
3839e657 | 295 | |
f3db3566 TT |
296 | #define EXT2_CHECK_MAGIC(struct, code) \ |
297 | if ((struct)->magic != (code)) return (code) | |
1e3472c5 TT |
298 | |
299 | ||
300 | /* | |
301 | * The ext2fs library private definition of the ext2 superblock, so we | |
302 | * don't have to depend on the kernel's definition of the superblock, | |
303 | * which might not have the latest features. | |
304 | */ | |
305 | struct ext2fs_sb { | |
306 | __u32 s_inodes_count; /* Inodes count */ | |
307 | __u32 s_blocks_count; /* Blocks count */ | |
308 | __u32 s_r_blocks_count; /* Reserved blocks count */ | |
309 | __u32 s_free_blocks_count; /* Free blocks count */ | |
310 | __u32 s_free_inodes_count; /* Free inodes count */ | |
311 | __u32 s_first_data_block; /* First Data Block */ | |
312 | __u32 s_log_block_size; /* Block size */ | |
313 | __s32 s_log_frag_size; /* Fragment size */ | |
314 | __u32 s_blocks_per_group; /* # Blocks per group */ | |
315 | __u32 s_frags_per_group; /* # Fragments per group */ | |
316 | __u32 s_inodes_per_group; /* # Inodes per group */ | |
317 | __u32 s_mtime; /* Mount time */ | |
318 | __u32 s_wtime; /* Write time */ | |
319 | __u16 s_mnt_count; /* Mount count */ | |
320 | __s16 s_max_mnt_count; /* Maximal mount count */ | |
321 | __u16 s_magic; /* Magic signature */ | |
322 | __u16 s_state; /* File system state */ | |
323 | __u16 s_errors; /* Behaviour when detecting errors */ | |
324 | __u16 s_minor_rev_level; /* minor revision level */ | |
325 | __u32 s_lastcheck; /* time of last check */ | |
326 | __u32 s_checkinterval; /* max. time between checks */ | |
327 | __u32 s_creator_os; /* OS */ | |
328 | __u32 s_rev_level; /* Revision level */ | |
329 | __u16 s_def_resuid; /* Default uid for reserved blocks */ | |
330 | __u16 s_def_resgid; /* Default gid for reserved blocks */ | |
331 | /* | |
332 | * These fields are for EXT2_DYNAMIC_REV superblocks only. | |
333 | * | |
334 | * Note: the difference between the compatible feature set and | |
335 | * the incompatible feature set is that if there is a bit set | |
336 | * in the incompatible feature set that the kernel doesn't | |
337 | * know about, it should refuse to mount the filesystem. | |
338 | * | |
339 | * e2fsck's requirements are more strict; if it doesn't know | |
340 | * about a feature in either the compatible or incompatible | |
341 | * feature set, it must abort and not try to meddle with | |
342 | * things it doesn't understand... | |
343 | */ | |
344 | __u32 s_first_ino; /* First non-reserved inode */ | |
345 | __u16 s_inode_size; /* size of inode structure */ | |
346 | __u16 s_block_group_nr; /* block group # of this superblock */ | |
347 | __u32 s_feature_compat; /* compatible feature set */ | |
348 | __u32 s_feature_incompat; /* incompatible feature set */ | |
349 | __u32 s_feature_ro_compat; /* readonly-compatible feature set */ | |
350 | __u8 s_uuid[16]; /* 128-bit uuid for volume */ | |
351 | char s_volume_name[16]; /* volume name */ | |
352 | char s_last_mounted[64]; /* directory where last mounted */ | |
353 | __u32 s_reserved[206]; /* Padding to the end of the block */ | |
354 | }; | |
521e3685 TT |
355 | |
356 | /* | |
357 | * Feature set definitions (that might not be in ext2_fs.h | |
358 | * (was EXT2_COMPAT_SPARSE_SUPER) | |
359 | */ | |
360 | #ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER | |
361 | #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 | |
362 | #endif | |
363 | ||
364 | #define EXT2_LIB_FEATURE_COMPAT_SUPP 0 | |
365 | #define EXT2_LIB_FEATURE_INCOMPAT_SUPP 0 | |
366 | #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER | |
367 | ||
3839e657 TT |
368 | /* |
369 | * function prototypes | |
370 | */ | |
371 | ||
372 | /* alloc.c */ | |
373 | extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode, | |
f3db3566 | 374 | ext2fs_inode_bitmap map, ino_t *ret); |
3839e657 | 375 | extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, |
f3db3566 | 376 | ext2fs_block_bitmap map, blk_t *ret); |
3839e657 | 377 | extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, |
f3db3566 TT |
378 | blk_t finish, int num, |
379 | ext2fs_block_bitmap map, | |
3839e657 TT |
380 | blk_t *ret); |
381 | ||
1e1da29f TT |
382 | /* alloc_tables.c */ |
383 | extern errcode_t ext2fs_allocate_tables(ext2_filsys fs); | |
384 | extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, int group, | |
385 | ext2fs_block_bitmap bmap); | |
19c78dc0 | 386 | |
3839e657 | 387 | /* badblocks.c */ |
19c78dc0 TT |
388 | extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, |
389 | int size); | |
19c78dc0 TT |
390 | extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, |
391 | blk_t blk); | |
392 | extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb, | |
393 | blk_t blk); | |
394 | extern errcode_t | |
395 | ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb, | |
396 | ext2_badblocks_iterate *ret); | |
397 | extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter, | |
398 | blk_t *blk); | |
399 | extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter); | |
a29f4d30 TT |
400 | extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, |
401 | ext2_badblocks_list *dest); | |
19c78dc0 TT |
402 | |
403 | /* bb_compat */ | |
3839e657 | 404 | extern errcode_t badblocks_list_create(badblocks_list *ret, int size); |
3839e657 TT |
405 | extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk); |
406 | extern int badblocks_list_test(badblocks_list bb, blk_t blk); | |
407 | extern errcode_t badblocks_list_iterate_begin(badblocks_list bb, | |
408 | badblocks_iterate *ret); | |
409 | extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk); | |
410 | extern void badblocks_list_iterate_end(badblocks_iterate iter); | |
a29f4d30 | 411 | extern void badblocks_list_free(badblocks_list bb); |
3839e657 TT |
412 | |
413 | /* bb_inode.c */ | |
414 | extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs, | |
19c78dc0 | 415 | ext2_badblocks_list bb_list); |
3839e657 TT |
416 | |
417 | /* bitmaps.c */ | |
418 | extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs); | |
419 | extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs); | |
420 | extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs); | |
421 | extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); | |
1e3472c5 TT |
422 | extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start, |
423 | __u32 end, | |
424 | __u32 real_end, | |
425 | const char *descr, | |
426 | ext2fs_generic_bitmap *ret); | |
50e1e10f TT |
427 | extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, |
428 | const char *descr, | |
429 | ext2fs_block_bitmap *ret); | |
430 | extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, | |
431 | const char *descr, | |
432 | ext2fs_inode_bitmap *ret); | |
433 | extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, | |
434 | ino_t end, ino_t *oend); | |
435 | extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, | |
436 | blk_t end, blk_t *oend); | |
437 | extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap); | |
438 | extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap); | |
3839e657 TT |
439 | extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs); |
440 | extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs); | |
441 | ||
442 | /* block.c */ | |
443 | extern errcode_t ext2fs_block_iterate(ext2_filsys fs, | |
444 | ino_t ino, | |
445 | int flags, | |
446 | char *block_buf, | |
447 | int (*func)(ext2_filsys fs, | |
448 | blk_t *blocknr, | |
449 | int blockcnt, | |
450 | void *private), | |
451 | void *private); | |
452 | ||
19c78dc0 TT |
453 | errcode_t ext2fs_block_iterate2(ext2_filsys fs, |
454 | ino_t ino, | |
455 | int flags, | |
456 | char *block_buf, | |
457 | int (*func)(ext2_filsys fs, | |
458 | blk_t *blocknr, | |
459 | int blockcnt, | |
460 | blk_t ref_blk, | |
461 | int ref_offset, | |
462 | void *private), | |
463 | void *private); | |
464 | ||
1e1da29f TT |
465 | /* bmove.c */ |
466 | extern errcode_t ext2fs_move_blocks(ext2_filsys fs, | |
467 | ext2fs_block_bitmap reserve, | |
9941fb73 | 468 | ext2fs_block_bitmap alloc_map, |
1e1da29f TT |
469 | int flags); |
470 | ||
f3db3566 TT |
471 | /* check_desc.c */ |
472 | extern errcode_t ext2fs_check_desc(ext2_filsys fs); | |
473 | ||
3839e657 TT |
474 | /* closefs.c */ |
475 | extern errcode_t ext2fs_close(ext2_filsys fs); | |
476 | extern errcode_t ext2fs_flush(ext2_filsys fs); | |
521e3685 | 477 | extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block); |
3839e657 | 478 | |
50e1e10f TT |
479 | /* cmp_bitmaps.c */ |
480 | extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, | |
481 | ext2fs_block_bitmap bm2); | |
482 | extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, | |
483 | ext2fs_inode_bitmap bm2); | |
484 | ||
19c78dc0 TT |
485 | /* dblist.c */ |
486 | ||
a29f4d30 TT |
487 | extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs); |
488 | extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist); | |
489 | extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino, | |
490 | blk_t blk, int blockcnt); | |
491 | extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, | |
492 | int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, | |
493 | void *private), | |
494 | void *private); | |
495 | extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino, | |
496 | blk_t blk, int blockcnt); | |
497 | extern errcode_t ext2fs_copy_dblist(ext2_dblist src, | |
498 | ext2_dblist *dest); | |
549860c5 | 499 | extern int ext2fs_dblist_count(ext2_dblist dblist); |
19c78dc0 TT |
500 | |
501 | /* dblist_dir.c */ | |
502 | extern errcode_t | |
503 | ext2fs_dblist_dir_iterate(ext2_dblist dblist, | |
504 | int flags, | |
505 | char *block_buf, | |
506 | int (*func)(ino_t dir, | |
507 | int entry, | |
508 | struct ext2_dir_entry *dirent, | |
509 | int offset, | |
510 | int blocksize, | |
511 | char *buf, | |
512 | void *private), | |
513 | void *private); | |
50e1e10f TT |
514 | |
515 | /* dirblock.c */ | |
516 | extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, | |
517 | void *buf); | |
518 | extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, | |
519 | void *buf); | |
520 | ||
19c78dc0 TT |
521 | /* dir_iterate.c */ |
522 | extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, | |
523 | ino_t dir, | |
524 | int flags, | |
525 | char *block_buf, | |
526 | int (*func)(struct ext2_dir_entry *dirent, | |
527 | int offset, | |
528 | int blocksize, | |
529 | char *buf, | |
530 | void *private), | |
531 | void *private); | |
532 | /* private to library */ | |
533 | extern int ext2fs_process_dir_block(ext2_filsys fs, | |
534 | blk_t *blocknr, | |
535 | int blockcnt, | |
536 | void *private); | |
537 | ||
a29f4d30 TT |
538 | /* dupfs.c */ |
539 | extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest); | |
19c78dc0 | 540 | |
3839e657 TT |
541 | /* expanddir.c */ |
542 | extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir); | |
543 | ||
544 | /* freefs.c */ | |
545 | extern void ext2fs_free(ext2_filsys fs); | |
1e3472c5 | 546 | extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap); |
50e1e10f TT |
547 | extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap); |
548 | extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap); | |
a29f4d30 TT |
549 | extern void ext2fs_free_dblist(ext2_dblist dblist); |
550 | extern void ext2fs_badblocks_list_free(badblocks_list bb); | |
50e1e10f TT |
551 | |
552 | /* getsize.c */ | |
553 | extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, | |
554 | blk_t *retblocks); | |
3839e657 TT |
555 | |
556 | /* initialize.c */ | |
557 | extern errcode_t ext2fs_initialize(const char *name, int flags, | |
558 | struct ext2_super_block *param, | |
559 | io_manager manager, ext2_filsys *ret_fs); | |
560 | ||
561 | /* inode.c */ | |
562 | extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, | |
563 | ext2_inode_scan *ret_scan); | |
564 | extern void ext2fs_close_inode_scan(ext2_inode_scan scan); | |
565 | extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino, | |
566 | struct ext2_inode *inode); | |
19c78dc0 TT |
567 | extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, |
568 | int group); | |
569 | extern void ext2fs_set_inode_callback | |
570 | (ext2_inode_scan scan, | |
571 | errcode_t (*done_group)(ext2_filsys fs, | |
572 | ext2_inode_scan scan, | |
573 | dgrp_t group, | |
574 | void * private), | |
575 | void *done_group_data); | |
576 | extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, | |
577 | int clear_flags); | |
578 | extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino, | |
3839e657 | 579 | struct ext2_inode * inode); |
19c78dc0 | 580 | extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino, |
3839e657 TT |
581 | struct ext2_inode * inode); |
582 | extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks); | |
583 | extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino); | |
584 | ||
19c78dc0 TT |
585 | /* icount.c */ |
586 | extern void ext2fs_free_icount(ext2_icount_t icount); | |
521e3685 TT |
587 | extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size, |
588 | ext2_icount_t hint, ext2_icount_t *ret); | |
19c78dc0 TT |
589 | extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size, |
590 | ext2_icount_t *ret); | |
591 | extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino, | |
592 | __u16 *ret); | |
593 | extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino, | |
594 | __u16 *ret); | |
595 | extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino, | |
596 | __u16 *ret); | |
597 | extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino, | |
598 | __u16 count); | |
599 | extern ino_t ext2fs_get_icount_size(ext2_icount_t icount); | |
521e3685 | 600 | errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); |
19c78dc0 | 601 | |
50e1e10f TT |
602 | /* ismounted.c */ |
603 | extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); | |
604 | ||
3839e657 | 605 | /* namei.c */ |
3839e657 TT |
606 | extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name, |
607 | int namelen, char *buf, ino_t *inode); | |
608 | extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd, | |
609 | const char *name, ino_t *inode); | |
1e3472c5 TT |
610 | errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd, |
611 | const char *name, ino_t *inode); | |
612 | extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd, | |
613 | ino_t inode, ino_t *res_inode); | |
614 | ||
615 | /* native.c */ | |
616 | int ext2fs_native_flag(void); | |
3839e657 TT |
617 | |
618 | /* newdir.c */ | |
619 | extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino, | |
620 | ino_t parent_ino, char **block); | |
621 | ||
622 | /* mkdir.c */ | |
623 | extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum, | |
624 | const char *name); | |
625 | ||
626 | /* openfs.c */ | |
627 | extern errcode_t ext2fs_open(const char *name, int flags, int superblock, | |
628 | int block_size, io_manager manager, | |
629 | ext2_filsys *ret_fs); | |
3839e657 TT |
630 | |
631 | /* get_pathname.c */ | |
632 | extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino, | |
633 | char **name); | |
634 | ||
635 | /* link.c */ | |
636 | errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name, | |
637 | ino_t ino, int flags); | |
638 | errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name, | |
639 | ino_t ino, int flags); | |
640 | ||
641 | /* read_bb.c */ | |
19c78dc0 TT |
642 | extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, |
643 | ext2_badblocks_list *bb_list); | |
3839e657 TT |
644 | |
645 | /* read_bb_file.c */ | |
646 | extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, | |
19c78dc0 | 647 | ext2_badblocks_list *bb_list, |
3839e657 TT |
648 | void (*invalid)(ext2_filsys fs, |
649 | blk_t blk)); | |
650 | ||
19c78dc0 TT |
651 | /* rs_bitmap.c */ |
652 | extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, | |
653 | __u32 new_real_end, | |
654 | ext2fs_generic_bitmap bmap); | |
655 | extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, | |
656 | ext2fs_inode_bitmap bmap); | |
657 | extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, | |
658 | ext2fs_block_bitmap bmap); | |
a29f4d30 TT |
659 | extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, |
660 | ext2fs_generic_bitmap *dest); | |
19c78dc0 | 661 | |
50e1e10f TT |
662 | /* swapfs.c */ |
663 | extern void ext2fs_swap_super(struct ext2_super_block * super); | |
664 | extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp); | |
1e3472c5 TT |
665 | extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, |
666 | struct ext2_inode *f, int hostorder); | |
667 | ||
19c78dc0 | 668 | /* valid_blk.c */ |
521e3685 TT |
669 | extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); |
670 | ||
671 | /* version.c */ | |
672 | extern int ext2fs_parse_version_string(const char *ver_string); | |
673 | extern int ext2fs_get_library_version(const char **ver_string, | |
674 | const char **date_string); | |
50e1e10f | 675 | |
3839e657 TT |
676 | /* inline functions */ |
677 | extern void ext2fs_mark_super_dirty(ext2_filsys fs); | |
678 | extern void ext2fs_mark_changed(ext2_filsys fs); | |
679 | extern int ext2fs_test_changed(ext2_filsys fs); | |
680 | extern void ext2fs_mark_valid(ext2_filsys fs); | |
681 | extern void ext2fs_unmark_valid(ext2_filsys fs); | |
682 | extern int ext2fs_test_valid(ext2_filsys fs); | |
683 | extern void ext2fs_mark_ib_dirty(ext2_filsys fs); | |
684 | extern void ext2fs_mark_bb_dirty(ext2_filsys fs); | |
685 | extern int ext2fs_test_ib_dirty(ext2_filsys fs); | |
686 | extern int ext2fs_test_bb_dirty(ext2_filsys fs); | |
687 | extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); | |
688 | extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino); | |
689 | ||
690 | /* | |
691 | * The actual inlined functions definitions themselves... | |
692 | * | |
693 | * If NO_INLINE_FUNCS is defined, then we won't try to do inline | |
694 | * functions at all! | |
695 | */ | |
696 | #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) | |
697 | #ifdef INCLUDE_INLINE_FUNCS | |
698 | #define _INLINE_ extern | |
699 | #else | |
700 | #define _INLINE_ extern __inline__ | |
701 | #endif | |
702 | ||
703 | /* | |
704 | * Mark a filesystem superblock as dirty | |
705 | */ | |
706 | _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs) | |
707 | { | |
708 | fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; | |
709 | } | |
710 | ||
711 | /* | |
712 | * Mark a filesystem as changed | |
713 | */ | |
714 | _INLINE_ void ext2fs_mark_changed(ext2_filsys fs) | |
715 | { | |
716 | fs->flags |= EXT2_FLAG_CHANGED; | |
717 | } | |
718 | ||
719 | /* | |
720 | * Check to see if a filesystem has changed | |
721 | */ | |
722 | _INLINE_ int ext2fs_test_changed(ext2_filsys fs) | |
723 | { | |
724 | return (fs->flags & EXT2_FLAG_CHANGED); | |
725 | } | |
726 | ||
727 | /* | |
728 | * Mark a filesystem as valid | |
729 | */ | |
730 | _INLINE_ void ext2fs_mark_valid(ext2_filsys fs) | |
731 | { | |
732 | fs->flags |= EXT2_FLAG_VALID; | |
733 | } | |
734 | ||
735 | /* | |
736 | * Mark a filesystem as NOT valid | |
737 | */ | |
738 | _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs) | |
739 | { | |
740 | fs->flags &= ~EXT2_FLAG_VALID; | |
741 | } | |
742 | ||
743 | /* | |
744 | * Check to see if a filesystem is valid | |
745 | */ | |
746 | _INLINE_ int ext2fs_test_valid(ext2_filsys fs) | |
747 | { | |
748 | return (fs->flags & EXT2_FLAG_VALID); | |
749 | } | |
750 | ||
751 | /* | |
752 | * Mark the inode bitmap as dirty | |
753 | */ | |
754 | _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs) | |
755 | { | |
756 | fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; | |
757 | } | |
758 | ||
759 | /* | |
760 | * Mark the block bitmap as dirty | |
761 | */ | |
762 | _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs) | |
763 | { | |
764 | fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; | |
765 | } | |
766 | ||
767 | /* | |
768 | * Check to see if a filesystem's inode bitmap is dirty | |
769 | */ | |
770 | _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs) | |
771 | { | |
772 | return (fs->flags & EXT2_FLAG_IB_DIRTY); | |
773 | } | |
774 | ||
775 | /* | |
776 | * Check to see if a filesystem's block bitmap is dirty | |
777 | */ | |
778 | _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) | |
779 | { | |
780 | return (fs->flags & EXT2_FLAG_BB_DIRTY); | |
781 | } | |
782 | ||
783 | /* | |
784 | * Return the group # of a block | |
785 | */ | |
786 | _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) | |
787 | { | |
788 | return (blk - fs->super->s_first_data_block) / | |
789 | fs->super->s_blocks_per_group; | |
790 | } | |
791 | ||
792 | /* | |
793 | * Return the group # of an inode number | |
794 | */ | |
795 | _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino) | |
796 | { | |
797 | return (ino - 1) / fs->super->s_inodes_per_group; | |
798 | } | |
799 | #undef _INLINE_ | |
800 | #endif | |
801 |