]> git.ozlabs.org Git - yaboot.git/blob - include/ext2fs/ext2fs.h
474c947681cd3a5ce84c68d10787f825a0b9fb7b
[yaboot.git] / include / ext2fs / ext2fs.h
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 <types.h>
48 #if defined(__GNUC__) && defined(__STRICT_ANSI__) && \
49         (((~0UL) == 0xffffffff) || defined(__i386__))
50 typedef __signed__ long long __s64;
51 typedef unsigned long long __u64;
52 #endif
53 #endif
54
55 typedef __u32           blk_t;
56 typedef __u32           dgrp_t;
57 typedef __u32           ext2_off_t;
58 typedef __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
79 typedef struct struct_ext2_filsys *ext2_filsys;
80
81 struct 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
96 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
97 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
98 typedef 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
111 typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
112 typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
113
114 /* old */
115 typedef struct ext2_struct_badblocks_list *badblocks_list;
116 typedef 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  */
123 struct ext2_db_entry {
124         ino_t   ino;
125         blk_t   blk;
126         int     blockcnt;
127 };
128
129 typedef 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
145 typedef 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
173 struct 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  */
291 typedef 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
353 typedef 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  */
373 struct 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 /*
439  * Feature set definitions (that might not be in ext2_fs.h
440  */
441
442 #ifndef EXT2_FEATURE_COMPAT_DIR_PREALLOC
443 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC        0x0001
444 #endif
445
446 #ifndef EXT2_FEATURE_COMPAT_IMAGIC_INODES /* for AFS, etc. */
447 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES               0x0002
448 #define EXT2_IMAGIC_FL          0x00002000
449 #endif
450
451 #ifndef EXT3_FEATURE_COMPAT_HAS_JOURNAL
452 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL         0x0004
453 #endif
454
455 #ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
456 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
457 #endif
458
459 #ifndef EXT2_FEATURE_RO_COMPAT_LARGE_FILE
460 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
461 #define i_size_high i_dir_acl
462 #endif
463
464 #ifndef EXT2_FEATURE_RO_COMPAT_BTREE_DIR
465 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
466 #endif
467
468 #ifndef EXT2_FEATURE_INCOMPAT_COMPRESSION
469 #define EXT2_FEATURE_INCOMPAT_COMPRESSION       0x0001
470 #endif
471
472 #ifndef EXT2_FEATURE_INCOMPAT_FILETYPE
473 #define EXT2_FEATURE_INCOMPAT_FILETYPE  0x0002
474 #endif
475
476 #ifndef EXT3_FEATURE_INCOMPAT_RECOVER 
477 #define EXT3_FEATURE_INCOMPAT_RECOVER   0x0004 /* Needs recovery */
478 #endif
479
480 #define EXT2_LIB_FEATURE_COMPAT_SUPP    (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
481                                          EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
482                                          EXT3_FEATURE_COMPAT_HAS_JOURNAL)
483 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP  EXT2_FEATURE_INCOMPAT_FILETYPE
484 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
485                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
486 /*
487  * function prototypes
488  */
489
490 /* alloc.c */
491 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
492                                   ext2fs_inode_bitmap map, ino_t *ret);
493 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
494                                   ext2fs_block_bitmap map, blk_t *ret);
495 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
496                                         blk_t finish, int num,
497                                         ext2fs_block_bitmap map,
498                                         blk_t *ret);
499 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
500                                     char *block_buf, blk_t *ret);
501
502 /* alloc_tables.c */
503 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
504 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
505                                              ext2fs_block_bitmap bmap);
506
507 /* badblocks.c */
508 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
509                                             int size);
510 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
511                                            blk_t blk);
512 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
513                                     blk_t blk);
514 extern errcode_t
515         ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
516                                             ext2_badblocks_iterate *ret);
517 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
518                                          blk_t *blk);
519 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
520 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
521                                        ext2_badblocks_list *dest);
522
523 /* bb_compat */
524 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
525 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
526 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
527 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
528                                               badblocks_iterate *ret);
529 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
530 extern void badblocks_list_iterate_end(badblocks_iterate iter);
531 extern void badblocks_list_free(badblocks_list bb);
532
533 /* bb_inode.c */
534 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
535                                         ext2_badblocks_list bb_list);
536
537 /* bitmaps.c */
538 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
539 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
540 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
541 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
542 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
543                                                 __u32 end,
544                                                 __u32 real_end,
545                                                 const char *descr,
546                                                 ext2fs_generic_bitmap *ret);
547 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
548                                               const char *descr,
549                                               ext2fs_block_bitmap *ret);
550 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
551                                               const char *descr,
552                                               ext2fs_inode_bitmap *ret);
553 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
554                                                ino_t end, ino_t *oend);
555 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
556                                                blk_t end, blk_t *oend);
557 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
558 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
559 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
560 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
561
562 /* block.c */
563 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
564                                       ino_t     ino,
565                                       int       flags,
566                                       char *block_buf,
567                                       int (*func)(ext2_filsys fs,
568                                                   blk_t *blocknr,
569                                                   int   blockcnt,
570                                                   void  *priv_data),
571                                       void *priv_data);
572 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
573                                 ino_t   ino,
574                                 int     flags,
575                                 char *block_buf,
576                                 int (*func)(ext2_filsys fs,
577                                             blk_t       *blocknr,
578                                             e2_blkcnt_t blockcnt,
579                                             blk_t       ref_blk,
580                                             int         ref_offset,
581                                             void        *priv_data),
582                                 void *priv_data);
583
584 /* bmap.c */
585 extern errcode_t ext2fs_bmap(ext2_filsys fs, ino_t ino,
586                              struct ext2_inode *inode, 
587                              char *block_buf, int bmap_flags,
588                              blk_t block, blk_t *phys_blk);
589
590
591 #if 0
592 /* bmove.c */
593 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
594                                     ext2fs_block_bitmap reserve,
595                                     ext2fs_block_bitmap alloc_map,
596                                     int flags);
597 #endif
598
599 /* check_desc.c */
600 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
601
602 /* closefs.c */
603 extern errcode_t ext2fs_close(ext2_filsys fs);
604 extern errcode_t ext2fs_flush(ext2_filsys fs);
605 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
606
607 /* cmp_bitmaps.c */
608 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
609                                              ext2fs_block_bitmap bm2);
610 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
611                                              ext2fs_inode_bitmap bm2);
612
613 /* dblist.c */
614
615 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs);
616 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
617 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino,
618                                       blk_t blk, int blockcnt);
619 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
620         int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
621                     void        *priv_data),
622        void *priv_data);
623 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino,
624                                       blk_t blk, int blockcnt);
625 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
626                                     ext2_dblist *dest);
627 extern int ext2fs_dblist_count(ext2_dblist dblist);
628
629 /* dblist_dir.c */
630 extern errcode_t
631         ext2fs_dblist_dir_iterate(ext2_dblist dblist,
632                                   int   flags,
633                                   char  *block_buf,
634                                   int (*func)(ino_t     dir,
635                                               int               entry,
636                                               struct ext2_dir_entry *dirent,
637                                               int       offset,
638                                               int       blocksize,
639                                               char      *buf,
640                                               void      *priv_data),
641                                   void *priv_data);
642
643 /* dirblock.c */
644 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
645                                        void *buf);
646 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
647                                         void *buf);
648
649 /* dir_iterate.c */
650 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, 
651                               ino_t dir,
652                               int flags,
653                               char *block_buf,
654                               int (*func)(struct ext2_dir_entry *dirent,
655                                           int   offset,
656                                           int   blocksize,
657                                           char  *buf,
658                                           void  *priv_data),
659                               void *priv_data);
660
661 /* dupfs.c */
662 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
663
664 /* expanddir.c */
665 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir);
666
667 /* fileio.c */
668 extern errcode_t ext2fs_file_open(ext2_filsys fs, ino_t ino,
669                                   int flags, ext2_file_t *ret);
670 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
671 extern errcode_t ext2fs_file_close(ext2_file_t file);
672 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
673                                   unsigned int wanted, unsigned int *got);
674 extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
675                                    unsigned int nbytes, unsigned int *written);
676 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
677                                    int whence, ext2_off_t *ret_pos);
678 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
679 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
680
681 /* freefs.c */
682 extern void ext2fs_free(ext2_filsys fs);
683 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
684 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
685 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
686 extern void ext2fs_free_dblist(ext2_dblist dblist);
687 extern void ext2fs_badblocks_list_free(badblocks_list bb);
688
689 /* getsize.c */
690 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
691                                         blk_t *retblocks);
692
693 /* initialize.c */
694 extern errcode_t ext2fs_initialize(const char *name, int flags,
695                                    struct ext2_super_block *param,
696                                    io_manager manager, ext2_filsys *ret_fs);
697
698 /* inode.c */
699 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
700                                   ext2_inode_scan *ret_scan);
701 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
702 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino,
703                                struct ext2_inode *inode);
704 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
705                                                    int  group);
706 extern void ext2fs_set_inode_callback
707         (ext2_inode_scan scan,
708          errcode_t (*done_group)(ext2_filsys fs,
709                                  ext2_inode_scan scan,
710                                  dgrp_t group,
711                                  void * priv_data),
712          void *done_group_data);
713 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
714                                    int clear_flags);
715 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
716                             struct ext2_inode * inode);
717 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
718                             struct ext2_inode * inode);
719 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks);
720 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino);
721
722 /* icount.c */
723 extern void ext2fs_free_icount(ext2_icount_t icount);
724 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
725                                        ext2_icount_t hint, ext2_icount_t *ret);
726 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
727                                       ext2_icount_t *ret);
728 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino,
729                                      __u16 *ret);
730 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
731                                          __u16 *ret);
732 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
733                                          __u16 *ret);
734 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
735                                      __u16 count);
736 extern ino_t ext2fs_get_icount_size(ext2_icount_t icount);
737 #if 0
738 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
739 #endif
740
741 /* ismounted.c */
742 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
743
744 /* namei.c */
745 extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name,
746                          int namelen, char *buf, ino_t *inode);
747 extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd,
748                         const char *name, ino_t *inode);
749 errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd,
750                               const char *name, ino_t *inode);
751 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd,
752                         ino_t inode, ino_t *res_inode);
753
754 /* native.c */
755 int ext2fs_native_flag(void);
756
757 /* newdir.c */
758 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino,
759                                 ino_t parent_ino, char **block);
760
761 /* mkdir.c */
762 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum,
763                               const char *name);
764
765 /* openfs.c */
766 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
767                              int block_size, io_manager manager,
768                              ext2_filsys *ret_fs);
769
770 /* get_pathname.c */
771 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino,
772                                char **name);
773
774 /* link.c */
775 errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name,
776                       ino_t ino, int flags);
777 errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name,
778                         ino_t ino, int flags);
779
780 /* read_bb.c */
781 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
782                                       ext2_badblocks_list *bb_list);
783
784 /* read_bb_file.c */
785 #if 0
786 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 
787                                      ext2_badblocks_list *bb_list,
788                                      void (*invalid)(ext2_filsys fs,
789                                                      blk_t blk));
790 #endif
791
792 /* rs_bitmap.c */
793 extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
794                                               __u32 new_real_end,
795                                               ext2fs_generic_bitmap bmap);
796 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
797                                             ext2fs_inode_bitmap bmap);
798 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
799                                             ext2fs_block_bitmap bmap);
800 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
801                                     ext2fs_generic_bitmap *dest);
802
803 /* swapfs.c */
804 extern void ext2fs_swap_super(struct ext2_super_block * super);
805 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
806 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
807                               struct ext2_inode *f, int hostorder);
808
809 /* valid_blk.c */
810 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
811
812 /* version.c */
813 extern int ext2fs_parse_version_string(const char *ver_string);
814 extern int ext2fs_get_library_version(const char **ver_string,
815                                       const char **date_string);
816
817 /* inline functions */
818 extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
819 extern errcode_t ext2fs_free_mem(void **ptr);
820 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
821                                    unsigned long size, void **ptr);
822 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
823 extern void ext2fs_mark_changed(ext2_filsys fs);
824 extern int ext2fs_test_changed(ext2_filsys fs);
825 extern void ext2fs_mark_valid(ext2_filsys fs);
826 extern void ext2fs_unmark_valid(ext2_filsys fs);
827 extern int ext2fs_test_valid(ext2_filsys fs);
828 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
829 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
830 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
831 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
832 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
833 extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino);
834
835 /*
836  * The actual inlined functions definitions themselves...
837  *
838  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
839  * functions at all!
840  */
841 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
842 #ifdef INCLUDE_INLINE_FUNCS
843 #define _INLINE_ extern
844 #else
845 #ifdef __GNUC__
846 #define _INLINE_ extern __inline__
847 #else                           /* For Watcom C */
848 #define _INLINE_ extern inline
849 #endif
850 #endif
851
852 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
853 /*
854  *  Allocate memory
855  */
856 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
857 {
858         *ptr = malloc(size);
859         if (!*ptr)
860                 return EXT2_ET_NO_MEMORY;
861         return 0;
862 }
863
864 /*
865  * Free memory
866  */
867 _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
868 {
869         free(*ptr);
870         *ptr = 0;
871         return 0;
872 }
873         
874 /*
875  *  Resize memory
876  */
877 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
878                                      unsigned long size, void **ptr)
879 {
880         void *p;
881
882         p = realloc(*ptr, size);
883         if (!p)
884                 return EXT2_ET_NO_MEMORY;
885         *ptr = p;
886         return 0;
887 }
888 #endif  /* Custom memory routines */
889
890 /*
891  * Mark a filesystem superblock as dirty
892  */
893 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
894 {
895         fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
896 }
897
898 /*
899  * Mark a filesystem as changed
900  */
901 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
902 {
903         fs->flags |= EXT2_FLAG_CHANGED;
904 }
905
906 /*
907  * Check to see if a filesystem has changed
908  */
909 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
910 {
911         return (fs->flags & EXT2_FLAG_CHANGED);
912 }
913
914 /*
915  * Mark a filesystem as valid
916  */
917 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
918 {
919         fs->flags |= EXT2_FLAG_VALID;
920 }
921
922 /*
923  * Mark a filesystem as NOT valid
924  */
925 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
926 {
927         fs->flags &= ~EXT2_FLAG_VALID;
928 }
929
930 /*
931  * Check to see if a filesystem is valid
932  */
933 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
934 {
935         return (fs->flags & EXT2_FLAG_VALID);
936 }
937
938 /*
939  * Mark the inode bitmap as dirty
940  */
941 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
942 {
943         fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
944 }
945
946 /*
947  * Mark the block bitmap as dirty
948  */
949 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
950 {
951         fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
952 }
953
954 /*
955  * Check to see if a filesystem's inode bitmap is dirty
956  */
957 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
958 {
959         return (fs->flags & EXT2_FLAG_IB_DIRTY);
960 }
961
962 /*
963  * Check to see if a filesystem's block bitmap is dirty
964  */
965 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
966 {
967         return (fs->flags & EXT2_FLAG_BB_DIRTY);
968 }
969
970 /*
971  * Return the group # of a block
972  */
973 _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
974 {
975         return (blk - fs->super->s_first_data_block) /
976                 fs->super->s_blocks_per_group;
977 }
978
979 /*
980  * Return the group # of an inode number
981  */
982 _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino)
983 {
984         return (ino - 1) / fs->super->s_inodes_per_group;
985 }
986 #undef _INLINE_
987 #endif
988
989 #endif /* _EXT2FS_EXT2FS_H */