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 #define EXT2FS_ATTR(x) __attribute__(x)
18 #define EXT2FS_ATTR(x)
26 * Non-GNU C compilers won't necessarily understand inline
28 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
29 #define NO_INLINE_FUNCS
33 * Build in support for byte-swapping filesystems if we the feature
34 * has been configured or if we're being built on a CPU architecture
35 * with a non-native byte order.
37 #if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
38 #define EXT2FS_ENABLE_SWAPFS
42 * Where the master copy of the superblock is located, and how big
43 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
44 * the size of the superblock structure is not necessarily trustworthy
45 * (some versions have the padding set up so that the superblock is
48 #define SUPERBLOCK_OFFSET 1024
49 #define SUPERBLOCK_SIZE 1024
52 * The last ext2fs revision level that this version of the library is
55 #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
57 #ifdef HAVE_SYS_TYPES_H
58 #include <sys/types.h>
64 #if EXT2_FLAT_INCLUDES
68 #include <ext2fs/ext2_types.h>
69 #include <ext2fs/ext2_fs.h>
70 #endif /* EXT2_FLAT_INCLUDES */
72 typedef __u32 ext2_ino_t;
75 typedef __u32 ext2_off_t;
76 typedef __s64 e2_blkcnt_t;
77 typedef __u32 ext2_dirhash_t;
79 #if EXT2_FLAT_INCLUDES
83 #include <ext2fs/ext2_io.h>
84 #include <ext2fs/ext2_err.h>
88 * Portability help for Microsoft Visual C++
91 #define EXT2_QSORT_TYPE int __cdecl
93 #define EXT2_QSORT_TYPE int
96 typedef struct struct_ext2_filsys *ext2_filsys;
98 struct ext2fs_struct_generic_bitmap {
105 errcode_t base_error_code;
109 #define EXT2FS_MARK_ERROR 0
110 #define EXT2FS_UNMARK_ERROR 1
111 #define EXT2FS_TEST_ERROR 2
113 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
114 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
115 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
117 #ifdef EXT2_DYNAMIC_REV
118 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
120 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
121 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
125 * badblocks list definitions
128 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
129 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
131 typedef struct ext2_struct_u32_list *ext2_u32_list;
132 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
135 typedef struct ext2_struct_u32_list *badblocks_list;
136 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
138 #define BADBLOCKS_FLAG_DIRTY 1
141 * ext2_dblist structure and abstractions (see dblist.c)
143 struct ext2_db_entry {
149 typedef struct ext2_struct_dblist *ext2_dblist;
151 #define DBLIST_ABORT 1
154 * ext2_fileio definitions
157 #define EXT2_FILE_WRITE 0x0001
158 #define EXT2_FILE_CREATE 0x0002
160 #define EXT2_FILE_MASK 0x00FF
162 #define EXT2_FILE_BUF_DIRTY 0x4000
163 #define EXT2_FILE_BUF_VALID 0x2000
165 typedef struct ext2_file *ext2_file_t;
167 #define EXT2_SEEK_SET 0
168 #define EXT2_SEEK_CUR 1
169 #define EXT2_SEEK_END 2
172 * Flags for the ext2_filsys structure and for ext2fs_open()
174 #define EXT2_FLAG_RW 0x01
175 #define EXT2_FLAG_CHANGED 0x02
176 #define EXT2_FLAG_DIRTY 0x04
177 #define EXT2_FLAG_VALID 0x08
178 #define EXT2_FLAG_IB_DIRTY 0x10
179 #define EXT2_FLAG_BB_DIRTY 0x20
180 #define EXT2_FLAG_SWAP_BYTES 0x40
181 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
182 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
183 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
184 #define EXT2_FLAG_FORCE 0x400
185 #define EXT2_FLAG_SUPER_ONLY 0x800
186 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
187 #define EXT2_FLAG_IMAGE_FILE 0x2000
190 * Special flag in the ext2 inode i_flag field that means that this is
191 * a new inode. (So that ext2_write_inode() can clear extra fields.)
193 #define EXT2_NEW_INODE_FL 0x80000000
196 * Flags for mkjournal
198 * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
200 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001
202 struct struct_ext2_filsys {
207 struct ext2_super_block * super;
208 unsigned int blocksize;
210 dgrp_t group_desc_count;
211 unsigned long desc_blocks;
212 struct ext2_group_desc * group_desc;
213 int inode_blocks_per_group;
214 ext2fs_inode_bitmap inode_map;
215 ext2fs_block_bitmap block_map;
216 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
217 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
218 errcode_t (*write_bitmaps)(ext2_filsys fs);
219 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
220 struct ext2_inode *inode);
221 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
222 struct ext2_inode *inode);
223 ext2_badblocks_list badblocks;
225 __u32 stride; /* for mke2fs */
226 struct ext2_super_block * orig_super;
227 struct ext2_image_hdr * image_header;
230 * Reserved for future expansion
235 * Reserved for the use of the calling application.
242 struct ext2_inode_cache *icache;
246 #if EXT2_FLAT_INCLUDES
247 #include "e2_bitops.h"
249 #include <ext2fs/bitops.h>
253 * Return flags for the block iterator functions
255 #define BLOCK_CHANGED 1
256 #define BLOCK_ABORT 2
257 #define BLOCK_ERROR 4
260 * Block interate flags
262 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
263 * function should be called on blocks where the block number is zero.
264 * This is used by ext2fs_expand_dir() to be able to add a new block
265 * to an inode. It can also be used for programs that want to be able
266 * to deal with files that contain "holes".
268 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
269 * indirect, doubly indirect, etc. blocks should be called after all
270 * of the blocks containined in the indirect blocks are processed.
271 * This is useful if you are going to be deallocating blocks from an
274 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
275 * called for data blocks only.
277 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
278 * ext2fs_block_iterate2 that large files won't be accepted.
280 #define BLOCK_FLAG_APPEND 1
281 #define BLOCK_FLAG_HOLE 1
282 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
283 #define BLOCK_FLAG_DATA_ONLY 4
285 #define BLOCK_FLAG_NO_LARGE 0x1000
288 * Magic "block count" return values for the block iterator function.
290 #define BLOCK_COUNT_IND (-1)
291 #define BLOCK_COUNT_DIND (-2)
292 #define BLOCK_COUNT_TIND (-3)
293 #define BLOCK_COUNT_TRANSLATOR (-4)
297 * Flags for ext2fs_move_blocks
299 #define EXT2_BMOVE_GET_DBLIST 0x0001
300 #define EXT2_BMOVE_DEBUG 0x0002
304 * Flags for directory block reading and writing functions
306 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
309 * Return flags for the directory iterator functions
311 #define DIRENT_CHANGED 1
312 #define DIRENT_ABORT 2
313 #define DIRENT_ERROR 3
316 * Directory iterator flags
319 #define DIRENT_FLAG_INCLUDE_EMPTY 1
320 #define DIRENT_FLAG_INCLUDE_REMOVED 2
322 #define DIRENT_DOT_FILE 1
323 #define DIRENT_DOT_DOT_FILE 2
324 #define DIRENT_OTHER_FILE 3
325 #define DIRENT_DELETED_FILE 4
328 * Inode scan definitions
330 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
335 #define EXT2_SF_CHK_BADBLOCKS 0x0001
336 #define EXT2_SF_BAD_INODE_BLK 0x0002
337 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
338 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
341 * ext2fs_check_if_mounted flags
343 #define EXT2_MF_MOUNTED 1
344 #define EXT2_MF_ISROOT 2
345 #define EXT2_MF_READONLY 4
346 #define EXT2_MF_SWAP 8
349 * Ext2/linux mode flags. We define them here so that we don't need
350 * to depend on the OS's sys/stat.h, since we may be compiling on a
353 #define LINUX_S_IFMT 00170000
354 #define LINUX_S_IFSOCK 0140000
355 #define LINUX_S_IFLNK 0120000
356 #define LINUX_S_IFREG 0100000
357 #define LINUX_S_IFBLK 0060000
358 #define LINUX_S_IFDIR 0040000
359 #define LINUX_S_IFCHR 0020000
360 #define LINUX_S_IFIFO 0010000
361 #define LINUX_S_ISUID 0004000
362 #define LINUX_S_ISGID 0002000
363 #define LINUX_S_ISVTX 0001000
365 #define LINUX_S_IRWXU 00700
366 #define LINUX_S_IRUSR 00400
367 #define LINUX_S_IWUSR 00200
368 #define LINUX_S_IXUSR 00100
370 #define LINUX_S_IRWXG 00070
371 #define LINUX_S_IRGRP 00040
372 #define LINUX_S_IWGRP 00020
373 #define LINUX_S_IXGRP 00010
375 #define LINUX_S_IRWXO 00007
376 #define LINUX_S_IROTH 00004
377 #define LINUX_S_IWOTH 00002
378 #define LINUX_S_IXOTH 00001
380 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
381 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
382 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
383 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
384 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
385 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
386 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
389 * ext2 size of an inode
391 #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
394 * ext2_icount_t abstraction
396 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
398 typedef struct ext2_icount *ext2_icount_t;
401 * Flags for ext2fs_bmap
403 #define BMAP_ALLOC 0x0001
404 #define BMAP_SET 0x0002
407 * Flags for imager.c functions
409 #define IMAGER_FLAG_INODEMAP 1
410 #define IMAGER_FLAG_SPARSEWRITE 2
413 * For checking structure magic numbers...
416 #define EXT2_CHECK_MAGIC(struct, code) \
417 if ((struct)->magic != (code)) return (code)
421 * For ext2 compression support
423 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
424 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
427 * Features supported by this version of the library
429 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
430 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
431 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
432 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
433 EXT2_FEATURE_COMPAT_DIR_INDEX|\
434 EXT2_FEATURE_COMPAT_EXT_ATTR)
436 /* This #ifdef is temporary until compression is fully supported */
437 #ifdef ENABLE_COMPRESSION
438 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
439 /* If the below warning bugs you, then have
440 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
441 environment at configure time. */
442 #warning "Compression support is experimental"
444 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
445 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
446 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
447 EXT2_FEATURE_INCOMPAT_META_BG|\
448 EXT3_FEATURE_INCOMPAT_RECOVER)
450 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
451 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
452 EXT2_FEATURE_INCOMPAT_META_BG|\
453 EXT3_FEATURE_INCOMPAT_RECOVER)
455 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
456 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
458 * function prototypes
462 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
463 ext2fs_inode_bitmap map, ext2_ino_t *ret);
464 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
465 ext2fs_block_bitmap map, blk_t *ret);
466 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
467 blk_t finish, int num,
468 ext2fs_block_bitmap map,
470 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
471 char *block_buf, blk_t *ret);
474 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
476 ext2fs_block_bitmap bmap);
479 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
480 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
481 int inuse, int isdir);
482 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
485 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
486 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
487 ext2fs_block_bitmap bmap);
490 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
491 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
492 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
493 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
494 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
495 ext2_u32_iterate *ret);
496 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
497 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
498 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
499 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
501 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
503 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
505 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
507 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
508 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
510 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
511 ext2_badblocks_iterate *ret);
512 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
514 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
515 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
516 ext2_badblocks_list *dest);
517 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
518 ext2_badblocks_list bb2);
519 extern int ext2fs_u32_list_count(ext2_u32_list bb);
522 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
523 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
524 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
525 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
526 badblocks_iterate *ret);
527 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
528 extern void badblocks_list_iterate_end(badblocks_iterate iter);
529 extern void badblocks_list_free(badblocks_list bb);
532 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
533 ext2_badblocks_list bb_list);
536 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
537 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
538 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
539 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
540 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
544 ext2fs_generic_bitmap *ret);
545 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
547 ext2fs_block_bitmap *ret);
548 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
550 ext2fs_inode_bitmap *ret);
551 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
552 ext2_ino_t end, ext2_ino_t *oend);
553 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
554 blk_t end, blk_t *oend);
555 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
556 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
557 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
558 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
561 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
565 int (*func)(ext2_filsys fs,
570 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
574 int (*func)(ext2_filsys fs,
576 e2_blkcnt_t blockcnt,
583 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
584 struct ext2_inode *inode,
585 char *block_buf, int bmap_flags,
586 blk_t block, blk_t *phys_blk);
591 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
592 ext2fs_block_bitmap reserve,
593 ext2fs_block_bitmap alloc_map,
598 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
601 extern errcode_t ext2fs_close(ext2_filsys fs);
602 extern errcode_t ext2fs_flush(ext2_filsys fs);
603 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
604 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
606 blk_t *ret_super_blk,
607 blk_t *ret_old_desc_blk,
608 blk_t *ret_new_desc_blk,
610 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
613 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
614 ext2fs_block_bitmap bm2);
615 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
616 ext2fs_inode_bitmap bm2);
620 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
621 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
622 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
623 blk_t blk, int blockcnt);
624 extern void ext2fs_dblist_sort(ext2_dblist dblist,
625 EXT2_QSORT_TYPE (*sortfunc)(const void *,
627 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
628 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
631 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
632 blk_t blk, int blockcnt);
633 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
635 extern int ext2fs_dblist_count(ext2_dblist dblist);
639 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
642 int (*func)(ext2_ino_t dir,
644 struct ext2_dir_entry *dirent,
652 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
654 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
655 void *buf, int flags);
656 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
658 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
659 void *buf, int flags);
662 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
664 ext2_dirhash_t *ret_hash,
665 ext2_dirhash_t *ret_minor_hash);
669 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
673 int (*func)(struct ext2_dir_entry *dirent,
679 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
683 int (*func)(ext2_ino_t dir,
685 struct ext2_dir_entry *dirent,
693 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
696 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
699 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
700 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
702 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
704 int adjust, __u32 *newcount);
707 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
708 struct ext2_inode *inode,
709 int flags, ext2_file_t *ret);
710 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
711 int flags, ext2_file_t *ret);
712 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
713 extern errcode_t ext2fs_file_close(ext2_file_t file);
714 extern errcode_t ext2fs_file_flush(ext2_file_t file);
715 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
716 unsigned int wanted, unsigned int *got);
717 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
718 unsigned int nbytes, unsigned int *written);
719 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
720 int whence, __u64 *ret_pos);
721 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
722 int whence, ext2_off_t *ret_pos);
723 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
724 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
725 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
728 extern char *ext2fs_find_block_device(dev_t device);
731 extern errcode_t ext2fs_sync_device(int fd, int flushb);
734 extern void ext2fs_free(ext2_filsys fs);
735 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
736 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
737 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
738 extern void ext2fs_free_dblist(ext2_dblist dblist);
739 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
740 extern void ext2fs_u32_list_free(ext2_u32_list bb);
743 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
747 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
750 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
751 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
752 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
753 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
754 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
755 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
758 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
759 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
762 extern errcode_t ext2fs_initialize(const char *name, int flags,
763 struct ext2_super_block *param,
764 io_manager manager, ext2_filsys *ret_fs);
767 extern void ext2fs_free_icount(ext2_icount_t icount);
768 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
770 ext2_icount_t hint, ext2_icount_t *ret);
771 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
774 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
776 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
778 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
780 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
782 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
783 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
786 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
787 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
789 struct ext2_inode *inode,
791 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
792 ext2_inode_scan *ret_scan);
793 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
794 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
795 struct ext2_inode *inode);
796 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
798 extern void ext2fs_set_inode_callback
799 (ext2_inode_scan scan,
800 errcode_t (*done_group)(ext2_filsys fs,
801 ext2_inode_scan scan,
804 void *done_group_data);
805 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
807 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
808 struct ext2_inode * inode,
810 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
811 struct ext2_inode * inode);
812 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
813 struct ext2_inode * inode,
815 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
816 struct ext2_inode * inode);
817 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
818 struct ext2_inode * inode);
819 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
820 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
823 extern io_manager inode_io_manager;
824 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
826 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
827 struct ext2_inode *inode,
831 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
832 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
833 char *mtpt, int mtlen);
836 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
837 int namelen, char *buf, ext2_ino_t *inode);
838 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
839 const char *name, ext2_ino_t *inode);
840 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
841 const char *name, ext2_ino_t *inode);
842 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
843 ext2_ino_t inode, ext2_ino_t *res_inode);
846 int ext2fs_native_flag(void);
849 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
850 ext2_ino_t parent_ino, char **block);
853 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
857 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
858 __u32 size, int flags,
860 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
861 ext2_filsys journal_dev);
862 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
866 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
867 unsigned int block_size, io_manager manager,
868 ext2_filsys *ret_fs);
869 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
870 int flags, int superblock,
871 unsigned int block_size, io_manager manager,
872 ext2_filsys *ret_fs);
873 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
875 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
876 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
877 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
880 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
884 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
885 ext2_ino_t ino, int flags);
886 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
887 ext2_ino_t ino, int flags);
890 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
891 ext2_badblocks_list *bb_list);
894 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
895 ext2_badblocks_list *bb_list,
897 void (*invalid)(ext2_filsys fs,
901 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
902 ext2_badblocks_list *bb_list,
903 void (*invalid)(ext2_filsys fs,
907 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
910 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
912 ext2fs_generic_bitmap bmap);
913 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
914 ext2fs_inode_bitmap bmap);
915 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
916 ext2fs_block_bitmap bmap);
917 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
918 ext2fs_generic_bitmap *dest);
921 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
923 extern void ext2fs_swap_super(struct ext2_super_block * super);
924 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
925 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
926 struct ext2_inode_large *f, int hostorder,
928 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
929 struct ext2_inode *f, int hostorder);
932 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
935 extern int ext2fs_parse_version_string(const char *ver_string);
936 extern int ext2fs_get_library_version(const char **ver_string,
937 const char **date_string);
939 /* write_bb_file.c */
940 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
945 /* inline functions */
946 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
947 extern errcode_t ext2fs_free_mem(void *ptr);
948 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
949 unsigned long size, void *ptr);
950 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
951 extern void ext2fs_mark_changed(ext2_filsys fs);
952 extern int ext2fs_test_changed(ext2_filsys fs);
953 extern void ext2fs_mark_valid(ext2_filsys fs);
954 extern void ext2fs_unmark_valid(ext2_filsys fs);
955 extern int ext2fs_test_valid(ext2_filsys fs);
956 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
957 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
958 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
959 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
960 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
961 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
962 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
963 struct ext2_inode *inode);
966 * The actual inlined functions definitions themselves...
968 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
971 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
972 #ifdef INCLUDE_INLINE_FUNCS
973 #define _INLINE_ extern
976 #define _INLINE_ extern __inline__
977 #else /* For Watcom C */
978 #define _INLINE_ extern inline
982 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
986 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
988 void **pp = (void **)ptr;
992 return EXT2_ET_NO_MEMORY;
999 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1001 void **pp = (void **)ptr;
1011 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1012 unsigned long size, void *ptr)
1015 void **pp = (void **)ptr;
1017 p = realloc(*pp, size);
1019 return EXT2_ET_NO_MEMORY;
1023 #endif /* Custom memory routines */
1026 * Mark a filesystem superblock as dirty
1028 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1030 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1034 * Mark a filesystem as changed
1036 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1038 fs->flags |= EXT2_FLAG_CHANGED;
1042 * Check to see if a filesystem has changed
1044 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1046 return (fs->flags & EXT2_FLAG_CHANGED);
1050 * Mark a filesystem as valid
1052 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1054 fs->flags |= EXT2_FLAG_VALID;
1058 * Mark a filesystem as NOT valid
1060 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1062 fs->flags &= ~EXT2_FLAG_VALID;
1066 * Check to see if a filesystem is valid
1068 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1070 return (fs->flags & EXT2_FLAG_VALID);
1074 * Mark the inode bitmap as dirty
1076 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1078 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1082 * Mark the block bitmap as dirty
1084 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1086 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1090 * Check to see if a filesystem's inode bitmap is dirty
1092 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1094 return (fs->flags & EXT2_FLAG_IB_DIRTY);
1098 * Check to see if a filesystem's block bitmap is dirty
1100 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1102 return (fs->flags & EXT2_FLAG_BB_DIRTY);
1106 * Return the group # of a block
1108 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1110 return (blk - fs->super->s_first_data_block) /
1111 fs->super->s_blocks_per_group;
1115 * Return the group # of an inode number
1117 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1119 return (ino - 1) / fs->super->s_inodes_per_group;
1122 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1123 struct ext2_inode *inode)
1125 return inode->i_blocks -
1126 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1135 #endif /* _EXT2FS_EXT2FS_H */