ext2fs.h 28.7 KB
Newer Older
Theodore Ts'o's avatar
Theodore Ts'o committed
1 2 3
/*
 * ext2fs.h --- ext2fs
 * 
Theodore Ts'o's avatar
Theodore Ts'o committed
4 5 6 7 8 9
 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
 *
 * %Begin-Header%
 * This file may be redistributed under the terms of the GNU Public
 * License.
 * %End-Header%
Theodore Ts'o's avatar
Theodore Ts'o committed
10 11
 */

12 13 14
#ifndef _EXT2FS_EXT2FS_H
#define _EXT2FS_EXT2FS_H

Theodore Ts'o's avatar
Theodore Ts'o committed
15 16 17 18
#ifdef __cplusplus
extern "C" {
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
19 20 21
/*
 * Non-GNU C compilers won't necessarily understand inline
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
22
#if (!defined(__GNUC__) && !defined(__WATCOMC__))
Theodore Ts'o's avatar
Theodore Ts'o committed
23 24 25
#define NO_INLINE_FUNCS
#endif

26 27 28 29 30 31 32 33 34
/*
 * Build in support for byte-swapping filesystems if we the feature
 * has been configured or if we're being built on a CPU architecture
 * with a non-native byte order.
 */
#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
#define EXT2FS_ENABLE_SWAPFS
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
35 36 37 38 39 40 41 42 43 44
/*
 * Where the master copy of the superblock is located, and how big
 * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
 * the size of the superblock structure is not necessarily trustworthy
 * (some versions have the padding set up so that the superblock is
 * 1032 bytes long).
 */
#define SUPERBLOCK_OFFSET	1024
#define SUPERBLOCK_SIZE 	1024

Theodore Ts'o's avatar
Theodore Ts'o committed
45 46 47 48
/*
 * The last ext2fs revision level that this version of the library is
 * able to support.
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
49
#define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
Theodore Ts'o's avatar
Theodore Ts'o committed
50

Theodore Ts'o's avatar
Theodore Ts'o committed
51
#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o's avatar
Theodore Ts'o committed
52
#include <sys/types.h>
Theodore Ts'o's avatar
Theodore Ts'o committed
53 54
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
55
#include <stdlib.h>
56 57 58 59

#if EXT2_FLAT_INCLUDES
#include "e2_types.h"
#else
Theodore Ts'o's avatar
Theodore Ts'o committed
60
#include <ext2fs/ext2_types.h>
Theodore Ts'o's avatar
Theodore Ts'o committed
61
#endif /* EXT2_FLAT_INCLUDES */
Theodore Ts'o's avatar
Theodore Ts'o committed
62

Theodore Ts'o's avatar
Theodore Ts'o committed
63
typedef __u32		ext2_ino_t;
Theodore Ts'o's avatar
Theodore Ts'o committed
64
typedef __u32		blk_t;
Theodore Ts'o's avatar
Theodore Ts'o committed
65
typedef __u32		dgrp_t;
Theodore Ts'o's avatar
Theodore Ts'o committed
66
typedef __u32		ext2_off_t;
Theodore Ts'o's avatar
Theodore Ts'o committed
67
typedef __s64		e2_blkcnt_t;
Theodore Ts'o's avatar
Theodore Ts'o committed
68

Theodore Ts'o's avatar
Theodore Ts'o committed
69 70 71 72 73
#if EXT2_FLAT_INCLUDES
#include "com_err.h"
#include "ext2_io.h"
#include "ext2_err.h"
#else
Theodore Ts'o's avatar
Theodore Ts'o committed
74 75 76
#include <et/com_err.h>
#include <ext2fs/ext2_io.h>
#include <ext2fs/ext2_err.h>
Theodore Ts'o's avatar
Theodore Ts'o committed
77
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
78

79 80 81 82 83 84 85 86 87
/*
 * Portability help for Microsoft Visual C++
 */
#ifdef _MSC_VER
#define EXT2_QSORT_TYPE int __cdecl
#else
#define EXT2_QSORT_TYPE int
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
88 89
typedef struct struct_ext2_filsys *ext2_filsys;

Theodore Ts'o's avatar
Theodore Ts'o committed
90
struct ext2fs_struct_generic_bitmap {
Theodore Ts'o's avatar
Theodore Ts'o committed
91
	errcode_t	magic;
Theodore Ts'o's avatar
Theodore Ts'o committed
92 93 94 95 96 97 98
	ext2_filsys 	fs;
	__u32		start, end;
	__u32		real_end;
	char	*	description;
	char	*	bitmap;
	errcode_t	base_error_code;
	__u32		reserved[7];
Theodore Ts'o's avatar
Theodore Ts'o committed
99 100
};

Theodore Ts'o's avatar
Theodore Ts'o committed
101 102 103
#define EXT2FS_MARK_ERROR 	0
#define EXT2FS_UNMARK_ERROR 	1
#define EXT2FS_TEST_ERROR	2
Theodore Ts'o's avatar
Theodore Ts'o committed
104

Theodore Ts'o's avatar
Theodore Ts'o committed
105 106 107
typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
Theodore Ts'o's avatar
Theodore Ts'o committed
108

Theodore Ts'o's avatar
Theodore Ts'o committed
109 110 111 112 113 114 115
#ifdef EXT2_DYNAMIC_REV
#define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO(s)
#else
#define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO
#define EXT2_INODE_SIZE(s)	sizeof(struct ext2_inode)
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
/*
 * badblocks list definitions
 */

typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;

/* old */
typedef struct ext2_struct_badblocks_list *badblocks_list;
typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;

#define BADBLOCKS_FLAG_DIRTY	1

/*
 * ext2_dblist structure and abstractions (see dblist.c)
 */
struct ext2_db_entry {
Theodore Ts'o's avatar
Theodore Ts'o committed
133
	ext2_ino_t	ino;
Theodore Ts'o's avatar
Theodore Ts'o committed
134 135 136 137 138 139 140 141
	blk_t	blk;
	int	blockcnt;
};

typedef struct ext2_struct_dblist *ext2_dblist;

#define DBLIST_ABORT	1

Theodore Ts'o's avatar
Theodore Ts'o committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
/*
 * ext2_fileio definitions
 */

#define EXT2_FILE_WRITE		0x0001
#define EXT2_FILE_CREATE	0x0002

#define EXT2_FILE_MASK		0x00FF

#define EXT2_FILE_BUF_DIRTY	0x4000
#define EXT2_FILE_BUF_VALID	0x2000

typedef struct ext2_file *ext2_file_t;

#define EXT2_SEEK_SET	0
#define EXT2_SEEK_CUR	1
#define EXT2_SEEK_END	2

Theodore Ts'o's avatar
Theodore Ts'o committed
160
/*
161
 * Flags for the ext2_filsys structure and for ext2fs_open()
Theodore Ts'o's avatar
Theodore Ts'o committed
162
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
163 164 165 166 167 168
#define EXT2_FLAG_RW			0x01
#define EXT2_FLAG_CHANGED		0x02
#define EXT2_FLAG_DIRTY			0x04
#define EXT2_FLAG_VALID			0x08
#define EXT2_FLAG_IB_DIRTY		0x10
#define EXT2_FLAG_BB_DIRTY		0x20
Theodore Ts'o's avatar
Theodore Ts'o committed
169 170 171 172
#define EXT2_FLAG_SWAP_BYTES		0x40
#define EXT2_FLAG_SWAP_BYTES_READ	0x80
#define EXT2_FLAG_SWAP_BYTES_WRITE	0x100
#define EXT2_FLAG_MASTER_SB_ONLY	0x200
Theodore Ts'o's avatar
Theodore Ts'o committed
173
#define EXT2_FLAG_FORCE			0x400
174
#define EXT2_FLAG_SUPER_ONLY		0x800
175
#define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
Theodore Ts'o's avatar
Theodore Ts'o committed
176
#define EXT2_FLAG_IMAGE_FILE		0x2000
Theodore Ts'o's avatar
Theodore Ts'o committed
177

Theodore Ts'o's avatar
Theodore Ts'o committed
178 179 180 181 182 183
/*
 * Special flag in the ext2 inode i_flag field that means that this is
 * a new inode.  (So that ext2_write_inode() can clear extra fields.)
 */
#define EXT2_NEW_INODE_FL	0x80000000

184 185 186 187 188 189 190
/*
 * Flags for mkjournal
 *
 * EXT2_MKJOURNAL_V1_SUPER	Make a (deprecated) V1 journal superblock
 */
#define EXT2_MKJOURNAL_V1_SUPER	0x0000001

Theodore Ts'o's avatar
Theodore Ts'o committed
191
struct struct_ext2_filsys {
Theodore Ts'o's avatar
Theodore Ts'o committed
192
	errcode_t			magic;
Theodore Ts'o's avatar
Theodore Ts'o committed
193 194 195 196 197 198
	io_channel			io;
	int				flags;
	char *				device_name;
	struct ext2_super_block	* 	super;
	int				blocksize;
	int				fragsize;
Theodore Ts'o's avatar
Theodore Ts'o committed
199
	dgrp_t				group_desc_count;
Theodore Ts'o's avatar
Theodore Ts'o committed
200 201 202
	unsigned long			desc_blocks;
	struct ext2_group_desc *	group_desc;
	int				inode_blocks_per_group;
Theodore Ts'o's avatar
Theodore Ts'o committed
203 204
	ext2fs_inode_bitmap		inode_map;
	ext2fs_block_bitmap		block_map;
Theodore Ts'o's avatar
Theodore Ts'o committed
205 206
	errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
	errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o's avatar
Theodore Ts'o committed
207
	errcode_t (*write_bitmaps)(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
208
	errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
209
				struct ext2_inode *inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
210
	errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
211
				struct ext2_inode *inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
212 213
	badblocks_list			badblocks;
	ext2_dblist			dblist;
Theodore Ts'o's avatar
Theodore Ts'o committed
214
	__u32				stride;	/* for mke2fs */
Theodore Ts'o's avatar
Theodore Ts'o committed
215
	struct ext2_super_block *	orig_super;
Theodore Ts'o's avatar
Theodore Ts'o committed
216
	struct ext2_image_hdr *		image_header;
217
	__u32				umask;
Theodore Ts'o's avatar
Theodore Ts'o committed
218 219 220
	/*
	 * Reserved for future expansion
	 */
221
	__u32				reserved[8];
Theodore Ts'o's avatar
Theodore Ts'o committed
222 223

	/*
Theodore Ts'o's avatar
Theodore Ts'o committed
224
	 * Reserved for the use of the calling application.
Theodore Ts'o's avatar
Theodore Ts'o committed
225
	 */
Theodore Ts'o's avatar
Theodore Ts'o committed
226
	void *				priv_data;
Theodore Ts'o's avatar
Theodore Ts'o committed
227 228 229 230 231

	/*
	 * Inode cache
	 */
	struct ext2_inode_cache		*icache;
Theodore Ts'o's avatar
Theodore Ts'o committed
232 233
};

234 235 236
#if EXT2_FLAT_INCLUDES
#include "e2_bitops.h"
#else
Theodore Ts'o's avatar
Theodore Ts'o committed
237
#include <ext2fs/bitops.h>
238
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
239

Theodore Ts'o's avatar
Theodore Ts'o committed
240 241 242 243 244 245 246 247 248
/*
 * Return flags for the block iterator functions
 */
#define BLOCK_CHANGED	1
#define BLOCK_ABORT	2
#define BLOCK_ERROR	4

/*
 * Block interate flags
Theodore Ts'o's avatar
Theodore Ts'o committed
249 250 251 252 253 254 255 256 257 258 259 260
 *
 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
 * function should be called on blocks where the block number is zero.
 * This is used by ext2fs_expand_dir() to be able to add a new block
 * to an inode.  It can also be used for programs that want to be able
 * to deal with files that contain "holes".
 * 
 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
 * indirect, doubly indirect, etc. blocks should be called after all
 * of the blocks containined in the indirect blocks are processed.
 * This is useful if you are going to be deallocating blocks from an
 * inode.
Theodore Ts'o's avatar
Theodore Ts'o committed
261 262 263
 *
 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
 * called for data blocks only.
Theodore Ts'o's avatar
Theodore Ts'o committed
264 265
 *
 * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
Theodore Ts'o's avatar
Theodore Ts'o committed
266
 * ext2fs_block_iterate2 that large files won't be accepted.
Theodore Ts'o's avatar
Theodore Ts'o committed
267 268
 */
#define BLOCK_FLAG_APPEND	1
Theodore Ts'o's avatar
Theodore Ts'o committed
269
#define BLOCK_FLAG_HOLE		1
Theodore Ts'o's avatar
Theodore Ts'o committed
270
#define BLOCK_FLAG_DEPTH_TRAVERSE	2
Theodore Ts'o's avatar
Theodore Ts'o committed
271 272
#define BLOCK_FLAG_DATA_ONLY	4

Theodore Ts'o's avatar
Theodore Ts'o committed
273 274
#define BLOCK_FLAG_NO_LARGE	0x1000

Theodore Ts'o's avatar
Theodore Ts'o committed
275 276 277 278 279 280 281
/*
 * Magic "block count" return values for the block iterator function.
 */
#define BLOCK_COUNT_IND		(-1)
#define BLOCK_COUNT_DIND	(-2)
#define BLOCK_COUNT_TIND	(-3)
#define BLOCK_COUNT_TRANSLATOR	(-4)
Theodore Ts'o's avatar
Theodore Ts'o committed
282

283
#if 0
Theodore Ts'o's avatar
Theodore Ts'o committed
284 285 286 287
/*
 * Flags for ext2fs_move_blocks
 */
#define EXT2_BMOVE_GET_DBLIST	0x0001	
Theodore Ts'o's avatar
Theodore Ts'o committed
288
#define EXT2_BMOVE_DEBUG	0x0002
289
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
290

Theodore Ts'o's avatar
Theodore Ts'o committed
291 292 293 294 295 296 297 298 299 300 301 302
/*
 * Return flags for the directory iterator functions
 */
#define DIRENT_CHANGED	1
#define DIRENT_ABORT	2
#define DIRENT_ERROR	3

/*
 * Directory iterator flags
 */

#define DIRENT_FLAG_INCLUDE_EMPTY	1
303
#define DIRENT_FLAG_INCLUDE_REMOVED	2
Theodore Ts'o's avatar
Theodore Ts'o committed
304 305 306 307

#define DIRENT_DOT_FILE		1
#define DIRENT_DOT_DOT_FILE	2
#define DIRENT_OTHER_FILE	3
308
#define DIRENT_DELETED_FILE	4
Theodore Ts'o's avatar
Theodore Ts'o committed
309

Theodore Ts'o's avatar
Theodore Ts'o committed
310 311 312
/*
 * Inode scan definitions
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
313 314
typedef struct ext2_struct_inode_scan *ext2_inode_scan;

Theodore Ts'o's avatar
Theodore Ts'o committed
315 316 317 318 319 320 321
/*
 * ext2fs_scan flags
 */
#define EXT2_SF_CHK_BADBLOCKS	0x0001
#define EXT2_SF_BAD_INODE_BLK	0x0002
#define EXT2_SF_BAD_EXTRA_BYTES	0x0004
#define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
Theodore Ts'o's avatar
Theodore Ts'o committed
322

Theodore Ts'o's avatar
Theodore Ts'o committed
323 324 325 326 327
/*
 * ext2fs_check_if_mounted flags
 */
#define EXT2_MF_MOUNTED		1
#define EXT2_MF_ISROOT		2
Theodore Ts'o's avatar
Theodore Ts'o committed
328
#define EXT2_MF_READONLY	4
329
#define EXT2_MF_SWAP		8
Theodore Ts'o's avatar
Theodore Ts'o committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

/*
 * Ext2/linux mode flags.  We define them here so that we don't need
 * to depend on the OS's sys/stat.h, since we may be compiling on a
 * non-Linux system.
 */
#define LINUX_S_IFMT  00170000
#define LINUX_S_IFSOCK 0140000
#define LINUX_S_IFLNK	 0120000
#define LINUX_S_IFREG  0100000
#define LINUX_S_IFBLK  0060000
#define LINUX_S_IFDIR  0040000
#define LINUX_S_IFCHR  0020000
#define LINUX_S_IFIFO  0010000
#define LINUX_S_ISUID  0004000
#define LINUX_S_ISGID  0002000
#define LINUX_S_ISVTX  0001000

Theodore Ts'o's avatar
Theodore Ts'o committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
#define LINUX_S_IRWXU 00700
#define LINUX_S_IRUSR 00400
#define LINUX_S_IWUSR 00200
#define LINUX_S_IXUSR 00100

#define LINUX_S_IRWXG 00070
#define LINUX_S_IRGRP 00040
#define LINUX_S_IWGRP 00020
#define LINUX_S_IXGRP 00010

#define LINUX_S_IRWXO 00007
#define LINUX_S_IROTH 00004
#define LINUX_S_IWOTH 00002
#define LINUX_S_IXOTH 00001

Theodore Ts'o's avatar
Theodore Ts'o committed
363 364 365 366 367 368 369 370
#define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
#define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
#define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
#define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
#define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
#define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
#define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)

Theodore Ts'o's avatar
Theodore Ts'o committed
371 372 373 374 375 376 377
/*
 * ext2_icount_t abstraction
 */
#define EXT2_ICOUNT_OPT_INCREMENT	0x01

typedef struct ext2_icount *ext2_icount_t;

Theodore Ts'o's avatar
Theodore Ts'o committed
378 379 380 381 382
/*
 * Flags for ext2fs_bmap
 */
#define BMAP_ALLOC	1

383 384 385 386 387 388
/*
 * Flags for imager.c functions
 */
#define IMAGER_FLAG_INODEMAP	1
#define IMAGER_FLAG_SPARSEWRITE	2

Theodore Ts'o's avatar
Theodore Ts'o committed
389 390 391
/*
 * For checking structure magic numbers...
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
392

Theodore Ts'o's avatar
Theodore Ts'o committed
393 394
#define EXT2_CHECK_MAGIC(struct, code) \
	  if ((struct)->magic != (code)) return (code)
Theodore Ts'o's avatar
Theodore Ts'o committed
395 396 397


/*
Theodore Ts'o's avatar
Theodore Ts'o committed
398
 * For ext2 compression support
Theodore Ts'o's avatar
Theodore Ts'o committed
399
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
400 401 402
#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)

Theodore Ts'o's avatar
Theodore Ts'o committed
403
/*
Theodore Ts'o's avatar
Theodore Ts'o committed
404
 * Features supported by this version of the library
Theodore Ts'o's avatar
Theodore Ts'o committed
405
 */
406 407
#define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
408 409
					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
					 EXT2_FEATURE_COMPAT_EXT_ATTR)
Theodore Ts'o's avatar
Theodore Ts'o committed
410

Theodore Ts'o's avatar
Theodore Ts'o committed
411 412
/* This #ifdef is temporary until compression is fully supported */
#ifdef ENABLE_COMPRESSION
Theodore Ts'o's avatar
Theodore Ts'o committed
413 414 415 416
#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
/* If the below warning bugs you, then have
   `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
   environment at configure time. */
Theodore Ts'o's avatar
Theodore Ts'o committed
417
 #warning "Compression support is experimental"
Theodore Ts'o's avatar
Theodore Ts'o committed
418
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
419
#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
Theodore Ts'o's avatar
Theodore Ts'o committed
420
					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
421
					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'o's avatar
Theodore Ts'o committed
422
					 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o's avatar
Theodore Ts'o committed
423
#else
Theodore Ts'o's avatar
Theodore Ts'o committed
424
#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
425
					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'o's avatar
Theodore Ts'o committed
426
					 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o's avatar
Theodore Ts'o committed
427
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
428 429
#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
Theodore Ts'o's avatar
Theodore Ts'o committed
430 431 432 433 434
/*
 * function prototypes
 */

/* alloc.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
435 436
extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
Theodore Ts'o's avatar
Theodore Ts'o committed
437
extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
Theodore Ts'o's avatar
Theodore Ts'o committed
438
				  ext2fs_block_bitmap map, blk_t *ret);
Theodore Ts'o's avatar
Theodore Ts'o committed
439
extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
Theodore Ts'o's avatar
Theodore Ts'o committed
440 441
					blk_t finish, int num,
					ext2fs_block_bitmap map,
Theodore Ts'o's avatar
Theodore Ts'o committed
442
					blk_t *ret);
Theodore Ts'o's avatar
Theodore Ts'o committed
443 444
extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
				    char *block_buf, blk_t *ret);
Theodore Ts'o's avatar
Theodore Ts'o committed
445

446 447
/* alloc_stats.c */
void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
448 449
void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
			       int inuse, int isdir);
450 451
void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);

Theodore Ts'o's avatar
Theodore Ts'o committed
452 453
/* alloc_tables.c */
extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
454
extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
Theodore Ts'o's avatar
Theodore Ts'o committed
455
					     ext2fs_block_bitmap bmap);
Theodore Ts'o's avatar
Theodore Ts'o committed
456

Theodore Ts'o's avatar
Theodore Ts'o committed
457
/* badblocks.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
458 459 460 461 462 463 464 465 466 467 468 469
extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
					    int size);
extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
					   blk_t blk);
extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
				    blk_t blk);
extern errcode_t
	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
					    ext2_badblocks_iterate *ret);
extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
					 blk_t *blk);
extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
Theodore Ts'o's avatar
Theodore Ts'o committed
470 471
extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
				       ext2_badblocks_list *dest);
Theodore Ts'o's avatar
Theodore Ts'o committed
472 473
extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
				  ext2_badblocks_list bb2);
Theodore Ts'o's avatar
Theodore Ts'o committed
474 475

/* bb_compat */
Theodore Ts'o's avatar
Theodore Ts'o committed
476 477 478 479 480 481 482
extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
extern int badblocks_list_test(badblocks_list bb, blk_t blk);
extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
					      badblocks_iterate *ret);
extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
extern void badblocks_list_iterate_end(badblocks_iterate iter);
Theodore Ts'o's avatar
Theodore Ts'o committed
483
extern void badblocks_list_free(badblocks_list bb);
Theodore Ts'o's avatar
Theodore Ts'o committed
484 485 486

/* bb_inode.c */
extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
Theodore Ts'o's avatar
Theodore Ts'o committed
487
					ext2_badblocks_list bb_list);
Theodore Ts'o's avatar
Theodore Ts'o committed
488 489 490 491 492 493

/* bitmaps.c */
extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
494 495 496 497 498
extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
						__u32 end,
						__u32 real_end,
						const char *descr,
						ext2fs_generic_bitmap *ret);
Theodore Ts'o's avatar
Theodore Ts'o committed
499 500 501 502 503 504 505
extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
					      const char *descr,
					      ext2fs_block_bitmap *ret);
extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
					      const char *descr,
					      ext2fs_inode_bitmap *ret);
extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
Theodore Ts'o's avatar
Theodore Ts'o committed
506
					       ext2_ino_t end, ext2_ino_t *oend);
Theodore Ts'o's avatar
Theodore Ts'o committed
507 508 509 510
extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
					       blk_t end, blk_t *oend);
extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
Theodore Ts'o's avatar
Theodore Ts'o committed
511 512 513 514 515
extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);

/* block.c */
extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
Theodore Ts'o's avatar
Theodore Ts'o committed
516
				      ext2_ino_t	ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
517 518 519 520 521
				      int	flags,
				      char *block_buf,
				      int (*func)(ext2_filsys fs,
						  blk_t	*blocknr,
						  int	blockcnt,
Theodore Ts'o's avatar
Theodore Ts'o committed
522 523
						  void	*priv_data),
				      void *priv_data);
Theodore Ts'o's avatar
Theodore Ts'o committed
524
errcode_t ext2fs_block_iterate2(ext2_filsys fs,
Theodore Ts'o's avatar
Theodore Ts'o committed
525
				ext2_ino_t	ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
526 527 528 529
				int	flags,
				char *block_buf,
				int (*func)(ext2_filsys fs,
					    blk_t	*blocknr,
Theodore Ts'o's avatar
Theodore Ts'o committed
530
					    e2_blkcnt_t	blockcnt,
Theodore Ts'o's avatar
Theodore Ts'o committed
531 532 533 534
					    blk_t	ref_blk,
					    int		ref_offset,
					    void	*priv_data),
				void *priv_data);
Theodore Ts'o's avatar
Theodore Ts'o committed
535

Theodore Ts'o's avatar
Theodore Ts'o committed
536
/* bmap.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
537
extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
538 539 540 541 542
			     struct ext2_inode *inode, 
			     char *block_buf, int bmap_flags,
			     blk_t block, blk_t *phys_blk);


543
#if 0
Theodore Ts'o's avatar
Theodore Ts'o committed
544 545 546
/* bmove.c */
extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
				    ext2fs_block_bitmap reserve,
Theodore Ts'o's avatar
Theodore Ts'o committed
547
				    ext2fs_block_bitmap alloc_map,
Theodore Ts'o's avatar
Theodore Ts'o committed
548
				    int flags);
549
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
550

Theodore Ts'o's avatar
Theodore Ts'o committed
551 552 553
/* check_desc.c */
extern errcode_t ext2fs_check_desc(ext2_filsys fs);

Theodore Ts'o's avatar
Theodore Ts'o committed
554 555 556
/* closefs.c */
extern errcode_t ext2fs_close(ext2_filsys fs);
extern errcode_t ext2fs_flush(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
557
extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
558
extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
559

Theodore Ts'o's avatar
Theodore Ts'o committed
560 561 562 563 564 565
/* cmp_bitmaps.c */
extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
					     ext2fs_block_bitmap bm2);
extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
					     ext2fs_inode_bitmap bm2);

Theodore Ts'o's avatar
Theodore Ts'o committed
566 567
/* dblist.c */

Theodore Ts'o's avatar
Theodore Ts'o committed
568
extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
Theodore Ts'o's avatar
Theodore Ts'o committed
569
extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
Theodore Ts'o's avatar
Theodore Ts'o committed
570
extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
571 572 573
				      blk_t blk, int blockcnt);
extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
Theodore Ts'o's avatar
Theodore Ts'o committed
574 575
		    void	*priv_data),
       void *priv_data);
Theodore Ts'o's avatar
Theodore Ts'o committed
576
extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
577 578 579
				      blk_t blk, int blockcnt);
extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
				    ext2_dblist *dest);
580
extern int ext2fs_dblist_count(ext2_dblist dblist);
Theodore Ts'o's avatar
Theodore Ts'o committed
581 582 583 584 585 586

/* dblist_dir.c */
extern errcode_t
	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
				  int	flags,
				  char	*block_buf,
Theodore Ts'o's avatar
Theodore Ts'o committed
587
				  int (*func)(ext2_ino_t	dir,
Theodore Ts'o's avatar
Theodore Ts'o committed
588 589 590 591 592
					      int		entry,
					      struct ext2_dir_entry *dirent,
					      int	offset,
					      int	blocksize,
					      char	*buf,
Theodore Ts'o's avatar
Theodore Ts'o committed
593 594
					      void	*priv_data),
				  void *priv_data);
Theodore Ts'o's avatar
Theodore Ts'o committed
595 596 597 598 599 600 601

/* dirblock.c */
extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
				       void *buf);
extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
					void *buf);

Theodore Ts'o's avatar
Theodore Ts'o committed
602 603
/* dir_iterate.c */
extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, 
Theodore Ts'o's avatar
Theodore Ts'o committed
604
			      ext2_ino_t dir,
Theodore Ts'o's avatar
Theodore Ts'o committed
605 606 607 608 609 610
			      int flags,
			      char *block_buf,
			      int (*func)(struct ext2_dir_entry *dirent,
					  int	offset,
					  int	blocksize,
					  char	*buf,
Theodore Ts'o's avatar
Theodore Ts'o committed
611 612
					  void	*priv_data),
			      void *priv_data);
613 614 615 616 617 618 619 620 621 622 623 624
extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs, 
			      ext2_ino_t dir,
			      int flags,
			      char *block_buf,
			      int (*func)(ext2_ino_t	dir,
					  int	entry,
					  struct ext2_dir_entry *dirent,
					  int	offset,
					  int	blocksize,
					  char	*buf,
					  void	*priv_data),
			      void *priv_data);
Theodore Ts'o's avatar
Theodore Ts'o committed
625

Theodore Ts'o's avatar
Theodore Ts'o committed
626 627
/* dupfs.c */
extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
Theodore Ts'o's avatar
Theodore Ts'o committed
628

Theodore Ts'o's avatar
Theodore Ts'o committed
629
/* expanddir.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
630
extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
Theodore Ts'o's avatar
Theodore Ts'o committed
631

632 633 634 635
/* ext_attr.c */
void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *buf); 
Theodore Ts'o's avatar
Theodore Ts'o committed
636
/* fileio.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
637
extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
638
				  int flags, ext2_file_t *ret);
639
extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
Theodore Ts'o's avatar
Theodore Ts'o committed
640
extern errcode_t ext2fs_file_close(ext2_file_t file);
641
extern errcode_t ext2fs_file_flush(ext2_file_t file);
Theodore Ts'o's avatar
Theodore Ts'o committed
642
extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
643
				  unsigned int wanted, unsigned int *got);
644
extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
645
				   unsigned int nbytes, unsigned int *written);
Theodore Ts'o's avatar
Theodore Ts'o committed
646 647
extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
				   int whence, ext2_off_t *ret_pos);
648 649
extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
Theodore Ts'o's avatar
Theodore Ts'o committed
650

651 652 653
/* finddev.c */
extern char *ext2fs_find_block_device(dev_t device);

654 655 656
/* flushb.c */
extern errcode_t ext2fs_sync_device(int fd, int flushb);

Theodore Ts'o's avatar
Theodore Ts'o committed
657 658
/* freefs.c */
extern void ext2fs_free(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
659
extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'o's avatar
Theodore Ts'o committed
660 661
extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'o's avatar
Theodore Ts'o committed
662 663
extern void ext2fs_free_dblist(ext2_dblist dblist);
extern void ext2fs_badblocks_list_free(badblocks_list bb);
Theodore Ts'o's avatar
Theodore Ts'o committed
664 665 666 667

/* getsize.c */
extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
					blk_t *retblocks);
Theodore Ts'o's avatar
Theodore Ts'o committed
668

669 670 671 672 673 674 675 676
/* imager.c */
extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);

Theodore Ts'o's avatar
Theodore Ts'o committed
677 678 679 680 681
/* initialize.c */
extern errcode_t ext2fs_initialize(const char *name, int flags,
				   struct ext2_super_block *param,
				   io_manager manager, ext2_filsys *ret_fs);

682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
/* icount.c */
extern void ext2fs_free_icount(ext2_icount_t icount);
extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
				       ext2_icount_t hint, ext2_icount_t *ret);
extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
				      ext2_icount_t *ret);
extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
				     __u16 *ret);
extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
					 __u16 *ret);
extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
					 __u16 *ret);
extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
				     __u16 count);
extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);

Theodore Ts'o's avatar
Theodore Ts'o committed
699
/* inode.c */
700
extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
Theodore Ts'o's avatar
Theodore Ts'o committed
701 702 703
extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
				  ext2_inode_scan *ret_scan);
extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
Theodore Ts'o's avatar
Theodore Ts'o committed
704
extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
705
			       struct ext2_inode *inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
706 707 708 709 710 711 712
extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
						   int	group);
extern void ext2fs_set_inode_callback
	(ext2_inode_scan scan,
	 errcode_t (*done_group)(ext2_filsys fs,
				 ext2_inode_scan scan,
				 dgrp_t group,
Theodore Ts'o's avatar
Theodore Ts'o committed
713
				 void * priv_data),
Theodore Ts'o's avatar
Theodore Ts'o committed
714 715 716
	 void *done_group_data);
extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
				   int clear_flags);
Theodore Ts'o's avatar
Theodore Ts'o committed
717
extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
718
			    struct ext2_inode * inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
719
extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
720
			    struct ext2_inode * inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
721 722
extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o's avatar
Theodore Ts'o committed
723

724 725 726
/* inode_io.c */
extern io_manager inode_io_manager;
	
Theodore Ts'o's avatar
Theodore Ts'o committed
727 728
/* ismounted.c */
extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
729 730
extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
					  char *mtpt, int mtlen);
Theodore Ts'o's avatar
Theodore Ts'o committed
731

Theodore Ts'o's avatar
Theodore Ts'o committed
732
/* namei.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
733 734 735 736 737 738 739 740
extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
			 int namelen, char *buf, ext2_ino_t *inode);
extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
			const char *name, ext2_ino_t *inode);
errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
			      const char *name, ext2_ino_t *inode);
extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
			ext2_ino_t inode, ext2_ino_t *res_inode);
Theodore Ts'o's avatar
Theodore Ts'o committed
741 742 743

/* native.c */
int ext2fs_native_flag(void);
Theodore Ts'o's avatar
Theodore Ts'o committed
744 745

/* newdir.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
746 747
extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
				ext2_ino_t parent_ino, char **block);
Theodore Ts'o's avatar
Theodore Ts'o committed
748 749

/* mkdir.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
750
extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
Theodore Ts'o's avatar
Theodore Ts'o committed
751 752
			      const char *name);

753
/* mkjournal.c */
754 755 756 757 758
extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
						  __u32 size, int flags,
						  char  **ret_jsb);
extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
					   ext2_filsys journal_dev);
759 760
extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
					  int flags);
761

Theodore Ts'o's avatar
Theodore Ts'o committed
762 763 764 765 766 767
/* openfs.c */
extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
			     int block_size, io_manager manager,
			     ext2_filsys *ret_fs);

/* get_pathname.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
768
extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
Theodore Ts'o's avatar
Theodore Ts'o committed
769 770 771
			       char **name);

/* link.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
772 773 774 775
errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
		      ext2_ino_t ino, int flags);
errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
			ext2_ino_t ino, int flags);
Theodore Ts'o's avatar
Theodore Ts'o committed
776 777

/* read_bb.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
778 779
extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
				      ext2_badblocks_list *bb_list);
Theodore Ts'o's avatar
Theodore Ts'o committed
780 781

/* read_bb_file.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
782 783 784 785 786 787 788
extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, 
				      ext2_badblocks_list *bb_list,
				      void *private,
				      void (*invalid)(ext2_filsys fs,
						      blk_t blk,
						      char *badstr,
						      void *private));
Theodore Ts'o's avatar
Theodore Ts'o committed
789
extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 
Theodore Ts'o's avatar
Theodore Ts'o committed
790
				     ext2_badblocks_list *bb_list,
Theodore Ts'o's avatar
Theodore Ts'o committed
791 792 793
				     void (*invalid)(ext2_filsys fs,
						     blk_t blk));

Theodore Ts'o's avatar
Theodore Ts'o committed
794 795 796 797 798 799 800 801
/* rs_bitmap.c */
extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
					      __u32 new_real_end,
					      ext2fs_generic_bitmap bmap);
extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
					    ext2fs_inode_bitmap bmap);
extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
					    ext2fs_block_bitmap bmap);
Theodore Ts'o's avatar
Theodore Ts'o committed
802 803
extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
				    ext2fs_generic_bitmap *dest);
Theodore Ts'o's avatar
Theodore Ts'o committed
804

Theodore Ts'o's avatar
Theodore Ts'o committed
805 806 807
/* swapfs.c */
extern void ext2fs_swap_super(struct ext2_super_block * super);
extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
Theodore Ts'o's avatar
Theodore Ts'o committed
808 809 810
extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
			      struct ext2_inode *f, int hostorder);

Theodore Ts'o's avatar
Theodore Ts'o committed
811
/* valid_blk.c */
Theodore Ts'o's avatar
Theodore Ts'o committed
812 813 814 815 816 817
extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);

/* version.c */
extern int ext2fs_parse_version_string(const char *ver_string);
extern int ext2fs_get_library_version(const char **ver_string,
				      const char **date_string);
Theodore Ts'o's avatar
Theodore Ts'o committed
818

Theodore Ts'o's avatar
Theodore Ts'o committed
819 820 821 822 823 824
/* write_bb_file.c */
extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
				      unsigned int flags,
				      FILE *f);


Theodore Ts'o's avatar
Theodore Ts'o committed
825
/* inline functions */
826
extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
Theodore Ts'o's avatar
Theodore Ts'o committed
827
extern errcode_t ext2fs_free_mem(void **ptr);
Theodore Ts'o's avatar
Theodore Ts'o committed
828 829
extern errcode_t ext2fs_resize_mem(unsigned long old_size,
				   unsigned long size, void **ptr);
Theodore Ts'o's avatar
Theodore Ts'o committed
830 831 832 833 834 835 836 837 838 839 840
extern void ext2fs_mark_super_dirty(ext2_filsys fs);
extern void ext2fs_mark_changed(ext2_filsys fs);
extern int ext2fs_test_changed(ext2_filsys fs);
extern void ext2fs_mark_valid(ext2_filsys fs);
extern void ext2fs_unmark_valid(ext2_filsys fs);
extern int ext2fs_test_valid(ext2_filsys fs);
extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
extern int ext2fs_test_ib_dirty(ext2_filsys fs);
extern int ext2fs_test_bb_dirty(ext2_filsys fs);
extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
Theodore Ts'o's avatar
Theodore Ts'o committed
841
extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o's avatar
Theodore Ts'o committed
842 843 844 845 846 847 848 849 850 851 852

/*
 * The actual inlined functions definitions themselves...
 *
 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
 * functions at all!
 */
#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
#ifdef INCLUDE_INLINE_FUNCS
#define _INLINE_ extern
#else
Theodore Ts'o's avatar
Theodore Ts'o committed
853
#ifdef __GNUC__
Theodore Ts'o's avatar
Theodore Ts'o committed
854
#define _INLINE_ extern __inline__
Theodore Ts'o's avatar
Theodore Ts'o committed
855 856 857
#else				/* For Watcom C */
#define _INLINE_ extern inline
#endif
Theodore Ts'o's avatar
Theodore Ts'o committed
858 859
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
860 861 862 863
#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
/*
 *  Allocate memory
 */
864
_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
Theodore Ts'o's avatar
Theodore Ts'o committed
865 866 867
{
	*ptr = malloc(size);
	if (!*ptr)
868
		return EXT2_ET_NO_MEMORY;
Theodore Ts'o's avatar
Theodore Ts'o committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
	return 0;
}

/*
 * Free memory
 */
_INLINE_ errcode_t ext2fs_free_mem(void **ptr)
{
	free(*ptr);
	*ptr = 0;
	return 0;
}
	
/*
 *  Resize memory
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
885 886
_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
				     unsigned long size, void **ptr)
Theodore Ts'o's avatar
Theodore Ts'o committed
887 888 889 890 891
{
	void *p;

	p = realloc(*ptr, size);
	if (!p)
892
		return EXT2_ET_NO_MEMORY;
Theodore Ts'o's avatar
Theodore Ts'o committed
893 894 895 896 897
	*ptr = p;
	return 0;
}
#endif	/* Custom memory routines */

Theodore Ts'o's avatar
Theodore Ts'o committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
/*
 * Mark a filesystem superblock as dirty
 */
_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
{
	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
}

/*
 * Mark a filesystem as changed
 */
_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
{
	fs->flags |= EXT2_FLAG_CHANGED;
}

/*
 * Check to see if a filesystem has changed
 */
_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
{
	return (fs->flags & EXT2_FLAG_CHANGED);
}

/*
 * Mark a filesystem as valid
 */
_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
{
	fs->flags |= EXT2_FLAG_VALID;
}

/*
 * Mark a filesystem as NOT valid
 */
_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
{
	fs->flags &= ~EXT2_FLAG_VALID;
}

/*
 * Check to see if a filesystem is valid
 */
_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
{
	return (fs->flags & EXT2_FLAG_VALID);
}

/*
 * Mark the inode bitmap as dirty
 */
_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
{
	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
}

/*
 * Mark the block bitmap as dirty
 */
_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
{
	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
}

/*
 * Check to see if a filesystem's inode bitmap is dirty
 */
_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
{
	return (fs->flags & EXT2_FLAG_IB_DIRTY);
}

/*
 * Check to see if a filesystem's block bitmap is dirty
 */
_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
{
	return (fs->flags & EXT2_FLAG_BB_DIRTY);
}

/*
 * Return the group # of a block
 */
_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
{
	return (blk - fs->super->s_first_data_block) /
		fs->super->s_blocks_per_group;
}

/*
 * Return the group # of an inode number
 */
Theodore Ts'o's avatar
Theodore Ts'o committed
990
_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
Theodore Ts'o's avatar
Theodore Ts'o committed
991 992 993 994 995 996
{
	return (ino - 1) / fs->super->s_inodes_per_group;
}
#undef _INLINE_
#endif

Theodore Ts'o's avatar
Theodore Ts'o committed
997 998 999 1000
#ifdef __cplusplus
}
#endif

1001
#endif /* _EXT2FS_EXT2FS_H */