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