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
47 #include <asm/types.h>
48 #if (defined(__GNUC__) && defined(__STRICT_ANSI__) && ((~0UL) == 0xffffffff))
49 typedef __signed__ long long __s64;
50 typedef unsigned long long __u64;
55 typedef unsigned int dgrp_t;
56 typedef __u32 ext2_off_t;
57 typedef __s64 e2_blkcnt_t;
59 #if EXT2_FLAT_INCLUDES
64 #include "et/com_err.h"
65 #include "ext2fs/ext2_io.h"
66 #include "ext2fs/ext2_err.h"
70 * Portability help for Microsoft Visual C++
73 #define EXT2_QSORT_TYPE int __cdecl
75 #define EXT2_QSORT_TYPE int
78 typedef struct struct_ext2_filsys *ext2_filsys;
80 struct ext2fs_struct_generic_bitmap {
87 errcode_t base_error_code;
91 #define EXT2FS_MARK_ERROR 0
92 #define EXT2FS_UNMARK_ERROR 1
93 #define EXT2FS_TEST_ERROR 2
95 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
96 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
97 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
99 #ifdef EXT2_DYNAMIC_REV
100 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
102 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
103 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
107 * badblocks list definitions
110 typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
111 typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
114 typedef struct ext2_struct_badblocks_list *badblocks_list;
115 typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
117 #define BADBLOCKS_FLAG_DIRTY 1
120 * ext2_dblist structure and abstractions (see dblist.c)
122 struct ext2_db_entry {
128 typedef struct ext2_struct_dblist *ext2_dblist;
130 #define DBLIST_ABORT 1
133 * ext2_fileio definitions
136 #define EXT2_FILE_WRITE 0x0001
137 #define EXT2_FILE_CREATE 0x0002
139 #define EXT2_FILE_MASK 0x00FF
141 #define EXT2_FILE_BUF_DIRTY 0x4000
142 #define EXT2_FILE_BUF_VALID 0x2000
144 typedef struct ext2_file *ext2_file_t;
146 #define EXT2_SEEK_SET 0
147 #define EXT2_SEEK_CUR 1
148 #define EXT2_SEEK_END 2
151 * Flags for the ext2_filsys structure
154 #define EXT2_FLAG_RW 0x01
155 #define EXT2_FLAG_CHANGED 0x02
156 #define EXT2_FLAG_DIRTY 0x04
157 #define EXT2_FLAG_VALID 0x08
158 #define EXT2_FLAG_IB_DIRTY 0x10
159 #define EXT2_FLAG_BB_DIRTY 0x20
160 #define EXT2_FLAG_SWAP_BYTES 0x40
161 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
162 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
163 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
164 #define EXT2_FLAG_FORCE 0x400
167 * Special flag in the ext2 inode i_flag field that means that this is
168 * a new inode. (So that ext2_write_inode() can clear extra fields.)
170 #define EXT2_NEW_INODE_FL 0x80000000
172 struct struct_ext2_filsys {
177 struct ext2_super_block * super;
180 unsigned long group_desc_count;
181 unsigned long desc_blocks;
182 struct ext2_group_desc * group_desc;
183 int inode_blocks_per_group;
184 ext2fs_inode_bitmap inode_map;
185 ext2fs_block_bitmap block_map;
186 errcode_t (*get_blocks)(ext2_filsys fs, ino_t ino, blk_t *blocks);
187 errcode_t (*check_directory)(ext2_filsys fs, ino_t ino);
188 errcode_t (*write_bitmaps)(ext2_filsys fs);
189 errcode_t (*read_inode)(ext2_filsys fs, ino_t ino,
190 struct ext2_inode *inode);
191 errcode_t (*write_inode)(ext2_filsys fs, ino_t ino,
192 struct ext2_inode *inode);
193 badblocks_list badblocks;
195 __u32 stride; /* for mke2fs */
197 * Reserved for future expansion
202 * Reserved for the use of the calling application.
209 struct ext2_inode_cache *icache;
212 #if EXT2_FLAT_INCLUDES
213 #include "e2_bitops.h"
215 #include "ext2fs/bitops.h"
219 * Return flags for the block iterator functions
221 #define BLOCK_CHANGED 1
222 #define BLOCK_ABORT 2
223 #define BLOCK_ERROR 4
226 * Block interate flags
228 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
229 * function should be called on blocks where the block number is zero.
230 * This is used by ext2fs_expand_dir() to be able to add a new block
231 * to an inode. It can also be used for programs that want to be able
232 * to deal with files that contain "holes".
234 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
235 * indirect, doubly indirect, etc. blocks should be called after all
236 * of the blocks containined in the indirect blocks are processed.
237 * This is useful if you are going to be deallocating blocks from an
240 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
241 * called for data blocks only.
243 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
244 * ext2fs_block_iterate2 that large files won't be accepted.
246 #define BLOCK_FLAG_APPEND 1
247 #define BLOCK_FLAG_HOLE 1
248 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
249 #define BLOCK_FLAG_DATA_ONLY 4
251 #define BLOCK_FLAG_NO_LARGE 0x1000
254 * Magic "block count" return values for the block iterator function.
256 #define BLOCK_COUNT_IND (-1)
257 #define BLOCK_COUNT_DIND (-2)
258 #define BLOCK_COUNT_TIND (-3)
259 #define BLOCK_COUNT_TRANSLATOR (-4)
263 * Flags for ext2fs_move_blocks
265 #define EXT2_BMOVE_GET_DBLIST 0x0001
266 #define EXT2_BMOVE_DEBUG 0x0002
270 * Return flags for the directory iterator functions
272 #define DIRENT_CHANGED 1
273 #define DIRENT_ABORT 2
274 #define DIRENT_ERROR 3
277 * Directory iterator flags
280 #define DIRENT_FLAG_INCLUDE_EMPTY 1
283 #define DIRENT_DOT_FILE 1
284 #define DIRENT_DOT_DOT_FILE 2
285 #define DIRENT_OTHER_FILE 3
288 * Inode scan definitions
290 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
295 #define EXT2_SF_CHK_BADBLOCKS 0x0001
296 #define EXT2_SF_BAD_INODE_BLK 0x0002
297 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
298 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
301 * ext2fs_check_if_mounted flags
303 #define EXT2_MF_MOUNTED 1
304 #define EXT2_MF_ISROOT 2
305 #define EXT2_MF_READONLY 4
308 * Ext2/linux mode flags. We define them here so that we don't need
309 * to depend on the OS's sys/stat.h, since we may be compiling on a
312 #define LINUX_S_IFMT 00170000
313 #define LINUX_S_IFSOCK 0140000
314 #define LINUX_S_IFLNK 0120000
315 #define LINUX_S_IFREG 0100000
316 #define LINUX_S_IFBLK 0060000
317 #define LINUX_S_IFDIR 0040000
318 #define LINUX_S_IFCHR 0020000
319 #define LINUX_S_IFIFO 0010000
320 #define LINUX_S_ISUID 0004000
321 #define LINUX_S_ISGID 0002000
322 #define LINUX_S_ISVTX 0001000
324 #define LINUX_S_IRWXU 00700
325 #define LINUX_S_IRUSR 00400
326 #define LINUX_S_IWUSR 00200
327 #define LINUX_S_IXUSR 00100
329 #define LINUX_S_IRWXG 00070
330 #define LINUX_S_IRGRP 00040
331 #define LINUX_S_IWGRP 00020
332 #define LINUX_S_IXGRP 00010
334 #define LINUX_S_IRWXO 00007
335 #define LINUX_S_IROTH 00004
336 #define LINUX_S_IWOTH 00002
337 #define LINUX_S_IXOTH 00001
339 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
340 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
341 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
342 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
343 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
344 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
345 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
348 * ext2_icount_t abstraction
350 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
352 typedef struct ext2_icount *ext2_icount_t;
355 * Flags for ext2fs_bmap
360 * For checking structure magic numbers...
363 #define EXT2_CHECK_MAGIC(struct, code) \
364 if ((struct)->magic != (code)) return (code)
368 * The ext2fs library private definition of the ext2 superblock, so we
369 * don't have to depend on the kernel's definition of the superblock,
370 * which might not have the latest features.
373 __u32 s_inodes_count; /* Inodes count */
374 __u32 s_blocks_count; /* Blocks count */
375 __u32 s_r_blocks_count; /* Reserved blocks count */
376 __u32 s_free_blocks_count; /* Free blocks count */
377 __u32 s_free_inodes_count; /* Free inodes count */
378 __u32 s_first_data_block; /* First Data Block */
379 __u32 s_log_block_size; /* Block size */
380 __s32 s_log_frag_size; /* Fragment size */
381 __u32 s_blocks_per_group; /* # Blocks per group */
382 __u32 s_frags_per_group; /* # Fragments per group */
383 __u32 s_inodes_per_group; /* # Inodes per group */
384 __u32 s_mtime; /* Mount time */
385 __u32 s_wtime; /* Write time */
386 __u16 s_mnt_count; /* Mount count */
387 __s16 s_max_mnt_count; /* Maximal mount count */
388 __u16 s_magic; /* Magic signature */
389 __u16 s_state; /* File system state */
390 __u16 s_errors; /* Behaviour when detecting errors */
391 __u16 s_minor_rev_level; /* minor revision level */
392 __u32 s_lastcheck; /* time of last check */
393 __u32 s_checkinterval; /* max. time between checks */
394 __u32 s_creator_os; /* OS */
395 __u32 s_rev_level; /* Revision level */
396 __u16 s_def_resuid; /* Default uid for reserved blocks */
397 __u16 s_def_resgid; /* Default gid for reserved blocks */
399 * These fields are for EXT2_DYNAMIC_REV superblocks only.
401 * Note: the difference between the compatible feature set and
402 * the incompatible feature set is that if there is a bit set
403 * in the incompatible feature set that the kernel doesn't
404 * know about, it should refuse to mount the filesystem.
406 * e2fsck's requirements are more strict; if it doesn't know
407 * about a feature in either the compatible or incompatible
408 * feature set, it must abort and not try to meddle with
409 * things it doesn't understand...
411 __u32 s_first_ino; /* First non-reserved inode */
412 __u16 s_inode_size; /* size of inode structure */
413 __u16 s_block_group_nr; /* block group # of this superblock */
414 __u32 s_feature_compat; /* compatible feature set */
415 __u32 s_feature_incompat; /* incompatible feature set */
416 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
417 __u8 s_uuid[16]; /* 128-bit uuid for volume */
418 char s_volume_name[16]; /* volume name */
419 char s_last_mounted[64]; /* directory where last mounted */
420 __u32 s_algorithm_usage_bitmap; /* For compression */
422 * Performance hints. Directory preallocation should only
423 * happen if the EXT2_COMPAT_PREALLOC flag is on.
425 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
426 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
428 __u32 s_reserved[204]; /* Padding to the end of the block */
432 * Feature set definitions (that might not be in ext2_fs.h
433 * (was EXT2_COMPAT_SPARSE_SUPER)
436 #ifndef EXT2_FEATURE_COMPAT_DIR_PREALLOC
437 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
440 #ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
441 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
444 #ifndef EXT2_FEATURE_RO_COMPAT_LARGE_FILE
445 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
446 #define i_size_high i_dir_acl
449 #ifndef EXT2_FEATURE_RO_COMPAT_BTREE_DIR
450 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
453 #ifndef EXT2_FEATURE_INCOMPAT_COMPRESSION
454 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
457 #ifndef EXT2_FEATURE_INCOMPAT_FILETYPE
458 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
461 #define EXT2_LIB_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_DIR_PREALLOC
462 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
463 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
464 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
466 * function prototypes
470 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
471 ext2fs_inode_bitmap map, ino_t *ret);
472 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
473 ext2fs_block_bitmap map, blk_t *ret);
474 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
475 blk_t finish, int num,
476 ext2fs_block_bitmap map,
478 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
479 char *block_buf, blk_t *ret);
482 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
483 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, int group,
484 ext2fs_block_bitmap bmap);
487 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
489 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
491 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
494 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
495 ext2_badblocks_iterate *ret);
496 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
498 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
499 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
500 ext2_badblocks_list *dest);
503 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
504 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
505 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
506 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
507 badblocks_iterate *ret);
508 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
509 extern void badblocks_list_iterate_end(badblocks_iterate iter);
510 extern void badblocks_list_free(badblocks_list bb);
513 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
514 ext2_badblocks_list bb_list);
517 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
518 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
519 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
520 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
521 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
525 ext2fs_generic_bitmap *ret);
526 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
528 ext2fs_block_bitmap *ret);
529 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
531 ext2fs_inode_bitmap *ret);
532 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
533 ino_t end, ino_t *oend);
534 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
535 blk_t end, blk_t *oend);
536 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
537 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
538 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
539 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
542 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
546 int (*func)(ext2_filsys fs,
551 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
555 int (*func)(ext2_filsys fs,
557 e2_blkcnt_t blockcnt,
564 extern errcode_t ext2fs_bmap(ext2_filsys fs, ino_t ino,
565 struct ext2_inode *inode,
566 char *block_buf, int bmap_flags,
567 blk_t block, blk_t *phys_blk);
572 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
573 ext2fs_block_bitmap reserve,
574 ext2fs_block_bitmap alloc_map,
579 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
582 extern errcode_t ext2fs_close(ext2_filsys fs);
583 extern errcode_t ext2fs_flush(ext2_filsys fs);
584 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
587 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
588 ext2fs_block_bitmap bm2);
589 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
590 ext2fs_inode_bitmap bm2);
594 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs);
595 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
596 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino,
597 blk_t blk, int blockcnt);
598 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
599 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
602 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino,
603 blk_t blk, int blockcnt);
604 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
606 extern int ext2fs_dblist_count(ext2_dblist dblist);
610 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
613 int (*func)(ino_t dir,
615 struct ext2_dir_entry *dirent,
623 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
625 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
629 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
633 int (*func)(struct ext2_dir_entry *dirent,
641 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
644 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir);
647 extern errcode_t ext2fs_file_open(ext2_filsys fs, ino_t ino,
648 int flags, ext2_file_t *ret);
649 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
650 extern errcode_t ext2fs_file_close(ext2_file_t file);
651 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
652 unsigned int wanted, unsigned int *got);
653 extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
654 unsigned int nbytes, unsigned int *written);
655 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
656 int whence, ext2_off_t *ret_pos);
657 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
658 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
661 extern void ext2fs_free(ext2_filsys fs);
662 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
663 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
664 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
665 extern void ext2fs_free_dblist(ext2_dblist dblist);
666 extern void ext2fs_badblocks_list_free(badblocks_list bb);
669 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
673 extern errcode_t ext2fs_initialize(const char *name, int flags,
674 struct ext2_super_block *param,
675 io_manager manager, ext2_filsys *ret_fs);
678 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
679 ext2_inode_scan *ret_scan);
680 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
681 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino,
682 struct ext2_inode *inode);
683 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
685 extern void ext2fs_set_inode_callback
686 (ext2_inode_scan scan,
687 errcode_t (*done_group)(ext2_filsys fs,
688 ext2_inode_scan scan,
691 void *done_group_data);
692 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
694 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
695 struct ext2_inode * inode);
696 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
697 struct ext2_inode * inode);
698 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks);
699 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino);
702 extern void ext2fs_free_icount(ext2_icount_t icount);
703 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
704 ext2_icount_t hint, ext2_icount_t *ret);
705 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
707 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino,
709 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
711 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
713 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
715 extern ino_t ext2fs_get_icount_size(ext2_icount_t icount);
716 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
719 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
722 extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name,
723 int namelen, char *buf, ino_t *inode);
724 extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd,
725 const char *name, ino_t *inode);
726 errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd,
727 const char *name, ino_t *inode);
728 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd,
729 ino_t inode, ino_t *res_inode);
732 int ext2fs_native_flag(void);
735 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino,
736 ino_t parent_ino, char **block);
739 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum,
743 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
744 int block_size, io_manager manager,
745 ext2_filsys *ret_fs);
748 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino,
752 errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name,
753 ino_t ino, int flags);
754 errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name,
755 ino_t ino, int flags);
758 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
759 ext2_badblocks_list *bb_list);
762 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
763 ext2_badblocks_list *bb_list,
764 void (*invalid)(ext2_filsys fs,
768 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
770 ext2fs_generic_bitmap bmap);
771 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
772 ext2fs_inode_bitmap bmap);
773 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
774 ext2fs_block_bitmap bmap);
775 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
776 ext2fs_generic_bitmap *dest);
779 extern void ext2fs_swap_super(struct ext2_super_block * super);
780 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
781 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
782 struct ext2_inode *f, int hostorder);
785 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
788 extern int ext2fs_parse_version_string(const char *ver_string);
789 extern int ext2fs_get_library_version(const char **ver_string,
790 const char **date_string);
792 /* inline functions */
793 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
794 extern errcode_t ext2fs_free_mem(void **ptr);
795 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
796 unsigned long size, void **ptr);
797 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
798 extern void ext2fs_mark_changed(ext2_filsys fs);
799 extern int ext2fs_test_changed(ext2_filsys fs);
800 extern void ext2fs_mark_valid(ext2_filsys fs);
801 extern void ext2fs_unmark_valid(ext2_filsys fs);
802 extern int ext2fs_test_valid(ext2_filsys fs);
803 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
804 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
805 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
806 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
807 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
808 extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino);
811 * The actual inlined functions definitions themselves...
813 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
816 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
817 #ifdef INCLUDE_INLINE_FUNCS
818 #define _INLINE_ extern
821 #define _INLINE_ extern __inline__
822 #else /* For Watcom C */
823 #define _INLINE_ extern inline
827 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
831 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
835 return EXT2_ET_NO_MEMORY;
842 _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
852 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
853 unsigned long size, void **ptr)
857 p = realloc(*ptr, size);
859 return EXT2_ET_NO_MEMORY;
863 #endif /* Custom memory routines */
866 * Mark a filesystem superblock as dirty
868 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
870 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
874 * Mark a filesystem as changed
876 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
878 fs->flags |= EXT2_FLAG_CHANGED;
882 * Check to see if a filesystem has changed
884 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
886 return (fs->flags & EXT2_FLAG_CHANGED);
890 * Mark a filesystem as valid
892 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
894 fs->flags |= EXT2_FLAG_VALID;
898 * Mark a filesystem as NOT valid
900 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
902 fs->flags &= ~EXT2_FLAG_VALID;
906 * Check to see if a filesystem is valid
908 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
910 return (fs->flags & EXT2_FLAG_VALID);
914 * Mark the inode bitmap as dirty
916 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
918 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
922 * Mark the block bitmap as dirty
924 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
926 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
930 * Check to see if a filesystem's inode bitmap is dirty
932 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
934 return (fs->flags & EXT2_FLAG_IB_DIRTY);
938 * Check to see if a filesystem's block bitmap is dirty
940 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
942 return (fs->flags & EXT2_FLAG_BB_DIRTY);
946 * Return the group # of a block
948 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
950 return (blk - fs->super->s_first_data_block) /
951 fs->super->s_blocks_per_group;
955 * Return the group # of an inode number
957 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino)
959 return (ino - 1) / fs->super->s_inodes_per_group;
964 #endif /* _EXT2FS_EXT2FS_H */