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