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