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