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