• 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  * The Apple compiler in Xcode 4.3 fails when inlines are enabled in
34  * so disable them for that compiler.
35  */
36 #if __APPLE_CC__ >= 5621
37 #define NO_INLINE_FUNCS
38 #endif
39 
40 /*
41  * Where the master copy of the superblock is located, and how big
42  * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
43  * the size of the superblock structure is not necessarily trustworthy
44  * (some versions have the padding set up so that the superblock is
45  * 1032 bytes long).
46  */
47 #define SUPERBLOCK_OFFSET	1024
48 #define SUPERBLOCK_SIZE 	1024
49 
50 /*
51  * The last ext2fs revision level that this version of the library is
52  * able to support.
53  */
54 #define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
55 
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
58 #endif
59 
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <errno.h>
64 
65 #if EXT2_FLAT_INCLUDES
66 #include "e2_types.h"
67 #include "ext2_fs.h"
68 #include "ext3_extents.h"
69 #else
70 #include <ext2fs/ext2_types.h>
71 #include <ext2fs/ext2_fs.h>
72 #include <ext2fs/ext3_extents.h>
73 #endif /* EXT2_FLAT_INCLUDES */
74 
75 typedef __u32		ext2_ino_t;
76 typedef __u32		blk_t;
77 typedef __u64		blk64_t;
78 typedef __u32		dgrp_t;
79 typedef __u32		ext2_off_t;
80 typedef __s64		e2_blkcnt_t;
81 typedef __u32		ext2_dirhash_t;
82 
83 #if EXT2_FLAT_INCLUDES
84 #include "com_err.h"
85 #include "ext2_io.h"
86 #include "ext2_err.h"
87 #include "ext2_ext_attr.h"
88 #else
89 #include <et/com_err.h>
90 #include <ext2fs/ext2_io.h>
91 #include <ext2fs/ext2_err.h>
92 #include <ext2fs/ext2_ext_attr.h>
93 #endif
94 
95 /*
96  * Portability help for Microsoft Visual C++
97  */
98 #ifdef _MSC_VER
99 #define EXT2_QSORT_TYPE int __cdecl
100 #else
101 #define EXT2_QSORT_TYPE int
102 #endif
103 
104 typedef struct struct_ext2_filsys *ext2_filsys;
105 
106 #define EXT2FS_MARK_ERROR 	0
107 #define EXT2FS_UNMARK_ERROR 	1
108 #define EXT2FS_TEST_ERROR	2
109 
110 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
111 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
112 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
113 
114 #define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO(s)
115 
116 
117 /*
118  * Badblocks list definitions
119  */
120 
121 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
122 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
123 
124 typedef struct ext2_struct_u32_list *ext2_u32_list;
125 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
126 
127 /* old */
128 typedef struct ext2_struct_u32_list *badblocks_list;
129 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
130 
131 #define BADBLOCKS_FLAG_DIRTY	1
132 
133 /*
134  * ext2_dblist structure and abstractions (see dblist.c)
135  */
136 struct ext2_db_entry {
137 	ext2_ino_t	ino;
138 	blk_t	blk;
139 	int	blockcnt;
140 };
141 
142 typedef struct ext2_struct_dblist *ext2_dblist;
143 
144 #define DBLIST_ABORT	1
145 
146 /*
147  * ext2_fileio definitions
148  */
149 
150 #define EXT2_FILE_WRITE		0x0001
151 #define EXT2_FILE_CREATE	0x0002
152 
153 #define EXT2_FILE_MASK		0x00FF
154 
155 #define EXT2_FILE_BUF_DIRTY	0x4000
156 #define EXT2_FILE_BUF_VALID	0x2000
157 
158 typedef struct ext2_file *ext2_file_t;
159 
160 #define EXT2_SEEK_SET	0
161 #define EXT2_SEEK_CUR	1
162 #define EXT2_SEEK_END	2
163 
164 /*
165  * Flags for the ext2_filsys structure and for ext2fs_open()
166  */
167 #define EXT2_FLAG_RW			0x01
168 #define EXT2_FLAG_CHANGED		0x02
169 #define EXT2_FLAG_DIRTY			0x04
170 #define EXT2_FLAG_VALID			0x08
171 #define EXT2_FLAG_IB_DIRTY		0x10
172 #define EXT2_FLAG_BB_DIRTY		0x20
173 #define EXT2_FLAG_SWAP_BYTES		0x40
174 #define EXT2_FLAG_SWAP_BYTES_READ	0x80
175 #define EXT2_FLAG_SWAP_BYTES_WRITE	0x100
176 #define EXT2_FLAG_MASTER_SB_ONLY	0x200
177 #define EXT2_FLAG_FORCE			0x400
178 #define EXT2_FLAG_SUPER_ONLY		0x800
179 #define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
180 #define EXT2_FLAG_IMAGE_FILE		0x2000
181 #define EXT2_FLAG_EXCLUSIVE		0x4000
182 #define EXT2_FLAG_SOFTSUPP_FEATURES	0x8000
183 #define EXT2_FLAG_NOFREE_ON_ERROR	0x10000
184 #define EXT2_FLAG_DIRECT_IO		0x80000
185 
186 /*
187  * Special flag in the ext2 inode i_flag field that means that this is
188  * a new inode.  (So that ext2_write_inode() can clear extra fields.)
189  */
190 #define EXT2_NEW_INODE_FL	0x80000000
191 
192 /*
193  * Flags for mkjournal
194  *
195  * EXT2_MKJOURNAL_V1_SUPER	Make a (deprecated) V1 journal superblock
196  */
197 #define EXT2_MKJOURNAL_V1_SUPER	0x0000001
198 
199 struct struct_ext2_filsys {
200 	errcode_t			magic;
201 	io_channel			io;
202 	int				flags;
203 	char *				device_name;
204 	struct ext2_super_block	* 	super;
205 	unsigned int			blocksize;
206 	int				fragsize;
207 	dgrp_t				group_desc_count;
208 	unsigned long			desc_blocks;
209 	struct ext2_group_desc *	group_desc;
210 	int				inode_blocks_per_group;
211 	ext2fs_inode_bitmap		inode_map;
212 	ext2fs_block_bitmap		block_map;
213 	errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
214 	errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
215 	errcode_t (*write_bitmaps)(ext2_filsys fs);
216 	errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
217 				struct ext2_inode *inode);
218 	errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
219 				struct ext2_inode *inode);
220 	ext2_badblocks_list		badblocks;
221 	ext2_dblist			dblist;
222 	__u32				stride;	/* for mke2fs */
223 	struct ext2_super_block *	orig_super;
224 	struct ext2_image_hdr *		image_header;
225 	__u32				umask;
226 	time_t				now;
227 	/*
228 	 * Reserved for future expansion
229 	 */
230 	__u32				reserved[7];
231 
232 	/*
233 	 * Reserved for the use of the calling application.
234 	 */
235 	void *				priv_data;
236 
237 	/*
238 	 * Inode cache
239 	 */
240 	struct ext2_inode_cache		*icache;
241 	io_channel			image_io;
242 
243 	/*
244 	 * More callback functions
245 	 */
246 	errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
247 				     blk64_t *ret);
248 	void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
249 };
250 
251 #if EXT2_FLAT_INCLUDES
252 #include "e2_bitops.h"
253 #else
254 #include <ext2fs/bitops.h>
255 #endif
256 
257 /*
258  * Return flags for the block iterator functions
259  */
260 #define BLOCK_CHANGED	1
261 #define BLOCK_ABORT	2
262 #define BLOCK_ERROR	4
263 
264 /*
265  * Block interate flags
266  *
267  * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
268  * function should be called on blocks where the block number is zero.
269  * This is used by ext2fs_expand_dir() to be able to add a new block
270  * to an inode.  It can also be used for programs that want to be able
271  * to deal with files that contain "holes".
272  *
273  * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
274  * the indirect, doubly indirect, etc. blocks should be called after
275  * all of the blocks containined in the indirect blocks are processed.
276  * This is useful if you are going to be deallocating blocks from an
277  * inode.
278  *
279  * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
280  * called for data blocks only.
281  *
282  * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
283  * modify returned block number.
284  *
285  * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
286  * ext2fs_block_iterate2 that large files won't be accepted.
287  */
288 #define BLOCK_FLAG_APPEND	1
289 #define BLOCK_FLAG_HOLE		1
290 #define BLOCK_FLAG_DEPTH_TRAVERSE	2
291 #define BLOCK_FLAG_DATA_ONLY	4
292 #define BLOCK_FLAG_READ_ONLY	8
293 
294 #define BLOCK_FLAG_NO_LARGE	0x1000
295 
296 /*
297  * Magic "block count" return values for the block iterator function.
298  */
299 #define BLOCK_COUNT_IND		(-1)
300 #define BLOCK_COUNT_DIND	(-2)
301 #define BLOCK_COUNT_TIND	(-3)
302 #define BLOCK_COUNT_TRANSLATOR	(-4)
303 
304 #if 0
305 /*
306  * Flags for ext2fs_move_blocks
307  */
308 #define EXT2_BMOVE_GET_DBLIST	0x0001
309 #define EXT2_BMOVE_DEBUG	0x0002
310 #endif
311 
312 /*
313  * Generic (non-filesystem layout specific) extents structure
314  */
315 
316 #define EXT2_EXTENT_FLAGS_LEAF		0x0001
317 #define EXT2_EXTENT_FLAGS_UNINIT	0x0002
318 #define EXT2_EXTENT_FLAGS_SECOND_VISIT	0x0004
319 
320 struct ext2fs_extent {
321 	blk64_t	e_pblk;		/* first physical block */
322 	blk64_t	e_lblk;		/* first logical block extent covers */
323 	__u32	e_len;		/* number of blocks covered by extent */
324 	__u32	e_flags;	/* extent flags */
325 };
326 
327 typedef struct ext2_extent_handle *ext2_extent_handle_t;
328 typedef struct ext2_extent_path *ext2_extent_path_t;
329 
330 /*
331  * Flags used by ext2fs_extent_get()
332  */
333 #define EXT2_EXTENT_CURRENT	0x0000
334 #define EXT2_EXTENT_MOVE_MASK	0x000F
335 #define EXT2_EXTENT_ROOT	0x0001
336 #define EXT2_EXTENT_LAST_LEAF	0x0002
337 #define EXT2_EXTENT_FIRST_SIB	0x0003
338 #define EXT2_EXTENT_LAST_SIB	0x0004
339 #define EXT2_EXTENT_NEXT_SIB	0x0005
340 #define EXT2_EXTENT_PREV_SIB	0x0006
341 #define EXT2_EXTENT_NEXT_LEAF	0x0007
342 #define EXT2_EXTENT_PREV_LEAF	0x0008
343 #define EXT2_EXTENT_NEXT	0x0009
344 #define EXT2_EXTENT_PREV	0x000A
345 #define EXT2_EXTENT_UP		0x000B
346 #define EXT2_EXTENT_DOWN	0x000C
347 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
348 
349 /*
350  * Flags used by ext2fs_extent_insert()
351  */
352 #define EXT2_EXTENT_INSERT_AFTER	0x0001 /* insert after handle loc'n */
353 #define EXT2_EXTENT_INSERT_NOSPLIT	0x0002 /* insert may not cause split */
354 
355 /*
356  * Flags used by ext2fs_extent_delete()
357  */
358 #define EXT2_EXTENT_DELETE_KEEP_EMPTY	0x001 /* keep node if last extnt gone */
359 
360 /*
361  * Flags used by ext2fs_extent_set_bmap()
362  */
363 #define EXT2_EXTENT_SET_BMAP_UNINIT	0x0001
364 
365 /*
366  * Data structure returned by ext2fs_extent_get_info()
367  */
368 struct ext2_extent_info {
369 	int		curr_entry;
370 	int		curr_level;
371 	int		num_entries;
372 	int		max_entries;
373 	int		max_depth;
374 	int		bytes_avail;
375 	blk64_t		max_lblk;
376 	blk64_t		max_pblk;
377 	__u32		max_len;
378 	__u32		max_uninit_len;
379 };
380 
381 /*
382  * Flags for directory block reading and writing functions
383  */
384 #define EXT2_DIRBLOCK_V2_STRUCT	0x0001
385 
386 /*
387  * Return flags for the directory iterator functions
388  */
389 #define DIRENT_CHANGED	1
390 #define DIRENT_ABORT	2
391 #define DIRENT_ERROR	3
392 
393 /*
394  * Directory iterator flags
395  */
396 
397 #define DIRENT_FLAG_INCLUDE_EMPTY	1
398 #define DIRENT_FLAG_INCLUDE_REMOVED	2
399 
400 #define DIRENT_DOT_FILE		1
401 #define DIRENT_DOT_DOT_FILE	2
402 #define DIRENT_OTHER_FILE	3
403 #define DIRENT_DELETED_FILE	4
404 
405 /*
406  * Inode scan definitions
407  */
408 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
409 
410 /*
411  * ext2fs_scan flags
412  */
413 #define EXT2_SF_CHK_BADBLOCKS	0x0001
414 #define EXT2_SF_BAD_INODE_BLK	0x0002
415 #define EXT2_SF_BAD_EXTRA_BYTES	0x0004
416 #define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
417 #define EXT2_SF_DO_LAZY		0x0010
418 
419 /*
420  * ext2fs_check_if_mounted flags
421  */
422 #define EXT2_MF_MOUNTED		1
423 #define EXT2_MF_ISROOT		2
424 #define EXT2_MF_READONLY	4
425 #define EXT2_MF_SWAP		8
426 #define EXT2_MF_BUSY		16
427 
428 /*
429  * Ext2/linux mode flags.  We define them here so that we don't need
430  * to depend on the OS's sys/stat.h, since we may be compiling on a
431  * non-Linux system.
432  */
433 #define LINUX_S_IFMT  00170000
434 #define LINUX_S_IFSOCK 0140000
435 #define LINUX_S_IFLNK	 0120000
436 #define LINUX_S_IFREG  0100000
437 #define LINUX_S_IFBLK  0060000
438 #define LINUX_S_IFDIR  0040000
439 #define LINUX_S_IFCHR  0020000
440 #define LINUX_S_IFIFO  0010000
441 #define LINUX_S_ISUID  0004000
442 #define LINUX_S_ISGID  0002000
443 #define LINUX_S_ISVTX  0001000
444 
445 #define LINUX_S_IRWXU 00700
446 #define LINUX_S_IRUSR 00400
447 #define LINUX_S_IWUSR 00200
448 #define LINUX_S_IXUSR 00100
449 
450 #define LINUX_S_IRWXG 00070
451 #define LINUX_S_IRGRP 00040
452 #define LINUX_S_IWGRP 00020
453 #define LINUX_S_IXGRP 00010
454 
455 #define LINUX_S_IRWXO 00007
456 #define LINUX_S_IROTH 00004
457 #define LINUX_S_IWOTH 00002
458 #define LINUX_S_IXOTH 00001
459 
460 #define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
461 #define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
462 #define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
463 #define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
464 #define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
465 #define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
466 #define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
467 
468 /*
469  * ext2 size of an inode
470  */
471 #define EXT2_I_SIZE(i)	((i)->i_size | ((__u64) (i)->i_size_high << 32))
472 
473 /*
474  * ext2_icount_t abstraction
475  */
476 #define EXT2_ICOUNT_OPT_INCREMENT	0x01
477 
478 typedef struct ext2_icount *ext2_icount_t;
479 
480 /*
481  * Flags for ext2fs_bmap
482  */
483 #define BMAP_ALLOC	0x0001
484 #define BMAP_SET	0x0002
485 
486 /*
487  * Returned flags from ext2fs_bmap
488  */
489 #define BMAP_RET_UNINIT	0x0001
490 
491 /*
492  * Flags for imager.c functions
493  */
494 #define IMAGER_FLAG_INODEMAP	1
495 #define IMAGER_FLAG_SPARSEWRITE	2
496 
497 /*
498  * For checking structure magic numbers...
499  */
500 
501 #define EXT2_CHECK_MAGIC(struct, code) \
502 	  if ((struct)->magic != (code)) return (code)
503 
504 
505 /*
506  * For ext2 compression support
507  */
508 #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
509 #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
510 
511 /*
512  * Features supported by this version of the library
513  */
514 #define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
515 					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
516 					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
517 					 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
518 					 EXT2_FEATURE_COMPAT_DIR_INDEX|\
519 					 EXT2_FEATURE_COMPAT_EXT_ATTR)
520 
521 /* This #ifdef is temporary until compression is fully supported */
522 #ifdef ENABLE_COMPRESSION
523 #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
524 /* If the below warning bugs you, then have
525    `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
526    environment at configure time. */
527  #warning "Compression support is experimental"
528 #endif
529 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
530 					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
531 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
532 					 EXT2_FEATURE_INCOMPAT_META_BG|\
533 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
534 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
535 					 EXT4_FEATURE_INCOMPAT_FLEX_BG)
536 #else
537 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
538 					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
539 					 EXT2_FEATURE_INCOMPAT_META_BG|\
540 					 EXT3_FEATURE_INCOMPAT_RECOVER|\
541 					 EXT3_FEATURE_INCOMPAT_EXTENTS|\
542 					 EXT4_FEATURE_INCOMPAT_FLEX_BG)
543 #endif
544 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
545 					 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
546 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
547 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
548 					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
549 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
550 
551 /*
552  * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
553  * to ext2fs_openfs()
554  */
555 #define EXT2_LIB_SOFTSUPP_INCOMPAT	(0)
556 #define EXT2_LIB_SOFTSUPP_RO_COMPAT	(0)
557 
558 /*
559  * function prototypes
560  */
561 
562 /* alloc.c */
563 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
564 				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
565 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
566 				  ext2fs_block_bitmap map, blk_t *ret);
567 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
568 					blk_t finish, int num,
569 					ext2fs_block_bitmap map,
570 					blk_t *ret);
571 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
572 				    char *block_buf, blk_t *ret);
573 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
574 					    errcode_t (*func)(ext2_filsys fs,
575 							      blk64_t goal,
576 							      blk64_t *ret),
577 					    errcode_t (**old)(ext2_filsys fs,
578 							      blk64_t goal,
579 							      blk64_t *ret));
580 
581 /* alloc_sb.c */
582 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
583 					dgrp_t group,
584 					ext2fs_block_bitmap bmap);
585 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
586 						  void (*func)(ext2_filsys fs,
587 							       blk64_t blk,
588 							       int inuse),
589 						  void (**old)(ext2_filsys fs,
590 							       blk64_t blk,
591 							       int inuse));
592 
593 /* alloc_stats.c */
594 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
595 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
596 			       int inuse, int isdir);
597 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
598 
599 /* alloc_tables.c */
600 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
601 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
602 					     ext2fs_block_bitmap bmap);
603 
604 /* badblocks.c */
605 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
606 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
607 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
608 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
609 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
610 					       ext2_u32_iterate *ret);
611 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
612 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
613 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
614 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
615 
616 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
617 					    int size);
618 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
619 					   blk_t blk);
620 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
621 				    blk_t blk);
622 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
623 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
624 extern errcode_t
625 	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
626 					    ext2_badblocks_iterate *ret);
627 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
628 					 blk_t *blk);
629 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
630 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
631 				       ext2_badblocks_list *dest);
632 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
633 				  ext2_badblocks_list bb2);
634 extern int ext2fs_u32_list_count(ext2_u32_list bb);
635 
636 /* bb_compat */
637 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
638 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
639 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
640 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
641 					      badblocks_iterate *ret);
642 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
643 extern void badblocks_list_iterate_end(badblocks_iterate iter);
644 extern void badblocks_list_free(badblocks_list bb);
645 
646 /* bb_inode.c */
647 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
648 					ext2_badblocks_list bb_list);
649 
650 /* bitmaps.c */
651 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
652 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
653 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
654 				    ext2fs_generic_bitmap *dest);
655 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
656 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
657 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
658 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
659 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
660 					      const char *descr,
661 					      ext2fs_block_bitmap *ret);
662 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
663 					      const char *descr,
664 					      ext2fs_inode_bitmap *ret);
665 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
666 					       ext2_ino_t end, ext2_ino_t *oend);
667 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
668 					       blk_t end, blk_t *oend);
669 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
670 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
671 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
672 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
673 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
674 					    ext2fs_inode_bitmap bmap);
675 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
676 					    ext2fs_block_bitmap bmap);
677 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
678 					     ext2fs_block_bitmap bm2);
679 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
680 					     ext2fs_inode_bitmap bm2);
681 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
682 					ext2_ino_t start, unsigned int num,
683 					void *in);
684 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
685 					ext2_ino_t start, unsigned int num,
686 					void *out);
687 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
688 					blk_t start, unsigned int num,
689 					void *in);
690 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
691 					blk_t start, unsigned int num,
692 					void *out);
693 
694 
695 /* block.c */
696 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
697 				      ext2_ino_t	ino,
698 				      int	flags,
699 				      char *block_buf,
700 				      int (*func)(ext2_filsys fs,
701 						  blk_t	*blocknr,
702 						  int	blockcnt,
703 						  void	*priv_data),
704 				      void *priv_data);
705 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
706 				ext2_ino_t	ino,
707 				int	flags,
708 				char *block_buf,
709 				int (*func)(ext2_filsys fs,
710 					    blk_t	*blocknr,
711 					    e2_blkcnt_t	blockcnt,
712 					    blk_t	ref_blk,
713 					    int		ref_offset,
714 					    void	*priv_data),
715 				void *priv_data);
716 
717 /* bmap.c */
718 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
719 			     struct ext2_inode *inode,
720 			     char *block_buf, int bmap_flags,
721 			     blk_t block, blk_t *phys_blk);
722 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
723 			      struct ext2_inode *inode,
724 			      char *block_buf, int bmap_flags, blk64_t block,
725 			      int *ret_flags, blk64_t *phys_blk);
726 
727 #if 0
728 /* bmove.c */
729 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
730 				    ext2fs_block_bitmap reserve,
731 				    ext2fs_block_bitmap alloc_map,
732 				    int flags);
733 #endif
734 
735 /* check_desc.c */
736 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
737 
738 /* closefs.c */
739 extern errcode_t ext2fs_close(ext2_filsys fs);
740 extern errcode_t ext2fs_flush(ext2_filsys fs);
741 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
742 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
743 				    dgrp_t group,
744 				    blk_t *ret_super_blk,
745 				    blk_t *ret_old_desc_blk,
746 				    blk_t *ret_new_desc_blk,
747 				    int *ret_meta_bg);
748 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
749 
750 /* csum.c */
751 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
752 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
753 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
754 
755 /* dblist.c */
756 
757 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
758 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
759 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
760 				      blk_t blk, int blockcnt);
761 extern void ext2fs_dblist_sort(ext2_dblist dblist,
762 			       EXT2_QSORT_TYPE (*sortfunc)(const void *,
763 							   const void *));
764 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
765 	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
766 		    void	*priv_data),
767        void *priv_data);
768 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
769 				      blk_t blk, int blockcnt);
770 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
771 				    ext2_dblist *dest);
772 extern int ext2fs_dblist_count(ext2_dblist dblist);
773 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
774 					struct ext2_db_entry **entry);
775 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
776 
777 /* dblist_dir.c */
778 extern errcode_t
779 	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
780 				  int	flags,
781 				  char	*block_buf,
782 				  int (*func)(ext2_ino_t	dir,
783 					      int		entry,
784 					      struct ext2_dir_entry *dirent,
785 					      int	offset,
786 					      int	blocksize,
787 					      char	*buf,
788 					      void	*priv_data),
789 				  void *priv_data);
790 
791 /* dirblock.c */
792 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
793 				       void *buf);
794 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
795 					void *buf, int flags);
796 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
797 					void *buf);
798 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
799 					 void *buf, int flags);
800 
801 /* dirhash.c */
802 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
803 				const __u32 *seed,
804 				ext2_dirhash_t *ret_hash,
805 				ext2_dirhash_t *ret_minor_hash);
806 
807 
808 /* dir_iterate.c */
809 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
810 				    struct ext2_dir_entry *dirent,
811 				    unsigned int *rec_len);
812 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
813 				    unsigned int len,
814 				    struct ext2_dir_entry *dirent);
815 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
816 			      ext2_ino_t dir,
817 			      int flags,
818 			      char *block_buf,
819 			      int (*func)(struct ext2_dir_entry *dirent,
820 					  int	offset,
821 					  int	blocksize,
822 					  char	*buf,
823 					  void	*priv_data),
824 			      void *priv_data);
825 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
826 			      ext2_ino_t dir,
827 			      int flags,
828 			      char *block_buf,
829 			      int (*func)(ext2_ino_t	dir,
830 					  int	entry,
831 					  struct ext2_dir_entry *dirent,
832 					  int	offset,
833 					  int	blocksize,
834 					  char	*buf,
835 					  void	*priv_data),
836 			      void *priv_data);
837 
838 /* dupfs.c */
839 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
840 
841 /* expanddir.c */
842 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
843 
844 /* ext_attr.c */
845 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
846 					void *data);
847 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
848 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
849 				       void *buf);
850 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
851 					   char *block_buf,
852 					   int adjust, __u32 *newcount);
853 
854 /* extent.c */
855 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
856 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
857 				    ext2_extent_handle_t *handle);
858 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
859 					struct ext2_inode *inode,
860 					ext2_extent_handle_t *ret_handle);
861 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
862 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
863 				   int flags, struct ext2fs_extent *extent);
864 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
865 				       struct ext2fs_extent *extent);
866 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
867 				      struct ext2fs_extent *extent);
868 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
869 					blk64_t logical, blk64_t physical,
870 					int flags);
871 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
872 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
873 					struct ext2_extent_info *info);
874 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
875 				    blk64_t blk);
876 
877 /* fileio.c */
878 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
879 				   struct ext2_inode *inode,
880 				   int flags, ext2_file_t *ret);
881 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
882 				  int flags, ext2_file_t *ret);
883 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
884 extern errcode_t ext2fs_file_close(ext2_file_t file);
885 extern errcode_t ext2fs_file_flush(ext2_file_t file);
886 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
887 				  unsigned int wanted, unsigned int *got);
888 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
889 				   unsigned int nbytes, unsigned int *written);
890 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
891 				   int whence, __u64 *ret_pos);
892 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
893 				   int whence, ext2_off_t *ret_pos);
894 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
895 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
896 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
897 
898 /* finddev.c */
899 extern char *ext2fs_find_block_device(dev_t device);
900 
901 /* flushb.c */
902 extern errcode_t ext2fs_sync_device(int fd, int flushb);
903 
904 /* freefs.c */
905 extern void ext2fs_free(ext2_filsys fs);
906 extern void ext2fs_free_dblist(ext2_dblist dblist);
907 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
908 extern void ext2fs_u32_list_free(ext2_u32_list bb);
909 
910 /* gen_bitmap.c */
911 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
912 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
913 					    __u32 start, __u32 end,
914 					    __u32 real_end,
915 					    const char *descr, char *init_map,
916 					    ext2fs_generic_bitmap *ret);
917 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
918 						__u32 end,
919 						__u32 real_end,
920 						const char *descr,
921 						ext2fs_generic_bitmap *ret);
922 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
923 					    ext2fs_generic_bitmap *dest);
924 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
925 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
926 						 errcode_t magic,
927 						 errcode_t neq,
928 						 ext2_ino_t end,
929 						 ext2_ino_t *oend);
930 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
931 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
932 					      __u32 new_end,
933 					      __u32 new_real_end,
934 					      ext2fs_generic_bitmap bmap);
935 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
936 					       ext2fs_generic_bitmap bm1,
937 					       ext2fs_generic_bitmap bm2);
938 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
939 						 errcode_t magic,
940 						 __u32 start, __u32 num,
941 						 void *out);
942 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
943 						 errcode_t magic,
944 						 __u32 start, __u32 num,
945 						 void *in);
946 
947 /* getsize.c */
948 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
949 					blk_t *retblocks);
950 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
951 					blk64_t *retblocks);
952 
953 /* getsectsize.c */
954 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
955 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
956 
957 /* i_block.c */
958 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
959 				 blk64_t num_blocks);
960 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
961 				 blk64_t num_blocks);
962 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
963 
964 /* imager.c */
965 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
966 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
967 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
968 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
969 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
970 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
971 
972 /* ind_block.c */
973 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
974 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
975 
976 /* initialize.c */
977 extern errcode_t ext2fs_initialize(const char *name, int flags,
978 				   struct ext2_super_block *param,
979 				   io_manager manager, ext2_filsys *ret_fs);
980 
981 /* icount.c */
982 extern void ext2fs_free_icount(ext2_icount_t icount);
983 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
984 					  int flags, ext2_icount_t *ret);
985 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
986 				       unsigned int size,
987 				       ext2_icount_t hint, ext2_icount_t *ret);
988 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
989 				      unsigned int size,
990 				      ext2_icount_t *ret);
991 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
992 				     __u16 *ret);
993 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
994 					 __u16 *ret);
995 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
996 					 __u16 *ret);
997 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
998 				     __u16 count);
999 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
1000 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
1001 
1002 /* inode.c */
1003 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
1004 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
1005 					    ext2_ino_t *ino,
1006 					    struct ext2_inode *inode,
1007 					    int bufsize);
1008 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
1009 				  ext2_inode_scan *ret_scan);
1010 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1011 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1012 			       struct ext2_inode *inode);
1013 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1014 						   int	group);
1015 extern void ext2fs_set_inode_callback
1016 	(ext2_inode_scan scan,
1017 	 errcode_t (*done_group)(ext2_filsys fs,
1018 				 ext2_inode_scan scan,
1019 				 dgrp_t group,
1020 				 void * priv_data),
1021 	 void *done_group_data);
1022 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1023 				   int clear_flags);
1024 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1025 					struct ext2_inode * inode,
1026 					int bufsize);
1027 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
1028 			    struct ext2_inode * inode);
1029 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1030 					 struct ext2_inode * inode,
1031 					 int bufsize);
1032 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1033 			    struct ext2_inode * inode);
1034 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1035 			    struct ext2_inode * inode);
1036 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1037 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1038 
1039 /* inode_io.c */
1040 extern io_manager inode_io_manager;
1041 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1042 					char **name);
1043 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1044 					 struct ext2_inode *inode,
1045 					 char **name);
1046 
1047 /* ismounted.c */
1048 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1049 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1050 					  char *mtpt, int mtlen);
1051 
1052 /* namei.c */
1053 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1054 			 int namelen, char *buf, ext2_ino_t *inode);
1055 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1056 			const char *name, ext2_ino_t *inode);
1057 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1058 			      const char *name, ext2_ino_t *inode);
1059 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1060 			ext2_ino_t inode, ext2_ino_t *res_inode);
1061 
1062 /* native.c */
1063 int ext2fs_native_flag(void);
1064 
1065 /* newdir.c */
1066 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1067 				ext2_ino_t parent_ino, char **block);
1068 
1069 /* mkdir.c */
1070 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1071 			      const char *name);
1072 
1073 /* mkjournal.c */
1074 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1075 				    blk_t *ret_blk, int *ret_count);
1076 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1077 						  __u32 size, int flags,
1078 						  char  **ret_jsb);
1079 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1080 					   ext2_filsys journal_dev);
1081 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
1082 					  int flags);
1083 extern int ext2fs_default_journal_size(__u64 blocks);
1084 
1085 /* openfs.c */
1086 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1087 			     unsigned int block_size, io_manager manager,
1088 			     ext2_filsys *ret_fs);
1089 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1090 			      int flags, int superblock,
1091 			      unsigned int block_size, io_manager manager,
1092 			      ext2_filsys *ret_fs);
1093 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1094 					 dgrp_t i);
1095 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1096 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1097 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1098 
1099 /* get_pathname.c */
1100 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1101 			       char **name);
1102 
1103 /* link.c */
1104 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1105 		      ext2_ino_t ino, int flags);
1106 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1107 			ext2_ino_t ino, int flags);
1108 
1109 /* read_bb.c */
1110 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1111 				      ext2_badblocks_list *bb_list);
1112 
1113 /* read_bb_file.c */
1114 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1115 				      ext2_badblocks_list *bb_list,
1116 				      void *priv_data,
1117 				      void (*invalid)(ext2_filsys fs,
1118 						      blk_t blk,
1119 						      char *badstr,
1120 						      void *priv_data));
1121 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1122 				     ext2_badblocks_list *bb_list,
1123 				     void (*invalid)(ext2_filsys fs,
1124 						     blk_t blk));
1125 
1126 /* res_gdt.c */
1127 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1128 
1129 /* swapfs.c */
1130 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1131 				 int has_header);
1132 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1133 					struct ext2_ext_attr_header *from_hdr);
1134 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1135 				       struct ext2_ext_attr_entry *from_entry);
1136 extern void ext2fs_swap_super(struct ext2_super_block * super);
1137 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1138 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1139 				   struct ext2_inode_large *f, int hostorder,
1140 				   int bufsize);
1141 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1142 			      struct ext2_inode *f, int hostorder);
1143 
1144 /* valid_blk.c */
1145 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1146 
1147 /* version.c */
1148 extern int ext2fs_parse_version_string(const char *ver_string);
1149 extern int ext2fs_get_library_version(const char **ver_string,
1150 				      const char **date_string);
1151 
1152 /* write_bb_file.c */
1153 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1154 				      unsigned int flags,
1155 				      FILE *f);
1156 
1157 
1158 /* inline functions */
1159 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1160 extern errcode_t ext2fs_get_memalign(unsigned long size,
1161 				     unsigned long align, void *ptr);
1162 extern errcode_t ext2fs_free_mem(void *ptr);
1163 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1164 				   unsigned long size, void *ptr);
1165 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1166 extern void ext2fs_mark_changed(ext2_filsys fs);
1167 extern int ext2fs_test_changed(ext2_filsys fs);
1168 extern void ext2fs_mark_valid(ext2_filsys fs);
1169 extern void ext2fs_unmark_valid(ext2_filsys fs);
1170 extern int ext2fs_test_valid(ext2_filsys fs);
1171 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1172 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1173 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1174 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1175 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1176 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1177 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1178 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1179 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1180 				      struct ext2_inode *inode);
1181 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1182 
1183 /*
1184  * The actual inlined functions definitions themselves...
1185  *
1186  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1187  * functions at all!
1188  */
1189 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1190 #ifdef INCLUDE_INLINE_FUNCS
1191 #define _INLINE_ extern
1192 #else
1193 #ifdef __GNUC__
1194 #define _INLINE_ extern __inline__
1195 #else				/* For Watcom C */
1196 #define _INLINE_ extern inline
1197 #endif
1198 #endif
1199 
1200 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1201 #include <string.h>
1202 /*
1203  *  Allocate memory
1204  */
ext2fs_get_mem(unsigned long size,void * ptr)1205 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1206 {
1207 	void *pp;
1208 
1209 	pp = malloc(size);
1210 	if (!pp)
1211 		return EXT2_ET_NO_MEMORY;
1212 	memcpy(ptr, &pp, sizeof (pp));
1213 	return 0;
1214 }
1215 
ext2fs_get_memalign(unsigned long size,unsigned long align,void * ptr)1216 _INLINE_ errcode_t ext2fs_get_memalign(unsigned long size,
1217 				       unsigned long align, void *ptr)
1218 {
1219 	errcode_t retval;
1220 
1221 	if (align == 0)
1222 		align = 8;
1223 
1224 #if defined(__APPLE__) && defined(__MACH__)
1225 	/* MacOS 10.5, which we build for, doesn't have posix_memalign.
1226 	 * The only option is valloc, but only use it if the requested
1227 	 * alignment is larger than the alignment provided by malloc.
1228 	 * The idea for this fix came from a patch on the macports website.
1229 	 */
1230 	*(void **) ptr = (align > 16) ? valloc(size) : malloc(size);
1231 	if (*(void **)ptr == NULL)
1232 		return EXT2_ET_NO_MEMORY;
1233 #else
1234 	if ((retval = posix_memalign((void **) ptr, align, size))) {
1235 		if (retval == ENOMEM)
1236 			return EXT2_ET_NO_MEMORY;
1237 		return retval;
1238 	}
1239 #endif
1240 	return 0;
1241 }
1242 
ext2fs_get_array(unsigned long count,unsigned long size,void * ptr)1243 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
1244 {
1245 	if (count && (-1UL)/count<size)
1246 		return EXT2_ET_NO_MEMORY; //maybe define EXT2_ET_OVERFLOW ?
1247 	return ext2fs_get_mem(count*size, ptr);
1248 }
1249 
1250 /*
1251  * Free memory
1252  */
ext2fs_free_mem(void * ptr)1253 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1254 {
1255 	void *p;
1256 
1257 	memcpy(&p, ptr, sizeof(p));
1258 	free(p);
1259 	p = 0;
1260 	memcpy(ptr, &p, sizeof(p));
1261 	return 0;
1262 }
1263 
1264 /*
1265  *  Resize memory
1266  */
ext2fs_resize_mem(unsigned long EXT2FS_ATTR ((unused))old_size,unsigned long size,void * ptr)1267 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1268 				     unsigned long size, void *ptr)
1269 {
1270 	void *p;
1271 
1272 	/* Use "memcpy" for pointer assignments here to avoid problems
1273 	 * with C99 strict type aliasing rules. */
1274 	memcpy(&p, ptr, sizeof(p));
1275 	p = realloc(p, size);
1276 	if (!p)
1277 		return EXT2_ET_NO_MEMORY;
1278 	memcpy(ptr, &p, sizeof(p));
1279 	return 0;
1280 }
1281 #endif	/* Custom memory routines */
1282 
1283 /*
1284  * Mark a filesystem superblock as dirty
1285  */
ext2fs_mark_super_dirty(ext2_filsys fs)1286 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1287 {
1288 	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1289 }
1290 
1291 /*
1292  * Mark a filesystem as changed
1293  */
ext2fs_mark_changed(ext2_filsys fs)1294 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1295 {
1296 	fs->flags |= EXT2_FLAG_CHANGED;
1297 }
1298 
1299 /*
1300  * Check to see if a filesystem has changed
1301  */
ext2fs_test_changed(ext2_filsys fs)1302 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1303 {
1304 	return (fs->flags & EXT2_FLAG_CHANGED);
1305 }
1306 
1307 /*
1308  * Mark a filesystem as valid
1309  */
ext2fs_mark_valid(ext2_filsys fs)1310 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1311 {
1312 	fs->flags |= EXT2_FLAG_VALID;
1313 }
1314 
1315 /*
1316  * Mark a filesystem as NOT valid
1317  */
ext2fs_unmark_valid(ext2_filsys fs)1318 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1319 {
1320 	fs->flags &= ~EXT2_FLAG_VALID;
1321 }
1322 
1323 /*
1324  * Check to see if a filesystem is valid
1325  */
ext2fs_test_valid(ext2_filsys fs)1326 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1327 {
1328 	return (fs->flags & EXT2_FLAG_VALID);
1329 }
1330 
1331 /*
1332  * Mark the inode bitmap as dirty
1333  */
ext2fs_mark_ib_dirty(ext2_filsys fs)1334 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1335 {
1336 	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1337 }
1338 
1339 /*
1340  * Mark the block bitmap as dirty
1341  */
ext2fs_mark_bb_dirty(ext2_filsys fs)1342 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1343 {
1344 	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1345 }
1346 
1347 /*
1348  * Check to see if a filesystem's inode bitmap is dirty
1349  */
ext2fs_test_ib_dirty(ext2_filsys fs)1350 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1351 {
1352 	return (fs->flags & EXT2_FLAG_IB_DIRTY);
1353 }
1354 
1355 /*
1356  * Check to see if a filesystem's block bitmap is dirty
1357  */
ext2fs_test_bb_dirty(ext2_filsys fs)1358 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1359 {
1360 	return (fs->flags & EXT2_FLAG_BB_DIRTY);
1361 }
1362 
1363 /*
1364  * Return the group # of a block
1365  */
ext2fs_group_of_blk(ext2_filsys fs,blk_t blk)1366 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1367 {
1368 	return (blk - fs->super->s_first_data_block) /
1369 		fs->super->s_blocks_per_group;
1370 }
1371 
1372 /*
1373  * Return the group # of an inode number
1374  */
ext2fs_group_of_ino(ext2_filsys fs,ext2_ino_t ino)1375 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1376 {
1377 	return (ino - 1) / fs->super->s_inodes_per_group;
1378 }
1379 
1380 /*
1381  * Return the first block (inclusive) in a group
1382  */
ext2fs_group_first_block(ext2_filsys fs,dgrp_t group)1383 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
1384 {
1385 	return fs->super->s_first_data_block +
1386 		(group * fs->super->s_blocks_per_group);
1387 }
1388 
1389 /*
1390  * Return the last block (inclusive) in a group
1391  */
ext2fs_group_last_block(ext2_filsys fs,dgrp_t group)1392 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
1393 {
1394 	return (group == fs->group_desc_count - 1 ?
1395 		fs->super->s_blocks_count - 1 :
1396 		ext2fs_group_first_block(fs, group) +
1397 			(fs->super->s_blocks_per_group - 1));
1398 }
1399 
ext2fs_inode_data_blocks(ext2_filsys fs,struct ext2_inode * inode)1400 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1401 					struct ext2_inode *inode)
1402 {
1403        return inode->i_blocks -
1404               (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1405 }
1406 
1407 /*
1408  * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
1409  */
ext2fs_div_ceil(unsigned int a,unsigned int b)1410 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
1411 {
1412 	if (!a)
1413 		return 0;
1414 	return ((a - 1) / b) + 1;
1415 }
1416 #undef _INLINE_
1417 #endif
1418 
1419 #ifdef __cplusplus
1420 }
1421 #endif
1422 
1423 #endif /* _EXT2FS_EXT2FS_H */
1424