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