4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 #ifndef _EXT2FS_EXT2FS_H
13 #define _EXT2FS_EXT2FS_H
20 * Non-GNU C compilers won't necessarily understand inline
22 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
23 #define NO_INLINE_FUNCS
27 * Build in support for byte-swapping filesystems if we the feature
28 * has been configured or if we're being built on a CPU architecture
29 * with a non-native byte order.
31 #if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
32 #define EXT2FS_ENABLE_SWAPFS
36 * Where the master copy of the superblock is located, and how big
37 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
38 * the size of the superblock structure is not necessarily trustworthy
39 * (some versions have the padding set up so that the superblock is
42 #define SUPERBLOCK_OFFSET 1024
43 #define SUPERBLOCK_SIZE 1024
46 * The last ext2fs revision level that this version of the library is
49 #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
51 #ifdef HAVE_SYS_TYPES_H
52 #include <sys/types.h>
57 #if EXT2_FLAT_INCLUDES
60 #include <ext2fs/ext2_types.h>
61 #endif /* EXT2_FLAT_INCLUDES */
63 typedef __u32 ext2_ino_t;
66 typedef __u32 ext2_off_t;
67 typedef __s64 e2_blkcnt_t;
68 typedef __u32 ext2_dirhash_t;
70 #if EXT2_FLAT_INCLUDES
75 #include <et/com_err.h>
76 #include <ext2fs/ext2_io.h>
77 #include <ext2fs/ext2_err.h>
81 * Portability help for Microsoft Visual C++
84 #define EXT2_QSORT_TYPE int __cdecl
86 #define EXT2_QSORT_TYPE int
89 typedef struct struct_ext2_filsys *ext2_filsys;
91 struct ext2fs_struct_generic_bitmap {
98 errcode_t base_error_code;
102 #define EXT2FS_MARK_ERROR 0
103 #define EXT2FS_UNMARK_ERROR 1
104 #define EXT2FS_TEST_ERROR 2
106 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
107 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
108 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
110 #ifdef EXT2_DYNAMIC_REV
111 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
113 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
114 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
118 * badblocks list definitions
121 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
122 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
124 typedef struct ext2_struct_u32_list *ext2_u32_list;
125 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
128 typedef struct ext2_struct_u32_list *badblocks_list;
129 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
131 #define BADBLOCKS_FLAG_DIRTY 1
134 * ext2_dblist structure and abstractions (see dblist.c)
136 struct ext2_db_entry {
142 typedef struct ext2_struct_dblist *ext2_dblist;
144 #define DBLIST_ABORT 1
147 * ext2_fileio definitions
150 #define EXT2_FILE_WRITE 0x0001
151 #define EXT2_FILE_CREATE 0x0002
153 #define EXT2_FILE_MASK 0x00FF
155 #define EXT2_FILE_BUF_DIRTY 0x4000
156 #define EXT2_FILE_BUF_VALID 0x2000
158 typedef struct ext2_file *ext2_file_t;
160 #define EXT2_SEEK_SET 0
161 #define EXT2_SEEK_CUR 1
162 #define EXT2_SEEK_END 2
165 * Flags for the ext2_filsys structure and for ext2fs_open()
167 #define EXT2_FLAG_RW 0x01
168 #define EXT2_FLAG_CHANGED 0x02
169 #define EXT2_FLAG_DIRTY 0x04
170 #define EXT2_FLAG_VALID 0x08
171 #define EXT2_FLAG_IB_DIRTY 0x10
172 #define EXT2_FLAG_BB_DIRTY 0x20
173 #define EXT2_FLAG_SWAP_BYTES 0x40
174 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
175 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
176 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
177 #define EXT2_FLAG_FORCE 0x400
178 #define EXT2_FLAG_SUPER_ONLY 0x800
179 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
180 #define EXT2_FLAG_IMAGE_FILE 0x2000
183 * Special flag in the ext2 inode i_flag field that means that this is
184 * a new inode. (So that ext2_write_inode() can clear extra fields.)
186 #define EXT2_NEW_INODE_FL 0x80000000
189 * Flags for mkjournal
191 * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
193 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001
195 struct struct_ext2_filsys {
200 struct ext2_super_block * super;
203 dgrp_t group_desc_count;
204 unsigned long desc_blocks;
205 struct ext2_group_desc * group_desc;
206 int inode_blocks_per_group;
207 ext2fs_inode_bitmap inode_map;
208 ext2fs_block_bitmap block_map;
209 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
210 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
211 errcode_t (*write_bitmaps)(ext2_filsys fs);
212 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
213 struct ext2_inode *inode);
214 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
215 struct ext2_inode *inode);
216 ext2_badblocks_list badblocks;
218 __u32 stride; /* for mke2fs */
219 struct ext2_super_block * orig_super;
220 struct ext2_image_hdr * image_header;
223 * Reserved for future expansion
228 * Reserved for the use of the calling application.
235 struct ext2_inode_cache *icache;
238 #if EXT2_FLAT_INCLUDES
239 #include "e2_bitops.h"
241 #include <ext2fs/bitops.h>
245 * Return flags for the block iterator functions
247 #define BLOCK_CHANGED 1
248 #define BLOCK_ABORT 2
249 #define BLOCK_ERROR 4
252 * Block interate flags
254 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
255 * function should be called on blocks where the block number is zero.
256 * This is used by ext2fs_expand_dir() to be able to add a new block
257 * to an inode. It can also be used for programs that want to be able
258 * to deal with files that contain "holes".
260 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
261 * indirect, doubly indirect, etc. blocks should be called after all
262 * of the blocks containined in the indirect blocks are processed.
263 * This is useful if you are going to be deallocating blocks from an
266 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
267 * called for data blocks only.
269 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
270 * ext2fs_block_iterate2 that large files won't be accepted.
272 #define BLOCK_FLAG_APPEND 1
273 #define BLOCK_FLAG_HOLE 1
274 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
275 #define BLOCK_FLAG_DATA_ONLY 4
277 #define BLOCK_FLAG_NO_LARGE 0x1000
280 * Magic "block count" return values for the block iterator function.
282 #define BLOCK_COUNT_IND (-1)
283 #define BLOCK_COUNT_DIND (-2)
284 #define BLOCK_COUNT_TIND (-3)
285 #define BLOCK_COUNT_TRANSLATOR (-4)
289 * Flags for ext2fs_move_blocks
291 #define EXT2_BMOVE_GET_DBLIST 0x0001
292 #define EXT2_BMOVE_DEBUG 0x0002
296 * Flags for directory block reading and writing functions
298 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
301 * Return flags for the directory iterator functions
303 #define DIRENT_CHANGED 1
304 #define DIRENT_ABORT 2
305 #define DIRENT_ERROR 3
308 * Directory iterator flags
311 #define DIRENT_FLAG_INCLUDE_EMPTY 1
312 #define DIRENT_FLAG_INCLUDE_REMOVED 2
314 #define DIRENT_DOT_FILE 1
315 #define DIRENT_DOT_DOT_FILE 2
316 #define DIRENT_OTHER_FILE 3
317 #define DIRENT_DELETED_FILE 4
320 * Inode scan definitions
322 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
327 #define EXT2_SF_CHK_BADBLOCKS 0x0001
328 #define EXT2_SF_BAD_INODE_BLK 0x0002
329 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
330 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
333 * ext2fs_check_if_mounted flags
335 #define EXT2_MF_MOUNTED 1
336 #define EXT2_MF_ISROOT 2
337 #define EXT2_MF_READONLY 4
338 #define EXT2_MF_SWAP 8
341 * Ext2/linux mode flags. We define them here so that we don't need
342 * to depend on the OS's sys/stat.h, since we may be compiling on a
345 #define LINUX_S_IFMT 00170000
346 #define LINUX_S_IFSOCK 0140000
347 #define LINUX_S_IFLNK 0120000
348 #define LINUX_S_IFREG 0100000
349 #define LINUX_S_IFBLK 0060000
350 #define LINUX_S_IFDIR 0040000
351 #define LINUX_S_IFCHR 0020000
352 #define LINUX_S_IFIFO 0010000
353 #define LINUX_S_ISUID 0004000
354 #define LINUX_S_ISGID 0002000
355 #define LINUX_S_ISVTX 0001000
357 #define LINUX_S_IRWXU 00700
358 #define LINUX_S_IRUSR 00400
359 #define LINUX_S_IWUSR 00200
360 #define LINUX_S_IXUSR 00100
362 #define LINUX_S_IRWXG 00070
363 #define LINUX_S_IRGRP 00040
364 #define LINUX_S_IWGRP 00020
365 #define LINUX_S_IXGRP 00010
367 #define LINUX_S_IRWXO 00007
368 #define LINUX_S_IROTH 00004
369 #define LINUX_S_IWOTH 00002
370 #define LINUX_S_IXOTH 00001
372 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
373 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
374 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
375 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
376 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
377 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
378 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
381 * ext2_icount_t abstraction
383 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
385 typedef struct ext2_icount *ext2_icount_t;
388 * Flags for ext2fs_bmap
393 * Flags for imager.c functions
395 #define IMAGER_FLAG_INODEMAP 1
396 #define IMAGER_FLAG_SPARSEWRITE 2
399 * For checking structure magic numbers...
402 #define EXT2_CHECK_MAGIC(struct, code) \
403 if ((struct)->magic != (code)) return (code)
407 * For ext2 compression support
409 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
410 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
413 * Features supported by this version of the library
415 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
416 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
417 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
418 EXT2_FEATURE_COMPAT_DIR_INDEX|\
419 EXT2_FEATURE_COMPAT_EXT_ATTR)
421 /* This #ifdef is temporary until compression is fully supported */
422 #ifdef ENABLE_COMPRESSION
423 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
424 /* If the below warning bugs you, then have
425 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
426 environment at configure time. */
427 #warning "Compression support is experimental"
429 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
430 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
431 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
432 EXT3_FEATURE_INCOMPAT_RECOVER)
434 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
435 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
436 EXT3_FEATURE_INCOMPAT_RECOVER)
438 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
439 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
441 * function prototypes
445 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
446 ext2fs_inode_bitmap map, ext2_ino_t *ret);
447 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
448 ext2fs_block_bitmap map, blk_t *ret);
449 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
450 blk_t finish, int num,
451 ext2fs_block_bitmap map,
453 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
454 char *block_buf, blk_t *ret);
457 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
458 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
459 int inuse, int isdir);
460 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
463 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
464 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
465 ext2fs_block_bitmap bmap);
468 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
469 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
470 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
471 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
472 ext2_u32_iterate *ret);
473 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
474 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
475 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
476 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
478 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
480 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
482 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
485 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
486 ext2_badblocks_iterate *ret);
487 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
489 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
490 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
491 ext2_badblocks_list *dest);
492 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
493 ext2_badblocks_list bb2);
496 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
497 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
498 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
499 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
500 badblocks_iterate *ret);
501 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
502 extern void badblocks_list_iterate_end(badblocks_iterate iter);
503 extern void badblocks_list_free(badblocks_list bb);
506 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
507 ext2_badblocks_list bb_list);
510 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
511 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
512 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
513 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
514 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
518 ext2fs_generic_bitmap *ret);
519 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
521 ext2fs_block_bitmap *ret);
522 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
524 ext2fs_inode_bitmap *ret);
525 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
526 ext2_ino_t end, ext2_ino_t *oend);
527 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
528 blk_t end, blk_t *oend);
529 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
530 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
531 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
532 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
535 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
539 int (*func)(ext2_filsys fs,
544 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
548 int (*func)(ext2_filsys fs,
550 e2_blkcnt_t blockcnt,
557 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
558 struct ext2_inode *inode,
559 char *block_buf, int bmap_flags,
560 blk_t block, blk_t *phys_blk);
565 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
566 ext2fs_block_bitmap reserve,
567 ext2fs_block_bitmap alloc_map,
572 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
575 extern errcode_t ext2fs_close(ext2_filsys fs);
576 extern errcode_t ext2fs_flush(ext2_filsys fs);
577 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
578 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
581 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
582 ext2fs_block_bitmap bm2);
583 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
584 ext2fs_inode_bitmap bm2);
588 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
589 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
590 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
591 blk_t blk, int blockcnt);
592 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
593 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
596 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
597 blk_t blk, int blockcnt);
598 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
600 extern int ext2fs_dblist_count(ext2_dblist dblist);
604 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
607 int (*func)(ext2_ino_t dir,
609 struct ext2_dir_entry *dirent,
617 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
619 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
620 void *buf, int flags);
621 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
623 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
624 void *buf, int flags);
627 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
629 ext2_dirhash_t *ret_hash,
630 ext2_dirhash_t *ret_minor_hash);
634 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
638 int (*func)(struct ext2_dir_entry *dirent,
644 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
648 int (*func)(ext2_ino_t dir,
650 struct ext2_dir_entry *dirent,
658 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
661 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
664 void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
665 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
666 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
668 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
670 int adjust, __u32 *newcount);
673 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
674 int flags, ext2_file_t *ret);
675 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
676 extern errcode_t ext2fs_file_close(ext2_file_t file);
677 extern errcode_t ext2fs_file_flush(ext2_file_t file);
678 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
679 unsigned int wanted, unsigned int *got);
680 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
681 unsigned int nbytes, unsigned int *written);
682 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
683 int whence, ext2_off_t *ret_pos);
684 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
685 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
688 extern char *ext2fs_find_block_device(dev_t device);
691 extern errcode_t ext2fs_sync_device(int fd, int flushb);
694 extern void ext2fs_free(ext2_filsys fs);
695 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
696 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
697 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
698 extern void ext2fs_free_dblist(ext2_dblist dblist);
699 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
700 extern void ext2fs_u32_list_free(ext2_u32_list bb);
703 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
707 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
708 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
709 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
710 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
711 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
712 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
715 extern errcode_t ext2fs_initialize(const char *name, int flags,
716 struct ext2_super_block *param,
717 io_manager manager, ext2_filsys *ret_fs);
720 extern void ext2fs_free_icount(ext2_icount_t icount);
721 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
722 ext2_icount_t hint, ext2_icount_t *ret);
723 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
725 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
727 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
729 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
731 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
733 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
734 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
737 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
738 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
739 ext2_inode_scan *ret_scan);
740 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
741 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
742 struct ext2_inode *inode);
743 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
745 extern void ext2fs_set_inode_callback
746 (ext2_inode_scan scan,
747 errcode_t (*done_group)(ext2_filsys fs,
748 ext2_inode_scan scan,
751 void *done_group_data);
752 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
754 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
755 struct ext2_inode * inode);
756 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
757 struct ext2_inode * inode);
758 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
759 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
762 extern io_manager inode_io_manager;
763 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
767 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
768 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
769 char *mtpt, int mtlen);
772 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
773 int namelen, char *buf, ext2_ino_t *inode);
774 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
775 const char *name, ext2_ino_t *inode);
776 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
777 const char *name, ext2_ino_t *inode);
778 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
779 ext2_ino_t inode, ext2_ino_t *res_inode);
782 int ext2fs_native_flag(void);
785 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
786 ext2_ino_t parent_ino, char **block);
789 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
793 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
794 __u32 size, int flags,
796 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
797 ext2_filsys journal_dev);
798 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
802 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
803 int block_size, io_manager manager,
804 ext2_filsys *ret_fs);
807 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
811 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
812 ext2_ino_t ino, int flags);
813 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
814 ext2_ino_t ino, int flags);
817 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
818 ext2_badblocks_list *bb_list);
821 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
822 ext2_badblocks_list *bb_list,
824 void (*invalid)(ext2_filsys fs,
828 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
829 ext2_badblocks_list *bb_list,
830 void (*invalid)(ext2_filsys fs,
834 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
836 ext2fs_generic_bitmap bmap);
837 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
838 ext2fs_inode_bitmap bmap);
839 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
840 ext2fs_block_bitmap bmap);
841 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
842 ext2fs_generic_bitmap *dest);
845 extern void ext2fs_swap_super(struct ext2_super_block * super);
846 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
847 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
848 struct ext2_inode *f, int hostorder);
851 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
854 extern int ext2fs_parse_version_string(const char *ver_string);
855 extern int ext2fs_get_library_version(const char **ver_string,
856 const char **date_string);
858 /* write_bb_file.c */
859 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
864 /* inline functions */
865 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
866 extern errcode_t ext2fs_free_mem(void **ptr);
867 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
868 unsigned long size, void **ptr);
869 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
870 extern void ext2fs_mark_changed(ext2_filsys fs);
871 extern int ext2fs_test_changed(ext2_filsys fs);
872 extern void ext2fs_mark_valid(ext2_filsys fs);
873 extern void ext2fs_unmark_valid(ext2_filsys fs);
874 extern int ext2fs_test_valid(ext2_filsys fs);
875 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
876 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
877 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
878 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
879 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
880 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
881 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
882 struct ext2_inode *inode);
885 * The actual inlined functions definitions themselves...
887 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
890 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
891 #ifdef INCLUDE_INLINE_FUNCS
892 #define _INLINE_ extern
895 #define _INLINE_ extern __inline__
896 #else /* For Watcom C */
897 #define _INLINE_ extern inline
901 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
905 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
909 return EXT2_ET_NO_MEMORY;
916 _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
926 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
927 unsigned long size, void **ptr)
931 p = realloc(*ptr, size);
933 return EXT2_ET_NO_MEMORY;
937 #endif /* Custom memory routines */
940 * Mark a filesystem superblock as dirty
942 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
944 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
948 * Mark a filesystem as changed
950 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
952 fs->flags |= EXT2_FLAG_CHANGED;
956 * Check to see if a filesystem has changed
958 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
960 return (fs->flags & EXT2_FLAG_CHANGED);
964 * Mark a filesystem as valid
966 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
968 fs->flags |= EXT2_FLAG_VALID;
972 * Mark a filesystem as NOT valid
974 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
976 fs->flags &= ~EXT2_FLAG_VALID;
980 * Check to see if a filesystem is valid
982 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
984 return (fs->flags & EXT2_FLAG_VALID);
988 * Mark the inode bitmap as dirty
990 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
992 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
996 * Mark the block bitmap as dirty
998 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1000 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1004 * Check to see if a filesystem's inode bitmap is dirty
1006 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1008 return (fs->flags & EXT2_FLAG_IB_DIRTY);
1012 * Check to see if a filesystem's block bitmap is dirty
1014 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1016 return (fs->flags & EXT2_FLAG_BB_DIRTY);
1020 * Return the group # of a block
1022 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1024 return (blk - fs->super->s_first_data_block) /
1025 fs->super->s_blocks_per_group;
1029 * Return the group # of an inode number
1031 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1033 return (ino - 1) / fs->super->s_inodes_per_group;
1036 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1037 struct ext2_inode *inode)
1039 return inode->i_blocks -
1040 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1049 #endif /* _EXT2FS_EXT2FS_H */