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