• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define EXT2FS_SHA256_LENGTH 32
540 #define EXT2FS_DIGEST_SIZE EXT2FS_SHA256_LENGTH
541 
542 /*
543  * For ext2 compression support
544  */
545 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
546 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
547 
548 /*
549  * Features supported by this version of the library
550  */
551 #define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
552 					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
553 					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
554 					 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
555 					 EXT2_FEATURE_COMPAT_DIR_INDEX|\
556 					 EXT2_FEATURE_COMPAT_EXT_ATTR)
557 
558 /* This #ifdef is temporary until compression is fully supported */
559 #ifdef ENABLE_COMPRESSION
560 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
561 /* If the below warning bugs you, then have
562    `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
563    environment at configure time. */
564  #warning "Compression support is experimental"
565 #endif
566 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
567 					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
568 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
569 					 EXT2_FEATURE_INCOMPAT_META_BG|\
570 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
571 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
572 					 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
573 					 EXT4_FEATURE_INCOMPAT_MMP|\
574 					 EXT4_FEATURE_INCOMPAT_64BIT|\
575 					 EXT4_FEATURE_INCOMPAT_ENCRYPT)
576 #else
577 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
578 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
579 					 EXT2_FEATURE_INCOMPAT_META_BG|\
580 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
581 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
582 					 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
583 					 EXT4_FEATURE_INCOMPAT_MMP|\
584 					 EXT4_FEATURE_INCOMPAT_64BIT|\
585 					 EXT4_FEATURE_INCOMPAT_ENCRYPT)
586 #endif
587 #ifdef CONFIG_QUOTA
588 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
589 					 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
590 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
591 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
592 					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
593 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
594 					 EXT4_FEATURE_RO_COMPAT_BIGALLOC|\
595 					 EXT4_FEATURE_RO_COMPAT_QUOTA)
596 #else
597 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
598 					 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
599 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
600 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
601 					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
602 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
603 					 EXT4_FEATURE_RO_COMPAT_BIGALLOC)
604 #endif
605 
606 /*
607  * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
608  * to ext2fs_openfs()
609  */
610 #define EXT2_LIB_SOFTSUPP_INCOMPAT	(0)
611 #define EXT2_LIB_SOFTSUPP_RO_COMPAT	(EXT4_FEATURE_RO_COMPAT_REPLICA)
612 
613 
614 /* Translate a block number to a cluster number */
615 #define EXT2FS_CLUSTER_RATIO(fs)	(1 << (fs)->cluster_ratio_bits)
616 #define EXT2FS_CLUSTER_MASK(fs)		(EXT2FS_CLUSTER_RATIO(fs) - 1)
617 #define EXT2FS_B2C(fs, blk)		((blk) >> (fs)->cluster_ratio_bits)
618 /* Translate a cluster number to a block number */
619 #define EXT2FS_C2B(fs, cluster)		((cluster) << (fs)->cluster_ratio_bits)
620 /* Translate # of blks to # of clusters */
621 #define EXT2FS_NUM_B2C(fs, blks)	(((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
622 					 (fs)->cluster_ratio_bits)
623 
624 #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
625 typedef struct stat64 ext2fs_struct_stat;
626 #else
627 typedef struct stat ext2fs_struct_stat;
628 #endif
629 
630 /*
631  * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
632  * avoid the fsync call.
633  */
634 #define EXT2_FLAG_FLUSH_NO_SYNC          1
635 
636 /*
637  * function prototypes
638  */
639 
640 /* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */
ext2fs_needs_large_file_feature(unsigned long long file_size)641 static inline int ext2fs_needs_large_file_feature(unsigned long long file_size)
642 {
643 	return file_size >= 0x80000000ULL;
644 }
645 
646 /* alloc.c */
647 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
648 				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
649 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
650 				  ext2fs_block_bitmap map, blk_t *ret);
651 extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
652 				   ext2fs_block_bitmap map, blk64_t *ret);
653 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
654 					blk_t finish, int num,
655 					ext2fs_block_bitmap map,
656 					blk_t *ret);
657 extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start,
658 					 blk64_t finish, int num,
659 					 ext2fs_block_bitmap map,
660 					 blk64_t *ret);
661 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
662 				    char *block_buf, blk_t *ret);
663 extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal,
664 				     char *block_buf, blk64_t *ret);
665 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
666 					    errcode_t (*func)(ext2_filsys fs,
667 							      blk64_t goal,
668 							      blk64_t *ret),
669 					    errcode_t (**old)(ext2_filsys fs,
670 							      blk64_t goal,
671 							      blk64_t *ret));
672 
673 /* alloc_sb.c */
674 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
675 					dgrp_t group,
676 					ext2fs_block_bitmap bmap);
677 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
678 						  void (*func)(ext2_filsys fs,
679 							       blk64_t blk,
680 							       int inuse),
681 						  void (**old)(ext2_filsys fs,
682 							       blk64_t blk,
683 							       int inuse));
684 
685 /* alloc_stats.c */
686 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
687 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
688 			       int inuse, int isdir);
689 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
690 void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
691 
692 /* alloc_tables.c */
693 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
694 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
695 					     ext2fs_block_bitmap bmap);
696 
697 /* badblocks.c */
698 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
699 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
700 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
701 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
702 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
703 					       ext2_u32_iterate *ret);
704 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
705 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
706 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
707 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
708 
709 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
710 					    int size);
711 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
712 					   blk_t blk);
713 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
714 				    blk_t blk);
715 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
716 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
717 extern errcode_t
718 	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
719 					    ext2_badblocks_iterate *ret);
720 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
721 					 blk_t *blk);
722 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
723 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
724 				       ext2_badblocks_list *dest);
725 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
726 				  ext2_badblocks_list bb2);
727 extern int ext2fs_u32_list_count(ext2_u32_list bb);
728 
729 /* bb_compat */
730 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
731 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
732 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
733 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
734 					      badblocks_iterate *ret);
735 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
736 extern void badblocks_list_iterate_end(badblocks_iterate iter);
737 extern void badblocks_list_free(badblocks_list bb);
738 
739 /* bb_inode.c */
740 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
741 					ext2_badblocks_list bb_list);
742 
743 /* bitmaps.c */
744 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
745 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
746 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
747 				    ext2fs_generic_bitmap *dest);
748 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
749 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
750 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
751 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
752 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
753 					      const char *descr,
754 					      ext2fs_block_bitmap *ret);
755 extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
756 						   const char *descr,
757 						   ext2fs_block_bitmap *ret);
758 extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap);
759 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
760 					      const char *descr,
761 					      ext2fs_inode_bitmap *ret);
762 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
763 					       ext2_ino_t end, ext2_ino_t *oend);
764 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
765 					       blk_t end, blk_t *oend);
766 extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
767 					 blk64_t end, blk64_t *oend);
768 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
769 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
770 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
771 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
772 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
773 					    ext2fs_inode_bitmap bmap);
774 extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end,
775 					     __u64 new_real_end,
776 					     ext2fs_inode_bitmap bmap);
777 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
778 					    ext2fs_block_bitmap bmap);
779 extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end,
780 					     __u64 new_real_end,
781 					     ext2fs_block_bitmap bmap);
782 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
783 					     ext2fs_block_bitmap bm2);
784 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
785 					     ext2fs_inode_bitmap bm2);
786 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
787 					ext2_ino_t start, unsigned int num,
788 					void *in);
789 extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
790 					 __u64 start, size_t num,
791 					 void *in);
792 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
793 					ext2_ino_t start, unsigned int num,
794 					void *out);
795 extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
796 					 __u64 start, size_t num,
797 					 void *out);
798 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
799 					blk_t start, unsigned int num,
800 					void *in);
801 extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
802 					 blk64_t start, size_t num,
803 					 void *in);
804 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
805 					blk_t start, unsigned int num,
806 					void *out);
807 extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
808 					 blk64_t start, size_t num,
809 					 void *out);
810 
811 /* blknum.c */
812 extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
813 extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
814 extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
815 extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
816 extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
817 					 struct ext2_inode *inode);
818 extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
819 					 struct ext2_inode *inode);
820 extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super);
821 extern void ext2fs_blocks_count_set(struct ext2_super_block *super,
822 				    blk64_t blk);
823 extern void ext2fs_blocks_count_add(struct ext2_super_block *super,
824 				    blk64_t blk);
825 extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super);
826 extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super,
827 				      blk64_t blk);
828 extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super,
829 				      blk64_t blk);
830 extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super);
831 extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super,
832 					 blk64_t blk);
833 extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super,
834 					 blk64_t blk);
835 /* Block group descriptor accessor functions */
836 extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
837 					  struct opaque_ext2_group_desc *gdp,
838 					  dgrp_t group);
839 extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group);
840 extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
841 					blk64_t blk);
842 extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group);
843 extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
844 					blk64_t blk);
845 extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group);
846 extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group,
847 				       blk64_t blk);
848 extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group);
849 extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group,
850 					 __u32 n);
851 extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group);
852 extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group,
853 					 __u32 n);
854 extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group);
855 extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group,
856 				       __u32 n);
857 extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
858 extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
859 				     __u32 n);
860 extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
861 extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
862 extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
863 extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
864 extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
865 extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
866 extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
867 extern blk64_t ext2fs_file_acl_block(ext2_filsys fs,
868 				     const struct ext2_inode *inode);
869 extern void ext2fs_file_acl_block_set(ext2_filsys fs,
870 				      struct ext2_inode *inode, blk64_t blk);
871 
872 /* block.c */
873 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
874 				      ext2_ino_t	ino,
875 				      int	flags,
876 				      char *block_buf,
877 				      int (*func)(ext2_filsys fs,
878 						  blk_t	*blocknr,
879 						  int	blockcnt,
880 						  void	*priv_data),
881 				      void *priv_data);
882 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
883 				ext2_ino_t	ino,
884 				int	flags,
885 				char *block_buf,
886 				int (*func)(ext2_filsys fs,
887 					    blk_t	*blocknr,
888 					    e2_blkcnt_t	blockcnt,
889 					    blk_t	ref_blk,
890 					    int		ref_offset,
891 					    void	*priv_data),
892 				void *priv_data);
893 errcode_t ext2fs_block_iterate3(ext2_filsys fs,
894 				ext2_ino_t ino,
895 				int	flags,
896 				char *block_buf,
897 				int (*func)(ext2_filsys fs,
898 					    blk64_t	*blocknr,
899 					    e2_blkcnt_t	blockcnt,
900 					    blk64_t	ref_blk,
901 					    int		ref_offset,
902 					    void	*priv_data),
903 				void *priv_data);
904 
905 /* bmap.c */
906 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
907 			     struct ext2_inode *inode,
908 			     char *block_buf, int bmap_flags,
909 			     blk_t block, blk_t *phys_blk);
910 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
911 			      struct ext2_inode *inode,
912 			      char *block_buf, int bmap_flags, blk64_t block,
913 			      int *ret_flags, blk64_t *phys_blk);
914 errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino,
915 				   struct ext2_inode *inode, blk64_t lblk,
916 				   blk64_t *pblk);
917 
918 #if 0
919 /* bmove.c */
920 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
921 				    ext2fs_block_bitmap reserve,
922 				    ext2fs_block_bitmap alloc_map,
923 				    int flags);
924 #endif
925 
926 /* check_desc.c */
927 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
928 
929 /* closefs.c */
930 extern errcode_t ext2fs_close(ext2_filsys fs);
931 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
932 extern errcode_t ext2fs_flush(ext2_filsys fs);
933 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
934 extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
935 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
936 				    dgrp_t group,
937 				    blk64_t *ret_super_blk,
938 				    blk64_t *ret_old_desc_blk,
939 				    blk64_t *ret_new_desc_blk,
940 				    blk_t *ret_used_blks);
941 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
942 				    dgrp_t group,
943 				    blk_t *ret_super_blk,
944 				    blk_t *ret_old_desc_blk,
945 				    blk_t *ret_new_desc_blk,
946 				    int *ret_meta_bg);
947 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
948 
949 /* crc32c.c */
950 extern __u32 ext2fs_crc32c_be(__u32 crc, unsigned char const *p, size_t len);
951 extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
952 
953 /* csum.c */
954 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
955 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
956 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
957 extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
958 
959 /* dblist.c */
960 
961 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
962 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
963 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
964 				      blk_t blk, int blockcnt);
965 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
966 				       blk64_t blk, e2_blkcnt_t blockcnt);
967 extern void ext2fs_dblist_sort(ext2_dblist dblist,
968 			       EXT2_QSORT_TYPE (*sortfunc)(const void *,
969 							   const void *));
970 extern void ext2fs_dblist_sort2(ext2_dblist dblist,
971 				EXT2_QSORT_TYPE (*sortfunc)(const void *,
972 							    const void *));
973 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
974 	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
975 		    void	*priv_data),
976        void *priv_data);
977 extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
978 	int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
979 		    void	*priv_data),
980        void *priv_data);
981 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
982 				      blk_t blk, int blockcnt);
983 extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
984 				       blk64_t blk, e2_blkcnt_t blockcnt);
985 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
986 				    ext2_dblist *dest);
987 extern int ext2fs_dblist_count(ext2_dblist dblist);
988 extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist);
989 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
990 					struct ext2_db_entry **entry);
991 extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
992 					struct ext2_db_entry2 **entry);
993 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
994 
995 /* dblist_dir.c */
996 extern errcode_t
997 	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
998 				  int	flags,
999 				  char	*block_buf,
1000 				  int (*func)(ext2_ino_t	dir,
1001 					      int		entry,
1002 					      struct ext2_dir_entry *dirent,
1003 					      int	offset,
1004 					      int	blocksize,
1005 					      char	*buf,
1006 					      void	*priv_data),
1007 				  void *priv_data);
1008 
1009 /* dirblock.c */
1010 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
1011 				       void *buf);
1012 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
1013 					void *buf, int flags);
1014 extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
1015 					void *buf, int flags);
1016 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
1017 					void *buf);
1018 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
1019 					 void *buf, int flags);
1020 extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
1021 					 void *buf, int flags);
1022 
1023 /* dirhash.c */
1024 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
1025 				const __u32 *seed,
1026 				ext2_dirhash_t *ret_hash,
1027 				ext2_dirhash_t *ret_minor_hash);
1028 
1029 
1030 /* dir_iterate.c */
1031 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
1032 				    struct ext2_dir_entry *dirent,
1033 				    unsigned int *rec_len);
1034 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
1035 				    unsigned int len,
1036 				    struct ext2_dir_entry *dirent);
1037 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
1038 			      ext2_ino_t dir,
1039 			      int flags,
1040 			      char *block_buf,
1041 			      int (*func)(struct ext2_dir_entry *dirent,
1042 					  int	offset,
1043 					  int	blocksize,
1044 					  char	*buf,
1045 					  void	*priv_data),
1046 			      void *priv_data);
1047 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
1048 			      ext2_ino_t dir,
1049 			      int flags,
1050 			      char *block_buf,
1051 			      int (*func)(ext2_ino_t	dir,
1052 					  int	entry,
1053 					  struct ext2_dir_entry *dirent,
1054 					  int	offset,
1055 					  int	blocksize,
1056 					  char	*buf,
1057 					  void	*priv_data),
1058 			      void *priv_data);
1059 
1060 /* dupfs.c */
1061 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
1062 
1063 /* expanddir.c */
1064 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
1065 
1066 /* ext_attr.c */
1067 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
1068 					void *data);
1069 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
1070 extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block,
1071 				       void *buf);
1072 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
1073 				       void *buf);
1074 extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block,
1075 				       void *buf);
1076 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
1077 					   char *block_buf,
1078 					   int adjust, __u32 *newcount);
1079 extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
1080 					   char *block_buf,
1081 					   int adjust, __u32 *newcount);
1082 
1083 /* extent.c */
1084 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
1085 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
1086 				    ext2_extent_handle_t *handle);
1087 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
1088 					struct ext2_inode *inode,
1089 					ext2_extent_handle_t *ret_handle);
1090 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
1091 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
1092 				   int flags, struct ext2fs_extent *extent);
1093 extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
1094 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
1095 				       struct ext2fs_extent *extent);
1096 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
1097 				      struct ext2fs_extent *extent);
1098 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
1099 					blk64_t logical, blk64_t physical,
1100 					int flags);
1101 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
1102 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
1103 					struct ext2_extent_info *info);
1104 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
1105 				    blk64_t blk);
1106 extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
1107 				     int leaf_level, blk64_t blk);
1108 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
1109 
1110 /* fileio.c */
1111 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
1112 				   struct ext2_inode *inode,
1113 				   int flags, ext2_file_t *ret);
1114 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
1115 				  int flags, ext2_file_t *ret);
1116 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
1117 struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);
1118 extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file);
1119 extern errcode_t ext2fs_file_close(ext2_file_t file);
1120 extern errcode_t ext2fs_file_flush(ext2_file_t file);
1121 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
1122 				  unsigned int wanted, unsigned int *got);
1123 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
1124 				   unsigned int nbytes, unsigned int *written);
1125 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
1126 				   int whence, __u64 *ret_pos);
1127 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
1128 				   int whence, ext2_off_t *ret_pos);
1129 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
1130 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
1131 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
1132 extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size);
1133 
1134 /* finddev.c */
1135 extern char *ext2fs_find_block_device(dev_t device);
1136 
1137 /* flushb.c */
1138 extern errcode_t ext2fs_sync_device(int fd, int flushb);
1139 
1140 /* freefs.c */
1141 extern void ext2fs_free(ext2_filsys fs);
1142 extern void ext2fs_free_dblist(ext2_dblist dblist);
1143 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
1144 extern void ext2fs_u32_list_free(ext2_u32_list bb);
1145 
1146 /* gen_bitmap.c */
1147 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
1148 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
1149 					    __u32 start, __u32 end,
1150 					    __u32 real_end,
1151 					    const char *descr, char *init_map,
1152 					    ext2fs_generic_bitmap *ret);
1153 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
1154 						__u32 end,
1155 						__u32 real_end,
1156 						const char *descr,
1157 						ext2fs_generic_bitmap *ret);
1158 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
1159 					    ext2fs_generic_bitmap *dest);
1160 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
1161 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
1162 						 errcode_t magic,
1163 						 errcode_t neq,
1164 						 ext2_ino_t end,
1165 						 ext2_ino_t *oend);
1166 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
1167 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
1168 					      __u32 new_end,
1169 					      __u32 new_real_end,
1170 					      ext2fs_generic_bitmap bmap);
1171 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
1172 					       ext2fs_generic_bitmap bm1,
1173 					       ext2fs_generic_bitmap bm2);
1174 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1175 						 errcode_t magic,
1176 						 __u32 start, __u32 num,
1177 						 void *out);
1178 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1179 						 errcode_t magic,
1180 						 __u32 start, __u32 num,
1181 						 void *in);
1182 extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap,
1183 						       __u32 start, __u32 end,
1184 						       __u32 *out);
1185 
1186 /* gen_bitmap64.c */
1187 
1188 /* Generate and print bitmap usage statistics */
1189 #define BMAP_STATS
1190 
1191 void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
1192 errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
1193 				    int type, __u64 start, __u64 end,
1194 				    __u64 real_end,
1195 				    const char *descr,
1196 				    ext2fs_generic_bitmap *ret);
1197 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
1198 				   ext2fs_generic_bitmap *dest);
1199 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
1200 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
1201 					errcode_t neq,
1202 					__u64 end, __u64 *oend);
1203 void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
1204 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
1205 				     __u64 new_end,
1206 				     __u64 new_real_end);
1207 errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
1208 				      ext2fs_generic_bitmap bm1,
1209 				      ext2fs_generic_bitmap bm2);
1210 errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
1211 					__u64 start, unsigned int num,
1212 					void *out);
1213 errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
1214 					__u64 start, unsigned int num,
1215 					void *in);
1216 errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
1217 					   ext2fs_block_bitmap *bitmap);
1218 
1219 /* getsize.c */
1220 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
1221 					blk_t *retblocks);
1222 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
1223 					blk64_t *retblocks);
1224 
1225 /* getsectsize.c */
1226 extern int ext2fs_get_dio_alignment(int fd);
1227 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
1228 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
1229 
1230 /* i_block.c */
1231 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
1232 				 blk64_t num_blocks);
1233 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
1234 				 blk64_t num_blocks);
1235 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
1236 
1237 /* imager.c */
1238 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
1239 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
1240 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
1241 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
1242 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
1243 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
1244 
1245 /* ind_block.c */
1246 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1247 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1248 
1249 /* initialize.c */
1250 extern errcode_t ext2fs_initialize(const char *name, int flags,
1251 				   struct ext2_super_block *param,
1252 				   io_manager manager, ext2_filsys *ret_fs);
1253 
1254 /* icount.c */
1255 extern void ext2fs_free_icount(ext2_icount_t icount);
1256 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
1257 					  int flags, ext2_icount_t *ret);
1258 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
1259 				       unsigned int size,
1260 				       ext2_icount_t hint, ext2_icount_t *ret);
1261 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
1262 				      unsigned int size,
1263 				      ext2_icount_t *ret);
1264 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
1265 				     __u16 *ret);
1266 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
1267 					 __u16 *ret);
1268 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
1269 					 __u16 *ret);
1270 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
1271 				     __u16 count);
1272 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
1273 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
1274 
1275 /* inline.c */
1276 
1277 extern errcode_t ext2fs_get_memalign(unsigned long size,
1278 				     unsigned long align, void *ptr);
1279 
1280 /* inode.c */
1281 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
1282 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
1283 					    ext2_ino_t *ino,
1284 					    struct ext2_inode *inode,
1285 					    int bufsize);
1286 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
1287 				  ext2_inode_scan *ret_scan);
1288 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1289 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1290 			       struct ext2_inode *inode);
1291 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1292 						   int	group);
1293 extern void ext2fs_set_inode_callback
1294 	(ext2_inode_scan scan,
1295 	 errcode_t (*done_group)(ext2_filsys fs,
1296 				 ext2_inode_scan scan,
1297 				 dgrp_t group,
1298 				 void * priv_data),
1299 	 void *done_group_data);
1300 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1301 				   int clear_flags);
1302 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1303 					struct ext2_inode * inode,
1304 					int bufsize);
1305 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
1306 			    struct ext2_inode * inode);
1307 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1308 					 struct ext2_inode * inode,
1309 					 int bufsize);
1310 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1311 			    struct ext2_inode * inode);
1312 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1313 			    struct ext2_inode * inode);
1314 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1315 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1316 
1317 /* inode_io.c */
1318 extern io_manager inode_io_manager;
1319 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1320 					char **name);
1321 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1322 					 struct ext2_inode *inode,
1323 					 char **name);
1324 
1325 /* ismounted.c */
1326 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1327 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1328 					  char *mtpt, int mtlen);
1329 
1330 /* punch.c */
1331 /*
1332  * NOTE: This function removes from an inode the blocks "start", "end", and
1333  * every block in between.
1334  */
1335 extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
1336 			      struct ext2_inode *inode,
1337 			      char *block_buf, blk64_t start,
1338 			      blk64_t end);
1339 
1340 /* namei.c */
1341 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1342 			 int namelen, char *buf, ext2_ino_t *inode);
1343 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1344 			const char *name, ext2_ino_t *inode);
1345 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1346 			      const char *name, ext2_ino_t *inode);
1347 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1348 			ext2_ino_t inode, ext2_ino_t *res_inode);
1349 
1350 /* native.c */
1351 int ext2fs_native_flag(void);
1352 
1353 /* newdir.c */
1354 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1355 				ext2_ino_t parent_ino, char **block);
1356 
1357 /* mkdir.c */
1358 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1359 			      const char *name);
1360 
1361 /* mkjournal.c */
1362 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1363 				    blk_t *ret_blk, int *ret_count);
1364 extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
1365 				     blk64_t *ret_blk, int *ret_count);
1366 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1367 						  __u32 num_blocks, int flags,
1368 						  char  **ret_jsb);
1369 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1370 					   ext2_filsys journal_dev);
1371 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,
1372 					  int flags);
1373 extern int ext2fs_default_journal_size(__u64 num_blocks);
1374 
1375 /* openfs.c */
1376 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1377 			     unsigned int block_size, io_manager manager,
1378 			     ext2_filsys *ret_fs);
1379 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1380 			      int flags, int superblock,
1381 			      unsigned int block_size, io_manager manager,
1382 			      ext2_filsys *ret_fs);
1383 extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs,
1384 					blk64_t group_block, dgrp_t i);
1385 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1386 					 dgrp_t i);
1387 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1388 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1389 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1390 
1391 /* get_pathname.c */
1392 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1393 			       char **name);
1394 
1395 /* link.c */
1396 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1397 		      ext2_ino_t ino, int flags);
1398 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1399 			ext2_ino_t ino, int flags);
1400 
1401 /* symlink.c */
1402 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
1403 			 const char *name, char *target);
1404 
1405 /* mmp.c */
1406 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1407 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1408 errcode_t ext2fs_mmp_clear(ext2_filsys fs);
1409 errcode_t ext2fs_mmp_init(ext2_filsys fs);
1410 errcode_t ext2fs_mmp_start(ext2_filsys fs);
1411 errcode_t ext2fs_mmp_update(ext2_filsys fs);
1412 errcode_t ext2fs_mmp_stop(ext2_filsys fs);
1413 unsigned ext2fs_mmp_new_seq(void);
1414 
1415 /* read_bb.c */
1416 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1417 				      ext2_badblocks_list *bb_list);
1418 
1419 /* read_bb_file.c */
1420 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1421 				      ext2_badblocks_list *bb_list,
1422 				      void *priv_data,
1423 				      void (*invalid)(ext2_filsys fs,
1424 						      blk_t blk,
1425 						      char *badstr,
1426 						      void *priv_data));
1427 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1428 				     ext2_badblocks_list *bb_list,
1429 				     void (*invalid)(ext2_filsys fs,
1430 						     blk_t blk));
1431 
1432 /* res_gdt.c */
1433 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1434 
1435 /* swapfs.c */
1436 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1437 				 int has_header);
1438 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1439 					struct ext2_ext_attr_header *from_hdr);
1440 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1441 				       struct ext2_ext_attr_entry *from_entry);
1442 extern void ext2fs_swap_super(struct ext2_super_block * super);
1443 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1444 extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp);
1445 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1446 				   struct ext2_inode_large *f, int hostorder,
1447 				   int bufsize);
1448 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1449 			      struct ext2_inode *f, int hostorder);
1450 extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
1451 
1452 /* unix_io.c */
1453 extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
1454 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
1455 extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
1456 
1457 /* valid_blk.c */
1458 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1459 extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs,
1460 					  struct ext2_inode *inode);
1461 
1462 /* version.c */
1463 extern int ext2fs_parse_version_string(const char *ver_string);
1464 extern int ext2fs_get_library_version(const char **ver_string,
1465 				      const char **date_string);
1466 
1467 /* write_bb_file.c */
1468 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1469 				      unsigned int flags,
1470 				      FILE *f);
1471 
1472 
1473 /* inline functions */
1474 #ifdef NO_INLINE_FUNCS
1475 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1476 extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr);
1477 extern errcode_t ext2fs_get_array(unsigned long count,
1478 				  unsigned long size, void *ptr);
1479 extern errcode_t ext2fs_get_arrayzero(unsigned long count,
1480 				      unsigned long size, void *ptr);
1481 extern errcode_t ext2fs_free_mem(void *ptr);
1482 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1483 				   unsigned long size, void *ptr);
1484 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1485 extern void ext2fs_mark_changed(ext2_filsys fs);
1486 extern int ext2fs_test_changed(ext2_filsys fs);
1487 extern void ext2fs_mark_valid(ext2_filsys fs);
1488 extern void ext2fs_unmark_valid(ext2_filsys fs);
1489 extern int ext2fs_test_valid(ext2_filsys fs);
1490 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1491 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1492 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1493 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1494 extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1495 extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1496 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1497 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1498 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1499 				      struct ext2_inode *inode);
1500 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1501 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
1502 #endif
1503 
1504 /*
1505  * The actual inlined functions definitions themselves...
1506  *
1507  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1508  * functions at all!
1509  */
1510 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1511 #ifdef INCLUDE_INLINE_FUNCS
1512 #define _INLINE_ extern
1513 #else
1514 #if (__STDC_VERSION__ >= 199901L)
1515 #define _INLINE_ inline
1516 #else
1517 #ifdef __GNUC__
1518 #define _INLINE_ extern __inline__
1519 #else				/* For Watcom C */
1520 #define _INLINE_ extern inline
1521 #endif /* __GNUC__ */
1522 #endif /* __STDC_VERSION__ >= 199901L */
1523 #endif
1524 
1525 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1526 #include <string.h>
1527 /*
1528  *  Allocate memory.  The 'ptr' arg must point to a pointer.
1529  */
ext2fs_get_mem(unsigned long size,void * ptr)1530 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1531 {
1532 	void *pp;
1533 
1534 	pp = malloc(size);
1535 	if (!pp)
1536 		return EXT2_ET_NO_MEMORY;
1537 	memcpy(ptr, &pp, sizeof (pp));
1538 	return 0;
1539 }
1540 
ext2fs_get_memzero(unsigned long size,void * ptr)1541 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
1542 {
1543 	void *pp;
1544 
1545 	pp = malloc(size);
1546 	if (!pp)
1547 		return EXT2_ET_NO_MEMORY;
1548 	memset(pp, 0, size);
1549 	memcpy(ptr, &pp, sizeof(pp));
1550 	return 0;
1551 }
1552 
ext2fs_get_array(unsigned long count,unsigned long size,void * ptr)1553 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
1554 {
1555 	if (count && (-1UL)/count<size)
1556 		return EXT2_ET_NO_MEMORY;
1557 	return ext2fs_get_mem(count*size, ptr);
1558 }
1559 
ext2fs_get_arrayzero(unsigned long count,unsigned long size,void * ptr)1560 _INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
1561 					unsigned long size, void *ptr)
1562 {
1563 	void *pp;
1564 
1565 	if (count && (-1UL)/count<size)
1566 		return EXT2_ET_NO_MEMORY;
1567 	pp = calloc(count, size);
1568 	if (!pp)
1569 		return EXT2_ET_NO_MEMORY;
1570 	memcpy(ptr, &pp, sizeof(pp));
1571 	return 0;
1572 }
1573 
1574 /*
1575  * Free memory.  The 'ptr' arg must point to a pointer.
1576  */
ext2fs_free_mem(void * ptr)1577 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1578 {
1579 	void *p;
1580 
1581 	memcpy(&p, ptr, sizeof(p));
1582 	free(p);
1583 	p = 0;
1584 	memcpy(ptr, &p, sizeof(p));
1585 	return 0;
1586 }
1587 
1588 /*
1589  *  Resize memory.  The 'ptr' arg must point to a pointer.
1590  */
ext2fs_resize_mem(unsigned long EXT2FS_ATTR ((unused))old_size,unsigned long size,void * ptr)1591 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1592 				     unsigned long size, void *ptr)
1593 {
1594 	void *p;
1595 
1596 	/* Use "memcpy" for pointer assignments here to avoid problems
1597 	 * with C99 strict type aliasing rules. */
1598 	memcpy(&p, ptr, sizeof(p));
1599 	p = realloc(p, size);
1600 	if (!p)
1601 		return EXT2_ET_NO_MEMORY;
1602 	memcpy(ptr, &p, sizeof(p));
1603 	return 0;
1604 }
1605 #endif	/* Custom memory routines */
1606 
1607 /*
1608  * Mark a filesystem superblock as dirty
1609  */
ext2fs_mark_super_dirty(ext2_filsys fs)1610 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1611 {
1612 	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1613 }
1614 
1615 /*
1616  * Mark a filesystem as changed
1617  */
ext2fs_mark_changed(ext2_filsys fs)1618 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1619 {
1620 	fs->flags |= EXT2_FLAG_CHANGED;
1621 }
1622 
1623 /*
1624  * Check to see if a filesystem has changed
1625  */
ext2fs_test_changed(ext2_filsys fs)1626 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1627 {
1628 	return (fs->flags & EXT2_FLAG_CHANGED);
1629 }
1630 
1631 /*
1632  * Mark a filesystem as valid
1633  */
ext2fs_mark_valid(ext2_filsys fs)1634 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1635 {
1636 	fs->flags |= EXT2_FLAG_VALID;
1637 }
1638 
1639 /*
1640  * Mark a filesystem as NOT valid
1641  */
ext2fs_unmark_valid(ext2_filsys fs)1642 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1643 {
1644 	fs->flags &= ~EXT2_FLAG_VALID;
1645 }
1646 
1647 /*
1648  * Check to see if a filesystem is valid
1649  */
ext2fs_test_valid(ext2_filsys fs)1650 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1651 {
1652 	return (fs->flags & EXT2_FLAG_VALID);
1653 }
1654 
1655 /*
1656  * Mark the inode bitmap as dirty
1657  */
ext2fs_mark_ib_dirty(ext2_filsys fs)1658 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1659 {
1660 	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1661 }
1662 
1663 /*
1664  * Mark the block bitmap as dirty
1665  */
ext2fs_mark_bb_dirty(ext2_filsys fs)1666 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1667 {
1668 	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1669 }
1670 
1671 /*
1672  * Check to see if a filesystem's inode bitmap is dirty
1673  */
ext2fs_test_ib_dirty(ext2_filsys fs)1674 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1675 {
1676 	return (fs->flags & EXT2_FLAG_IB_DIRTY);
1677 }
1678 
1679 /*
1680  * Check to see if a filesystem's block bitmap is dirty
1681  */
ext2fs_test_bb_dirty(ext2_filsys fs)1682 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1683 {
1684 	return (fs->flags & EXT2_FLAG_BB_DIRTY);
1685 }
1686 
1687 /*
1688  * Return the group # of a block
1689  */
ext2fs_group_of_blk(ext2_filsys fs,blk_t blk)1690 _INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1691 {
1692 	return ext2fs_group_of_blk2(fs, blk);
1693 }
1694 /*
1695  * Return the group # of an inode number
1696  */
ext2fs_group_of_ino(ext2_filsys fs,ext2_ino_t ino)1697 _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1698 {
1699 	return (ino - 1) / fs->super->s_inodes_per_group;
1700 }
1701 
1702 /*
1703  * Return the first block (inclusive) in a group
1704  */
ext2fs_group_first_block(ext2_filsys fs,dgrp_t group)1705 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
1706 {
1707 	return (blk_t) ext2fs_group_first_block2(fs, group);
1708 }
1709 
1710 /*
1711  * Return the last block (inclusive) in a group
1712  */
ext2fs_group_last_block(ext2_filsys fs,dgrp_t group)1713 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
1714 {
1715 	return (blk_t) ext2fs_group_last_block2(fs, group);
1716 }
1717 
ext2fs_inode_data_blocks(ext2_filsys fs,struct ext2_inode * inode)1718 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1719 					struct ext2_inode *inode)
1720 {
1721 	return (blk_t) ext2fs_inode_data_blocks2(fs, inode);
1722 }
1723 
1724 /*
1725  * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
1726  */
ext2fs_div_ceil(unsigned int a,unsigned int b)1727 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
1728 {
1729 	if (!a)
1730 		return 0;
1731 	return ((a - 1) / b) + 1;
1732 }
1733 
ext2fs_div64_ceil(__u64 a,__u64 b)1734 _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b)
1735 {
1736 	if (!a)
1737 		return 0;
1738 	return ((a - 1) / b) + 1;
1739 }
1740 
1741 #undef _INLINE_
1742 #endif
1743 
1744 #ifdef __cplusplus
1745 }
1746 #endif
1747 
1748 #endif /* _EXT2FS_EXT2FS_H */
1749