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