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