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