Home | History | Annotate | Download | only in ext2fs
      1 /*
      2  * ext2fs.h --- ext2fs
      3  *
      4  * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
      5  *
      6  * %Begin-Header%
      7  * This file may be redistributed under the terms of the GNU Library
      8  * General Public License, version 2.
      9  * %End-Header%
     10  */
     11 
     12 #ifndef _EXT2FS_EXT2FS_H
     13 #define _EXT2FS_EXT2FS_H
     14 
     15 #ifdef __GNUC__
     16 #define EXT2FS_ATTR(x) __attribute__(x)
     17 #else
     18 #define EXT2FS_ATTR(x)
     19 #endif
     20 
     21 #ifdef __cplusplus
     22 extern "C" {
     23 #endif
     24 
     25 /*
     26  * Non-GNU C compilers won't necessarily understand inline
     27  */
     28 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
     29 #define NO_INLINE_FUNCS
     30 #endif
     31 
     32 /*
     33  * Where the master copy of the superblock is located, and how big
     34  * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
     35  * the size of the superblock structure is not necessarily trustworthy
     36  * (some versions have the padding set up so that the superblock is
     37  * 1032 bytes long).
     38  */
     39 #define SUPERBLOCK_OFFSET	1024
     40 #define SUPERBLOCK_SIZE		1024
     41 
     42 /*
     43  * The last ext2fs revision level that this version of the library is
     44  * able to support.
     45  */
     46 #define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
     47 
     48 #ifdef HAVE_SYS_TYPES_H
     49 #include <sys/types.h>
     50 #endif
     51 
     52 #include <stdio.h>
     53 #include <stdlib.h>
     54 #include <string.h>
     55 #include <errno.h>
     56 
     57 #if EXT2_FLAT_INCLUDES
     58 #include "e2_types.h"
     59 #include "ext2_fs.h"
     60 #include "ext3_extents.h"
     61 #else
     62 #include <ext2fs/ext2_types.h>
     63 #include <ext2fs/ext2_fs.h>
     64 #include <ext2fs/ext3_extents.h>
     65 #endif /* EXT2_FLAT_INCLUDES */
     66 
     67 #ifdef __CHECK_ENDIAN__
     68 #define __bitwise __attribute__((bitwise))
     69 #else
     70 #define __bitwise
     71 #endif
     72 
     73 typedef __u32 __bitwise		ext2_ino_t;
     74 typedef __u32 __bitwise		blk_t;
     75 typedef __u64 __bitwise		blk64_t;
     76 typedef __u32 __bitwise		dgrp_t;
     77 typedef __u32 __bitwise		ext2_off_t;
     78 typedef __u64 __bitwise		ext2_off64_t;
     79 typedef __s64 __bitwise		e2_blkcnt_t;
     80 typedef __u32 __bitwise		ext2_dirhash_t;
     81 
     82 #if EXT2_FLAT_INCLUDES
     83 #include "com_err.h"
     84 #include "ext2_io.h"
     85 #include "ext2_err.h"
     86 #include "ext2_ext_attr.h"
     87 #else
     88 #include <et/com_err.h>
     89 #include <ext2fs/ext2_io.h>
     90 #include <ext2fs/ext2_err.h>
     91 #include <ext2fs/ext2_ext_attr.h>
     92 #endif
     93 
     94 /*
     95  * Portability help for Microsoft Visual C++
     96  */
     97 #ifdef _MSC_VER
     98 #define EXT2_QSORT_TYPE int __cdecl
     99 #else
    100 #define EXT2_QSORT_TYPE int
    101 #endif
    102 
    103 typedef struct struct_ext2_filsys *ext2_filsys;
    104 
    105 #define EXT2FS_MARK_ERROR 	0
    106 #define EXT2FS_UNMARK_ERROR 	1
    107 #define EXT2FS_TEST_ERROR	2
    108 
    109 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
    110 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
    111 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
    112 
    113 #define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO(s)
    114 
    115 
    116 /*
    117  * Badblocks list definitions
    118  */
    119 
    120 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
    121 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
    122 
    123 typedef struct ext2_struct_u32_list *ext2_u32_list;
    124 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
    125 
    126 /* old */
    127 typedef struct ext2_struct_u32_list *badblocks_list;
    128 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
    129 
    130 #define BADBLOCKS_FLAG_DIRTY	1
    131 
    132 /*
    133  * ext2_dblist structure and abstractions (see dblist.c)
    134  */
    135 struct ext2_db_entry2 {
    136 	ext2_ino_t	ino;
    137 	blk64_t	blk;
    138 	e2_blkcnt_t	blockcnt;
    139 };
    140 
    141 /* Ye Olde 32-bit version */
    142 struct ext2_db_entry {
    143 	ext2_ino_t	ino;
    144 	blk_t	blk;
    145 	int	blockcnt;
    146 };
    147 
    148 typedef struct ext2_struct_dblist *ext2_dblist;
    149 
    150 #define DBLIST_ABORT	1
    151 
    152 /*
    153  * ext2_fileio definitions
    154  */
    155 
    156 #define EXT2_FILE_WRITE		0x0001
    157 #define EXT2_FILE_CREATE	0x0002
    158 
    159 #define EXT2_FILE_MASK		0x00FF
    160 
    161 #define EXT2_FILE_BUF_DIRTY	0x4000
    162 #define EXT2_FILE_BUF_VALID	0x2000
    163 
    164 typedef struct ext2_file *ext2_file_t;
    165 
    166 #define EXT2_SEEK_SET	0
    167 #define EXT2_SEEK_CUR	1
    168 #define EXT2_SEEK_END	2
    169 
    170 /*
    171  * Flags for the ext2_filsys structure and for ext2fs_open()
    172  */
    173 #define EXT2_FLAG_RW			0x01
    174 #define EXT2_FLAG_CHANGED		0x02
    175 #define EXT2_FLAG_DIRTY			0x04
    176 #define EXT2_FLAG_VALID			0x08
    177 #define EXT2_FLAG_IB_DIRTY		0x10
    178 #define EXT2_FLAG_BB_DIRTY		0x20
    179 #define EXT2_FLAG_SWAP_BYTES		0x40
    180 #define EXT2_FLAG_SWAP_BYTES_READ	0x80
    181 #define EXT2_FLAG_SWAP_BYTES_WRITE	0x100
    182 #define EXT2_FLAG_MASTER_SB_ONLY	0x200
    183 #define EXT2_FLAG_FORCE			0x400
    184 #define EXT2_FLAG_SUPER_ONLY		0x800
    185 #define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
    186 #define EXT2_FLAG_IMAGE_FILE		0x2000
    187 #define EXT2_FLAG_EXCLUSIVE		0x4000
    188 #define EXT2_FLAG_SOFTSUPP_FEATURES	0x8000
    189 #define EXT2_FLAG_NOFREE_ON_ERROR	0x10000
    190 #define EXT2_FLAG_64BITS		0x20000
    191 #define EXT2_FLAG_PRINT_PROGRESS	0x40000
    192 #define EXT2_FLAG_DIRECT_IO		0x80000
    193 #define EXT2_FLAG_SKIP_MMP		0x100000
    194 
    195 /*
    196  * Special flag in the ext2 inode i_flag field that means that this is
    197  * a new inode.  (So that ext2_write_inode() can clear extra fields.)
    198  */
    199 #define EXT2_NEW_INODE_FL	0x80000000
    200 
    201 /*
    202  * Flags for mkjournal
    203  */
    204 #define EXT2_MKJOURNAL_V1_SUPER	0x0000001 /* create V1 superblock (deprecated) */
    205 #define EXT2_MKJOURNAL_LAZYINIT	0x0000002 /* don't zero journal inode before use*/
    206 #define EXT2_MKJOURNAL_NO_MNT_CHECK 0x0000004 /* don't check mount status */
    207 
    208 struct opaque_ext2_group_desc;
    209 
    210 struct struct_ext2_filsys {
    211 	errcode_t			magic;
    212 	io_channel			io;
    213 	int				flags;
    214 	char *				device_name;
    215 	struct ext2_super_block	* 	super;
    216 	unsigned int			blocksize;
    217 	int				fragsize;
    218 	dgrp_t				group_desc_count;
    219 	unsigned long			desc_blocks;
    220 	struct opaque_ext2_group_desc *	group_desc;
    221 	unsigned int			inode_blocks_per_group;
    222 	ext2fs_inode_bitmap		inode_map;
    223 	ext2fs_block_bitmap		block_map;
    224 	/* XXX FIXME-64: not 64-bit safe, but not used? */
    225 	errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
    226 	errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
    227 	errcode_t (*write_bitmaps)(ext2_filsys fs);
    228 	errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
    229 				struct ext2_inode *inode);
    230 	errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
    231 				struct ext2_inode *inode);
    232 	ext2_badblocks_list		badblocks;
    233 	ext2_dblist			dblist;
    234 	__u32				stride;	/* for mke2fs */
    235 	struct ext2_super_block *	orig_super;
    236 	struct ext2_image_hdr *		image_header;
    237 	__u32				umask;
    238 	time_t				now;
    239 	int				cluster_ratio_bits;
    240 	__u16				default_bitmap_type;
    241 	__u16				pad;
    242 	/*
    243 	 * Reserved for future expansion
    244 	 */
    245 	__u32				reserved[5];
    246 
    247 	/*
    248 	 * Reserved for the use of the calling application.
    249 	 */
    250 	void *				priv_data;
    251 
    252 	/*
    253 	 * Inode cache
    254 	 */
    255 	struct ext2_inode_cache		*icache;
    256 	io_channel			image_io;
    257 
    258 	/*
    259 	 * More callback functions
    260 	 */
    261 	errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
    262 				     blk64_t *ret);
    263 	void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
    264 
    265 	/*
    266 	 * Buffers for Multiple mount protection(MMP) block.
    267 	 */
    268 	void *mmp_buf;
    269 	void *mmp_cmp;
    270 	int mmp_fd;
    271 
    272 	/*
    273 	 * Time at which e2fsck last updated the MMP block.
    274 	 */
    275 	long mmp_last_written;
    276 };
    277 
    278 #if EXT2_FLAT_INCLUDES
    279 #include "e2_bitops.h"
    280 #else
    281 #include <ext2fs/bitops.h>
    282 #endif
    283 
    284 /*
    285  * 64-bit bitmap backend types
    286  */
    287 #define EXT2FS_BMAP64_BITARRAY	1
    288 #define EXT2FS_BMAP64_RBTREE	2
    289 #define EXT2FS_BMAP64_AUTODIR	3
    290 
    291 /*
    292  * Return flags for the block iterator functions
    293  */
    294 #define BLOCK_CHANGED	1
    295 #define BLOCK_ABORT	2
    296 #define BLOCK_ERROR	4
    297 
    298 /*
    299  * Block interate flags
    300  *
    301  * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
    302  * function should be called on blocks where the block number is zero.
    303  * This is used by ext2fs_expand_dir() to be able to add a new block
    304  * to an inode.  It can also be used for programs that want to be able
    305  * to deal with files that contain "holes".
    306  *
    307  * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
    308  * the indirect, doubly indirect, etc. blocks should be called after
    309  * all of the blocks containined in the indirect blocks are processed.
    310  * This is useful if you are going to be deallocating blocks from an
    311  * inode.
    312  *
    313  * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
    314  * called for data blocks only.
    315  *
    316  * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
    317  * modify returned block number.
    318  *
    319  * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
    320  * ext2fs_block_iterate2 that large files won't be accepted.
    321  */
    322 #define BLOCK_FLAG_APPEND	1
    323 #define BLOCK_FLAG_HOLE		1
    324 #define BLOCK_FLAG_DEPTH_TRAVERSE	2
    325 #define BLOCK_FLAG_DATA_ONLY	4
    326 #define BLOCK_FLAG_READ_ONLY	8
    327 
    328 #define BLOCK_FLAG_NO_LARGE	0x1000
    329 
    330 /*
    331  * Magic "block count" return values for the block iterator function.
    332  */
    333 #define BLOCK_COUNT_IND		(-1)
    334 #define BLOCK_COUNT_DIND	(-2)
    335 #define BLOCK_COUNT_TIND	(-3)
    336 #define BLOCK_COUNT_TRANSLATOR	(-4)
    337 
    338 #if 0
    339 /*
    340  * Flags for ext2fs_move_blocks
    341  */
    342 #define EXT2_BMOVE_GET_DBLIST	0x0001
    343 #define EXT2_BMOVE_DEBUG	0x0002
    344 #endif
    345 
    346 /*
    347  * Generic (non-filesystem layout specific) extents structure
    348  */
    349 
    350 #define EXT2_EXTENT_FLAGS_LEAF		0x0001
    351 #define EXT2_EXTENT_FLAGS_UNINIT	0x0002
    352 #define EXT2_EXTENT_FLAGS_SECOND_VISIT	0x0004
    353 
    354 struct ext2fs_extent {
    355 	blk64_t	e_pblk;		/* first physical block */
    356 	blk64_t	e_lblk;		/* first logical block extent covers */
    357 	__u32	e_len;		/* number of blocks covered by extent */
    358 	__u32	e_flags;	/* extent flags */
    359 };
    360 
    361 typedef struct ext2_extent_handle *ext2_extent_handle_t;
    362 typedef struct ext2_extent_path *ext2_extent_path_t;
    363 
    364 /*
    365  * Flags used by ext2fs_extent_get()
    366  */
    367 #define EXT2_EXTENT_CURRENT	0x0000
    368 #define EXT2_EXTENT_MOVE_MASK	0x000F
    369 #define EXT2_EXTENT_ROOT	0x0001
    370 #define EXT2_EXTENT_LAST_LEAF	0x0002
    371 #define EXT2_EXTENT_FIRST_SIB	0x0003
    372 #define EXT2_EXTENT_LAST_SIB	0x0004
    373 #define EXT2_EXTENT_NEXT_SIB	0x0005
    374 #define EXT2_EXTENT_PREV_SIB	0x0006
    375 #define EXT2_EXTENT_NEXT_LEAF	0x0007
    376 #define EXT2_EXTENT_PREV_LEAF	0x0008
    377 #define EXT2_EXTENT_NEXT	0x0009
    378 #define EXT2_EXTENT_PREV	0x000A
    379 #define EXT2_EXTENT_UP		0x000B
    380 #define EXT2_EXTENT_DOWN	0x000C
    381 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
    382 
    383 /*
    384  * Flags used by ext2fs_extent_insert()
    385  */
    386 #define EXT2_EXTENT_INSERT_AFTER	0x0001 /* insert after handle loc'n */
    387 #define EXT2_EXTENT_INSERT_NOSPLIT	0x0002 /* insert may not cause split */
    388 
    389 /*
    390  * Flags used by ext2fs_extent_delete()
    391  */
    392 #define EXT2_EXTENT_DELETE_KEEP_EMPTY	0x001 /* keep node if last extnt gone */
    393 
    394 /*
    395  * Flags used by ext2fs_extent_set_bmap()
    396  */
    397 #define EXT2_EXTENT_SET_BMAP_UNINIT	0x0001
    398 
    399 /*
    400  * Data structure returned by ext2fs_extent_get_info()
    401  */
    402 struct ext2_extent_info {
    403 	int		curr_entry;
    404 	int		curr_level;
    405 	int		num_entries;
    406 	int		max_entries;
    407 	int		max_depth;
    408 	int		bytes_avail;
    409 	blk64_t		max_lblk;
    410 	blk64_t		max_pblk;
    411 	__u32		max_len;
    412 	__u32		max_uninit_len;
    413 };
    414 
    415 /*
    416  * Flags for directory block reading and writing functions
    417  */
    418 #define EXT2_DIRBLOCK_V2_STRUCT	0x0001
    419 
    420 /*
    421  * Return flags for the directory iterator functions
    422  */
    423 #define DIRENT_CHANGED	1
    424 #define DIRENT_ABORT	2
    425 #define DIRENT_ERROR	3
    426 
    427 /*
    428  * Directory iterator flags
    429  */
    430 
    431 #define DIRENT_FLAG_INCLUDE_EMPTY	1
    432 #define DIRENT_FLAG_INCLUDE_REMOVED	2
    433 
    434 #define DIRENT_DOT_FILE		1
    435 #define DIRENT_DOT_DOT_FILE	2
    436 #define DIRENT_OTHER_FILE	3
    437 #define DIRENT_DELETED_FILE	4
    438 
    439 /*
    440  * Inode scan definitions
    441  */
    442 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
    443 
    444 /*
    445  * ext2fs_scan flags
    446  */
    447 #define EXT2_SF_CHK_BADBLOCKS	0x0001
    448 #define EXT2_SF_BAD_INODE_BLK	0x0002
    449 #define EXT2_SF_BAD_EXTRA_BYTES	0x0004
    450 #define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
    451 #define EXT2_SF_DO_LAZY		0x0010
    452 
    453 /*
    454  * ext2fs_check_if_mounted flags
    455  */
    456 #define EXT2_MF_MOUNTED		1
    457 #define EXT2_MF_ISROOT		2
    458 #define EXT2_MF_READONLY	4
    459 #define EXT2_MF_SWAP		8
    460 #define EXT2_MF_BUSY		16
    461 
    462 /*
    463  * Ext2/linux mode flags.  We define them here so that we don't need
    464  * to depend on the OS's sys/stat.h, since we may be compiling on a
    465  * non-Linux system.
    466  */
    467 #define LINUX_S_IFMT  00170000
    468 #define LINUX_S_IFSOCK 0140000
    469 #define LINUX_S_IFLNK	 0120000
    470 #define LINUX_S_IFREG  0100000
    471 #define LINUX_S_IFBLK  0060000
    472 #define LINUX_S_IFDIR  0040000
    473 #define LINUX_S_IFCHR  0020000
    474 #define LINUX_S_IFIFO  0010000
    475 #define LINUX_S_ISUID  0004000
    476 #define LINUX_S_ISGID  0002000
    477 #define LINUX_S_ISVTX  0001000
    478 
    479 #define LINUX_S_IRWXU 00700
    480 #define LINUX_S_IRUSR 00400
    481 #define LINUX_S_IWUSR 00200
    482 #define LINUX_S_IXUSR 00100
    483 
    484 #define LINUX_S_IRWXG 00070
    485 #define LINUX_S_IRGRP 00040
    486 #define LINUX_S_IWGRP 00020
    487 #define LINUX_S_IXGRP 00010
    488 
    489 #define LINUX_S_IRWXO 00007
    490 #define LINUX_S_IROTH 00004
    491 #define LINUX_S_IWOTH 00002
    492 #define LINUX_S_IXOTH 00001
    493 
    494 #define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
    495 #define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
    496 #define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
    497 #define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
    498 #define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
    499 #define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
    500 #define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
    501 
    502 /*
    503  * ext2 size of an inode
    504  */
    505 #define EXT2_I_SIZE(i)	((i)->i_size | ((__u64) (i)->i_size_high << 32))
    506 
    507 /*
    508  * ext2_icount_t abstraction
    509  */
    510 #define EXT2_ICOUNT_OPT_INCREMENT	0x01
    511 
    512 typedef struct ext2_icount *ext2_icount_t;
    513 
    514 /*
    515  * Flags for ext2fs_bmap
    516  */
    517 #define BMAP_ALLOC	0x0001
    518 #define BMAP_SET	0x0002
    519 
    520 /*
    521  * Returned flags from ext2fs_bmap
    522  */
    523 #define BMAP_RET_UNINIT	0x0001
    524 
    525 /*
    526  * Flags for imager.c functions
    527  */
    528 #define IMAGER_FLAG_INODEMAP	1
    529 #define IMAGER_FLAG_SPARSEWRITE	2
    530 
    531 /*
    532  * For checking structure magic numbers...
    533  */
    534 
    535 #define EXT2_CHECK_MAGIC(struct, code) \
    536 	  if ((struct)->magic != (code)) return (code)
    537 
    538 
    539 /*
    540  * For ext2 compression support
    541  */
    542 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
    543 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
    544 
    545 /*
    546  * Features supported by this version of the library
    547  */
    548 #define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
    549 					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
    550 					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
    551 					 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
    552 					 EXT2_FEATURE_COMPAT_DIR_INDEX|\
    553 					 EXT2_FEATURE_COMPAT_EXT_ATTR)
    554 
    555 /* This #ifdef is temporary until compression is fully supported */
    556 #ifdef ENABLE_COMPRESSION
    557 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
    558 /* If the below warning bugs you, then have
    559    `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
    560    environment at configure time. */
    561  #warning "Compression support is experimental"
    562 #endif
    563 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
    564 					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
    565 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
    566 					 EXT2_FEATURE_INCOMPAT_META_BG|\
    567 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
    568 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
    569 					 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
    570 					 EXT4_FEATURE_INCOMPAT_MMP|\
    571 					 EXT4_FEATURE_INCOMPAT_64BIT)
    572 #else
    573 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
    574 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
    575 					 EXT2_FEATURE_INCOMPAT_META_BG|\
    576 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
    577 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
    578 					 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
    579 					 EXT4_FEATURE_INCOMPAT_MMP|\
    580 					 EXT4_FEATURE_INCOMPAT_64BIT)
    581 #endif
    582 #ifdef CONFIG_QUOTA
    583 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
    584 					 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
    585 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
    586 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
    587 					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
    588 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
    589 					 EXT4_FEATURE_RO_COMPAT_BIGALLOC|\
    590 					 EXT4_FEATURE_RO_COMPAT_QUOTA)
    591 #else
    592 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
    593 					 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
    594 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
    595 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
    596 					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
    597 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
    598 					 EXT4_FEATURE_RO_COMPAT_BIGALLOC)
    599 #endif
    600 
    601 /*
    602  * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
    603  * to ext2fs_openfs()
    604  */
    605 #define EXT2_LIB_SOFTSUPP_INCOMPAT	(0)
    606 #define EXT2_LIB_SOFTSUPP_RO_COMPAT	(EXT4_FEATURE_RO_COMPAT_REPLICA)
    607 
    608 
    609 /* Translate a block number to a cluster number */
    610 #define EXT2FS_CLUSTER_RATIO(fs)	(1 << (fs)->cluster_ratio_bits)
    611 #define EXT2FS_CLUSTER_MASK(fs)		(EXT2FS_CLUSTER_RATIO(fs) - 1)
    612 #define EXT2FS_B2C(fs, blk)		((blk) >> (fs)->cluster_ratio_bits)
    613 /* Translate a cluster number to a block number */
    614 #define EXT2FS_C2B(fs, cluster)		((cluster) << (fs)->cluster_ratio_bits)
    615 /* Translate # of blks to # of clusters */
    616 #define EXT2FS_NUM_B2C(fs, blks)	(((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
    617 					 (fs)->cluster_ratio_bits)
    618 
    619 #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
    620 typedef struct stat64 ext2fs_struct_stat;
    621 #else
    622 typedef struct stat ext2fs_struct_stat;
    623 #endif
    624 
    625 /*
    626  * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
    627  * avoid the fsync call.
    628  */
    629 #define EXT2_FLAG_FLUSH_NO_SYNC          1
    630 
    631 /*
    632  * function prototypes
    633  */
    634 
    635 /* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */
    636 static inline int ext2fs_needs_large_file_feature(unsigned long long file_size)
    637 {
    638 	return file_size >= 0x80000000ULL;
    639 }
    640 
    641 /* alloc.c */
    642 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
    643 				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
    644 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
    645 				  ext2fs_block_bitmap map, blk_t *ret);
    646 extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
    647 				   ext2fs_block_bitmap map, blk64_t *ret);
    648 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
    649 					blk_t finish, int num,
    650 					ext2fs_block_bitmap map,
    651 					blk_t *ret);
    652 extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start,
    653 					 blk64_t finish, int num,
    654 					 ext2fs_block_bitmap map,
    655 					 blk64_t *ret);
    656 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
    657 				    char *block_buf, blk_t *ret);
    658 extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal,
    659 				     char *block_buf, blk64_t *ret);
    660 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
    661 					    errcode_t (*func)(ext2_filsys fs,
    662 							      blk64_t goal,
    663 							      blk64_t *ret),
    664 					    errcode_t (**old)(ext2_filsys fs,
    665 							      blk64_t goal,
    666 							      blk64_t *ret));
    667 
    668 /* alloc_sb.c */
    669 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
    670 					dgrp_t group,
    671 					ext2fs_block_bitmap bmap);
    672 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
    673 						  void (*func)(ext2_filsys fs,
    674 							       blk64_t blk,
    675 							       int inuse),
    676 						  void (**old)(ext2_filsys fs,
    677 							       blk64_t blk,
    678 							       int inuse));
    679 
    680 /* alloc_stats.c */
    681 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
    682 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
    683 			       int inuse, int isdir);
    684 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
    685 void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
    686 
    687 /* alloc_tables.c */
    688 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
    689 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
    690 					     ext2fs_block_bitmap bmap);
    691 
    692 /* badblocks.c */
    693 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
    694 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
    695 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
    696 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
    697 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
    698 					       ext2_u32_iterate *ret);
    699 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
    700 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
    701 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
    702 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
    703 
    704 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
    705 					    int size);
    706 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
    707 					   blk_t blk);
    708 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
    709 				    blk_t blk);
    710 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
    711 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
    712 extern errcode_t
    713 	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
    714 					    ext2_badblocks_iterate *ret);
    715 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
    716 					 blk_t *blk);
    717 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
    718 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
    719 				       ext2_badblocks_list *dest);
    720 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
    721 				  ext2_badblocks_list bb2);
    722 extern int ext2fs_u32_list_count(ext2_u32_list bb);
    723 
    724 /* bb_compat */
    725 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
    726 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
    727 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
    728 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
    729 					      badblocks_iterate *ret);
    730 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
    731 extern void badblocks_list_iterate_end(badblocks_iterate iter);
    732 extern void badblocks_list_free(badblocks_list bb);
    733 
    734 /* bb_inode.c */
    735 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
    736 					ext2_badblocks_list bb_list);
    737 
    738 /* bitmaps.c */
    739 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
    740 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
    741 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
    742 				    ext2fs_generic_bitmap *dest);
    743 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
    744 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
    745 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
    746 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
    747 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
    748 					      const char *descr,
    749 					      ext2fs_block_bitmap *ret);
    750 extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
    751 						   const char *descr,
    752 						   ext2fs_block_bitmap *ret);
    753 extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap);
    754 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
    755 					      const char *descr,
    756 					      ext2fs_inode_bitmap *ret);
    757 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
    758 					       ext2_ino_t end, ext2_ino_t *oend);
    759 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
    760 					       blk_t end, blk_t *oend);
    761 extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
    762 					 blk64_t end, blk64_t *oend);
    763 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
    764 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
    765 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
    766 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
    767 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
    768 					    ext2fs_inode_bitmap bmap);
    769 extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end,
    770 					     __u64 new_real_end,
    771 					     ext2fs_inode_bitmap bmap);
    772 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
    773 					    ext2fs_block_bitmap bmap);
    774 extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end,
    775 					     __u64 new_real_end,
    776 					     ext2fs_block_bitmap bmap);
    777 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
    778 					     ext2fs_block_bitmap bm2);
    779 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
    780 					     ext2fs_inode_bitmap bm2);
    781 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
    782 					ext2_ino_t start, unsigned int num,
    783 					void *in);
    784 extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
    785 					 __u64 start, size_t num,
    786 					 void *in);
    787 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
    788 					ext2_ino_t start, unsigned int num,
    789 					void *out);
    790 extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
    791 					 __u64 start, size_t num,
    792 					 void *out);
    793 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
    794 					blk_t start, unsigned int num,
    795 					void *in);
    796 extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
    797 					 blk64_t start, size_t num,
    798 					 void *in);
    799 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
    800 					blk_t start, unsigned int num,
    801 					void *out);
    802 extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
    803 					 blk64_t start, size_t num,
    804 					 void *out);
    805 
    806 /* blknum.c */
    807 extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
    808 extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
    809 extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
    810 extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
    811 extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
    812 					 struct ext2_inode *inode);
    813 extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
    814 					 struct ext2_inode *inode);
    815 extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super);
    816 extern void ext2fs_blocks_count_set(struct ext2_super_block *super,
    817 				    blk64_t blk);
    818 extern void ext2fs_blocks_count_add(struct ext2_super_block *super,
    819 				    blk64_t blk);
    820 extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super);
    821 extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super,
    822 				      blk64_t blk);
    823 extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super,
    824 				      blk64_t blk);
    825 extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super);
    826 extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super,
    827 					 blk64_t blk);
    828 extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super,
    829 					 blk64_t blk);
    830 /* Block group descriptor accessor functions */
    831 extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
    832 					  struct opaque_ext2_group_desc *gdp,
    833 					  dgrp_t group);
    834 extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group);
    835 extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
    836 					blk64_t blk);
    837 extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group);
    838 extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
    839 					blk64_t blk);
    840 extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group);
    841 extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group,
    842 				       blk64_t blk);
    843 extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group);
    844 extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group,
    845 					 __u32 n);
    846 extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group);
    847 extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group,
    848 					 __u32 n);
    849 extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group);
    850 extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group,
    851 				       __u32 n);
    852 extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
    853 extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
    854 				     __u32 n);
    855 extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
    856 extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
    857 extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
    858 extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
    859 extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
    860 extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
    861 extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
    862 extern blk64_t ext2fs_file_acl_block(ext2_filsys fs,
    863 				     const struct ext2_inode *inode);
    864 extern void ext2fs_file_acl_block_set(ext2_filsys fs,
    865 				      struct ext2_inode *inode, blk64_t blk);
    866 
    867 /* block.c */
    868 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
    869 				      ext2_ino_t	ino,
    870 				      int	flags,
    871 				      char *block_buf,
    872 				      int (*func)(ext2_filsys fs,
    873 						  blk_t	*blocknr,
    874 						  int	blockcnt,
    875 						  void	*priv_data),
    876 				      void *priv_data);
    877 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
    878 				ext2_ino_t	ino,
    879 				int	flags,
    880 				char *block_buf,
    881 				int (*func)(ext2_filsys fs,
    882 					    blk_t	*blocknr,
    883 					    e2_blkcnt_t	blockcnt,
    884 					    blk_t	ref_blk,
    885 					    int		ref_offset,
    886 					    void	*priv_data),
    887 				void *priv_data);
    888 errcode_t ext2fs_block_iterate3(ext2_filsys fs,
    889 				ext2_ino_t ino,
    890 				int	flags,
    891 				char *block_buf,
    892 				int (*func)(ext2_filsys fs,
    893 					    blk64_t	*blocknr,
    894 					    e2_blkcnt_t	blockcnt,
    895 					    blk64_t	ref_blk,
    896 					    int		ref_offset,
    897 					    void	*priv_data),
    898 				void *priv_data);
    899 
    900 /* bmap.c */
    901 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
    902 			     struct ext2_inode *inode,
    903 			     char *block_buf, int bmap_flags,
    904 			     blk_t block, blk_t *phys_blk);
    905 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
    906 			      struct ext2_inode *inode,
    907 			      char *block_buf, int bmap_flags, blk64_t block,
    908 			      int *ret_flags, blk64_t *phys_blk);
    909 errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino,
    910 				   struct ext2_inode *inode, blk64_t lblk,
    911 				   blk64_t *pblk);
    912 
    913 #if 0
    914 /* bmove.c */
    915 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
    916 				    ext2fs_block_bitmap reserve,
    917 				    ext2fs_block_bitmap alloc_map,
    918 				    int flags);
    919 #endif
    920 
    921 /* check_desc.c */
    922 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
    923 
    924 /* closefs.c */
    925 extern errcode_t ext2fs_close(ext2_filsys fs);
    926 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
    927 extern errcode_t ext2fs_flush(ext2_filsys fs);
    928 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
    929 extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
    930 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
    931 				    dgrp_t group,
    932 				    blk64_t *ret_super_blk,
    933 				    blk64_t *ret_old_desc_blk,
    934 				    blk64_t *ret_new_desc_blk,
    935 				    blk_t *ret_used_blks);
    936 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
    937 				    dgrp_t group,
    938 				    blk_t *ret_super_blk,
    939 				    blk_t *ret_old_desc_blk,
    940 				    blk_t *ret_new_desc_blk,
    941 				    int *ret_meta_bg);
    942 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
    943 
    944 /* crc32c.c */
    945 extern __u32 ext2fs_crc32c_be(__u32 crc, unsigned char const *p, size_t len);
    946 extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
    947 
    948 /* csum.c */
    949 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
    950 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
    951 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
    952 extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
    953 
    954 /* dblist.c */
    955 
    956 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
    957 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
    958 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
    959 				      blk_t blk, int blockcnt);
    960 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
    961 				       blk64_t blk, e2_blkcnt_t blockcnt);
    962 extern void ext2fs_dblist_sort(ext2_dblist dblist,
    963 			       EXT2_QSORT_TYPE (*sortfunc)(const void *,
    964 							   const void *));
    965 extern void ext2fs_dblist_sort2(ext2_dblist dblist,
    966 				EXT2_QSORT_TYPE (*sortfunc)(const void *,
    967 							    const void *));
    968 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
    969 	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
    970 		    void	*priv_data),
    971        void *priv_data);
    972 extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
    973 	int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
    974 		    void	*priv_data),
    975        void *priv_data);
    976 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
    977 				      blk_t blk, int blockcnt);
    978 extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
    979 				       blk64_t blk, e2_blkcnt_t blockcnt);
    980 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
    981 				    ext2_dblist *dest);
    982 extern int ext2fs_dblist_count(ext2_dblist dblist);
    983 extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist);
    984 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
    985 					struct ext2_db_entry **entry);
    986 extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
    987 					struct ext2_db_entry2 **entry);
    988 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
    989 
    990 /* dblist_dir.c */
    991 extern errcode_t
    992 	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
    993 				  int	flags,
    994 				  char	*block_buf,
    995 				  int (*func)(ext2_ino_t	dir,
    996 					      int		entry,
    997 					      struct ext2_dir_entry *dirent,
    998 					      int	offset,
    999 					      int	blocksize,
   1000 					      char	*buf,
   1001 					      void	*priv_data),
   1002 				  void *priv_data);
   1003 
   1004 /* dirblock.c */
   1005 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
   1006 				       void *buf);
   1007 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
   1008 					void *buf, int flags);
   1009 extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
   1010 					void *buf, int flags);
   1011 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
   1012 					void *buf);
   1013 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
   1014 					 void *buf, int flags);
   1015 extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
   1016 					 void *buf, int flags);
   1017 
   1018 /* dirhash.c */
   1019 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
   1020 				const __u32 *seed,
   1021 				ext2_dirhash_t *ret_hash,
   1022 				ext2_dirhash_t *ret_minor_hash);
   1023 
   1024 
   1025 /* dir_iterate.c */
   1026 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
   1027 				    struct ext2_dir_entry *dirent,
   1028 				    unsigned int *rec_len);
   1029 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
   1030 				    unsigned int len,
   1031 				    struct ext2_dir_entry *dirent);
   1032 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
   1033 			      ext2_ino_t dir,
   1034 			      int flags,
   1035 			      char *block_buf,
   1036 			      int (*func)(struct ext2_dir_entry *dirent,
   1037 					  int	offset,
   1038 					  int	blocksize,
   1039 					  char	*buf,
   1040 					  void	*priv_data),
   1041 			      void *priv_data);
   1042 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
   1043 			      ext2_ino_t dir,
   1044 			      int flags,
   1045 			      char *block_buf,
   1046 			      int (*func)(ext2_ino_t	dir,
   1047 					  int	entry,
   1048 					  struct ext2_dir_entry *dirent,
   1049 					  int	offset,
   1050 					  int	blocksize,
   1051 					  char	*buf,
   1052 					  void	*priv_data),
   1053 			      void *priv_data);
   1054 
   1055 /* dupfs.c */
   1056 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
   1057 
   1058 /* expanddir.c */
   1059 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
   1060 
   1061 /* ext_attr.c */
   1062 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
   1063 					void *data);
   1064 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
   1065 extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block,
   1066 				       void *buf);
   1067 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
   1068 				       void *buf);
   1069 extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block,
   1070 				       void *buf);
   1071 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
   1072 					   char *block_buf,
   1073 					   int adjust, __u32 *newcount);
   1074 extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
   1075 					   char *block_buf,
   1076 					   int adjust, __u32 *newcount);
   1077 
   1078 /* extent.c */
   1079 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
   1080 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
   1081 				    ext2_extent_handle_t *handle);
   1082 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
   1083 					struct ext2_inode *inode,
   1084 					ext2_extent_handle_t *ret_handle);
   1085 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
   1086 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
   1087 				   int flags, struct ext2fs_extent *extent);
   1088 extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
   1089 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
   1090 				       struct ext2fs_extent *extent);
   1091 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
   1092 				      struct ext2fs_extent *extent);
   1093 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
   1094 					blk64_t logical, blk64_t physical,
   1095 					int flags);
   1096 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
   1097 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
   1098 					struct ext2_extent_info *info);
   1099 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
   1100 				    blk64_t blk);
   1101 extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
   1102 				     int leaf_level, blk64_t blk);
   1103 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
   1104 
   1105 /* fileio.c */
   1106 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
   1107 				   struct ext2_inode *inode,
   1108 				   int flags, ext2_file_t *ret);
   1109 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
   1110 				  int flags, ext2_file_t *ret);
   1111 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
   1112 struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);
   1113 extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file);
   1114 extern errcode_t ext2fs_file_close(ext2_file_t file);
   1115 extern errcode_t ext2fs_file_flush(ext2_file_t file);
   1116 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
   1117 				  unsigned int wanted, unsigned int *got);
   1118 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
   1119 				   unsigned int nbytes, unsigned int *written);
   1120 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
   1121 				   int whence, __u64 *ret_pos);
   1122 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
   1123 				   int whence, ext2_off_t *ret_pos);
   1124 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
   1125 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
   1126 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
   1127 extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size);
   1128 
   1129 /* finddev.c */
   1130 extern char *ext2fs_find_block_device(dev_t device);
   1131 
   1132 /* flushb.c */
   1133 extern errcode_t ext2fs_sync_device(int fd, int flushb);
   1134 
   1135 /* freefs.c */
   1136 extern void ext2fs_free(ext2_filsys fs);
   1137 extern void ext2fs_free_dblist(ext2_dblist dblist);
   1138 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
   1139 extern void ext2fs_u32_list_free(ext2_u32_list bb);
   1140 
   1141 /* gen_bitmap.c */
   1142 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
   1143 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
   1144 					    __u32 start, __u32 end,
   1145 					    __u32 real_end,
   1146 					    const char *descr, char *init_map,
   1147 					    ext2fs_generic_bitmap *ret);
   1148 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
   1149 						__u32 end,
   1150 						__u32 real_end,
   1151 						const char *descr,
   1152 						ext2fs_generic_bitmap *ret);
   1153 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
   1154 					    ext2fs_generic_bitmap *dest);
   1155 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
   1156 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
   1157 						 errcode_t magic,
   1158 						 errcode_t neq,
   1159 						 ext2_ino_t end,
   1160 						 ext2_ino_t *oend);
   1161 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
   1162 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
   1163 					      __u32 new_end,
   1164 					      __u32 new_real_end,
   1165 					      ext2fs_generic_bitmap bmap);
   1166 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
   1167 					       ext2fs_generic_bitmap bm1,
   1168 					       ext2fs_generic_bitmap bm2);
   1169 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
   1170 						 errcode_t magic,
   1171 						 __u32 start, __u32 num,
   1172 						 void *out);
   1173 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
   1174 						 errcode_t magic,
   1175 						 __u32 start, __u32 num,
   1176 						 void *in);
   1177 extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap,
   1178 						       __u32 start, __u32 end,
   1179 						       __u32 *out);
   1180 
   1181 /* gen_bitmap64.c */
   1182 
   1183 /* Generate and print bitmap usage statistics */
   1184 #define BMAP_STATS
   1185 
   1186 void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
   1187 errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
   1188 				    int type, __u64 start, __u64 end,
   1189 				    __u64 real_end,
   1190 				    const char *descr,
   1191 				    ext2fs_generic_bitmap *ret);
   1192 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
   1193 				   ext2fs_generic_bitmap *dest);
   1194 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
   1195 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
   1196 					errcode_t neq,
   1197 					__u64 end, __u64 *oend);
   1198 void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
   1199 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
   1200 				     __u64 new_end,
   1201 				     __u64 new_real_end);
   1202 errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
   1203 				      ext2fs_generic_bitmap bm1,
   1204 				      ext2fs_generic_bitmap bm2);
   1205 errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
   1206 					__u64 start, unsigned int num,
   1207 					void *out);
   1208 errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
   1209 					__u64 start, unsigned int num,
   1210 					void *in);
   1211 errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
   1212 					   ext2fs_block_bitmap *bitmap);
   1213 
   1214 /* getsize.c */
   1215 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
   1216 					blk_t *retblocks);
   1217 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
   1218 					blk64_t *retblocks);
   1219 
   1220 /* getsectsize.c */
   1221 extern int ext2fs_get_dio_alignment(int fd);
   1222 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
   1223 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
   1224 
   1225 /* i_block.c */
   1226 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
   1227 				 blk64_t num_blocks);
   1228 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
   1229 				 blk64_t num_blocks);
   1230 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
   1231 
   1232 /* imager.c */
   1233 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
   1234 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
   1235 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
   1236 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
   1237 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
   1238 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
   1239 
   1240 /* ind_block.c */
   1241 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
   1242 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
   1243 
   1244 /* initialize.c */
   1245 extern errcode_t ext2fs_initialize(const char *name, int flags,
   1246 				   struct ext2_super_block *param,
   1247 				   io_manager manager, ext2_filsys *ret_fs);
   1248 
   1249 /* icount.c */
   1250 extern void ext2fs_free_icount(ext2_icount_t icount);
   1251 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
   1252 					  int flags, ext2_icount_t *ret);
   1253 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
   1254 				       unsigned int size,
   1255 				       ext2_icount_t hint, ext2_icount_t *ret);
   1256 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
   1257 				      unsigned int size,
   1258 				      ext2_icount_t *ret);
   1259 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
   1260 				     __u16 *ret);
   1261 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
   1262 					 __u16 *ret);
   1263 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
   1264 					 __u16 *ret);
   1265 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
   1266 				     __u16 count);
   1267 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
   1268 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
   1269 
   1270 /* inline.c */
   1271 
   1272 extern errcode_t ext2fs_get_memalign(unsigned long size,
   1273 				     unsigned long align, void *ptr);
   1274 
   1275 /* inode.c */
   1276 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
   1277 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
   1278 					    ext2_ino_t *ino,
   1279 					    struct ext2_inode *inode,
   1280 					    int bufsize);
   1281 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
   1282 				  ext2_inode_scan *ret_scan);
   1283 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
   1284 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
   1285 			       struct ext2_inode *inode);
   1286 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
   1287 						   int	group);
   1288 extern void ext2fs_set_inode_callback
   1289 	(ext2_inode_scan scan,
   1290 	 errcode_t (*done_group)(ext2_filsys fs,
   1291 				 ext2_inode_scan scan,
   1292 				 dgrp_t group,
   1293 				 void * priv_data),
   1294 	 void *done_group_data);
   1295 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
   1296 				   int clear_flags);
   1297 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
   1298 					struct ext2_inode * inode,
   1299 					int bufsize);
   1300 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
   1301 			    struct ext2_inode * inode);
   1302 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
   1303 					 struct ext2_inode * inode,
   1304 					 int bufsize);
   1305 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
   1306 			    struct ext2_inode * inode);
   1307 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
   1308 			    struct ext2_inode * inode);
   1309 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
   1310 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
   1311 
   1312 /* inode_io.c */
   1313 extern io_manager inode_io_manager;
   1314 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
   1315 					char **name);
   1316 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
   1317 					 struct ext2_inode *inode,
   1318 					 char **name);
   1319 
   1320 /* ismounted.c */
   1321 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
   1322 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
   1323 					  char *mtpt, int mtlen);
   1324 
   1325 /* punch.c */
   1326 /*
   1327  * NOTE: This function removes from an inode the blocks "start", "end", and
   1328  * every block in between.
   1329  */
   1330 extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
   1331 			      struct ext2_inode *inode,
   1332 			      char *block_buf, blk64_t start,
   1333 			      blk64_t end);
   1334 
   1335 /* namei.c */
   1336 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
   1337 			 int namelen, char *buf, ext2_ino_t *inode);
   1338 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
   1339 			const char *name, ext2_ino_t *inode);
   1340 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
   1341 			      const char *name, ext2_ino_t *inode);
   1342 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
   1343 			ext2_ino_t inode, ext2_ino_t *res_inode);
   1344 
   1345 /* native.c */
   1346 int ext2fs_native_flag(void);
   1347 
   1348 /* newdir.c */
   1349 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
   1350 				ext2_ino_t parent_ino, char **block);
   1351 
   1352 /* mkdir.c */
   1353 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
   1354 			      const char *name);
   1355 
   1356 /* mkjournal.c */
   1357 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
   1358 				    blk_t *ret_blk, int *ret_count);
   1359 extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
   1360 				     blk64_t *ret_blk, int *ret_count);
   1361 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
   1362 						  __u32 num_blocks, int flags,
   1363 						  char  **ret_jsb);
   1364 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
   1365 					   ext2_filsys journal_dev);
   1366 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,
   1367 					  int flags);
   1368 extern int ext2fs_default_journal_size(__u64 num_blocks);
   1369 
   1370 /* openfs.c */
   1371 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
   1372 			     unsigned int block_size, io_manager manager,
   1373 			     ext2_filsys *ret_fs);
   1374 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
   1375 			      int flags, int superblock,
   1376 			      unsigned int block_size, io_manager manager,
   1377 			      ext2_filsys *ret_fs);
   1378 extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs,
   1379 					blk64_t group_block, dgrp_t i);
   1380 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
   1381 					 dgrp_t i);
   1382 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
   1383 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
   1384 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
   1385 
   1386 /* get_pathname.c */
   1387 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
   1388 			       char **name);
   1389 
   1390 /* link.c */
   1391 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
   1392 		      ext2_ino_t ino, int flags);
   1393 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
   1394 			ext2_ino_t ino, int flags);
   1395 
   1396 /* symlink.c */
   1397 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
   1398 			 const char *name, char *target);
   1399 
   1400 /* mmp.c */
   1401 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
   1402 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
   1403 errcode_t ext2fs_mmp_clear(ext2_filsys fs);
   1404 errcode_t ext2fs_mmp_init(ext2_filsys fs);
   1405 errcode_t ext2fs_mmp_start(ext2_filsys fs);
   1406 errcode_t ext2fs_mmp_update(ext2_filsys fs);
   1407 errcode_t ext2fs_mmp_stop(ext2_filsys fs);
   1408 unsigned ext2fs_mmp_new_seq(void);
   1409 
   1410 /* read_bb.c */
   1411 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
   1412 				      ext2_badblocks_list *bb_list);
   1413 
   1414 /* read_bb_file.c */
   1415 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
   1416 				      ext2_badblocks_list *bb_list,
   1417 				      void *priv_data,
   1418 				      void (*invalid)(ext2_filsys fs,
   1419 						      blk_t blk,
   1420 						      char *badstr,
   1421 						      void *priv_data));
   1422 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
   1423 				     ext2_badblocks_list *bb_list,
   1424 				     void (*invalid)(ext2_filsys fs,
   1425 						     blk_t blk));
   1426 
   1427 /* res_gdt.c */
   1428 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
   1429 
   1430 /* swapfs.c */
   1431 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
   1432 				 int has_header);
   1433 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
   1434 					struct ext2_ext_attr_header *from_hdr);
   1435 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
   1436 				       struct ext2_ext_attr_entry *from_entry);
   1437 extern void ext2fs_swap_super(struct ext2_super_block * super);
   1438 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
   1439 extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp);
   1440 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
   1441 				   struct ext2_inode_large *f, int hostorder,
   1442 				   int bufsize);
   1443 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
   1444 			      struct ext2_inode *f, int hostorder);
   1445 extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
   1446 
   1447 /* unix_io.c */
   1448 extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
   1449 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
   1450 extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
   1451 
   1452 /* valid_blk.c */
   1453 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
   1454 extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs,
   1455 					  struct ext2_inode *inode);
   1456 
   1457 /* version.c */
   1458 extern int ext2fs_parse_version_string(const char *ver_string);
   1459 extern int ext2fs_get_library_version(const char **ver_string,
   1460 				      const char **date_string);
   1461 
   1462 /* write_bb_file.c */
   1463 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
   1464 				      unsigned int flags,
   1465 				      FILE *f);
   1466 
   1467 
   1468 /* inline functions */
   1469 #ifdef NO_INLINE_FUNCS
   1470 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
   1471 extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr);
   1472 extern errcode_t ext2fs_get_array(unsigned long count,
   1473 				  unsigned long size, void *ptr);
   1474 extern errcode_t ext2fs_get_arrayzero(unsigned long count,
   1475 				      unsigned long size, void *ptr);
   1476 extern errcode_t ext2fs_free_mem(void *ptr);
   1477 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
   1478 				   unsigned long size, void *ptr);
   1479 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
   1480 extern void ext2fs_mark_changed(ext2_filsys fs);
   1481 extern int ext2fs_test_changed(ext2_filsys fs);
   1482 extern void ext2fs_mark_valid(ext2_filsys fs);
   1483 extern void ext2fs_unmark_valid(ext2_filsys fs);
   1484 extern int ext2fs_test_valid(ext2_filsys fs);
   1485 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
   1486 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
   1487 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
   1488 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
   1489 extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
   1490 extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
   1491 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
   1492 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
   1493 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
   1494 				      struct ext2_inode *inode);
   1495 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
   1496 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
   1497 #endif
   1498 
   1499 /*
   1500  * The actual inlined functions definitions themselves...
   1501  *
   1502  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
   1503  * functions at all!
   1504  */
   1505 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
   1506 #ifdef INCLUDE_INLINE_FUNCS
   1507 #define _INLINE_ extern
   1508 #else
   1509 #if (__STDC_VERSION__ >= 199901L)
   1510 #define _INLINE_ inline
   1511 #else
   1512 #ifdef __GNUC__
   1513 #define _INLINE_ extern __inline__
   1514 #else				/* For Watcom C */
   1515 #define _INLINE_ extern inline
   1516 #endif /* __GNUC__ */
   1517 #endif /* __STDC_VERSION__ >= 199901L */
   1518 #endif
   1519 
   1520 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
   1521 #include <string.h>
   1522 /*
   1523  *  Allocate memory.  The 'ptr' arg must point to a pointer.
   1524  */
   1525 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
   1526 {
   1527 	void *pp;
   1528 
   1529 	pp = malloc(size);
   1530 	if (!pp)
   1531 		return EXT2_ET_NO_MEMORY;
   1532 	memcpy(ptr, &pp, sizeof (pp));
   1533 	return 0;
   1534 }
   1535 
   1536 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
   1537 {
   1538 	void *pp;
   1539 
   1540 	pp = malloc(size);
   1541 	if (!pp)
   1542 		return EXT2_ET_NO_MEMORY;
   1543 	memset(pp, 0, size);
   1544 	memcpy(ptr, &pp, sizeof(pp));
   1545 	return 0;
   1546 }
   1547 
   1548 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
   1549 {
   1550 	if (count && (-1UL)/count<size)
   1551 		return EXT2_ET_NO_MEMORY;
   1552 	return ext2fs_get_mem(count*size, ptr);
   1553 }
   1554 
   1555 _INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
   1556 					unsigned long size, void *ptr)
   1557 {
   1558 	void *pp;
   1559 
   1560 	if (count && (-1UL)/count<size)
   1561 		return EXT2_ET_NO_MEMORY;
   1562 	pp = calloc(count, size);
   1563 	if (!pp)
   1564 		return EXT2_ET_NO_MEMORY;
   1565 	memcpy(ptr, &pp, sizeof(pp));
   1566 	return 0;
   1567 }
   1568 
   1569 /*
   1570  * Free memory.  The 'ptr' arg must point to a pointer.
   1571  */
   1572 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
   1573 {
   1574 	void *p;
   1575 
   1576 	memcpy(&p, ptr, sizeof(p));
   1577 	free(p);
   1578 	p = 0;
   1579 	memcpy(ptr, &p, sizeof(p));
   1580 	return 0;
   1581 }
   1582 
   1583 /*
   1584  *  Resize memory.  The 'ptr' arg must point to a pointer.
   1585  */
   1586 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
   1587 				     unsigned long size, void *ptr)
   1588 {
   1589 	void *p;
   1590 
   1591 	/* Use "memcpy" for pointer assignments here to avoid problems
   1592 	 * with C99 strict type aliasing rules. */
   1593 	memcpy(&p, ptr, sizeof(p));
   1594 	p = realloc(p, size);
   1595 	if (!p)
   1596 		return EXT2_ET_NO_MEMORY;
   1597 	memcpy(ptr, &p, sizeof(p));
   1598 	return 0;
   1599 }
   1600 #endif	/* Custom memory routines */
   1601 
   1602 /*
   1603  * Mark a filesystem superblock as dirty
   1604  */
   1605 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
   1606 {
   1607 	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
   1608 }
   1609 
   1610 /*
   1611  * Mark a filesystem as changed
   1612  */
   1613 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
   1614 {
   1615 	fs->flags |= EXT2_FLAG_CHANGED;
   1616 }
   1617 
   1618 /*
   1619  * Check to see if a filesystem has changed
   1620  */
   1621 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
   1622 {
   1623 	return (fs->flags & EXT2_FLAG_CHANGED);
   1624 }
   1625 
   1626 /*
   1627  * Mark a filesystem as valid
   1628  */
   1629 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
   1630 {
   1631 	fs->flags |= EXT2_FLAG_VALID;
   1632 }
   1633 
   1634 /*
   1635  * Mark a filesystem as NOT valid
   1636  */
   1637 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
   1638 {
   1639 	fs->flags &= ~EXT2_FLAG_VALID;
   1640 }
   1641 
   1642 /*
   1643  * Check to see if a filesystem is valid
   1644  */
   1645 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
   1646 {
   1647 	return (fs->flags & EXT2_FLAG_VALID);
   1648 }
   1649 
   1650 /*
   1651  * Mark the inode bitmap as dirty
   1652  */
   1653 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
   1654 {
   1655 	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
   1656 }
   1657 
   1658 /*
   1659  * Mark the block bitmap as dirty
   1660  */
   1661 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
   1662 {
   1663 	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
   1664 }
   1665 
   1666 /*
   1667  * Check to see if a filesystem's inode bitmap is dirty
   1668  */
   1669 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
   1670 {
   1671 	return (fs->flags & EXT2_FLAG_IB_DIRTY);
   1672 }
   1673 
   1674 /*
   1675  * Check to see if a filesystem's block bitmap is dirty
   1676  */
   1677 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
   1678 {
   1679 	return (fs->flags & EXT2_FLAG_BB_DIRTY);
   1680 }
   1681 
   1682 /*
   1683  * Return the group # of a block
   1684  */
   1685 _INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
   1686 {
   1687 	return ext2fs_group_of_blk2(fs, blk);
   1688 }
   1689 /*
   1690  * Return the group # of an inode number
   1691  */
   1692 _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
   1693 {
   1694 	return (ino - 1) / fs->super->s_inodes_per_group;
   1695 }
   1696 
   1697 /*
   1698  * Return the first block (inclusive) in a group
   1699  */
   1700 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
   1701 {
   1702 	return (blk_t) ext2fs_group_first_block2(fs, group);
   1703 }
   1704 
   1705 /*
   1706  * Return the last block (inclusive) in a group
   1707  */
   1708 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
   1709 {
   1710 	return (blk_t) ext2fs_group_last_block2(fs, group);
   1711 }
   1712 
   1713 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
   1714 					struct ext2_inode *inode)
   1715 {
   1716 	return (blk_t) ext2fs_inode_data_blocks2(fs, inode);
   1717 }
   1718 
   1719 /*
   1720  * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
   1721  */
   1722 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
   1723 {
   1724 	if (!a)
   1725 		return 0;
   1726 	return ((a - 1) / b) + 1;
   1727 }
   1728 
   1729 _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b)
   1730 {
   1731 	if (!a)
   1732 		return 0;
   1733 	return ((a - 1) / b) + 1;
   1734 }
   1735 
   1736 #undef _INLINE_
   1737 #endif
   1738 
   1739 #ifdef __cplusplus
   1740 }
   1741 #endif
   1742 
   1743 #endif /* _EXT2FS_EXT2FS_H */
   1744