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