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