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