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