ext2fs.h revision a78926effb15bbabb1c0ed3e438b03be25c4d48c
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 Public
8 * License.
9 * %End-Header%
10 */
11
12#ifndef _EXT2FS_EXT2FS_H
13#define _EXT2FS_EXT2FS_H
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/*
20 * Non-GNU C compilers won't necessarily understand inline
21 */
22#if (!defined(__GNUC__) && !defined(__WATCOMC__))
23#define NO_INLINE_FUNCS
24#endif
25
26/*
27 * Where the master copy of the superblock is located, and how big
28 * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
29 * the size of the superblock structure is not necessarily trustworthy
30 * (some versions have the padding set up so that the superblock is
31 * 1032 bytes long).
32 */
33#define SUPERBLOCK_OFFSET	1024
34#define SUPERBLOCK_SIZE 	1024
35
36/*
37 * The last ext2fs revision level that this version of the library is
38 * able to support.
39 */
40#define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
41
42#ifdef HAVE_SYS_TYPES_H
43#include <sys/types.h>
44#endif
45
46#include <stdlib.h>
47
48#if EXT2_FLAT_INCLUDES
49#include "e2_types.h"
50#else
51#include <asm/types.h>
52#if !defined(__GNUC__) || defined(__STRICT_ANSI__)  /* asm/types.h already defines __s64 and __u64 otherwise */
53#if SIZEOF_LONG == 8
54typedef __signed__ long __s64;
55typedef unsigned long __u64;
56#elif SIZEOF_LONG_LONG == 8 || \
57  defined(__GNUC__) && (((~0UL) == 0xffffffff) || defined(__i386__))
58typedef __signed__ long long __s64;
59typedef unsigned long long __u64;
60#endif /* SIZEOF_LONG == 8 */
61#endif
62#endif /* EXT2_FLAT_INCLUDES */
63
64typedef __u32		ext2_ino_t;
65typedef __u32		blk_t;
66typedef __u32		dgrp_t;
67typedef __u32		ext2_off_t;
68typedef __s64		e2_blkcnt_t;
69
70#if EXT2_FLAT_INCLUDES
71#include "com_err.h"
72#include "ext2_io.h"
73#include "ext2_err.h"
74#else
75#include "et/com_err.h"
76#include "ext2fs/ext2_io.h"
77#include "ext2fs/ext2_err.h"
78#endif
79
80/*
81 * Portability help for Microsoft Visual C++
82 */
83#ifdef _MSC_VER
84#define EXT2_QSORT_TYPE int __cdecl
85#else
86#define EXT2_QSORT_TYPE int
87#endif
88
89typedef struct struct_ext2_filsys *ext2_filsys;
90
91struct ext2fs_struct_generic_bitmap {
92	errcode_t	magic;
93	ext2_filsys 	fs;
94	__u32		start, end;
95	__u32		real_end;
96	char	*	description;
97	char	*	bitmap;
98	errcode_t	base_error_code;
99	__u32		reserved[7];
100};
101
102#define EXT2FS_MARK_ERROR 	0
103#define EXT2FS_UNMARK_ERROR 	1
104#define EXT2FS_TEST_ERROR	2
105
106typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
107typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
108typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
109
110#ifdef EXT2_DYNAMIC_REV
111#define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO(s)
112#else
113#define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO
114#define EXT2_INODE_SIZE(s)	sizeof(struct ext2_inode)
115#endif
116
117/*
118 * badblocks list definitions
119 */
120
121typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
122typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
123
124/* old */
125typedef struct ext2_struct_badblocks_list *badblocks_list;
126typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
127
128#define BADBLOCKS_FLAG_DIRTY	1
129
130/*
131 * ext2_dblist structure and abstractions (see dblist.c)
132 */
133struct ext2_db_entry {
134	ext2_ino_t	ino;
135	blk_t	blk;
136	int	blockcnt;
137};
138
139typedef struct ext2_struct_dblist *ext2_dblist;
140
141#define DBLIST_ABORT	1
142
143/*
144 * ext2_fileio definitions
145 */
146
147#define EXT2_FILE_WRITE		0x0001
148#define EXT2_FILE_CREATE	0x0002
149
150#define EXT2_FILE_MASK		0x00FF
151
152#define EXT2_FILE_BUF_DIRTY	0x4000
153#define EXT2_FILE_BUF_VALID	0x2000
154
155typedef struct ext2_file *ext2_file_t;
156
157#define EXT2_SEEK_SET	0
158#define EXT2_SEEK_CUR	1
159#define EXT2_SEEK_END	2
160
161/*
162 * Flags for the ext2_filsys structure and for ext2fs_open()
163 */
164#define EXT2_FLAG_RW			0x01
165#define EXT2_FLAG_CHANGED		0x02
166#define EXT2_FLAG_DIRTY			0x04
167#define EXT2_FLAG_VALID			0x08
168#define EXT2_FLAG_IB_DIRTY		0x10
169#define EXT2_FLAG_BB_DIRTY		0x20
170#define EXT2_FLAG_SWAP_BYTES		0x40
171#define EXT2_FLAG_SWAP_BYTES_READ	0x80
172#define EXT2_FLAG_SWAP_BYTES_WRITE	0x100
173#define EXT2_FLAG_MASTER_SB_ONLY	0x200
174#define EXT2_FLAG_FORCE			0x400
175#define EXT2_FLAG_SUPER_ONLY		0x800
176#define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
177#define EXT2_FLAG_IMAGE_FILE		0x2000
178
179/*
180 * Special flag in the ext2 inode i_flag field that means that this is
181 * a new inode.  (So that ext2_write_inode() can clear extra fields.)
182 */
183#define EXT2_NEW_INODE_FL	0x80000000
184
185/*
186 * Flags for mkjournal
187 *
188 * EXT2_MKJOURNAL_V1_SUPER	Make a (deprecated) V1 journal superblock
189 */
190#define EXT2_MKJOURNAL_V1_SUPER	0x0000001
191
192struct struct_ext2_filsys {
193	errcode_t			magic;
194	io_channel			io;
195	int				flags;
196	char *				device_name;
197	struct ext2_super_block	* 	super;
198	int				blocksize;
199	int				fragsize;
200	dgrp_t				group_desc_count;
201	unsigned long			desc_blocks;
202	struct ext2_group_desc *	group_desc;
203	int				inode_blocks_per_group;
204	ext2fs_inode_bitmap		inode_map;
205	ext2fs_block_bitmap		block_map;
206	errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
207	errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
208	errcode_t (*write_bitmaps)(ext2_filsys fs);
209	errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
210				struct ext2_inode *inode);
211	errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
212				struct ext2_inode *inode);
213	badblocks_list			badblocks;
214	ext2_dblist			dblist;
215	__u32				stride;	/* for mke2fs */
216	struct ext2_super_block *	orig_super;
217	struct ext2_image_hdr *		image_header;
218	/*
219	 * Reserved for future expansion
220	 */
221	__u32				reserved[9];
222
223	/*
224	 * Reserved for the use of the calling application.
225	 */
226	void *				priv_data;
227
228	/*
229	 * Inode cache
230	 */
231	struct ext2_inode_cache		*icache;
232};
233
234#if EXT2_FLAT_INCLUDES
235#include "e2_bitops.h"
236#else
237#include "ext2fs/bitops.h"
238#endif
239
240/*
241 * Return flags for the block iterator functions
242 */
243#define BLOCK_CHANGED	1
244#define BLOCK_ABORT	2
245#define BLOCK_ERROR	4
246
247/*
248 * Block interate flags
249 *
250 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
251 * function should be called on blocks where the block number is zero.
252 * This is used by ext2fs_expand_dir() to be able to add a new block
253 * to an inode.  It can also be used for programs that want to be able
254 * to deal with files that contain "holes".
255 *
256 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
257 * indirect, doubly indirect, etc. blocks should be called after all
258 * of the blocks containined in the indirect blocks are processed.
259 * This is useful if you are going to be deallocating blocks from an
260 * inode.
261 *
262 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
263 * called for data blocks only.
264 *
265 * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
266 * ext2fs_block_iterate2 that large files won't be accepted.
267 */
268#define BLOCK_FLAG_APPEND	1
269#define BLOCK_FLAG_HOLE		1
270#define BLOCK_FLAG_DEPTH_TRAVERSE	2
271#define BLOCK_FLAG_DATA_ONLY	4
272
273#define BLOCK_FLAG_NO_LARGE	0x1000
274
275/*
276 * Magic "block count" return values for the block iterator function.
277 */
278#define BLOCK_COUNT_IND		(-1)
279#define BLOCK_COUNT_DIND	(-2)
280#define BLOCK_COUNT_TIND	(-3)
281#define BLOCK_COUNT_TRANSLATOR	(-4)
282
283#if 0
284/*
285 * Flags for ext2fs_move_blocks
286 */
287#define EXT2_BMOVE_GET_DBLIST	0x0001
288#define EXT2_BMOVE_DEBUG	0x0002
289#endif
290
291/*
292 * Return flags for the directory iterator functions
293 */
294#define DIRENT_CHANGED	1
295#define DIRENT_ABORT	2
296#define DIRENT_ERROR	3
297
298/*
299 * Directory iterator flags
300 */
301
302#define DIRENT_FLAG_INCLUDE_EMPTY	1
303
304
305#define DIRENT_DOT_FILE		1
306#define DIRENT_DOT_DOT_FILE	2
307#define DIRENT_OTHER_FILE	3
308
309/*
310 * Inode scan definitions
311 */
312typedef struct ext2_struct_inode_scan *ext2_inode_scan;
313
314/*
315 * ext2fs_scan flags
316 */
317#define EXT2_SF_CHK_BADBLOCKS	0x0001
318#define EXT2_SF_BAD_INODE_BLK	0x0002
319#define EXT2_SF_BAD_EXTRA_BYTES	0x0004
320#define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
321
322/*
323 * ext2fs_check_if_mounted flags
324 */
325#define EXT2_MF_MOUNTED		1
326#define EXT2_MF_ISROOT		2
327#define EXT2_MF_READONLY	4
328
329/*
330 * Ext2/linux mode flags.  We define them here so that we don't need
331 * to depend on the OS's sys/stat.h, since we may be compiling on a
332 * non-Linux system.
333 */
334#define LINUX_S_IFMT  00170000
335#define LINUX_S_IFSOCK 0140000
336#define LINUX_S_IFLNK	 0120000
337#define LINUX_S_IFREG  0100000
338#define LINUX_S_IFBLK  0060000
339#define LINUX_S_IFDIR  0040000
340#define LINUX_S_IFCHR  0020000
341#define LINUX_S_IFIFO  0010000
342#define LINUX_S_ISUID  0004000
343#define LINUX_S_ISGID  0002000
344#define LINUX_S_ISVTX  0001000
345
346#define LINUX_S_IRWXU 00700
347#define LINUX_S_IRUSR 00400
348#define LINUX_S_IWUSR 00200
349#define LINUX_S_IXUSR 00100
350
351#define LINUX_S_IRWXG 00070
352#define LINUX_S_IRGRP 00040
353#define LINUX_S_IWGRP 00020
354#define LINUX_S_IXGRP 00010
355
356#define LINUX_S_IRWXO 00007
357#define LINUX_S_IROTH 00004
358#define LINUX_S_IWOTH 00002
359#define LINUX_S_IXOTH 00001
360
361#define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
362#define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
363#define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
364#define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
365#define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
366#define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
367#define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
368
369/*
370 * ext2_icount_t abstraction
371 */
372#define EXT2_ICOUNT_OPT_INCREMENT	0x01
373
374typedef struct ext2_icount *ext2_icount_t;
375
376/*
377 * Flags for ext2fs_bmap
378 */
379#define BMAP_ALLOC	1
380
381/*
382 * Flags for imager.c functions
383 */
384#define IMAGER_FLAG_INODEMAP	1
385#define IMAGER_FLAG_SPARSEWRITE	2
386
387/*
388 * For checking structure magic numbers...
389 */
390
391#define EXT2_CHECK_MAGIC(struct, code) \
392	  if ((struct)->magic != (code)) return (code)
393
394
395/*
396 * For ext2 compression support
397 */
398#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
399#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
400
401/*
402 * Features supported by this version of the library
403 */
404#define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
405					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
406					 EXT3_FEATURE_COMPAT_HAS_JOURNAL)
407
408/* This #ifdef is temporary until compression is fully supported */
409#ifdef ENABLE_COMPRESSION
410#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
411/* If the below warning bugs you, then have
412   `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
413   environment at configure time. */
414 #warning "Compression support is experimental"
415#endif
416#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
417					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
418					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
419					 EXT3_FEATURE_INCOMPAT_RECOVER)
420#else
421#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
422					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
423					 EXT3_FEATURE_INCOMPAT_RECOVER)
424#endif
425#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
426					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
427/*
428 * function prototypes
429 */
430
431/* alloc.c */
432extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
433				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
434extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
435				  ext2fs_block_bitmap map, blk_t *ret);
436extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
437					blk_t finish, int num,
438					ext2fs_block_bitmap map,
439					blk_t *ret);
440extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
441				    char *block_buf, blk_t *ret);
442
443/* alloc_tables.c */
444extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
445extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
446					     ext2fs_block_bitmap bmap);
447
448/* badblocks.c */
449extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
450					    int size);
451extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
452					   blk_t blk);
453extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
454				    blk_t blk);
455extern errcode_t
456	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
457					    ext2_badblocks_iterate *ret);
458extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
459					 blk_t *blk);
460extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
461extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
462				       ext2_badblocks_list *dest);
463extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
464				  ext2_badblocks_list bb2);
465
466/* bb_compat */
467extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
468extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
469extern int badblocks_list_test(badblocks_list bb, blk_t blk);
470extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
471					      badblocks_iterate *ret);
472extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
473extern void badblocks_list_iterate_end(badblocks_iterate iter);
474extern void badblocks_list_free(badblocks_list bb);
475
476/* bb_inode.c */
477extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
478					ext2_badblocks_list bb_list);
479
480/* bitmaps.c */
481extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
482extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
483extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
484extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
485extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
486						__u32 end,
487						__u32 real_end,
488						const char *descr,
489						ext2fs_generic_bitmap *ret);
490extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
491					      const char *descr,
492					      ext2fs_block_bitmap *ret);
493extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
494					      const char *descr,
495					      ext2fs_inode_bitmap *ret);
496extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
497					       ext2_ino_t end, ext2_ino_t *oend);
498extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
499					       blk_t end, blk_t *oend);
500extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
501extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
502extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
503extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
504
505/* block.c */
506extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
507				      ext2_ino_t	ino,
508				      int	flags,
509				      char *block_buf,
510				      int (*func)(ext2_filsys fs,
511						  blk_t	*blocknr,
512						  int	blockcnt,
513						  void	*priv_data),
514				      void *priv_data);
515errcode_t ext2fs_block_iterate2(ext2_filsys fs,
516				ext2_ino_t	ino,
517				int	flags,
518				char *block_buf,
519				int (*func)(ext2_filsys fs,
520					    blk_t	*blocknr,
521					    e2_blkcnt_t	blockcnt,
522					    blk_t	ref_blk,
523					    int		ref_offset,
524					    void	*priv_data),
525				void *priv_data);
526
527/* bmap.c */
528extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
529			     struct ext2_inode *inode,
530			     char *block_buf, int bmap_flags,
531			     blk_t block, blk_t *phys_blk);
532
533
534#if 0
535/* bmove.c */
536extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
537				    ext2fs_block_bitmap reserve,
538				    ext2fs_block_bitmap alloc_map,
539				    int flags);
540#endif
541
542/* check_desc.c */
543extern errcode_t ext2fs_check_desc(ext2_filsys fs);
544
545/* closefs.c */
546extern errcode_t ext2fs_close(ext2_filsys fs);
547extern errcode_t ext2fs_flush(ext2_filsys fs);
548extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
549extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
550
551/* cmp_bitmaps.c */
552extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
553					     ext2fs_block_bitmap bm2);
554extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
555					     ext2fs_inode_bitmap bm2);
556
557/* dblist.c */
558
559extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
560extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
561extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
562				      blk_t blk, int blockcnt);
563extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
564	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
565		    void	*priv_data),
566       void *priv_data);
567extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
568				      blk_t blk, int blockcnt);
569extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
570				    ext2_dblist *dest);
571extern int ext2fs_dblist_count(ext2_dblist dblist);
572
573/* dblist_dir.c */
574extern errcode_t
575	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
576				  int	flags,
577				  char	*block_buf,
578				  int (*func)(ext2_ino_t	dir,
579					      int		entry,
580					      struct ext2_dir_entry *dirent,
581					      int	offset,
582					      int	blocksize,
583					      char	*buf,
584					      void	*priv_data),
585				  void *priv_data);
586
587/* dirblock.c */
588extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
589				       void *buf);
590extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
591					void *buf);
592
593/* dir_iterate.c */
594extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
595			      ext2_ino_t dir,
596			      int flags,
597			      char *block_buf,
598			      int (*func)(struct ext2_dir_entry *dirent,
599					  int	offset,
600					  int	blocksize,
601					  char	*buf,
602					  void	*priv_data),
603			      void *priv_data);
604
605/* dupfs.c */
606extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
607
608/* expanddir.c */
609extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
610
611/* fileio.c */
612extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
613				  int flags, ext2_file_t *ret);
614extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
615extern errcode_t ext2fs_file_close(ext2_file_t file);
616extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
617				  unsigned int wanted, unsigned int *got);
618extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
619				   unsigned int nbytes, unsigned int *written);
620extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
621				   int whence, ext2_off_t *ret_pos);
622extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
623extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
624
625/* finddev.c */
626extern char *ext2fs_find_block_device(dev_t device);
627
628/* flushb.c */
629extern errcode_t ext2fs_sync_device(int fd, int flushb);
630
631/* freefs.c */
632extern void ext2fs_free(ext2_filsys fs);
633extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
634extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
635extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
636extern void ext2fs_free_dblist(ext2_dblist dblist);
637extern void ext2fs_badblocks_list_free(badblocks_list bb);
638
639/* getsize.c */
640extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
641					blk_t *retblocks);
642
643/* imager.c */
644extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
645extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
646extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
647extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
648extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
649extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
650
651/* initialize.c */
652extern errcode_t ext2fs_initialize(const char *name, int flags,
653				   struct ext2_super_block *param,
654				   io_manager manager, ext2_filsys *ret_fs);
655
656/* inode.c */
657extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
658extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
659				  ext2_inode_scan *ret_scan);
660extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
661extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
662			       struct ext2_inode *inode);
663extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
664						   int	group);
665extern void ext2fs_set_inode_callback
666	(ext2_inode_scan scan,
667	 errcode_t (*done_group)(ext2_filsys fs,
668				 ext2_inode_scan scan,
669				 dgrp_t group,
670				 void * priv_data),
671	 void *done_group_data);
672extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
673				   int clear_flags);
674extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
675			    struct ext2_inode * inode);
676extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
677			    struct ext2_inode * inode);
678extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
679extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
680
681/* icount.c */
682extern void ext2fs_free_icount(ext2_icount_t icount);
683extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
684				       ext2_icount_t hint, ext2_icount_t *ret);
685extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
686				      ext2_icount_t *ret);
687extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
688				     __u16 *ret);
689extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
690					 __u16 *ret);
691extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
692					 __u16 *ret);
693extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
694				     __u16 count);
695extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
696errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
697
698/* ismounted.c */
699extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
700extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
701					  char *mtpt, int mtlen);
702
703/* namei.c */
704extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
705			 int namelen, char *buf, ext2_ino_t *inode);
706extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
707			const char *name, ext2_ino_t *inode);
708errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
709			      const char *name, ext2_ino_t *inode);
710extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
711			ext2_ino_t inode, ext2_ino_t *res_inode);
712
713/* native.c */
714int ext2fs_native_flag(void);
715
716/* newdir.c */
717extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
718				ext2_ino_t parent_ino, char **block);
719
720/* mkdir.c */
721extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
722			      const char *name);
723
724/* mkjournal.c */
725extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
726						  __u32 size, int flags,
727						  char  **ret_jsb);
728extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
729					   ext2_filsys journal_dev);
730extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
731					  int flags);
732
733/* openfs.c */
734extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
735			     int block_size, io_manager manager,
736			     ext2_filsys *ret_fs);
737
738/* get_pathname.c */
739extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
740			       char **name);
741
742/* link.c */
743errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
744		      ext2_ino_t ino, int flags);
745errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
746			ext2_ino_t ino, int flags);
747
748/* read_bb.c */
749extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
750				      ext2_badblocks_list *bb_list);
751
752/* read_bb_file.c */
753extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
754				      ext2_badblocks_list *bb_list,
755				      void *private,
756				      void (*invalid)(ext2_filsys fs,
757						      blk_t blk,
758						      char *badstr,
759						      void *private));
760extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
761				     ext2_badblocks_list *bb_list,
762				     void (*invalid)(ext2_filsys fs,
763						     blk_t blk));
764
765/* rs_bitmap.c */
766extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
767					      __u32 new_real_end,
768					      ext2fs_generic_bitmap bmap);
769extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
770					    ext2fs_inode_bitmap bmap);
771extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
772					    ext2fs_block_bitmap bmap);
773extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
774				    ext2fs_generic_bitmap *dest);
775
776/* swapfs.c */
777extern void ext2fs_swap_super(struct ext2_super_block * super);
778extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
779extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
780			      struct ext2_inode *f, int hostorder);
781
782/* valid_blk.c */
783extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
784
785/* version.c */
786extern int ext2fs_parse_version_string(const char *ver_string);
787extern int ext2fs_get_library_version(const char **ver_string,
788				      const char **date_string);
789
790/* write_bb_file.c */
791extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
792				      unsigned int flags,
793				      FILE *f);
794
795
796/* inline functions */
797extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
798extern errcode_t ext2fs_free_mem(void **ptr);
799extern errcode_t ext2fs_resize_mem(unsigned long old_size,
800				   unsigned long size, void **ptr);
801extern void ext2fs_mark_super_dirty(ext2_filsys fs);
802extern void ext2fs_mark_changed(ext2_filsys fs);
803extern int ext2fs_test_changed(ext2_filsys fs);
804extern void ext2fs_mark_valid(ext2_filsys fs);
805extern void ext2fs_unmark_valid(ext2_filsys fs);
806extern int ext2fs_test_valid(ext2_filsys fs);
807extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
808extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
809extern int ext2fs_test_ib_dirty(ext2_filsys fs);
810extern int ext2fs_test_bb_dirty(ext2_filsys fs);
811extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
812extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
813
814/*
815 * The actual inlined functions definitions themselves...
816 *
817 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
818 * functions at all!
819 */
820#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
821#ifdef INCLUDE_INLINE_FUNCS
822#define _INLINE_ extern
823#else
824#ifdef __GNUC__
825#define _INLINE_ extern __inline__
826#else				/* For Watcom C */
827#define _INLINE_ extern inline
828#endif
829#endif
830
831#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
832/*
833 *  Allocate memory
834 */
835_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
836{
837	*ptr = malloc(size);
838	if (!*ptr)
839		return EXT2_ET_NO_MEMORY;
840	return 0;
841}
842
843/*
844 * Free memory
845 */
846_INLINE_ errcode_t ext2fs_free_mem(void **ptr)
847{
848	free(*ptr);
849	*ptr = 0;
850	return 0;
851}
852
853/*
854 *  Resize memory
855 */
856_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
857				     unsigned long size, void **ptr)
858{
859	void *p;
860
861	p = realloc(*ptr, size);
862	if (!p)
863		return EXT2_ET_NO_MEMORY;
864	*ptr = p;
865	return 0;
866}
867#endif	/* Custom memory routines */
868
869/*
870 * Mark a filesystem superblock as dirty
871 */
872_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
873{
874	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
875}
876
877/*
878 * Mark a filesystem as changed
879 */
880_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
881{
882	fs->flags |= EXT2_FLAG_CHANGED;
883}
884
885/*
886 * Check to see if a filesystem has changed
887 */
888_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
889{
890	return (fs->flags & EXT2_FLAG_CHANGED);
891}
892
893/*
894 * Mark a filesystem as valid
895 */
896_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
897{
898	fs->flags |= EXT2_FLAG_VALID;
899}
900
901/*
902 * Mark a filesystem as NOT valid
903 */
904_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
905{
906	fs->flags &= ~EXT2_FLAG_VALID;
907}
908
909/*
910 * Check to see if a filesystem is valid
911 */
912_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
913{
914	return (fs->flags & EXT2_FLAG_VALID);
915}
916
917/*
918 * Mark the inode bitmap as dirty
919 */
920_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
921{
922	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
923}
924
925/*
926 * Mark the block bitmap as dirty
927 */
928_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
929{
930	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
931}
932
933/*
934 * Check to see if a filesystem's inode bitmap is dirty
935 */
936_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
937{
938	return (fs->flags & EXT2_FLAG_IB_DIRTY);
939}
940
941/*
942 * Check to see if a filesystem's block bitmap is dirty
943 */
944_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
945{
946	return (fs->flags & EXT2_FLAG_BB_DIRTY);
947}
948
949/*
950 * Return the group # of a block
951 */
952_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
953{
954	return (blk - fs->super->s_first_data_block) /
955		fs->super->s_blocks_per_group;
956}
957
958/*
959 * Return the group # of an inode number
960 */
961_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
962{
963	return (ino - 1) / fs->super->s_inodes_per_group;
964}
965#undef _INLINE_
966#endif
967
968#ifdef __cplusplus
969}
970#endif
971
972#endif /* _EXT2FS_EXT2FS_H */
973