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_badblocks_list *ext2_badblocks_list;
122 typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
125 typedef struct ext2_struct_badblocks_list *badblocks_list;
126 typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
128 #define BADBLOCKS_FLAG_DIRTY 1
131 * ext2_dblist structure and abstractions (see dblist.c)
133 struct ext2_db_entry {
139 typedef struct ext2_struct_dblist *ext2_dblist;
141 #define DBLIST_ABORT 1
144 * ext2_fileio definitions
147 #define EXT2_FILE_WRITE 0x0001
148 #define EXT2_FILE_CREATE 0x0002
150 #define EXT2_FILE_MASK 0x00FF
152 #define EXT2_FILE_BUF_DIRTY 0x4000
153 #define EXT2_FILE_BUF_VALID 0x2000
155 typedef struct ext2_file *ext2_file_t;
157 #define EXT2_SEEK_SET 0
158 #define EXT2_SEEK_CUR 1
159 #define EXT2_SEEK_END 2
162 * Flags for the ext2_filsys structure and for ext2fs_open()
164 #define EXT2_FLAG_RW 0x01
165 #define EXT2_FLAG_CHANGED 0x02
166 #define EXT2_FLAG_DIRTY 0x04
167 #define EXT2_FLAG_VALID 0x08
168 #define EXT2_FLAG_IB_DIRTY 0x10
169 #define EXT2_FLAG_BB_DIRTY 0x20
170 #define EXT2_FLAG_SWAP_BYTES 0x40
171 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
172 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
173 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
174 #define EXT2_FLAG_FORCE 0x400
175 #define EXT2_FLAG_SUPER_ONLY 0x800
176 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
177 #define EXT2_FLAG_IMAGE_FILE 0x2000
180 * Special flag in the ext2 inode i_flag field that means that this is
181 * a new inode. (So that ext2_write_inode() can clear extra fields.)
183 #define EXT2_NEW_INODE_FL 0x80000000
186 * Flags for mkjournal
188 * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
190 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001
192 struct struct_ext2_filsys {
197 struct ext2_super_block * super;
200 dgrp_t group_desc_count;
201 unsigned long desc_blocks;
202 struct ext2_group_desc * group_desc;
203 int inode_blocks_per_group;
204 ext2fs_inode_bitmap inode_map;
205 ext2fs_block_bitmap block_map;
206 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
207 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
208 errcode_t (*write_bitmaps)(ext2_filsys fs);
209 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
210 struct ext2_inode *inode);
211 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
212 struct ext2_inode *inode);
213 badblocks_list badblocks;
215 __u32 stride; /* for mke2fs */
216 struct ext2_super_block * orig_super;
217 struct ext2_image_hdr * image_header;
220 * Reserved for future expansion
225 * Reserved for the use of the calling application.
232 struct ext2_inode_cache *icache;
235 #if EXT2_FLAT_INCLUDES
236 #include "e2_bitops.h"
238 #include <ext2fs/bitops.h>
242 * Return flags for the block iterator functions
244 #define BLOCK_CHANGED 1
245 #define BLOCK_ABORT 2
246 #define BLOCK_ERROR 4
249 * Block interate flags
251 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
252 * function should be called on blocks where the block number is zero.
253 * This is used by ext2fs_expand_dir() to be able to add a new block
254 * to an inode. It can also be used for programs that want to be able
255 * to deal with files that contain "holes".
257 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
258 * indirect, doubly indirect, etc. blocks should be called after all
259 * of the blocks containined in the indirect blocks are processed.
260 * This is useful if you are going to be deallocating blocks from an
263 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
264 * called for data blocks only.
266 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
267 * ext2fs_block_iterate2 that large files won't be accepted.
269 #define BLOCK_FLAG_APPEND 1
270 #define BLOCK_FLAG_HOLE 1
271 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
272 #define BLOCK_FLAG_DATA_ONLY 4
274 #define BLOCK_FLAG_NO_LARGE 0x1000
277 * Magic "block count" return values for the block iterator function.
279 #define BLOCK_COUNT_IND (-1)
280 #define BLOCK_COUNT_DIND (-2)
281 #define BLOCK_COUNT_TIND (-3)
282 #define BLOCK_COUNT_TRANSLATOR (-4)
286 * Flags for ext2fs_move_blocks
288 #define EXT2_BMOVE_GET_DBLIST 0x0001
289 #define EXT2_BMOVE_DEBUG 0x0002
293 * Flags for directory block reading and writing functions
295 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
298 * Return flags for the directory iterator functions
300 #define DIRENT_CHANGED 1
301 #define DIRENT_ABORT 2
302 #define DIRENT_ERROR 3
305 * Directory iterator flags
308 #define DIRENT_FLAG_INCLUDE_EMPTY 1
309 #define DIRENT_FLAG_INCLUDE_REMOVED 2
311 #define DIRENT_DOT_FILE 1
312 #define DIRENT_DOT_DOT_FILE 2
313 #define DIRENT_OTHER_FILE 3
314 #define DIRENT_DELETED_FILE 4
317 * Inode scan definitions
319 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
324 #define EXT2_SF_CHK_BADBLOCKS 0x0001
325 #define EXT2_SF_BAD_INODE_BLK 0x0002
326 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
327 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
330 * ext2fs_check_if_mounted flags
332 #define EXT2_MF_MOUNTED 1
333 #define EXT2_MF_ISROOT 2
334 #define EXT2_MF_READONLY 4
335 #define EXT2_MF_SWAP 8
338 * Ext2/linux mode flags. We define them here so that we don't need
339 * to depend on the OS's sys/stat.h, since we may be compiling on a
342 #define LINUX_S_IFMT 00170000
343 #define LINUX_S_IFSOCK 0140000
344 #define LINUX_S_IFLNK 0120000
345 #define LINUX_S_IFREG 0100000
346 #define LINUX_S_IFBLK 0060000
347 #define LINUX_S_IFDIR 0040000
348 #define LINUX_S_IFCHR 0020000
349 #define LINUX_S_IFIFO 0010000
350 #define LINUX_S_ISUID 0004000
351 #define LINUX_S_ISGID 0002000
352 #define LINUX_S_ISVTX 0001000
354 #define LINUX_S_IRWXU 00700
355 #define LINUX_S_IRUSR 00400
356 #define LINUX_S_IWUSR 00200
357 #define LINUX_S_IXUSR 00100
359 #define LINUX_S_IRWXG 00070
360 #define LINUX_S_IRGRP 00040
361 #define LINUX_S_IWGRP 00020
362 #define LINUX_S_IXGRP 00010
364 #define LINUX_S_IRWXO 00007
365 #define LINUX_S_IROTH 00004
366 #define LINUX_S_IWOTH 00002
367 #define LINUX_S_IXOTH 00001
369 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
370 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
371 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
372 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
373 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
374 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
375 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
378 * ext2_icount_t abstraction
380 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
382 typedef struct ext2_icount *ext2_icount_t;
385 * Flags for ext2fs_bmap
390 * Flags for imager.c functions
392 #define IMAGER_FLAG_INODEMAP 1
393 #define IMAGER_FLAG_SPARSEWRITE 2
396 * For checking structure magic numbers...
399 #define EXT2_CHECK_MAGIC(struct, code) \
400 if ((struct)->magic != (code)) return (code)
404 * For ext2 compression support
406 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
407 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
410 * Features supported by this version of the library
412 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
413 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
414 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
415 EXT2_FEATURE_COMPAT_DIR_INDEX|\
416 EXT2_FEATURE_COMPAT_EXT_ATTR)
418 /* This #ifdef is temporary until compression is fully supported */
419 #ifdef ENABLE_COMPRESSION
420 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
421 /* If the below warning bugs you, then have
422 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
423 environment at configure time. */
424 #warning "Compression support is experimental"
426 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
427 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
428 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
429 EXT3_FEATURE_INCOMPAT_RECOVER)
431 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
432 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
433 EXT3_FEATURE_INCOMPAT_RECOVER)
435 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
436 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
438 * function prototypes
442 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
443 ext2fs_inode_bitmap map, ext2_ino_t *ret);
444 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
445 ext2fs_block_bitmap map, blk_t *ret);
446 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
447 blk_t finish, int num,
448 ext2fs_block_bitmap map,
450 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
451 char *block_buf, blk_t *ret);
454 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
455 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
456 int inuse, int isdir);
457 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
460 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
461 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
462 ext2fs_block_bitmap bmap);
465 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
467 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
469 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
472 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
473 ext2_badblocks_iterate *ret);
474 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
476 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
477 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
478 ext2_badblocks_list *dest);
479 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
480 ext2_badblocks_list bb2);
483 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
484 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
485 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
486 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
487 badblocks_iterate *ret);
488 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
489 extern void badblocks_list_iterate_end(badblocks_iterate iter);
490 extern void badblocks_list_free(badblocks_list bb);
493 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
494 ext2_badblocks_list bb_list);
497 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
498 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
499 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
500 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
501 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
505 ext2fs_generic_bitmap *ret);
506 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
508 ext2fs_block_bitmap *ret);
509 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
511 ext2fs_inode_bitmap *ret);
512 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
513 ext2_ino_t end, ext2_ino_t *oend);
514 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
515 blk_t end, blk_t *oend);
516 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
517 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
518 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
519 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
522 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
526 int (*func)(ext2_filsys fs,
531 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
535 int (*func)(ext2_filsys fs,
537 e2_blkcnt_t blockcnt,
544 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
545 struct ext2_inode *inode,
546 char *block_buf, int bmap_flags,
547 blk_t block, blk_t *phys_blk);
552 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
553 ext2fs_block_bitmap reserve,
554 ext2fs_block_bitmap alloc_map,
559 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
562 extern errcode_t ext2fs_close(ext2_filsys fs);
563 extern errcode_t ext2fs_flush(ext2_filsys fs);
564 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
565 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
568 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
569 ext2fs_block_bitmap bm2);
570 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
571 ext2fs_inode_bitmap bm2);
575 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
576 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
577 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
578 blk_t blk, int blockcnt);
579 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
580 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
583 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
584 blk_t blk, int blockcnt);
585 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
587 extern int ext2fs_dblist_count(ext2_dblist dblist);
591 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
594 int (*func)(ext2_ino_t dir,
596 struct ext2_dir_entry *dirent,
604 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
606 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
607 void *buf, int flags);
608 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
610 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
611 void *buf, int flags);
614 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
616 ext2_dirhash_t *ret_hash,
617 ext2_dirhash_t *ret_minor_hash);
621 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
625 int (*func)(struct ext2_dir_entry *dirent,
631 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
635 int (*func)(ext2_ino_t dir,
637 struct ext2_dir_entry *dirent,
645 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
648 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
651 void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
652 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
653 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *buf);
655 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
656 int flags, ext2_file_t *ret);
657 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
658 extern errcode_t ext2fs_file_close(ext2_file_t file);
659 extern errcode_t ext2fs_file_flush(ext2_file_t file);
660 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
661 unsigned int wanted, unsigned int *got);
662 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
663 unsigned int nbytes, unsigned int *written);
664 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
665 int whence, ext2_off_t *ret_pos);
666 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
667 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
670 extern char *ext2fs_find_block_device(dev_t device);
673 extern errcode_t ext2fs_sync_device(int fd, int flushb);
676 extern void ext2fs_free(ext2_filsys fs);
677 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
678 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
679 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
680 extern void ext2fs_free_dblist(ext2_dblist dblist);
681 extern void ext2fs_badblocks_list_free(badblocks_list bb);
684 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
688 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
689 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
690 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
691 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
692 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
693 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
696 extern errcode_t ext2fs_initialize(const char *name, int flags,
697 struct ext2_super_block *param,
698 io_manager manager, ext2_filsys *ret_fs);
701 extern void ext2fs_free_icount(ext2_icount_t icount);
702 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
703 ext2_icount_t hint, ext2_icount_t *ret);
704 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
706 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
708 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
710 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
712 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
714 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
715 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
718 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
719 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
720 ext2_inode_scan *ret_scan);
721 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
722 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
723 struct ext2_inode *inode);
724 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
726 extern void ext2fs_set_inode_callback
727 (ext2_inode_scan scan,
728 errcode_t (*done_group)(ext2_filsys fs,
729 ext2_inode_scan scan,
732 void *done_group_data);
733 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
735 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
736 struct ext2_inode * inode);
737 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
738 struct ext2_inode * inode);
739 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
740 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
743 extern io_manager inode_io_manager;
744 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
748 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
749 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
750 char *mtpt, int mtlen);
753 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
754 int namelen, char *buf, ext2_ino_t *inode);
755 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
756 const char *name, ext2_ino_t *inode);
757 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
758 const char *name, ext2_ino_t *inode);
759 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
760 ext2_ino_t inode, ext2_ino_t *res_inode);
763 int ext2fs_native_flag(void);
766 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
767 ext2_ino_t parent_ino, char **block);
770 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
774 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
775 __u32 size, int flags,
777 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
778 ext2_filsys journal_dev);
779 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
783 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
784 int block_size, io_manager manager,
785 ext2_filsys *ret_fs);
788 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
792 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
793 ext2_ino_t ino, int flags);
794 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
795 ext2_ino_t ino, int flags);
798 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
799 ext2_badblocks_list *bb_list);
802 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
803 ext2_badblocks_list *bb_list,
805 void (*invalid)(ext2_filsys fs,
809 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
810 ext2_badblocks_list *bb_list,
811 void (*invalid)(ext2_filsys fs,
815 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
817 ext2fs_generic_bitmap bmap);
818 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
819 ext2fs_inode_bitmap bmap);
820 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
821 ext2fs_block_bitmap bmap);
822 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
823 ext2fs_generic_bitmap *dest);
826 extern void ext2fs_swap_super(struct ext2_super_block * super);
827 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
828 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
829 struct ext2_inode *f, int hostorder);
832 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
835 extern int ext2fs_parse_version_string(const char *ver_string);
836 extern int ext2fs_get_library_version(const char **ver_string,
837 const char **date_string);
839 /* write_bb_file.c */
840 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
845 /* inline functions */
846 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
847 extern errcode_t ext2fs_free_mem(void **ptr);
848 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
849 unsigned long size, void **ptr);
850 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
851 extern void ext2fs_mark_changed(ext2_filsys fs);
852 extern int ext2fs_test_changed(ext2_filsys fs);
853 extern void ext2fs_mark_valid(ext2_filsys fs);
854 extern void ext2fs_unmark_valid(ext2_filsys fs);
855 extern int ext2fs_test_valid(ext2_filsys fs);
856 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
857 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
858 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
859 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
860 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
861 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
864 * The actual inlined functions definitions themselves...
866 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
869 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
870 #ifdef INCLUDE_INLINE_FUNCS
871 #define _INLINE_ extern
874 #define _INLINE_ extern __inline__
875 #else /* For Watcom C */
876 #define _INLINE_ extern inline
880 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
884 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
888 return EXT2_ET_NO_MEMORY;
895 _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
905 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
906 unsigned long size, void **ptr)
910 p = realloc(*ptr, size);
912 return EXT2_ET_NO_MEMORY;
916 #endif /* Custom memory routines */
919 * Mark a filesystem superblock as dirty
921 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
923 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
927 * Mark a filesystem as changed
929 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
931 fs->flags |= EXT2_FLAG_CHANGED;
935 * Check to see if a filesystem has changed
937 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
939 return (fs->flags & EXT2_FLAG_CHANGED);
943 * Mark a filesystem as valid
945 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
947 fs->flags |= EXT2_FLAG_VALID;
951 * Mark a filesystem as NOT valid
953 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
955 fs->flags &= ~EXT2_FLAG_VALID;
959 * Check to see if a filesystem is valid
961 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
963 return (fs->flags & EXT2_FLAG_VALID);
967 * Mark the inode bitmap as dirty
969 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
971 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
975 * Mark the block bitmap as dirty
977 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
979 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
983 * Check to see if a filesystem's inode bitmap is dirty
985 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
987 return (fs->flags & EXT2_FLAG_IB_DIRTY);
991 * Check to see if a filesystem's block bitmap is dirty
993 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
995 return (fs->flags & EXT2_FLAG_BB_DIRTY);
999 * Return the group # of a block
1001 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1003 return (blk - fs->super->s_first_data_block) /
1004 fs->super->s_blocks_per_group;
1008 * Return the group # of an inode number
1010 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1012 return (ino - 1) / fs->super->s_inodes_per_group;
1021 #endif /* _EXT2FS_EXT2FS_H */