ext2fs.h revision 503f9e7f6eb331c5b75d7f1ad126f71bcdcfb4e3
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 * Build in support for byte-swapping filesystems if we the feature
28 * has been configured or if we're being built on a CPU architecture
29 * with a non-native byte order.
30 */
31#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
32#define EXT2FS_ENABLE_SWAPFS
33#endif
34
35/*
36 * Where the master copy of the superblock is located, and how big
37 * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
38 * the size of the superblock structure is not necessarily trustworthy
39 * (some versions have the padding set up so that the superblock is
40 * 1032 bytes long).
41 */
42#define SUPERBLOCK_OFFSET	1024
43#define SUPERBLOCK_SIZE 	1024
44
45/*
46 * The last ext2fs revision level that this version of the library is
47 * able to support.
48 */
49#define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
50
51#ifdef HAVE_SYS_TYPES_H
52#include <sys/types.h>
53#endif
54
55#include <stdlib.h>
56
57#if EXT2_FLAT_INCLUDES
58#include "e2_types.h"
59#else
60#include <ext2fs/ext2_types.h>
61#endif /* EXT2_FLAT_INCLUDES */
62
63typedef __u32		ext2_ino_t;
64typedef __u32		blk_t;
65typedef __u32		dgrp_t;
66typedef __u32		ext2_off_t;
67typedef __s64		e2_blkcnt_t;
68typedef __u32		ext2_dirhash_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	__u32				umask;
219	/*
220	 * Reserved for future expansion
221	 */
222	__u32				reserved[8];
223
224	/*
225	 * Reserved for the use of the calling application.
226	 */
227	void *				priv_data;
228
229	/*
230	 * Inode cache
231	 */
232	struct ext2_inode_cache		*icache;
233};
234
235#if EXT2_FLAT_INCLUDES
236#include "e2_bitops.h"
237#else
238#include <ext2fs/bitops.h>
239#endif
240
241/*
242 * Return flags for the block iterator functions
243 */
244#define BLOCK_CHANGED	1
245#define BLOCK_ABORT	2
246#define BLOCK_ERROR	4
247
248/*
249 * Block interate flags
250 *
251 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
252 * function should be called on blocks where the block number is zero.
253 * This is used by ext2fs_expand_dir() to be able to add a new block
254 * to an inode.  It can also be used for programs that want to be able
255 * to deal with files that contain "holes".
256 *
257 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
258 * indirect, doubly indirect, etc. blocks should be called after all
259 * of the blocks containined in the indirect blocks are processed.
260 * This is useful if you are going to be deallocating blocks from an
261 * inode.
262 *
263 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
264 * called for data blocks only.
265 *
266 * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
267 * ext2fs_block_iterate2 that large files won't be accepted.
268 */
269#define BLOCK_FLAG_APPEND	1
270#define BLOCK_FLAG_HOLE		1
271#define BLOCK_FLAG_DEPTH_TRAVERSE	2
272#define BLOCK_FLAG_DATA_ONLY	4
273
274#define BLOCK_FLAG_NO_LARGE	0x1000
275
276/*
277 * Magic "block count" return values for the block iterator function.
278 */
279#define BLOCK_COUNT_IND		(-1)
280#define BLOCK_COUNT_DIND	(-2)
281#define BLOCK_COUNT_TIND	(-3)
282#define BLOCK_COUNT_TRANSLATOR	(-4)
283
284#if 0
285/*
286 * Flags for ext2fs_move_blocks
287 */
288#define EXT2_BMOVE_GET_DBLIST	0x0001
289#define EXT2_BMOVE_DEBUG	0x0002
290#endif
291
292/*
293 * Flags for directory block reading and writing functions
294 */
295#define EXT2_DIRBLOCK_V2_STRUCT	0x0001
296
297/*
298 * Return flags for the directory iterator functions
299 */
300#define DIRENT_CHANGED	1
301#define DIRENT_ABORT	2
302#define DIRENT_ERROR	3
303
304/*
305 * Directory iterator flags
306 */
307
308#define DIRENT_FLAG_INCLUDE_EMPTY	1
309#define DIRENT_FLAG_INCLUDE_REMOVED	2
310
311#define DIRENT_DOT_FILE		1
312#define DIRENT_DOT_DOT_FILE	2
313#define DIRENT_OTHER_FILE	3
314#define DIRENT_DELETED_FILE	4
315
316/*
317 * Inode scan definitions
318 */
319typedef struct ext2_struct_inode_scan *ext2_inode_scan;
320
321/*
322 * ext2fs_scan flags
323 */
324#define EXT2_SF_CHK_BADBLOCKS	0x0001
325#define EXT2_SF_BAD_INODE_BLK	0x0002
326#define EXT2_SF_BAD_EXTRA_BYTES	0x0004
327#define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
328
329/*
330 * ext2fs_check_if_mounted flags
331 */
332#define EXT2_MF_MOUNTED		1
333#define EXT2_MF_ISROOT		2
334#define EXT2_MF_READONLY	4
335#define EXT2_MF_SWAP		8
336
337/*
338 * Ext2/linux mode flags.  We define them here so that we don't need
339 * to depend on the OS's sys/stat.h, since we may be compiling on a
340 * non-Linux system.
341 */
342#define LINUX_S_IFMT  00170000
343#define LINUX_S_IFSOCK 0140000
344#define LINUX_S_IFLNK	 0120000
345#define LINUX_S_IFREG  0100000
346#define LINUX_S_IFBLK  0060000
347#define LINUX_S_IFDIR  0040000
348#define LINUX_S_IFCHR  0020000
349#define LINUX_S_IFIFO  0010000
350#define LINUX_S_ISUID  0004000
351#define LINUX_S_ISGID  0002000
352#define LINUX_S_ISVTX  0001000
353
354#define LINUX_S_IRWXU 00700
355#define LINUX_S_IRUSR 00400
356#define LINUX_S_IWUSR 00200
357#define LINUX_S_IXUSR 00100
358
359#define LINUX_S_IRWXG 00070
360#define LINUX_S_IRGRP 00040
361#define LINUX_S_IWGRP 00020
362#define LINUX_S_IXGRP 00010
363
364#define LINUX_S_IRWXO 00007
365#define LINUX_S_IROTH 00004
366#define LINUX_S_IWOTH 00002
367#define LINUX_S_IXOTH 00001
368
369#define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
370#define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
371#define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
372#define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
373#define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
374#define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
375#define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
376
377/*
378 * ext2_icount_t abstraction
379 */
380#define EXT2_ICOUNT_OPT_INCREMENT	0x01
381
382typedef struct ext2_icount *ext2_icount_t;
383
384/*
385 * Flags for ext2fs_bmap
386 */
387#define BMAP_ALLOC	1
388
389/*
390 * Flags for imager.c functions
391 */
392#define IMAGER_FLAG_INODEMAP	1
393#define IMAGER_FLAG_SPARSEWRITE	2
394
395/*
396 * For checking structure magic numbers...
397 */
398
399#define EXT2_CHECK_MAGIC(struct, code) \
400	  if ((struct)->magic != (code)) return (code)
401
402
403/*
404 * For ext2 compression support
405 */
406#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
407#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
408
409/*
410 * Features supported by this version of the library
411 */
412#define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
413					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
414					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
415					 EXT2_FEATURE_COMPAT_DIR_INDEX|\
416					 EXT2_FEATURE_COMPAT_EXT_ATTR)
417
418/* This #ifdef is temporary until compression is fully supported */
419#ifdef ENABLE_COMPRESSION
420#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
421/* If the below warning bugs you, then have
422   `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
423   environment at configure time. */
424 #warning "Compression support is experimental"
425#endif
426#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
427					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
428					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
429					 EXT3_FEATURE_INCOMPAT_RECOVER)
430#else
431#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
432					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
433					 EXT3_FEATURE_INCOMPAT_RECOVER)
434#endif
435#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
436					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
437/*
438 * function prototypes
439 */
440
441/* alloc.c */
442extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
443				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
444extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
445				  ext2fs_block_bitmap map, blk_t *ret);
446extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
447					blk_t finish, int num,
448					ext2fs_block_bitmap map,
449					blk_t *ret);
450extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
451				    char *block_buf, blk_t *ret);
452
453/* alloc_stats.c */
454void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
455void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
456			       int inuse, int isdir);
457void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
458
459/* alloc_tables.c */
460extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
461extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
462					     ext2fs_block_bitmap bmap);
463
464/* badblocks.c */
465extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
466					    int size);
467extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
468					   blk_t blk);
469extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
470				    blk_t blk);
471extern errcode_t
472	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
473					    ext2_badblocks_iterate *ret);
474extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
475					 blk_t *blk);
476extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
477extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
478				       ext2_badblocks_list *dest);
479extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
480				  ext2_badblocks_list bb2);
481
482/* bb_compat */
483extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
484extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
485extern int badblocks_list_test(badblocks_list bb, blk_t blk);
486extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
487					      badblocks_iterate *ret);
488extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
489extern void badblocks_list_iterate_end(badblocks_iterate iter);
490extern void badblocks_list_free(badblocks_list bb);
491
492/* bb_inode.c */
493extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
494					ext2_badblocks_list bb_list);
495
496/* bitmaps.c */
497extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
498extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
499extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
500extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
501extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
502						__u32 end,
503						__u32 real_end,
504						const char *descr,
505						ext2fs_generic_bitmap *ret);
506extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
507					      const char *descr,
508					      ext2fs_block_bitmap *ret);
509extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
510					      const char *descr,
511					      ext2fs_inode_bitmap *ret);
512extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
513					       ext2_ino_t end, ext2_ino_t *oend);
514extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
515					       blk_t end, blk_t *oend);
516extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
517extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
518extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
519extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
520
521/* block.c */
522extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
523				      ext2_ino_t	ino,
524				      int	flags,
525				      char *block_buf,
526				      int (*func)(ext2_filsys fs,
527						  blk_t	*blocknr,
528						  int	blockcnt,
529						  void	*priv_data),
530				      void *priv_data);
531errcode_t ext2fs_block_iterate2(ext2_filsys fs,
532				ext2_ino_t	ino,
533				int	flags,
534				char *block_buf,
535				int (*func)(ext2_filsys fs,
536					    blk_t	*blocknr,
537					    e2_blkcnt_t	blockcnt,
538					    blk_t	ref_blk,
539					    int		ref_offset,
540					    void	*priv_data),
541				void *priv_data);
542
543/* bmap.c */
544extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
545			     struct ext2_inode *inode,
546			     char *block_buf, int bmap_flags,
547			     blk_t block, blk_t *phys_blk);
548
549
550#if 0
551/* bmove.c */
552extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
553				    ext2fs_block_bitmap reserve,
554				    ext2fs_block_bitmap alloc_map,
555				    int flags);
556#endif
557
558/* check_desc.c */
559extern errcode_t ext2fs_check_desc(ext2_filsys fs);
560
561/* closefs.c */
562extern errcode_t ext2fs_close(ext2_filsys fs);
563extern errcode_t ext2fs_flush(ext2_filsys fs);
564extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
565extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
566
567/* cmp_bitmaps.c */
568extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
569					     ext2fs_block_bitmap bm2);
570extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
571					     ext2fs_inode_bitmap bm2);
572
573/* dblist.c */
574
575extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
576extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
577extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
578				      blk_t blk, int blockcnt);
579extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
580	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
581		    void	*priv_data),
582       void *priv_data);
583extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
584				      blk_t blk, int blockcnt);
585extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
586				    ext2_dblist *dest);
587extern int ext2fs_dblist_count(ext2_dblist dblist);
588
589/* dblist_dir.c */
590extern errcode_t
591	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
592				  int	flags,
593				  char	*block_buf,
594				  int (*func)(ext2_ino_t	dir,
595					      int		entry,
596					      struct ext2_dir_entry *dirent,
597					      int	offset,
598					      int	blocksize,
599					      char	*buf,
600					      void	*priv_data),
601				  void *priv_data);
602
603/* dirblock.c */
604extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
605				       void *buf);
606extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
607					void *buf, int flags);
608extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
609					void *buf);
610extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
611					 void *buf, int flags);
612
613/* dirhash.c */
614extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
615				const __u32 seed[4],
616				ext2_dirhash_t *ret_hash,
617				ext2_dirhash_t *ret_minor_hash);
618
619
620/* dir_iterate.c */
621extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
622			      ext2_ino_t dir,
623			      int flags,
624			      char *block_buf,
625			      int (*func)(struct ext2_dir_entry *dirent,
626					  int	offset,
627					  int	blocksize,
628					  char	*buf,
629					  void	*priv_data),
630			      void *priv_data);
631extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
632			      ext2_ino_t dir,
633			      int flags,
634			      char *block_buf,
635			      int (*func)(ext2_ino_t	dir,
636					  int	entry,
637					  struct ext2_dir_entry *dirent,
638					  int	offset,
639					  int	blocksize,
640					  char	*buf,
641					  void	*priv_data),
642			      void *priv_data);
643
644/* dupfs.c */
645extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
646
647/* expanddir.c */
648extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
649
650/* ext_attr.c */
651void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
652extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
653extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *buf);
654/* fileio.c */
655extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
656				  int flags, ext2_file_t *ret);
657extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
658extern errcode_t ext2fs_file_close(ext2_file_t file);
659extern errcode_t ext2fs_file_flush(ext2_file_t file);
660extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
661				  unsigned int wanted, unsigned int *got);
662extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
663				   unsigned int nbytes, unsigned int *written);
664extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
665				   int whence, ext2_off_t *ret_pos);
666extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
667extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
668
669/* finddev.c */
670extern char *ext2fs_find_block_device(dev_t device);
671
672/* flushb.c */
673extern errcode_t ext2fs_sync_device(int fd, int flushb);
674
675/* freefs.c */
676extern void ext2fs_free(ext2_filsys fs);
677extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
678extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
679extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
680extern void ext2fs_free_dblist(ext2_dblist dblist);
681extern void ext2fs_badblocks_list_free(badblocks_list bb);
682
683/* getsize.c */
684extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
685					blk_t *retblocks);
686
687/* imager.c */
688extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
689extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
690extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
691extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
692extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
693extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
694
695/* initialize.c */
696extern errcode_t ext2fs_initialize(const char *name, int flags,
697				   struct ext2_super_block *param,
698				   io_manager manager, ext2_filsys *ret_fs);
699
700/* icount.c */
701extern void ext2fs_free_icount(ext2_icount_t icount);
702extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
703				       ext2_icount_t hint, ext2_icount_t *ret);
704extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
705				      ext2_icount_t *ret);
706extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
707				     __u16 *ret);
708extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
709					 __u16 *ret);
710extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
711					 __u16 *ret);
712extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
713				     __u16 count);
714extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
715errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
716
717/* inode.c */
718extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
719extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
720				  ext2_inode_scan *ret_scan);
721extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
722extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
723			       struct ext2_inode *inode);
724extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
725						   int	group);
726extern void ext2fs_set_inode_callback
727	(ext2_inode_scan scan,
728	 errcode_t (*done_group)(ext2_filsys fs,
729				 ext2_inode_scan scan,
730				 dgrp_t group,
731				 void * priv_data),
732	 void *done_group_data);
733extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
734				   int clear_flags);
735extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
736			    struct ext2_inode * inode);
737extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
738			    struct ext2_inode * inode);
739extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
740extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
741
742/* inode_io.c */
743extern io_manager inode_io_manager;
744extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
745					char **name);
746
747/* ismounted.c */
748extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
749extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
750					  char *mtpt, int mtlen);
751
752/* namei.c */
753extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
754			 int namelen, char *buf, ext2_ino_t *inode);
755extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
756			const char *name, ext2_ino_t *inode);
757errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
758			      const char *name, ext2_ino_t *inode);
759extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
760			ext2_ino_t inode, ext2_ino_t *res_inode);
761
762/* native.c */
763int ext2fs_native_flag(void);
764
765/* newdir.c */
766extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
767				ext2_ino_t parent_ino, char **block);
768
769/* mkdir.c */
770extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
771			      const char *name);
772
773/* mkjournal.c */
774extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
775						  __u32 size, int flags,
776						  char  **ret_jsb);
777extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
778					   ext2_filsys journal_dev);
779extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
780					  int flags);
781
782/* openfs.c */
783extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
784			     int block_size, io_manager manager,
785			     ext2_filsys *ret_fs);
786
787/* get_pathname.c */
788extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
789			       char **name);
790
791/* link.c */
792errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
793		      ext2_ino_t ino, int flags);
794errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
795			ext2_ino_t ino, int flags);
796
797/* read_bb.c */
798extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
799				      ext2_badblocks_list *bb_list);
800
801/* read_bb_file.c */
802extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
803				      ext2_badblocks_list *bb_list,
804				      void *private,
805				      void (*invalid)(ext2_filsys fs,
806						      blk_t blk,
807						      char *badstr,
808						      void *private));
809extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
810				     ext2_badblocks_list *bb_list,
811				     void (*invalid)(ext2_filsys fs,
812						     blk_t blk));
813
814/* rs_bitmap.c */
815extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
816					      __u32 new_real_end,
817					      ext2fs_generic_bitmap bmap);
818extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
819					    ext2fs_inode_bitmap bmap);
820extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
821					    ext2fs_block_bitmap bmap);
822extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
823				    ext2fs_generic_bitmap *dest);
824
825/* swapfs.c */
826extern void ext2fs_swap_super(struct ext2_super_block * super);
827extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
828extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
829			      struct ext2_inode *f, int hostorder);
830
831/* valid_blk.c */
832extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
833
834/* version.c */
835extern int ext2fs_parse_version_string(const char *ver_string);
836extern int ext2fs_get_library_version(const char **ver_string,
837				      const char **date_string);
838
839/* write_bb_file.c */
840extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
841				      unsigned int flags,
842				      FILE *f);
843
844
845/* inline functions */
846extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
847extern errcode_t ext2fs_free_mem(void **ptr);
848extern errcode_t ext2fs_resize_mem(unsigned long old_size,
849				   unsigned long size, void **ptr);
850extern void ext2fs_mark_super_dirty(ext2_filsys fs);
851extern void ext2fs_mark_changed(ext2_filsys fs);
852extern int ext2fs_test_changed(ext2_filsys fs);
853extern void ext2fs_mark_valid(ext2_filsys fs);
854extern void ext2fs_unmark_valid(ext2_filsys fs);
855extern int ext2fs_test_valid(ext2_filsys fs);
856extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
857extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
858extern int ext2fs_test_ib_dirty(ext2_filsys fs);
859extern int ext2fs_test_bb_dirty(ext2_filsys fs);
860extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
861extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
862
863/*
864 * The actual inlined functions definitions themselves...
865 *
866 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
867 * functions at all!
868 */
869#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
870#ifdef INCLUDE_INLINE_FUNCS
871#define _INLINE_ extern
872#else
873#ifdef __GNUC__
874#define _INLINE_ extern __inline__
875#else				/* For Watcom C */
876#define _INLINE_ extern inline
877#endif
878#endif
879
880#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
881/*
882 *  Allocate memory
883 */
884_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
885{
886	*ptr = malloc(size);
887	if (!*ptr)
888		return EXT2_ET_NO_MEMORY;
889	return 0;
890}
891
892/*
893 * Free memory
894 */
895_INLINE_ errcode_t ext2fs_free_mem(void **ptr)
896{
897	free(*ptr);
898	*ptr = 0;
899	return 0;
900}
901
902/*
903 *  Resize memory
904 */
905_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
906				     unsigned long size, void **ptr)
907{
908	void *p;
909
910	p = realloc(*ptr, size);
911	if (!p)
912		return EXT2_ET_NO_MEMORY;
913	*ptr = p;
914	return 0;
915}
916#endif	/* Custom memory routines */
917
918/*
919 * Mark a filesystem superblock as dirty
920 */
921_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
922{
923	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
924}
925
926/*
927 * Mark a filesystem as changed
928 */
929_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
930{
931	fs->flags |= EXT2_FLAG_CHANGED;
932}
933
934/*
935 * Check to see if a filesystem has changed
936 */
937_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
938{
939	return (fs->flags & EXT2_FLAG_CHANGED);
940}
941
942/*
943 * Mark a filesystem as valid
944 */
945_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
946{
947	fs->flags |= EXT2_FLAG_VALID;
948}
949
950/*
951 * Mark a filesystem as NOT valid
952 */
953_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
954{
955	fs->flags &= ~EXT2_FLAG_VALID;
956}
957
958/*
959 * Check to see if a filesystem is valid
960 */
961_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
962{
963	return (fs->flags & EXT2_FLAG_VALID);
964}
965
966/*
967 * Mark the inode bitmap as dirty
968 */
969_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
970{
971	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
972}
973
974/*
975 * Mark the block bitmap as dirty
976 */
977_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
978{
979	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
980}
981
982/*
983 * Check to see if a filesystem's inode bitmap is dirty
984 */
985_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
986{
987	return (fs->flags & EXT2_FLAG_IB_DIRTY);
988}
989
990/*
991 * Check to see if a filesystem's block bitmap is dirty
992 */
993_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
994{
995	return (fs->flags & EXT2_FLAG_BB_DIRTY);
996}
997
998/*
999 * Return the group # of a block
1000 */
1001_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1002{
1003	return (blk - fs->super->s_first_data_block) /
1004		fs->super->s_blocks_per_group;
1005}
1006
1007/*
1008 * Return the group # of an inode number
1009 */
1010_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1011{
1012	return (ino - 1) / fs->super->s_inodes_per_group;
1013}
1014#undef _INLINE_
1015#endif
1016
1017#ifdef __cplusplus
1018}
1019#endif
1020
1021#endif /* _EXT2FS_EXT2FS_H */
1022