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