1 /*
2 * ext2fs.h --- ext2fs
3 *
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%
10 */
11
12 #ifndef _EXT2FS_EXT2FS_H
13 #define _EXT2FS_EXT2FS_H
14
15 #ifdef __GNUC__
16 #define EXT2FS_ATTR(x) __attribute__(x)
17 #else
18 #define EXT2FS_ATTR(x)
19 #endif
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*
26 * Non-GNU C compilers won't necessarily understand inline
27 */
28 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
29 #define NO_INLINE_FUNCS
30 #endif
31
32 /*
33 * Where the master copy of the superblock is located, and how big
34 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
35 * the size of the superblock structure is not necessarily trustworthy
36 * (some versions have the padding set up so that the superblock is
37 * 1032 bytes long).
38 */
39 #define SUPERBLOCK_OFFSET 1024
40 #define SUPERBLOCK_SIZE 1024
41
42 /*
43 * The last ext2fs revision level that this version of the library is
44 * able to support.
45 */
46 #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
47
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
50 #endif
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55
56 #if EXT2_FLAT_INCLUDES
57 #include "e2_types.h"
58 #include "ext2_fs.h"
59 #include "ext3_extents.h"
60 #else
61 #include <ext2fs/ext2_types.h>
62 #include <ext2fs/ext2_fs.h>
63 #include <ext2fs/ext3_extents.h>
64 #endif /* EXT2_FLAT_INCLUDES */
65
66 typedef __u32 ext2_ino_t;
67 typedef __u32 blk_t;
68 typedef __u64 blk64_t;
69 typedef __u32 dgrp_t;
70 typedef __u32 ext2_off_t;
71 typedef __s64 e2_blkcnt_t;
72 typedef __u32 ext2_dirhash_t;
73
74 #if EXT2_FLAT_INCLUDES
75 #include "com_err.h"
76 #include "ext2_io.h"
77 #include "ext2_err.h"
78 #include "ext2_ext_attr.h"
79 #else
80 #include <et/com_err.h>
81 #include <ext2fs/ext2_io.h>
82 #include <ext2fs/ext2_err.h>
83 #include <ext2fs/ext2_ext_attr.h>
84 #endif
85
86 /*
87 * Portability help for Microsoft Visual C++
88 */
89 #ifdef _MSC_VER
90 #define EXT2_QSORT_TYPE int __cdecl
91 #else
92 #define EXT2_QSORT_TYPE int
93 #endif
94
95 typedef struct struct_ext2_filsys *ext2_filsys;
96
97 #define EXT2FS_MARK_ERROR 0
98 #define EXT2FS_UNMARK_ERROR 1
99 #define EXT2FS_TEST_ERROR 2
100
101 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
102 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
103 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
104
105 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
106
107
108 /*
109 * Badblocks list definitions
110 */
111
112 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
113 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
114
115 typedef struct ext2_struct_u32_list *ext2_u32_list;
116 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
117
118 /* old */
119 typedef struct ext2_struct_u32_list *badblocks_list;
120 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
121
122 #define BADBLOCKS_FLAG_DIRTY 1
123
124 /*
125 * ext2_dblist structure and abstractions (see dblist.c)
126 */
127 struct ext2_db_entry {
128 ext2_ino_t ino;
129 blk_t blk;
130 int blockcnt;
131 };
132
133 typedef struct ext2_struct_dblist *ext2_dblist;
134
135 #define DBLIST_ABORT 1
136
137 /*
138 * ext2_fileio definitions
139 */
140
141 #define EXT2_FILE_WRITE 0x0001
142 #define EXT2_FILE_CREATE 0x0002
143
144 #define EXT2_FILE_MASK 0x00FF
145
146 #define EXT2_FILE_BUF_DIRTY 0x4000
147 #define EXT2_FILE_BUF_VALID 0x2000
148
149 typedef struct ext2_file *ext2_file_t;
150
151 #define EXT2_SEEK_SET 0
152 #define EXT2_SEEK_CUR 1
153 #define EXT2_SEEK_END 2
154
155 /*
156 * Flags for the ext2_filsys structure and for ext2fs_open()
157 */
158 #define EXT2_FLAG_RW 0x01
159 #define EXT2_FLAG_CHANGED 0x02
160 #define EXT2_FLAG_DIRTY 0x04
161 #define EXT2_FLAG_VALID 0x08
162 #define EXT2_FLAG_IB_DIRTY 0x10
163 #define EXT2_FLAG_BB_DIRTY 0x20
164 #define EXT2_FLAG_SWAP_BYTES 0x40
165 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
166 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
167 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
168 #define EXT2_FLAG_FORCE 0x400
169 #define EXT2_FLAG_SUPER_ONLY 0x800
170 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
171 #define EXT2_FLAG_IMAGE_FILE 0x2000
172 #define EXT2_FLAG_EXCLUSIVE 0x4000
173 #define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000
174 #define EXT2_FLAG_NOFREE_ON_ERROR 0x10000
175
176 /*
177 * Special flag in the ext2 inode i_flag field that means that this is
178 * a new inode. (So that ext2_write_inode() can clear extra fields.)
179 */
180 #define EXT2_NEW_INODE_FL 0x80000000
181
182 /*
183 * Flags for mkjournal
184 *
185 * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
186 */
187 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001
188
189 struct struct_ext2_filsys {
190 errcode_t magic;
191 io_channel io;
192 int flags;
193 char * device_name;
194 struct ext2_super_block * super;
195 unsigned int blocksize;
196 int fragsize;
197 dgrp_t group_desc_count;
198 unsigned long desc_blocks;
199 struct ext2_group_desc * group_desc;
200 int inode_blocks_per_group;
201 ext2fs_inode_bitmap inode_map;
202 ext2fs_block_bitmap block_map;
203 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
204 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
205 errcode_t (*write_bitmaps)(ext2_filsys fs);
206 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
207 struct ext2_inode *inode);
208 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
209 struct ext2_inode *inode);
210 ext2_badblocks_list badblocks;
211 ext2_dblist dblist;
212 __u32 stride; /* for mke2fs */
213 struct ext2_super_block * orig_super;
214 struct ext2_image_hdr * image_header;
215 __u32 umask;
216 time_t now;
217 /*
218 * Reserved for future expansion
219 */
220 __u32 reserved[7];
221
222 /*
223 * Reserved for the use of the calling application.
224 */
225 void * priv_data;
226
227 /*
228 * Inode cache
229 */
230 struct ext2_inode_cache *icache;
231 io_channel image_io;
232
233 /*
234 * More callback functions
235 */
236 errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
237 blk64_t *ret);
238 void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
239 };
240
241 #if EXT2_FLAT_INCLUDES
242 #include "e2_bitops.h"
243 #else
244 #include <ext2fs/bitops.h>
245 #endif
246
247 /*
248 * Return flags for the block iterator functions
249 */
250 #define BLOCK_CHANGED 1
251 #define BLOCK_ABORT 2
252 #define BLOCK_ERROR 4
253
254 /*
255 * Block interate flags
256 *
257 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
258 * function should be called on blocks where the block number is zero.
259 * This is used by ext2fs_expand_dir() to be able to add a new block
260 * to an inode. It can also be used for programs that want to be able
261 * to deal with files that contain "holes".
262 *
263 * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
264 * the indirect, doubly indirect, etc. blocks should be called after
265 * all of the blocks containined in the indirect blocks are processed.
266 * This is useful if you are going to be deallocating blocks from an
267 * inode.
268 *
269 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
270 * called for data blocks only.
271 *
272 * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
273 * modify returned block number.
274 *
275 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
276 * ext2fs_block_iterate2 that large files won't be accepted.
277 */
278 #define BLOCK_FLAG_APPEND 1
279 #define BLOCK_FLAG_HOLE 1
280 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
281 #define BLOCK_FLAG_DATA_ONLY 4
282 #define BLOCK_FLAG_READ_ONLY 8
283
284 #define BLOCK_FLAG_NO_LARGE 0x1000
285
286 /*
287 * Magic "block count" return values for the block iterator function.
288 */
289 #define BLOCK_COUNT_IND (-1)
290 #define BLOCK_COUNT_DIND (-2)
291 #define BLOCK_COUNT_TIND (-3)
292 #define BLOCK_COUNT_TRANSLATOR (-4)
293
294 #if 0
295 /*
296 * Flags for ext2fs_move_blocks
297 */
298 #define EXT2_BMOVE_GET_DBLIST 0x0001
299 #define EXT2_BMOVE_DEBUG 0x0002
300 #endif
301
302 /*
303 * Generic (non-filesystem layout specific) extents structure
304 */
305
306 #define EXT2_EXTENT_FLAGS_LEAF 0x0001
307 #define EXT2_EXTENT_FLAGS_UNINIT 0x0002
308 #define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004
309
310 struct ext2fs_extent {
311 blk64_t e_pblk; /* first physical block */
312 blk64_t e_lblk; /* first logical block extent covers */
313 __u32 e_len; /* number of blocks covered by extent */
314 __u32 e_flags; /* extent flags */
315 };
316
317 typedef struct ext2_extent_handle *ext2_extent_handle_t;
318 typedef struct ext2_extent_path *ext2_extent_path_t;
319
320 /*
321 * Flags used by ext2fs_extent_get()
322 */
323 #define EXT2_EXTENT_CURRENT 0x0000
324 #define EXT2_EXTENT_MOVE_MASK 0x000F
325 #define EXT2_EXTENT_ROOT 0x0001
326 #define EXT2_EXTENT_LAST_LEAF 0x0002
327 #define EXT2_EXTENT_FIRST_SIB 0x0003
328 #define EXT2_EXTENT_LAST_SIB 0x0004
329 #define EXT2_EXTENT_NEXT_SIB 0x0005
330 #define EXT2_EXTENT_PREV_SIB 0x0006
331 #define EXT2_EXTENT_NEXT_LEAF 0x0007
332 #define EXT2_EXTENT_PREV_LEAF 0x0008
333 #define EXT2_EXTENT_NEXT 0x0009
334 #define EXT2_EXTENT_PREV 0x000A
335 #define EXT2_EXTENT_UP 0x000B
336 #define EXT2_EXTENT_DOWN 0x000C
337 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
338
339 /*
340 * Flags used by ext2fs_extent_insert()
341 */
342 #define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */
343 #define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */
344
345 /*
346 * Flags used by ext2fs_extent_delete()
347 */
348 #define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extnt gone */
349
350 /*
351 * Flags used by ext2fs_extent_set_bmap()
352 */
353 #define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001
354
355 /*
356 * Data structure returned by ext2fs_extent_get_info()
357 */
358 struct ext2_extent_info {
359 int curr_entry;
360 int curr_level;
361 int num_entries;
362 int max_entries;
363 int max_depth;
364 int bytes_avail;
365 blk64_t max_lblk;
366 blk64_t max_pblk;
367 __u32 max_len;
368 __u32 max_uninit_len;
369 };
370
371 /*
372 * Flags for directory block reading and writing functions
373 */
374 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
375
376 /*
377 * Return flags for the directory iterator functions
378 */
379 #define DIRENT_CHANGED 1
380 #define DIRENT_ABORT 2
381 #define DIRENT_ERROR 3
382
383 /*
384 * Directory iterator flags
385 */
386
387 #define DIRENT_FLAG_INCLUDE_EMPTY 1
388 #define DIRENT_FLAG_INCLUDE_REMOVED 2
389
390 #define DIRENT_DOT_FILE 1
391 #define DIRENT_DOT_DOT_FILE 2
392 #define DIRENT_OTHER_FILE 3
393 #define DIRENT_DELETED_FILE 4
394
395 /*
396 * Inode scan definitions
397 */
398 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
399
400 /*
401 * ext2fs_scan flags
402 */
403 #define EXT2_SF_CHK_BADBLOCKS 0x0001
404 #define EXT2_SF_BAD_INODE_BLK 0x0002
405 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
406 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
407 #define EXT2_SF_DO_LAZY 0x0010
408
409 /*
410 * ext2fs_check_if_mounted flags
411 */
412 #define EXT2_MF_MOUNTED 1
413 #define EXT2_MF_ISROOT 2
414 #define EXT2_MF_READONLY 4
415 #define EXT2_MF_SWAP 8
416 #define EXT2_MF_BUSY 16
417
418 /*
419 * Ext2/linux mode flags. We define them here so that we don't need
420 * to depend on the OS's sys/stat.h, since we may be compiling on a
421 * non-Linux system.
422 */
423 #define LINUX_S_IFMT 00170000
424 #define LINUX_S_IFSOCK 0140000
425 #define LINUX_S_IFLNK 0120000
426 #define LINUX_S_IFREG 0100000
427 #define LINUX_S_IFBLK 0060000
428 #define LINUX_S_IFDIR 0040000
429 #define LINUX_S_IFCHR 0020000
430 #define LINUX_S_IFIFO 0010000
431 #define LINUX_S_ISUID 0004000
432 #define LINUX_S_ISGID 0002000
433 #define LINUX_S_ISVTX 0001000
434
435 #define LINUX_S_IRWXU 00700
436 #define LINUX_S_IRUSR 00400
437 #define LINUX_S_IWUSR 00200
438 #define LINUX_S_IXUSR 00100
439
440 #define LINUX_S_IRWXG 00070
441 #define LINUX_S_IRGRP 00040
442 #define LINUX_S_IWGRP 00020
443 #define LINUX_S_IXGRP 00010
444
445 #define LINUX_S_IRWXO 00007
446 #define LINUX_S_IROTH 00004
447 #define LINUX_S_IWOTH 00002
448 #define LINUX_S_IXOTH 00001
449
450 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
451 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
452 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
453 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
454 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
455 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
456 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
457
458 /*
459 * ext2 size of an inode
460 */
461 #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
462
463 /*
464 * ext2_icount_t abstraction
465 */
466 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
467
468 typedef struct ext2_icount *ext2_icount_t;
469
470 /*
471 * Flags for ext2fs_bmap
472 */
473 #define BMAP_ALLOC 0x0001
474 #define BMAP_SET 0x0002
475
476 /*
477 * Returned flags from ext2fs_bmap
478 */
479 #define BMAP_RET_UNINIT 0x0001
480
481 /*
482 * Flags for imager.c functions
483 */
484 #define IMAGER_FLAG_INODEMAP 1
485 #define IMAGER_FLAG_SPARSEWRITE 2
486
487 /*
488 * For checking structure magic numbers...
489 */
490
491 #define EXT2_CHECK_MAGIC(struct, code) \
492 if ((struct)->magic != (code)) return (code)
493
494
495 /*
496 * For ext2 compression support
497 */
498 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
499 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
500
501 /*
502 * Features supported by this version of the library
503 */
504 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
505 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
506 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
507 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
508 EXT2_FEATURE_COMPAT_DIR_INDEX|\
509 EXT2_FEATURE_COMPAT_EXT_ATTR)
510
511 /* This #ifdef is temporary until compression is fully supported */
512 #ifdef ENABLE_COMPRESSION
513 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
514 /* If the below warning bugs you, then have
515 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
516 environment at configure time. */
517 #warning "Compression support is experimental"
518 #endif
519 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
520 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
521 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
522 EXT2_FEATURE_INCOMPAT_META_BG|\
523 EXT3_FEATURE_INCOMPAT_RECOVER|\
524 EXT3_FEATURE_INCOMPAT_EXTENTS|\
525 EXT4_FEATURE_INCOMPAT_FLEX_BG)
526 #else
527 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
528 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
529 EXT2_FEATURE_INCOMPAT_META_BG|\
530 EXT3_FEATURE_INCOMPAT_RECOVER|\
531 EXT3_FEATURE_INCOMPAT_EXTENTS|\
532 EXT4_FEATURE_INCOMPAT_FLEX_BG)
533 #endif
534 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
535 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
536 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
537 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
538 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
539 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
540
541 /*
542 * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
543 * to ext2fs_openfs()
544 */
545 #define EXT2_LIB_SOFTSUPP_INCOMPAT (0)
546 #define EXT2_LIB_SOFTSUPP_RO_COMPAT (0)
547
548 /*
549 * function prototypes
550 */
551
552 /* alloc.c */
553 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
554 ext2fs_inode_bitmap map, ext2_ino_t *ret);
555 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
556 ext2fs_block_bitmap map, blk_t *ret);
557 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
558 blk_t finish, int num,
559 ext2fs_block_bitmap map,
560 blk_t *ret);
561 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
562 char *block_buf, blk_t *ret);
563 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
564 errcode_t (*func)(ext2_filsys fs,
565 blk64_t goal,
566 blk64_t *ret),
567 errcode_t (**old)(ext2_filsys fs,
568 blk64_t goal,
569 blk64_t *ret));
570
571 /* alloc_sb.c */
572 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
573 dgrp_t group,
574 ext2fs_block_bitmap bmap);
575 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
576 void (*func)(ext2_filsys fs,
577 blk64_t blk,
578 int inuse),
579 void (**old)(ext2_filsys fs,
580 blk64_t blk,
581 int inuse));
582
583 /* alloc_stats.c */
584 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
585 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
586 int inuse, int isdir);
587 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
588
589 /* alloc_tables.c */
590 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
591 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
592 ext2fs_block_bitmap bmap);
593
594 /* badblocks.c */
595 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
596 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
597 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
598 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
599 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
600 ext2_u32_iterate *ret);
601 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
602 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
603 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
604 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
605
606 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
607 int size);
608 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
609 blk_t blk);
610 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
611 blk_t blk);
612 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
613 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
614 extern errcode_t
615 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
616 ext2_badblocks_iterate *ret);
617 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
618 blk_t *blk);
619 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
620 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
621 ext2_badblocks_list *dest);
622 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
623 ext2_badblocks_list bb2);
624 extern int ext2fs_u32_list_count(ext2_u32_list bb);
625
626 /* bb_compat */
627 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
628 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
629 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
630 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
631 badblocks_iterate *ret);
632 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
633 extern void badblocks_list_iterate_end(badblocks_iterate iter);
634 extern void badblocks_list_free(badblocks_list bb);
635
636 /* bb_inode.c */
637 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
638 ext2_badblocks_list bb_list);
639
640 /* bitmaps.c */
641 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
642 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
643 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
644 ext2fs_generic_bitmap *dest);
645 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
646 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
647 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
648 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
649 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
650 const char *descr,
651 ext2fs_block_bitmap *ret);
652 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
653 const char *descr,
654 ext2fs_inode_bitmap *ret);
655 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
656 ext2_ino_t end, ext2_ino_t *oend);
657 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
658 blk_t end, blk_t *oend);
659 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
660 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
661 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
662 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
663 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
664 ext2fs_inode_bitmap bmap);
665 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
666 ext2fs_block_bitmap bmap);
667 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
668 ext2fs_block_bitmap bm2);
669 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
670 ext2fs_inode_bitmap bm2);
671 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
672 ext2_ino_t start, unsigned int num,
673 void *in);
674 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
675 ext2_ino_t start, unsigned int num,
676 void *out);
677 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
678 blk_t start, unsigned int num,
679 void *in);
680 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
681 blk_t start, unsigned int num,
682 void *out);
683
684
685 /* block.c */
686 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
687 ext2_ino_t ino,
688 int flags,
689 char *block_buf,
690 int (*func)(ext2_filsys fs,
691 blk_t *blocknr,
692 int blockcnt,
693 void *priv_data),
694 void *priv_data);
695 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
696 ext2_ino_t ino,
697 int flags,
698 char *block_buf,
699 int (*func)(ext2_filsys fs,
700 blk_t *blocknr,
701 e2_blkcnt_t blockcnt,
702 blk_t ref_blk,
703 int ref_offset,
704 void *priv_data),
705 void *priv_data);
706
707 /* bmap.c */
708 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
709 struct ext2_inode *inode,
710 char *block_buf, int bmap_flags,
711 blk_t block, blk_t *phys_blk);
712 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
713 struct ext2_inode *inode,
714 char *block_buf, int bmap_flags, blk64_t block,
715 int *ret_flags, blk64_t *phys_blk);
716
717 #if 0
718 /* bmove.c */
719 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
720 ext2fs_block_bitmap reserve,
721 ext2fs_block_bitmap alloc_map,
722 int flags);
723 #endif
724
725 /* check_desc.c */
726 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
727
728 /* closefs.c */
729 extern errcode_t ext2fs_close(ext2_filsys fs);
730 extern errcode_t ext2fs_flush(ext2_filsys fs);
731 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
732 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
733 dgrp_t group,
734 blk_t *ret_super_blk,
735 blk_t *ret_old_desc_blk,
736 blk_t *ret_new_desc_blk,
737 int *ret_meta_bg);
738 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
739
740 /* csum.c */
741 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
742 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
743 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
744
745 /* dblist.c */
746
747 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
748 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
749 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
750 blk_t blk, int blockcnt);
751 extern void ext2fs_dblist_sort(ext2_dblist dblist,
752 EXT2_QSORT_TYPE (*sortfunc)(const void *,
753 const void *));
754 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
755 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
756 void *priv_data),
757 void *priv_data);
758 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
759 blk_t blk, int blockcnt);
760 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
761 ext2_dblist *dest);
762 extern int ext2fs_dblist_count(ext2_dblist dblist);
763 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
764 struct ext2_db_entry **entry);
765 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
766
767 /* dblist_dir.c */
768 extern errcode_t
769 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
770 int flags,
771 char *block_buf,
772 int (*func)(ext2_ino_t dir,
773 int entry,
774 struct ext2_dir_entry *dirent,
775 int offset,
776 int blocksize,
777 char *buf,
778 void *priv_data),
779 void *priv_data);
780
781 /* dirblock.c */
782 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
783 void *buf);
784 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
785 void *buf, int flags);
786 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
787 void *buf);
788 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
789 void *buf, int flags);
790
791 /* dirhash.c */
792 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
793 const __u32 *seed,
794 ext2_dirhash_t *ret_hash,
795 ext2_dirhash_t *ret_minor_hash);
796
797
798 /* dir_iterate.c */
799 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
800 struct ext2_dir_entry *dirent,
801 unsigned int *rec_len);
802 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
803 unsigned int len,
804 struct ext2_dir_entry *dirent);
805 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
806 ext2_ino_t dir,
807 int flags,
808 char *block_buf,
809 int (*func)(struct ext2_dir_entry *dirent,
810 int offset,
811 int blocksize,
812 char *buf,
813 void *priv_data),
814 void *priv_data);
815 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
816 ext2_ino_t dir,
817 int flags,
818 char *block_buf,
819 int (*func)(ext2_ino_t dir,
820 int entry,
821 struct ext2_dir_entry *dirent,
822 int offset,
823 int blocksize,
824 char *buf,
825 void *priv_data),
826 void *priv_data);
827
828 /* dupfs.c */
829 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
830
831 /* expanddir.c */
832 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
833
834 /* ext_attr.c */
835 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
836 void *data);
837 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
838 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
839 void *buf);
840 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
841 char *block_buf,
842 int adjust, __u32 *newcount);
843
844 /* extent.c */
845 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
846 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
847 ext2_extent_handle_t *handle);
848 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
849 struct ext2_inode *inode,
850 ext2_extent_handle_t *ret_handle);
851 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
852 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
853 int flags, struct ext2fs_extent *extent);
854 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
855 struct ext2fs_extent *extent);
856 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
857 struct ext2fs_extent *extent);
858 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
859 blk64_t logical, blk64_t physical,
860 int flags);
861 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
862 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
863 struct ext2_extent_info *info);
864 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
865 blk64_t blk);
866
867 /* fileio.c */
868 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
869 struct ext2_inode *inode,
870 int flags, ext2_file_t *ret);
871 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
872 int flags, ext2_file_t *ret);
873 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
874 extern errcode_t ext2fs_file_close(ext2_file_t file);
875 extern errcode_t ext2fs_file_flush(ext2_file_t file);
876 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
877 unsigned int wanted, unsigned int *got);
878 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
879 unsigned int nbytes, unsigned int *written);
880 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
881 int whence, __u64 *ret_pos);
882 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
883 int whence, ext2_off_t *ret_pos);
884 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
885 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
886 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
887
888 /* finddev.c */
889 extern char *ext2fs_find_block_device(dev_t device);
890
891 /* flushb.c */
892 extern errcode_t ext2fs_sync_device(int fd, int flushb);
893
894 /* freefs.c */
895 extern void ext2fs_free(ext2_filsys fs);
896 extern void ext2fs_free_dblist(ext2_dblist dblist);
897 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
898 extern void ext2fs_u32_list_free(ext2_u32_list bb);
899
900 /* gen_bitmap.c */
901 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
902 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
903 __u32 start, __u32 end,
904 __u32 real_end,
905 const char *descr, char *init_map,
906 ext2fs_generic_bitmap *ret);
907 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
908 __u32 end,
909 __u32 real_end,
910 const char *descr,
911 ext2fs_generic_bitmap *ret);
912 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
913 ext2fs_generic_bitmap *dest);
914 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
915 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
916 errcode_t magic,
917 errcode_t neq,
918 ext2_ino_t end,
919 ext2_ino_t *oend);
920 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
921 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
922 __u32 new_end,
923 __u32 new_real_end,
924 ext2fs_generic_bitmap bmap);
925 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
926 ext2fs_generic_bitmap bm1,
927 ext2fs_generic_bitmap bm2);
928 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
929 errcode_t magic,
930 __u32 start, __u32 num,
931 void *out);
932 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
933 errcode_t magic,
934 __u32 start, __u32 num,
935 void *in);
936
937 /* getsize.c */
938 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
939 blk_t *retblocks);
940 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
941 blk64_t *retblocks);
942
943 /* getsectsize.c */
944 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
945
946 /* i_block.c */
947 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
948 blk64_t num_blocks);
949 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
950 blk64_t num_blocks);
951 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
952
953 /* imager.c */
954 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
955 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
956 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
957 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
958 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
959 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
960
961 /* ind_block.c */
962 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
963 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
964
965 /* initialize.c */
966 extern errcode_t ext2fs_initialize(const char *name, int flags,
967 struct ext2_super_block *param,
968 io_manager manager, ext2_filsys *ret_fs);
969
970 /* icount.c */
971 extern void ext2fs_free_icount(ext2_icount_t icount);
972 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
973 int flags, ext2_icount_t *ret);
974 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
975 unsigned int size,
976 ext2_icount_t hint, ext2_icount_t *ret);
977 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
978 unsigned int size,
979 ext2_icount_t *ret);
980 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
981 __u16 *ret);
982 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
983 __u16 *ret);
984 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
985 __u16 *ret);
986 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
987 __u16 count);
988 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
989 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
990
991 /* inode.c */
992 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
993 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
994 ext2_ino_t *ino,
995 struct ext2_inode *inode,
996 int bufsize);
997 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
998 ext2_inode_scan *ret_scan);
999 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1000 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1001 struct ext2_inode *inode);
1002 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1003 int group);
1004 extern void ext2fs_set_inode_callback
1005 (ext2_inode_scan scan,
1006 errcode_t (*done_group)(ext2_filsys fs,
1007 ext2_inode_scan scan,
1008 dgrp_t group,
1009 void * priv_data),
1010 void *done_group_data);
1011 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1012 int clear_flags);
1013 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1014 struct ext2_inode * inode,
1015 int bufsize);
1016 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
1017 struct ext2_inode * inode);
1018 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1019 struct ext2_inode * inode,
1020 int bufsize);
1021 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1022 struct ext2_inode * inode);
1023 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1024 struct ext2_inode * inode);
1025 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1026 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1027
1028 /* inode_io.c */
1029 extern io_manager inode_io_manager;
1030 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1031 char **name);
1032 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1033 struct ext2_inode *inode,
1034 char **name);
1035
1036 /* ismounted.c */
1037 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1038 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1039 char *mtpt, int mtlen);
1040
1041 /* namei.c */
1042 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1043 int namelen, char *buf, ext2_ino_t *inode);
1044 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1045 const char *name, ext2_ino_t *inode);
1046 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1047 const char *name, ext2_ino_t *inode);
1048 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1049 ext2_ino_t inode, ext2_ino_t *res_inode);
1050
1051 /* native.c */
1052 int ext2fs_native_flag(void);
1053
1054 /* newdir.c */
1055 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1056 ext2_ino_t parent_ino, char **block);
1057
1058 /* mkdir.c */
1059 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1060 const char *name);
1061
1062 /* mkjournal.c */
1063 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1064 blk_t *ret_blk, int *ret_count);
1065 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1066 __u32 size, int flags,
1067 char **ret_jsb);
1068 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1069 ext2_filsys journal_dev);
1070 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
1071 int flags);
1072 extern int ext2fs_default_journal_size(__u64 blocks);
1073
1074 /* openfs.c */
1075 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1076 unsigned int block_size, io_manager manager,
1077 ext2_filsys *ret_fs);
1078 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1079 int flags, int superblock,
1080 unsigned int block_size, io_manager manager,
1081 ext2_filsys *ret_fs);
1082 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1083 dgrp_t i);
1084 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1085 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1086 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1087
1088 /* get_pathname.c */
1089 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1090 char **name);
1091
1092 /* link.c */
1093 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1094 ext2_ino_t ino, int flags);
1095 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1096 ext2_ino_t ino, int flags);
1097
1098 /* read_bb.c */
1099 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1100 ext2_badblocks_list *bb_list);
1101
1102 /* read_bb_file.c */
1103 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1104 ext2_badblocks_list *bb_list,
1105 void *priv_data,
1106 void (*invalid)(ext2_filsys fs,
1107 blk_t blk,
1108 char *badstr,
1109 void *priv_data));
1110 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1111 ext2_badblocks_list *bb_list,
1112 void (*invalid)(ext2_filsys fs,
1113 blk_t blk));
1114
1115 /* res_gdt.c */
1116 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1117
1118 /* swapfs.c */
1119 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1120 int has_header);
1121 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1122 struct ext2_ext_attr_header *from_hdr);
1123 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1124 struct ext2_ext_attr_entry *from_entry);
1125 extern void ext2fs_swap_super(struct ext2_super_block * super);
1126 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1127 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1128 struct ext2_inode_large *f, int hostorder,
1129 int bufsize);
1130 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1131 struct ext2_inode *f, int hostorder);
1132
1133 /* valid_blk.c */
1134 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1135
1136 /* version.c */
1137 extern int ext2fs_parse_version_string(const char *ver_string);
1138 extern int ext2fs_get_library_version(const char **ver_string,
1139 const char **date_string);
1140
1141 /* write_bb_file.c */
1142 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1143 unsigned int flags,
1144 FILE *f);
1145
1146
1147 /* inline functions */
1148 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1149 extern errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr);
1150 extern errcode_t ext2fs_free_mem(void *ptr);
1151 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1152 unsigned long size, void *ptr);
1153 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1154 extern void ext2fs_mark_changed(ext2_filsys fs);
1155 extern int ext2fs_test_changed(ext2_filsys fs);
1156 extern void ext2fs_mark_valid(ext2_filsys fs);
1157 extern void ext2fs_unmark_valid(ext2_filsys fs);
1158 extern int ext2fs_test_valid(ext2_filsys fs);
1159 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1160 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1161 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1162 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1163 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1164 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1165 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1166 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1167 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1168 struct ext2_inode *inode);
1169 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1170
1171 /*
1172 * The actual inlined functions definitions themselves...
1173 *
1174 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1175 * functions at all!
1176 */
1177 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1178 #ifdef INCLUDE_INLINE_FUNCS
1179 #define _INLINE_ extern
1180 #else
1181 #ifdef __GNUC__
1182 #define _INLINE_ extern __inline__
1183 #else /* For Watcom C */
1184 #define _INLINE_ extern inline
1185 #endif
1186 #endif
1187
1188 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1189 #include <string.h>
1190 /*
1191 * Allocate memory
1192 */
ext2fs_get_mem(unsigned long size,void * ptr)1193 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1194 {
1195 void *pp;
1196
1197 pp = malloc(size);
1198 if (!pp)
1199 return EXT2_ET_NO_MEMORY;
1200 memcpy(ptr, &pp, sizeof (pp));
1201 return 0;
1202 }
1203
ext2fs_get_array(unsigned long count,unsigned long size,void * ptr)1204 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
1205 {
1206 if (count && (-1UL)/count<size)
1207 return EXT2_ET_NO_MEMORY; //maybe define EXT2_ET_OVERFLOW ?
1208 return ext2fs_get_mem(count*size, ptr);
1209 }
1210
1211 /*
1212 * Free memory
1213 */
ext2fs_free_mem(void * ptr)1214 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1215 {
1216 void *p;
1217
1218 memcpy(&p, ptr, sizeof(p));
1219 free(p);
1220 p = 0;
1221 memcpy(ptr, &p, sizeof(p));
1222 return 0;
1223 }
1224
1225 /*
1226 * Resize memory
1227 */
ext2fs_resize_mem(unsigned long EXT2FS_ATTR ((unused))old_size,unsigned long size,void * ptr)1228 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1229 unsigned long size, void *ptr)
1230 {
1231 void *p;
1232
1233 /* Use "memcpy" for pointer assignments here to avoid problems
1234 * with C99 strict type aliasing rules. */
1235 memcpy(&p, ptr, sizeof(p));
1236 p = realloc(p, size);
1237 if (!p)
1238 return EXT2_ET_NO_MEMORY;
1239 memcpy(ptr, &p, sizeof(p));
1240 return 0;
1241 }
1242 #endif /* Custom memory routines */
1243
1244 /*
1245 * Mark a filesystem superblock as dirty
1246 */
ext2fs_mark_super_dirty(ext2_filsys fs)1247 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1248 {
1249 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1250 }
1251
1252 /*
1253 * Mark a filesystem as changed
1254 */
ext2fs_mark_changed(ext2_filsys fs)1255 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1256 {
1257 fs->flags |= EXT2_FLAG_CHANGED;
1258 }
1259
1260 /*
1261 * Check to see if a filesystem has changed
1262 */
ext2fs_test_changed(ext2_filsys fs)1263 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1264 {
1265 return (fs->flags & EXT2_FLAG_CHANGED);
1266 }
1267
1268 /*
1269 * Mark a filesystem as valid
1270 */
ext2fs_mark_valid(ext2_filsys fs)1271 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1272 {
1273 fs->flags |= EXT2_FLAG_VALID;
1274 }
1275
1276 /*
1277 * Mark a filesystem as NOT valid
1278 */
ext2fs_unmark_valid(ext2_filsys fs)1279 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1280 {
1281 fs->flags &= ~EXT2_FLAG_VALID;
1282 }
1283
1284 /*
1285 * Check to see if a filesystem is valid
1286 */
ext2fs_test_valid(ext2_filsys fs)1287 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1288 {
1289 return (fs->flags & EXT2_FLAG_VALID);
1290 }
1291
1292 /*
1293 * Mark the inode bitmap as dirty
1294 */
ext2fs_mark_ib_dirty(ext2_filsys fs)1295 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1296 {
1297 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1298 }
1299
1300 /*
1301 * Mark the block bitmap as dirty
1302 */
ext2fs_mark_bb_dirty(ext2_filsys fs)1303 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1304 {
1305 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1306 }
1307
1308 /*
1309 * Check to see if a filesystem's inode bitmap is dirty
1310 */
ext2fs_test_ib_dirty(ext2_filsys fs)1311 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1312 {
1313 return (fs->flags & EXT2_FLAG_IB_DIRTY);
1314 }
1315
1316 /*
1317 * Check to see if a filesystem's block bitmap is dirty
1318 */
ext2fs_test_bb_dirty(ext2_filsys fs)1319 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1320 {
1321 return (fs->flags & EXT2_FLAG_BB_DIRTY);
1322 }
1323
1324 /*
1325 * Return the group # of a block
1326 */
ext2fs_group_of_blk(ext2_filsys fs,blk_t blk)1327 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1328 {
1329 return (blk - fs->super->s_first_data_block) /
1330 fs->super->s_blocks_per_group;
1331 }
1332
1333 /*
1334 * Return the group # of an inode number
1335 */
ext2fs_group_of_ino(ext2_filsys fs,ext2_ino_t ino)1336 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1337 {
1338 return (ino - 1) / fs->super->s_inodes_per_group;
1339 }
1340
1341 /*
1342 * Return the first block (inclusive) in a group
1343 */
ext2fs_group_first_block(ext2_filsys fs,dgrp_t group)1344 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
1345 {
1346 return fs->super->s_first_data_block +
1347 (group * fs->super->s_blocks_per_group);
1348 }
1349
1350 /*
1351 * Return the last block (inclusive) in a group
1352 */
ext2fs_group_last_block(ext2_filsys fs,dgrp_t group)1353 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
1354 {
1355 return (group == fs->group_desc_count - 1 ?
1356 fs->super->s_blocks_count - 1 :
1357 ext2fs_group_first_block(fs, group) +
1358 (fs->super->s_blocks_per_group - 1));
1359 }
1360
ext2fs_inode_data_blocks(ext2_filsys fs,struct ext2_inode * inode)1361 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1362 struct ext2_inode *inode)
1363 {
1364 return inode->i_blocks -
1365 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1366 }
1367
1368 /*
1369 * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
1370 */
ext2fs_div_ceil(unsigned int a,unsigned int b)1371 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
1372 {
1373 if (!a)
1374 return 0;
1375 return ((a - 1) / b) + 1;
1376 }
1377 #undef _INLINE_
1378 #endif
1379
1380 #ifdef __cplusplus
1381 }
1382 #endif
1383
1384 #endif /* _EXT2FS_EXT2FS_H */
1385