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
16 * Non-GNU C compilers won't necessarily understand inline
18 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
19 #define NO_INLINE_FUNCS
23 * Where the master copy of the superblock is located, and how big
24 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
25 * the size of the superblock structure is not necessarily trustworthy
26 * (some versions have the padding set up so that the superblock is
29 #define SUPERBLOCK_OFFSET 1024
30 #define SUPERBLOCK_SIZE 1024
33 * The last ext2fs revision level that this version of the library is
36 #define EXT2_LIB_CURRENT_REV 0
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
44 #if EXT2_FLAT_INCLUDES
48 #if defined(__GNUC__) && defined(__STRICT_ANSI__) && \
49 (((~0UL) == 0xffffffff) || defined(__i386__))
50 typedef __signed__ long long __s64;
51 typedef unsigned long long __u64;
57 typedef __u32 ext2_off_t;
58 typedef __s64 e2_blkcnt_t;
60 #if EXT2_FLAT_INCLUDES
65 #include "et/com_err.h"
66 #include "ext2fs/ext2_io.h"
67 #include "ext2fs/ext2_err.h"
71 * Portability help for Microsoft Visual C++
74 #define EXT2_QSORT_TYPE int __cdecl
76 #define EXT2_QSORT_TYPE int
79 typedef struct struct_ext2_filsys *ext2_filsys;
81 struct ext2fs_struct_generic_bitmap {
88 errcode_t base_error_code;
92 #define EXT2FS_MARK_ERROR 0
93 #define EXT2FS_UNMARK_ERROR 1
94 #define EXT2FS_TEST_ERROR 2
96 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
97 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
98 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
100 #ifdef EXT2_DYNAMIC_REV
101 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
103 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
104 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
108 * badblocks list definitions
111 typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
112 typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
115 typedef struct ext2_struct_badblocks_list *badblocks_list;
116 typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
118 #define BADBLOCKS_FLAG_DIRTY 1
121 * ext2_dblist structure and abstractions (see dblist.c)
123 struct ext2_db_entry {
129 typedef struct ext2_struct_dblist *ext2_dblist;
131 #define DBLIST_ABORT 1
134 * ext2_fileio definitions
137 #define EXT2_FILE_WRITE 0x0001
138 #define EXT2_FILE_CREATE 0x0002
140 #define EXT2_FILE_MASK 0x00FF
142 #define EXT2_FILE_BUF_DIRTY 0x4000
143 #define EXT2_FILE_BUF_VALID 0x2000
145 typedef struct ext2_file *ext2_file_t;
147 #define EXT2_SEEK_SET 0
148 #define EXT2_SEEK_CUR 1
149 #define EXT2_SEEK_END 2
152 * Flags for the ext2_filsys structure
155 #define EXT2_FLAG_RW 0x01
156 #define EXT2_FLAG_CHANGED 0x02
157 #define EXT2_FLAG_DIRTY 0x04
158 #define EXT2_FLAG_VALID 0x08
159 #define EXT2_FLAG_IB_DIRTY 0x10
160 #define EXT2_FLAG_BB_DIRTY 0x20
161 #define EXT2_FLAG_SWAP_BYTES 0x40
162 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
163 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
164 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
165 #define EXT2_FLAG_FORCE 0x400
168 * Special flag in the ext2 inode i_flag field that means that this is
169 * a new inode. (So that ext2_write_inode() can clear extra fields.)
171 #define EXT2_NEW_INODE_FL 0x80000000
173 struct struct_ext2_filsys {
178 struct ext2_super_block * super;
181 dgrp_t group_desc_count;
182 unsigned long desc_blocks;
183 struct ext2_group_desc * group_desc;
184 int inode_blocks_per_group;
185 ext2fs_inode_bitmap inode_map;
186 ext2fs_block_bitmap block_map;
187 errcode_t (*get_blocks)(ext2_filsys fs, ino_t ino, blk_t *blocks);
188 errcode_t (*check_directory)(ext2_filsys fs, ino_t ino);
189 errcode_t (*write_bitmaps)(ext2_filsys fs);
190 errcode_t (*read_inode)(ext2_filsys fs, ino_t ino,
191 struct ext2_inode *inode);
192 errcode_t (*write_inode)(ext2_filsys fs, ino_t ino,
193 struct ext2_inode *inode);
194 badblocks_list badblocks;
196 __u32 stride; /* for mke2fs */
198 * Reserved for future expansion
203 * Reserved for the use of the calling application.
210 struct ext2_inode_cache *icache;
213 #if EXT2_FLAT_INCLUDES
214 #include "e2_bitops.h"
216 #include "ext2fs/bitops.h"
220 * Return flags for the block iterator functions
222 #define BLOCK_CHANGED 1
223 #define BLOCK_ABORT 2
224 #define BLOCK_ERROR 4
227 * Block interate flags
229 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
230 * function should be called on blocks where the block number is zero.
231 * This is used by ext2fs_expand_dir() to be able to add a new block
232 * to an inode. It can also be used for programs that want to be able
233 * to deal with files that contain "holes".
235 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
236 * indirect, doubly indirect, etc. blocks should be called after all
237 * of the blocks containined in the indirect blocks are processed.
238 * This is useful if you are going to be deallocating blocks from an
241 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
242 * called for data blocks only.
244 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
245 * ext2fs_block_iterate2 that large files won't be accepted.
247 #define BLOCK_FLAG_APPEND 1
248 #define BLOCK_FLAG_HOLE 1
249 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
250 #define BLOCK_FLAG_DATA_ONLY 4
252 #define BLOCK_FLAG_NO_LARGE 0x1000
255 * Magic "block count" return values for the block iterator function.
257 #define BLOCK_COUNT_IND (-1)
258 #define BLOCK_COUNT_DIND (-2)
259 #define BLOCK_COUNT_TIND (-3)
260 #define BLOCK_COUNT_TRANSLATOR (-4)
264 * Flags for ext2fs_move_blocks
266 #define EXT2_BMOVE_GET_DBLIST 0x0001
267 #define EXT2_BMOVE_DEBUG 0x0002
271 * Return flags for the directory iterator functions
273 #define DIRENT_CHANGED 1
274 #define DIRENT_ABORT 2
275 #define DIRENT_ERROR 3
278 * Directory iterator flags
281 #define DIRENT_FLAG_INCLUDE_EMPTY 1
284 #define DIRENT_DOT_FILE 1
285 #define DIRENT_DOT_DOT_FILE 2
286 #define DIRENT_OTHER_FILE 3
289 * Inode scan definitions
291 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
296 #define EXT2_SF_CHK_BADBLOCKS 0x0001
297 #define EXT2_SF_BAD_INODE_BLK 0x0002
298 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
299 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
302 * ext2fs_check_if_mounted flags
304 #define EXT2_MF_MOUNTED 1
305 #define EXT2_MF_ISROOT 2
306 #define EXT2_MF_READONLY 4
309 * Ext2/linux mode flags. We define them here so that we don't need
310 * to depend on the OS's sys/stat.h, since we may be compiling on a
313 #define LINUX_S_IFMT 00170000
314 #define LINUX_S_IFSOCK 0140000
315 #define LINUX_S_IFLNK 0120000
316 #define LINUX_S_IFREG 0100000
317 #define LINUX_S_IFBLK 0060000
318 #define LINUX_S_IFDIR 0040000
319 #define LINUX_S_IFCHR 0020000
320 #define LINUX_S_IFIFO 0010000
321 #define LINUX_S_ISUID 0004000
322 #define LINUX_S_ISGID 0002000
323 #define LINUX_S_ISVTX 0001000
325 #define LINUX_S_IRWXU 00700
326 #define LINUX_S_IRUSR 00400
327 #define LINUX_S_IWUSR 00200
328 #define LINUX_S_IXUSR 00100
330 #define LINUX_S_IRWXG 00070
331 #define LINUX_S_IRGRP 00040
332 #define LINUX_S_IWGRP 00020
333 #define LINUX_S_IXGRP 00010
335 #define LINUX_S_IRWXO 00007
336 #define LINUX_S_IROTH 00004
337 #define LINUX_S_IWOTH 00002
338 #define LINUX_S_IXOTH 00001
340 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
341 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
342 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
343 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
344 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
345 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
346 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
349 * ext2_icount_t abstraction
351 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
353 typedef struct ext2_icount *ext2_icount_t;
356 * Flags for ext2fs_bmap
361 * For checking structure magic numbers...
364 #define EXT2_CHECK_MAGIC(struct, code) \
365 if ((struct)->magic != (code)) return (code)
369 * The ext2fs library private definition of the ext2 superblock, so we
370 * don't have to depend on the kernel's definition of the superblock,
371 * which might not have the latest features.
374 __u32 s_inodes_count; /* Inodes count */
375 __u32 s_blocks_count; /* Blocks count */
376 __u32 s_r_blocks_count; /* Reserved blocks count */
377 __u32 s_free_blocks_count; /* Free blocks count */
378 __u32 s_free_inodes_count; /* Free inodes count */
379 __u32 s_first_data_block; /* First Data Block */
380 __u32 s_log_block_size; /* Block size */
381 __s32 s_log_frag_size; /* Fragment size */
382 __u32 s_blocks_per_group; /* # Blocks per group */
383 __u32 s_frags_per_group; /* # Fragments per group */
384 __u32 s_inodes_per_group; /* # Inodes per group */
385 __u32 s_mtime; /* Mount time */
386 __u32 s_wtime; /* Write time */
387 __u16 s_mnt_count; /* Mount count */
388 __s16 s_max_mnt_count; /* Maximal mount count */
389 __u16 s_magic; /* Magic signature */
390 __u16 s_state; /* File system state */
391 __u16 s_errors; /* Behaviour when detecting errors */
392 __u16 s_minor_rev_level; /* minor revision level */
393 __u32 s_lastcheck; /* time of last check */
394 __u32 s_checkinterval; /* max. time between checks */
395 __u32 s_creator_os; /* OS */
396 __u32 s_rev_level; /* Revision level */
397 __u16 s_def_resuid; /* Default uid for reserved blocks */
398 __u16 s_def_resgid; /* Default gid for reserved blocks */
400 * These fields are for EXT2_DYNAMIC_REV superblocks only.
402 * Note: the difference between the compatible feature set and
403 * the incompatible feature set is that if there is a bit set
404 * in the incompatible feature set that the kernel doesn't
405 * know about, it should refuse to mount the filesystem.
407 * e2fsck's requirements are more strict; if it doesn't know
408 * about a feature in either the compatible or incompatible
409 * feature set, it must abort and not try to meddle with
410 * things it doesn't understand...
412 __u32 s_first_ino; /* First non-reserved inode */
413 __u16 s_inode_size; /* size of inode structure */
414 __u16 s_block_group_nr; /* block group # of this superblock */
415 __u32 s_feature_compat; /* compatible feature set */
416 __u32 s_feature_incompat; /* incompatible feature set */
417 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
418 __u8 s_uuid[16]; /* 128-bit uuid for volume */
419 char s_volume_name[16]; /* volume name */
420 char s_last_mounted[64]; /* directory where last mounted */
421 __u32 s_algorithm_usage_bitmap; /* For compression */
423 * Performance hints. Directory preallocation should only
424 * happen if the EXT2_COMPAT_PREALLOC flag is on.
426 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
427 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
430 * Journaling support.
432 __u8 s_journal_uuid[16]; /* uuid of journal superblock */
433 __u32 s_journal_inum; /* inode number of journal file */
435 __u32 s_reserved[199]; /* Padding to the end of the block */
439 * Feature set definitions (that might not be in ext2_fs.h
442 #ifndef EXT2_FEATURE_COMPAT_DIR_PREALLOC
443 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
446 #ifndef EXT2_FEATURE_COMPAT_IMAGIC_INODES /* for AFS, etc. */
447 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
448 #define EXT2_IMAGIC_FL 0x00002000
451 #ifndef EXT3_FEATURE_COMPAT_HAS_JOURNAL
452 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
455 #ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
456 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
459 #ifndef EXT2_FEATURE_RO_COMPAT_LARGE_FILE
460 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
461 #define i_size_high i_dir_acl
464 #ifndef EXT2_FEATURE_RO_COMPAT_BTREE_DIR
465 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
468 #ifndef EXT2_FEATURE_INCOMPAT_COMPRESSION
469 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
472 #ifndef EXT2_FEATURE_INCOMPAT_FILETYPE
473 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
476 #ifndef EXT3_FEATURE_INCOMPAT_RECOVER
477 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
480 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
481 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
482 EXT3_FEATURE_COMPAT_HAS_JOURNAL)
483 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
484 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
485 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
487 * function prototypes
491 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
492 ext2fs_inode_bitmap map, ino_t *ret);
493 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
494 ext2fs_block_bitmap map, blk_t *ret);
495 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
496 blk_t finish, int num,
497 ext2fs_block_bitmap map,
499 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
500 char *block_buf, blk_t *ret);
503 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
504 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
505 ext2fs_block_bitmap bmap);
508 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
510 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
512 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
515 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
516 ext2_badblocks_iterate *ret);
517 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
519 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
520 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
521 ext2_badblocks_list *dest);
524 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
525 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
526 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
527 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
528 badblocks_iterate *ret);
529 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
530 extern void badblocks_list_iterate_end(badblocks_iterate iter);
531 extern void badblocks_list_free(badblocks_list bb);
534 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
535 ext2_badblocks_list bb_list);
538 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
539 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
540 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
541 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
542 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
546 ext2fs_generic_bitmap *ret);
547 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
549 ext2fs_block_bitmap *ret);
550 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
552 ext2fs_inode_bitmap *ret);
553 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
554 ino_t end, ino_t *oend);
555 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
556 blk_t end, blk_t *oend);
557 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
558 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
559 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
560 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
563 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
567 int (*func)(ext2_filsys fs,
572 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
576 int (*func)(ext2_filsys fs,
578 e2_blkcnt_t blockcnt,
585 extern errcode_t ext2fs_bmap(ext2_filsys fs, ino_t ino,
586 struct ext2_inode *inode,
587 char *block_buf, int bmap_flags,
588 blk_t block, blk_t *phys_blk);
593 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
594 ext2fs_block_bitmap reserve,
595 ext2fs_block_bitmap alloc_map,
600 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
603 extern errcode_t ext2fs_close(ext2_filsys fs);
604 extern errcode_t ext2fs_flush(ext2_filsys fs);
605 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
608 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
609 ext2fs_block_bitmap bm2);
610 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
611 ext2fs_inode_bitmap bm2);
615 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs);
616 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
617 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino,
618 blk_t blk, int blockcnt);
619 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
620 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
623 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino,
624 blk_t blk, int blockcnt);
625 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
627 extern int ext2fs_dblist_count(ext2_dblist dblist);
631 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
634 int (*func)(ino_t dir,
636 struct ext2_dir_entry *dirent,
644 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
646 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
650 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
654 int (*func)(struct ext2_dir_entry *dirent,
662 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
665 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir);
668 extern errcode_t ext2fs_file_open(ext2_filsys fs, ino_t ino,
669 int flags, ext2_file_t *ret);
670 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
671 extern errcode_t ext2fs_file_close(ext2_file_t file);
672 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
673 unsigned int wanted, unsigned int *got);
674 extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
675 unsigned int nbytes, unsigned int *written);
676 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
677 int whence, ext2_off_t *ret_pos);
678 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
679 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
682 extern void ext2fs_free(ext2_filsys fs);
683 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
684 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
685 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
686 extern void ext2fs_free_dblist(ext2_dblist dblist);
687 extern void ext2fs_badblocks_list_free(badblocks_list bb);
690 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
694 extern errcode_t ext2fs_initialize(const char *name, int flags,
695 struct ext2_super_block *param,
696 io_manager manager, ext2_filsys *ret_fs);
699 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
700 ext2_inode_scan *ret_scan);
701 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
702 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino,
703 struct ext2_inode *inode);
704 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
706 extern void ext2fs_set_inode_callback
707 (ext2_inode_scan scan,
708 errcode_t (*done_group)(ext2_filsys fs,
709 ext2_inode_scan scan,
712 void *done_group_data);
713 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
715 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
716 struct ext2_inode * inode);
717 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
718 struct ext2_inode * inode);
719 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks);
720 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino);
723 extern void ext2fs_free_icount(ext2_icount_t icount);
724 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
725 ext2_icount_t hint, ext2_icount_t *ret);
726 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
728 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino,
730 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
732 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
734 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
736 extern ino_t ext2fs_get_icount_size(ext2_icount_t icount);
738 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
742 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
745 extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name,
746 int namelen, char *buf, ino_t *inode);
747 extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd,
748 const char *name, ino_t *inode);
749 errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd,
750 const char *name, ino_t *inode);
751 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd,
752 ino_t inode, ino_t *res_inode);
755 int ext2fs_native_flag(void);
758 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino,
759 ino_t parent_ino, char **block);
762 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum,
766 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
767 int block_size, io_manager manager,
768 ext2_filsys *ret_fs);
771 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino,
775 errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name,
776 ino_t ino, int flags);
777 errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name,
778 ino_t ino, int flags);
781 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
782 ext2_badblocks_list *bb_list);
786 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
787 ext2_badblocks_list *bb_list,
788 void (*invalid)(ext2_filsys fs,
793 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
795 ext2fs_generic_bitmap bmap);
796 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
797 ext2fs_inode_bitmap bmap);
798 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
799 ext2fs_block_bitmap bmap);
800 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
801 ext2fs_generic_bitmap *dest);
804 extern void ext2fs_swap_super(struct ext2_super_block * super);
805 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
806 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
807 struct ext2_inode *f, int hostorder);
810 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
813 extern int ext2fs_parse_version_string(const char *ver_string);
814 extern int ext2fs_get_library_version(const char **ver_string,
815 const char **date_string);
817 /* inline functions */
818 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
819 extern errcode_t ext2fs_free_mem(void **ptr);
820 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
821 unsigned long size, void **ptr);
822 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
823 extern void ext2fs_mark_changed(ext2_filsys fs);
824 extern int ext2fs_test_changed(ext2_filsys fs);
825 extern void ext2fs_mark_valid(ext2_filsys fs);
826 extern void ext2fs_unmark_valid(ext2_filsys fs);
827 extern int ext2fs_test_valid(ext2_filsys fs);
828 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
829 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
830 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
831 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
832 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
833 extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino);
836 * The actual inlined functions definitions themselves...
838 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
841 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
842 #ifdef INCLUDE_INLINE_FUNCS
843 #define _INLINE_ extern
846 #define _INLINE_ extern __inline__
847 #else /* For Watcom C */
848 #define _INLINE_ extern inline
852 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
856 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
860 return EXT2_ET_NO_MEMORY;
867 _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
877 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
878 unsigned long size, void **ptr)
882 p = realloc(*ptr, size);
884 return EXT2_ET_NO_MEMORY;
888 #endif /* Custom memory routines */
891 * Mark a filesystem superblock as dirty
893 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
895 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
899 * Mark a filesystem as changed
901 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
903 fs->flags |= EXT2_FLAG_CHANGED;
907 * Check to see if a filesystem has changed
909 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
911 return (fs->flags & EXT2_FLAG_CHANGED);
915 * Mark a filesystem as valid
917 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
919 fs->flags |= EXT2_FLAG_VALID;
923 * Mark a filesystem as NOT valid
925 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
927 fs->flags &= ~EXT2_FLAG_VALID;
931 * Check to see if a filesystem is valid
933 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
935 return (fs->flags & EXT2_FLAG_VALID);
939 * Mark the inode bitmap as dirty
941 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
943 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
947 * Mark the block bitmap as dirty
949 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
951 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
955 * Check to see if a filesystem's inode bitmap is dirty
957 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
959 return (fs->flags & EXT2_FLAG_IB_DIRTY);
963 * Check to see if a filesystem's block bitmap is dirty
965 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
967 return (fs->flags & EXT2_FLAG_BB_DIRTY);
971 * Return the group # of a block
973 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
975 return (blk - fs->super->s_first_data_block) /
976 fs->super->s_blocks_per_group;
980 * Return the group # of an inode number
982 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino)
984 return (ino - 1) / fs->super->s_inodes_per_group;
989 #endif /* _EXT2FS_EXT2FS_H */