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