blob: 762b7eb8a8adda93627e6c0e7325a765ab6bb21e [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * ext2fs.h --- ext2fs
3 *
Theodore Ts'o19c78dc1997-04-29 16:17:09 +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%
Theodore Ts'o3839e651997-04-26 13:21:57 +000010 */
11
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +000012#ifndef _EXT2FS_EXT2FS_H
13#define _EXT2FS_EXT2FS_H
14
Theodore Ts'ofa7ef712000-05-19 02:11:41 +000015#ifdef __cplusplus
16extern "C" {
17#endif
18
Theodore Ts'o3839e651997-04-26 13:21:57 +000019/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000020 * Non-GNU C compilers won't necessarily understand inline
21 */
Theodore Ts'o76f875d1998-04-27 01:41:13 +000022#if (!defined(__GNUC__) && !defined(__WATCOMC__))
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000023#define NO_INLINE_FUNCS
24#endif
25
26/*
Theodore Ts'o3839e651997-04-26 13:21:57 +000027 * Where the master copy of the superblock is located, and how big
28 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
29 * the size of the superblock structure is not necessarily trustworthy
30 * (some versions have the padding set up so that the superblock is
31 * 1032 bytes long).
32 */
33#define SUPERBLOCK_OFFSET 1024
34#define SUPERBLOCK_SIZE 1024
35
Theodore Ts'of3db3561997-04-26 13:34:30 +000036/*
37 * The last ext2fs revision level that this version of the library is
38 * able to support.
39 */
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000040#define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
Theodore Ts'of3db3561997-04-26 13:34:30 +000041
Theodore Ts'od40259f1997-10-20 00:44:26 +000042#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000043#include <sys/types.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000044#endif
45
Theodore Ts'o5be8dc21997-12-01 18:24:10 +000046#include <stdlib.h>
Theodore Ts'o5953b9d1998-02-01 13:23:02 +000047
48#if EXT2_FLAT_INCLUDES
49#include "e2_types.h"
50#else
Theodore Ts'o76f875d1998-04-27 01:41:13 +000051#include <asm/types.h>
Theodore Ts'oe589f672000-04-03 13:45:40 +000052#if !defined(__GNUC__) || defined(__STRICT_ANSI__) /* asm/types.h already defines __s64 and __u64 otherwise */
53#if SIZEOF_LONG == 8
54typedef __signed__ long __s64;
55typedef unsigned long __u64;
56#elif SIZEOF_LONG_LONG == 8 || \
57 defined(__GNUC__) && (((~0UL) == 0xffffffff) || defined(__i386__))
Theodore Ts'o4a31c481998-03-30 01:27:25 +000058typedef __signed__ long long __s64;
59typedef unsigned long long __u64;
Theodore Ts'oe589f672000-04-03 13:45:40 +000060#endif /* SIZEOF_LONG == 8 */
Theodore Ts'o4a31c481998-03-30 01:27:25 +000061#endif
Theodore Ts'oe589f672000-04-03 13:45:40 +000062#endif /* EXT2_FLAT_INCLUDES */
Theodore Ts'o50e1e101997-04-26 13:58:21 +000063
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000064typedef __u32 ext2_ino_t;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000065typedef __u32 blk_t;
Theodore Ts'o2eb374c1998-09-03 01:22:57 +000066typedef __u32 dgrp_t;
Theodore Ts'o30fab291997-10-25 22:37:42 +000067typedef __u32 ext2_off_t;
Theodore Ts'o03673db1998-06-10 20:39:43 +000068typedef __s64 e2_blkcnt_t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000069
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000070#if EXT2_FLAT_INCLUDES
71#include "com_err.h"
72#include "ext2_io.h"
73#include "ext2_err.h"
74#else
Theodore Ts'o7c2d2562001-05-21 02:54:21 +000075#include <et/com_err.h>
76#include <ext2fs/ext2_io.h>
77#include <ext2fs/ext2_err.h>
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000078#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000079
Theodore Ts'o4c77fe51998-04-30 17:35:59 +000080/*
81 * Portability help for Microsoft Visual C++
82 */
83#ifdef _MSC_VER
84#define EXT2_QSORT_TYPE int __cdecl
85#else
86#define EXT2_QSORT_TYPE int
87#endif
88
Theodore Ts'of3db3561997-04-26 13:34:30 +000089typedef struct struct_ext2_filsys *ext2_filsys;
90
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000091struct ext2fs_struct_generic_bitmap {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000092 errcode_t magic;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000093 ext2_filsys fs;
94 __u32 start, end;
95 __u32 real_end;
96 char * description;
97 char * bitmap;
98 errcode_t base_error_code;
99 __u32 reserved[7];
Theodore Ts'of3db3561997-04-26 13:34:30 +0000100};
101
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000102#define EXT2FS_MARK_ERROR 0
103#define EXT2FS_UNMARK_ERROR 1
104#define EXT2FS_TEST_ERROR 2
Theodore Ts'of3db3561997-04-26 13:34:30 +0000105
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000106typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000107typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000108typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000109
Theodore Ts'o7f88b041997-04-26 14:48:50 +0000110#ifdef EXT2_DYNAMIC_REV
111#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
112#else
113#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
114#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
115#endif
116
Theodore Ts'o3839e651997-04-26 13:21:57 +0000117/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000118 * badblocks list definitions
119 */
120
121typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
122typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
123
124/* old */
125typedef struct ext2_struct_badblocks_list *badblocks_list;
126typedef struct ext2_struct_badblocks_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 {
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000134 ext2_ino_t ino;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000135 blk_t blk;
136 int blockcnt;
137};
138
139typedef struct ext2_struct_dblist *ext2_dblist;
140
141#define DBLIST_ABORT 1
142
143/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000144 * 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/*
Theodore Ts'oa1128472001-01-16 06:56:14 +0000162 * Flags for the ext2_filsys structure and for ext2fs_open()
Theodore Ts'o3839e651997-04-26 13:21:57 +0000163 */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000164#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
Theodore Ts'o5c576471997-04-29 15:29:49 +0000170#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
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000174#define EXT2_FLAG_FORCE 0x400
Theodore Ts'o43ec8732001-01-03 14:56:46 +0000175#define EXT2_FLAG_SUPER_ONLY 0x800
Theodore Ts'oa1128472001-01-16 06:56:14 +0000176#define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
Theodore Ts'oa78926e2001-05-03 04:02:29 +0000177#define EXT2_FLAG_IMAGE_FILE 0x2000
Theodore Ts'o3839e651997-04-26 13:21:57 +0000178
Theodore Ts'o7f88b041997-04-26 14:48:50 +0000179/*
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
Theodore Ts'o4e246702000-12-09 14:39:16 +0000185/*
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
Theodore Ts'o3839e651997-04-26 13:21:57 +0000192struct struct_ext2_filsys {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +0000193 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000194 io_channel io;
195 int flags;
196 char * device_name;
197 struct ext2_super_block * super;
198 int blocksize;
199 int fragsize;
Theodore Ts'o2eb374c1998-09-03 01:22:57 +0000200 dgrp_t group_desc_count;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000201 unsigned long desc_blocks;
202 struct ext2_group_desc * group_desc;
203 int inode_blocks_per_group;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000204 ext2fs_inode_bitmap inode_map;
205 ext2fs_block_bitmap block_map;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000206 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);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000208 errcode_t (*write_bitmaps)(ext2_filsys fs);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000209 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000210 struct ext2_inode *inode);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000211 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000212 struct ext2_inode *inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000213 badblocks_list badblocks;
214 ext2_dblist dblist;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000215 __u32 stride; /* for mke2fs */
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000216 struct ext2_super_block * orig_super;
Theodore Ts'oa78926e2001-05-03 04:02:29 +0000217 struct ext2_image_hdr * image_header;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000218 /*
219 * Reserved for future expansion
220 */
Theodore Ts'oa78926e2001-05-03 04:02:29 +0000221 __u32 reserved[9];
Theodore Ts'o3839e651997-04-26 13:21:57 +0000222
223 /*
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000224 * Reserved for the use of the calling application.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000225 */
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000226 void * priv_data;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000227
228 /*
229 * Inode cache
230 */
231 struct ext2_inode_cache *icache;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000232};
233
Theodore Ts'o5953b9d1998-02-01 13:23:02 +0000234#if EXT2_FLAT_INCLUDES
235#include "e2_bitops.h"
236#else
Theodore Ts'o7c2d2562001-05-21 02:54:21 +0000237#include <ext2fs/bitops.h>
Theodore Ts'o5953b9d1998-02-01 13:23:02 +0000238#endif
Theodore Ts'od40259f1997-10-20 00:44:26 +0000239
Theodore Ts'o3839e651997-04-26 13:21:57 +0000240/*
241 * Return flags for the block iterator functions
242 */
243#define BLOCK_CHANGED 1
244#define BLOCK_ABORT 2
245#define BLOCK_ERROR 4
246
247/*
248 * Block interate flags
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000249 *
250 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
251 * function should be called on blocks where the block number is zero.
252 * This is used by ext2fs_expand_dir() to be able to add a new block
253 * to an inode. It can also be used for programs that want to be able
254 * to deal with files that contain "holes".
255 *
256 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
257 * indirect, doubly indirect, etc. blocks should be called after all
258 * of the blocks containined in the indirect blocks are processed.
259 * This is useful if you are going to be deallocating blocks from an
260 * inode.
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000261 *
262 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
263 * called for data blocks only.
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000264 *
265 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
Theodore Ts'o36a43d61998-03-24 16:17:51 +0000266 * ext2fs_block_iterate2 that large files won't be accepted.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000267 */
268#define BLOCK_FLAG_APPEND 1
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000269#define BLOCK_FLAG_HOLE 1
Theodore Ts'o3839e651997-04-26 13:21:57 +0000270#define BLOCK_FLAG_DEPTH_TRAVERSE 2
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000271#define BLOCK_FLAG_DATA_ONLY 4
272
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000273#define BLOCK_FLAG_NO_LARGE 0x1000
274
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000275/*
276 * Magic "block count" return values for the block iterator function.
277 */
278#define BLOCK_COUNT_IND (-1)
279#define BLOCK_COUNT_DIND (-2)
280#define BLOCK_COUNT_TIND (-3)
281#define BLOCK_COUNT_TRANSLATOR (-4)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000282
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000283#if 0
Theodore Ts'o3839e651997-04-26 13:21:57 +0000284/*
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000285 * Flags for ext2fs_move_blocks
286 */
287#define EXT2_BMOVE_GET_DBLIST 0x0001
Theodore Ts'o36f21431997-06-14 07:25:40 +0000288#define EXT2_BMOVE_DEBUG 0x0002
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000289#endif
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000290
291/*
Theodore Ts'o3839e651997-04-26 13:21:57 +0000292 * Return flags for the directory iterator functions
293 */
294#define DIRENT_CHANGED 1
295#define DIRENT_ABORT 2
296#define DIRENT_ERROR 3
297
298/*
299 * Directory iterator flags
300 */
301
302#define DIRENT_FLAG_INCLUDE_EMPTY 1
303
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000304
305#define DIRENT_DOT_FILE 1
306#define DIRENT_DOT_DOT_FILE 2
307#define DIRENT_OTHER_FILE 3
308
Theodore Ts'o3839e651997-04-26 13:21:57 +0000309/*
310 * Inode scan definitions
311 */
Theodore Ts'of3db3561997-04-26 13:34:30 +0000312typedef struct ext2_struct_inode_scan *ext2_inode_scan;
313
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000314/*
315 * ext2fs_scan flags
316 */
317#define EXT2_SF_CHK_BADBLOCKS 0x0001
318#define EXT2_SF_BAD_INODE_BLK 0x0002
319#define EXT2_SF_BAD_EXTRA_BYTES 0x0004
320#define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
Theodore Ts'o3839e651997-04-26 13:21:57 +0000321
Theodore Ts'of3db3561997-04-26 13:34:30 +0000322/*
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000323 * ext2fs_check_if_mounted flags
324 */
325#define EXT2_MF_MOUNTED 1
326#define EXT2_MF_ISROOT 2
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000327#define EXT2_MF_READONLY 4
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000328
329/*
330 * Ext2/linux mode flags. We define them here so that we don't need
331 * to depend on the OS's sys/stat.h, since we may be compiling on a
332 * non-Linux system.
333 */
334#define LINUX_S_IFMT 00170000
335#define LINUX_S_IFSOCK 0140000
336#define LINUX_S_IFLNK 0120000
337#define LINUX_S_IFREG 0100000
338#define LINUX_S_IFBLK 0060000
339#define LINUX_S_IFDIR 0040000
340#define LINUX_S_IFCHR 0020000
341#define LINUX_S_IFIFO 0010000
342#define LINUX_S_ISUID 0004000
343#define LINUX_S_ISGID 0002000
344#define LINUX_S_ISVTX 0001000
345
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000346#define LINUX_S_IRWXU 00700
347#define LINUX_S_IRUSR 00400
348#define LINUX_S_IWUSR 00200
349#define LINUX_S_IXUSR 00100
350
351#define LINUX_S_IRWXG 00070
352#define LINUX_S_IRGRP 00040
353#define LINUX_S_IWGRP 00020
354#define LINUX_S_IXGRP 00010
355
356#define LINUX_S_IRWXO 00007
357#define LINUX_S_IROTH 00004
358#define LINUX_S_IWOTH 00002
359#define LINUX_S_IXOTH 00001
360
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000361#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
362#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
363#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
364#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
365#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
366#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
367#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
368
369/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000370 * ext2_icount_t abstraction
371 */
372#define EXT2_ICOUNT_OPT_INCREMENT 0x01
373
374typedef struct ext2_icount *ext2_icount_t;
375
376/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000377 * Flags for ext2fs_bmap
378 */
379#define BMAP_ALLOC 1
380
381/*
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000382 * Flags for imager.c functions
383 */
384#define IMAGER_FLAG_INODEMAP 1
385#define IMAGER_FLAG_SPARSEWRITE 2
386
387/*
Theodore Ts'of3db3561997-04-26 13:34:30 +0000388 * For checking structure magic numbers...
389 */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000390
Theodore Ts'of3db3561997-04-26 13:34:30 +0000391#define EXT2_CHECK_MAGIC(struct, code) \
392 if ((struct)->magic != (code)) return (code)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000393
394
395/*
Theodore Ts'oe5b38a52001-01-01 16:17:12 +0000396 * For ext2 compression support
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000397 */
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000398#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
399#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
400
Theodore Ts'o521e3681997-04-29 17:48:10 +0000401/*
Theodore Ts'o426d7342001-01-13 01:29:05 +0000402 * Features supported by this version of the library
Theodore Ts'o521e3681997-04-29 17:48:10 +0000403 */
Theodore Ts'o3a5f8ea1999-09-14 20:21:26 +0000404#define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
405 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
406 EXT3_FEATURE_COMPAT_HAS_JOURNAL)
Theodore Ts'o2fe1efe2000-12-31 13:39:17 +0000407
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000408/* This #ifdef is temporary until compression is fully supported */
409#ifdef ENABLE_COMPRESSION
Theodore Ts'oe589f672000-04-03 13:45:40 +0000410#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
411/* If the below warning bugs you, then have
412 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
413 environment at configure time. */
Theodore Ts'ocdaf1fa2001-01-05 22:23:22 +0000414 #warning "Compression support is experimental"
Theodore Ts'oe589f672000-04-03 13:45:40 +0000415#endif
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000416#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000417 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
Theodore Ts'oa1128472001-01-16 06:56:14 +0000418 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000419 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000420#else
Theodore Ts'oab146762000-07-07 04:37:35 +0000421#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
Theodore Ts'oa1128472001-01-16 06:56:14 +0000422 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000423 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000424#endif
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000425#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
426 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000427/*
428 * function prototypes
429 */
430
431/* alloc.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000432extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
433 ext2fs_inode_bitmap map, ext2_ino_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000434extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000435 ext2fs_block_bitmap map, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000436extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000437 blk_t finish, int num,
438 ext2fs_block_bitmap map,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000439 blk_t *ret);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000440extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
441 char *block_buf, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000442
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000443/* alloc_tables.c */
444extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
Theodore Ts'o2eb374c1998-09-03 01:22:57 +0000445extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000446 ext2fs_block_bitmap bmap);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000447
Theodore Ts'o3839e651997-04-26 13:21:57 +0000448/* badblocks.c */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000449extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
450 int size);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000451extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
452 blk_t blk);
453extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
454 blk_t blk);
455extern errcode_t
456 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
457 ext2_badblocks_iterate *ret);
458extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
459 blk_t *blk);
460extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000461extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
462 ext2_badblocks_list *dest);
Theodore Ts'o57dca852000-07-04 19:20:25 +0000463extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
464 ext2_badblocks_list bb2);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000465
466/* bb_compat */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000467extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000468extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
469extern int badblocks_list_test(badblocks_list bb, blk_t blk);
470extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
471 badblocks_iterate *ret);
472extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
473extern void badblocks_list_iterate_end(badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000474extern void badblocks_list_free(badblocks_list bb);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000475
476/* bb_inode.c */
477extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000478 ext2_badblocks_list bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000479
480/* bitmaps.c */
481extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
482extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
483extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
484extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000485extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
486 __u32 end,
487 __u32 real_end,
488 const char *descr,
489 ext2fs_generic_bitmap *ret);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000490extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
491 const char *descr,
492 ext2fs_block_bitmap *ret);
493extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
494 const char *descr,
495 ext2fs_inode_bitmap *ret);
496extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000497 ext2_ino_t end, ext2_ino_t *oend);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000498extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
499 blk_t end, blk_t *oend);
500extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
501extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000502extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
503extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
504
505/* block.c */
506extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000507 ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000508 int flags,
509 char *block_buf,
510 int (*func)(ext2_filsys fs,
511 blk_t *blocknr,
512 int blockcnt,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000513 void *priv_data),
514 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000515errcode_t ext2fs_block_iterate2(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000516 ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000517 int flags,
518 char *block_buf,
519 int (*func)(ext2_filsys fs,
520 blk_t *blocknr,
Theodore Ts'o03673db1998-06-10 20:39:43 +0000521 e2_blkcnt_t blockcnt,
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000522 blk_t ref_blk,
523 int ref_offset,
524 void *priv_data),
525 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000526
Theodore Ts'o30fab291997-10-25 22:37:42 +0000527/* bmap.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000528extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o30fab291997-10-25 22:37:42 +0000529 struct ext2_inode *inode,
530 char *block_buf, int bmap_flags,
531 blk_t block, blk_t *phys_blk);
532
533
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000534#if 0
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000535/* bmove.c */
536extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
537 ext2fs_block_bitmap reserve,
Theodore Ts'o9941fb71997-06-11 22:27:41 +0000538 ext2fs_block_bitmap alloc_map,
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000539 int flags);
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000540#endif
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000541
Theodore Ts'of3db3561997-04-26 13:34:30 +0000542/* check_desc.c */
543extern errcode_t ext2fs_check_desc(ext2_filsys fs);
544
Theodore Ts'o3839e651997-04-26 13:21:57 +0000545/* closefs.c */
546extern errcode_t ext2fs_close(ext2_filsys fs);
547extern errcode_t ext2fs_flush(ext2_filsys fs);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000548extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
Theodore Ts'oa917d1c2000-12-13 18:36:23 +0000549extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000550
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000551/* cmp_bitmaps.c */
552extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
553 ext2fs_block_bitmap bm2);
554extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
555 ext2fs_inode_bitmap bm2);
556
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000557/* dblist.c */
558
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000559extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000560extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000561extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000562 blk_t blk, int blockcnt);
563extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
564 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000565 void *priv_data),
566 void *priv_data);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000567extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000568 blk_t blk, int blockcnt);
569extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
570 ext2_dblist *dest);
Theodore Ts'o549860c1997-06-17 03:55:00 +0000571extern int ext2fs_dblist_count(ext2_dblist dblist);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000572
573/* dblist_dir.c */
574extern errcode_t
575 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
576 int flags,
577 char *block_buf,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000578 int (*func)(ext2_ino_t dir,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000579 int entry,
580 struct ext2_dir_entry *dirent,
581 int offset,
582 int blocksize,
583 char *buf,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000584 void *priv_data),
585 void *priv_data);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000586
587/* dirblock.c */
588extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
589 void *buf);
590extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
591 void *buf);
592
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000593/* dir_iterate.c */
594extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000595 ext2_ino_t dir,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000596 int flags,
597 char *block_buf,
598 int (*func)(struct ext2_dir_entry *dirent,
599 int offset,
600 int blocksize,
601 char *buf,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000602 void *priv_data),
603 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000604
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000605/* dupfs.c */
606extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000607
Theodore Ts'o3839e651997-04-26 13:21:57 +0000608/* expanddir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000609extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000610
Theodore Ts'o30fab291997-10-25 22:37:42 +0000611/* fileio.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000612extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o30fab291997-10-25 22:37:42 +0000613 int flags, ext2_file_t *ret);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000614extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000615extern errcode_t ext2fs_file_close(ext2_file_t file);
616extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000617 unsigned int wanted, unsigned int *got);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000618extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000619 unsigned int nbytes, unsigned int *written);
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000620extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
621 int whence, ext2_off_t *ret_pos);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000622extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
623extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000624
Theodore Ts'ode23aa12000-08-19 17:00:47 +0000625/* finddev.c */
626extern char *ext2fs_find_block_device(dev_t device);
627
Theodore Ts'o4d0f3e12001-01-11 15:48:50 +0000628/* flushb.c */
629extern errcode_t ext2fs_sync_device(int fd, int flushb);
630
Theodore Ts'o3839e651997-04-26 13:21:57 +0000631/* freefs.c */
632extern void ext2fs_free(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000633extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000634extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
635extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000636extern void ext2fs_free_dblist(ext2_dblist dblist);
637extern void ext2fs_badblocks_list_free(badblocks_list bb);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000638
639/* getsize.c */
640extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
641 blk_t *retblocks);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000642
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000643/* imager.c */
644extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
645extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
646extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
647extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
648extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
649extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
650
Theodore Ts'o3839e651997-04-26 13:21:57 +0000651/* initialize.c */
652extern errcode_t ext2fs_initialize(const char *name, int flags,
653 struct ext2_super_block *param,
654 io_manager manager, ext2_filsys *ret_fs);
655
656/* inode.c */
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000657extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000658extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
659 ext2_inode_scan *ret_scan);
660extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000661extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000662 struct ext2_inode *inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000663extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
664 int group);
665extern void ext2fs_set_inode_callback
666 (ext2_inode_scan scan,
667 errcode_t (*done_group)(ext2_filsys fs,
668 ext2_inode_scan scan,
669 dgrp_t group,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000670 void * priv_data),
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000671 void *done_group_data);
672extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
673 int clear_flags);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000674extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000675 struct ext2_inode * inode);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000676extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000677 struct ext2_inode * inode);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000678extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
679extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000680
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000681/* icount.c */
682extern void ext2fs_free_icount(ext2_icount_t icount);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000683extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
684 ext2_icount_t hint, ext2_icount_t *ret);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000685extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
686 ext2_icount_t *ret);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000687extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000688 __u16 *ret);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000689extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000690 __u16 *ret);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000691extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000692 __u16 *ret);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000693extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000694 __u16 count);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000695extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000696errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000697
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000698/* ismounted.c */
699extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
Theodore Ts'o43ec8732001-01-03 14:56:46 +0000700extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
701 char *mtpt, int mtlen);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000702
Theodore Ts'o3839e651997-04-26 13:21:57 +0000703/* namei.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000704extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
705 int namelen, char *buf, ext2_ino_t *inode);
706extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
707 const char *name, ext2_ino_t *inode);
708errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
709 const char *name, ext2_ino_t *inode);
710extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
711 ext2_ino_t inode, ext2_ino_t *res_inode);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000712
713/* native.c */
714int ext2fs_native_flag(void);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000715
716/* newdir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000717extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
718 ext2_ino_t parent_ino, char **block);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000719
720/* mkdir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000721extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000722 const char *name);
723
Theodore Ts'od3cd93c2000-10-24 18:33:16 +0000724/* mkjournal.c */
Theodore Ts'oa1128472001-01-16 06:56:14 +0000725extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
726 __u32 size, int flags,
727 char **ret_jsb);
728extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
729 ext2_filsys journal_dev);
Theodore Ts'o31a17b32001-01-03 13:04:12 +0000730extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
731 int flags);
Theodore Ts'od3cd93c2000-10-24 18:33:16 +0000732
Theodore Ts'o3839e651997-04-26 13:21:57 +0000733/* openfs.c */
734extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
735 int block_size, io_manager manager,
736 ext2_filsys *ret_fs);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000737
738/* get_pathname.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000739extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000740 char **name);
741
742/* link.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000743errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
744 ext2_ino_t ino, int flags);
745errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
746 ext2_ino_t ino, int flags);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000747
748/* read_bb.c */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000749extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
750 ext2_badblocks_list *bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000751
752/* read_bb_file.c */
Theodore Ts'o57dca852000-07-04 19:20:25 +0000753extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
754 ext2_badblocks_list *bb_list,
755 void *private,
756 void (*invalid)(ext2_filsys fs,
757 blk_t blk,
758 char *badstr,
759 void *private));
Theodore Ts'o3839e651997-04-26 13:21:57 +0000760extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000761 ext2_badblocks_list *bb_list,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000762 void (*invalid)(ext2_filsys fs,
763 blk_t blk));
764
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000765/* rs_bitmap.c */
766extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
767 __u32 new_real_end,
768 ext2fs_generic_bitmap bmap);
769extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
770 ext2fs_inode_bitmap bmap);
771extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
772 ext2fs_block_bitmap bmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000773extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
774 ext2fs_generic_bitmap *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000775
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000776/* swapfs.c */
777extern void ext2fs_swap_super(struct ext2_super_block * super);
778extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000779extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
780 struct ext2_inode *f, int hostorder);
781
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000782/* valid_blk.c */
Theodore Ts'o521e3681997-04-29 17:48:10 +0000783extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
784
785/* version.c */
786extern int ext2fs_parse_version_string(const char *ver_string);
787extern int ext2fs_get_library_version(const char **ver_string,
788 const char **date_string);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000789
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000790/* write_bb_file.c */
791extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
792 unsigned int flags,
793 FILE *f);
794
795
Theodore Ts'o3839e651997-04-26 13:21:57 +0000796/* inline functions */
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000797extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000798extern errcode_t ext2fs_free_mem(void **ptr);
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000799extern errcode_t ext2fs_resize_mem(unsigned long old_size,
800 unsigned long size, void **ptr);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000801extern void ext2fs_mark_super_dirty(ext2_filsys fs);
802extern void ext2fs_mark_changed(ext2_filsys fs);
803extern int ext2fs_test_changed(ext2_filsys fs);
804extern void ext2fs_mark_valid(ext2_filsys fs);
805extern void ext2fs_unmark_valid(ext2_filsys fs);
806extern int ext2fs_test_valid(ext2_filsys fs);
807extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
808extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
809extern int ext2fs_test_ib_dirty(ext2_filsys fs);
810extern int ext2fs_test_bb_dirty(ext2_filsys fs);
811extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000812extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000813
814/*
815 * The actual inlined functions definitions themselves...
816 *
817 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
818 * functions at all!
819 */
820#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
821#ifdef INCLUDE_INLINE_FUNCS
822#define _INLINE_ extern
823#else
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000824#ifdef __GNUC__
Theodore Ts'o3839e651997-04-26 13:21:57 +0000825#define _INLINE_ extern __inline__
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000826#else /* For Watcom C */
827#define _INLINE_ extern inline
828#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +0000829#endif
830
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000831#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
832/*
833 * Allocate memory
834 */
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000835_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000836{
837 *ptr = malloc(size);
838 if (!*ptr)
Theodore Ts'o291c9041997-10-31 06:17:08 +0000839 return EXT2_ET_NO_MEMORY;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000840 return 0;
841}
842
843/*
844 * Free memory
845 */
846_INLINE_ errcode_t ext2fs_free_mem(void **ptr)
847{
848 free(*ptr);
849 *ptr = 0;
850 return 0;
851}
852
853/*
854 * Resize memory
855 */
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000856_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
857 unsigned long size, void **ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000858{
859 void *p;
860
861 p = realloc(*ptr, size);
862 if (!p)
Theodore Ts'o291c9041997-10-31 06:17:08 +0000863 return EXT2_ET_NO_MEMORY;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000864 *ptr = p;
865 return 0;
866}
867#endif /* Custom memory routines */
868
Theodore Ts'o3839e651997-04-26 13:21:57 +0000869/*
870 * Mark a filesystem superblock as dirty
871 */
872_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
873{
874 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
875}
876
877/*
878 * Mark a filesystem as changed
879 */
880_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
881{
882 fs->flags |= EXT2_FLAG_CHANGED;
883}
884
885/*
886 * Check to see if a filesystem has changed
887 */
888_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
889{
890 return (fs->flags & EXT2_FLAG_CHANGED);
891}
892
893/*
894 * Mark a filesystem as valid
895 */
896_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
897{
898 fs->flags |= EXT2_FLAG_VALID;
899}
900
901/*
902 * Mark a filesystem as NOT valid
903 */
904_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
905{
906 fs->flags &= ~EXT2_FLAG_VALID;
907}
908
909/*
910 * Check to see if a filesystem is valid
911 */
912_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
913{
914 return (fs->flags & EXT2_FLAG_VALID);
915}
916
917/*
918 * Mark the inode bitmap as dirty
919 */
920_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
921{
922 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
923}
924
925/*
926 * Mark the block bitmap as dirty
927 */
928_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
929{
930 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
931}
932
933/*
934 * Check to see if a filesystem's inode bitmap is dirty
935 */
936_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
937{
938 return (fs->flags & EXT2_FLAG_IB_DIRTY);
939}
940
941/*
942 * Check to see if a filesystem's block bitmap is dirty
943 */
944_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
945{
946 return (fs->flags & EXT2_FLAG_BB_DIRTY);
947}
948
949/*
950 * Return the group # of a block
951 */
952_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
953{
954 return (blk - fs->super->s_first_data_block) /
955 fs->super->s_blocks_per_group;
956}
957
958/*
959 * Return the group # of an inode number
960 */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000961_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000962{
963 return (ino - 1) / fs->super->s_inodes_per_group;
964}
965#undef _INLINE_
966#endif
967
Theodore Ts'ofa7ef712000-05-19 02:11:41 +0000968#ifdef __cplusplus
969}
970#endif
971
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +0000972#endif /* _EXT2FS_EXT2FS_H */