blob: f9eb34e45934f33764c2cf6200e4e63ca7180761 [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
12/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000013 * Non-GNU C compilers won't necessarily understand inline
14 */
15#ifndef __GNUC__
16#define NO_INLINE_FUNCS
17#endif
18
19/*
Theodore Ts'o3839e651997-04-26 13:21:57 +000020 * Where the master copy of the superblock is located, and how big
21 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
22 * the size of the superblock structure is not necessarily trustworthy
23 * (some versions have the padding set up so that the superblock is
24 * 1032 bytes long).
25 */
26#define SUPERBLOCK_OFFSET 1024
27#define SUPERBLOCK_SIZE 1024
28
Theodore Ts'of3db3561997-04-26 13:34:30 +000029/*
30 * The last ext2fs revision level that this version of the library is
31 * able to support.
32 */
33#define EXT2_LIB_CURRENT_REV 0
34
Theodore Ts'od40259f1997-10-20 00:44:26 +000035#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000036#include <sys/types.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000037#endif
38
Theodore Ts'o50e1e101997-04-26 13:58:21 +000039#include <linux/types.h>
40
41typedef __u32 blk_t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000042typedef unsigned int dgrp_t;
Theodore Ts'o30fab291997-10-25 22:37:42 +000043typedef __u32 ext2_off_t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000044
45#include "et/com_err.h"
Theodore Ts'od40259f1997-10-20 00:44:26 +000046#include "ext2fs/ext2_io.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000047#include "ext2fs/ext2_err.h"
48
Theodore Ts'of3db3561997-04-26 13:34:30 +000049typedef struct struct_ext2_filsys *ext2_filsys;
50
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000051struct ext2fs_struct_generic_bitmap {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000052 errcode_t magic;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000053 ext2_filsys fs;
54 __u32 start, end;
55 __u32 real_end;
56 char * description;
57 char * bitmap;
58 errcode_t base_error_code;
59 __u32 reserved[7];
Theodore Ts'of3db3561997-04-26 13:34:30 +000060};
61
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000062#define EXT2FS_MARK_ERROR 0
63#define EXT2FS_UNMARK_ERROR 1
64#define EXT2FS_TEST_ERROR 2
Theodore Ts'of3db3561997-04-26 13:34:30 +000065
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000066typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000067typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000068typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
Theodore Ts'of3db3561997-04-26 13:34:30 +000069
Theodore Ts'o7f88b041997-04-26 14:48:50 +000070#ifdef EXT2_DYNAMIC_REV
71#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
72#else
73#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
74#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
75#endif
76
Theodore Ts'o3839e651997-04-26 13:21:57 +000077/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000078 * badblocks list definitions
79 */
80
81typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
82typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
83
84/* old */
85typedef struct ext2_struct_badblocks_list *badblocks_list;
86typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
87
88#define BADBLOCKS_FLAG_DIRTY 1
89
90/*
91 * ext2_dblist structure and abstractions (see dblist.c)
92 */
93struct ext2_db_entry {
94 ino_t ino;
95 blk_t blk;
96 int blockcnt;
97};
98
99typedef struct ext2_struct_dblist *ext2_dblist;
100
101#define DBLIST_ABORT 1
102
103/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000104 * ext2_fileio definitions
105 */
106
107#define EXT2_FILE_WRITE 0x0001
108#define EXT2_FILE_CREATE 0x0002
109
110#define EXT2_FILE_MASK 0x00FF
111
112#define EXT2_FILE_BUF_DIRTY 0x4000
113#define EXT2_FILE_BUF_VALID 0x2000
114
115typedef struct ext2_file *ext2_file_t;
116
117#define EXT2_SEEK_SET 0
118#define EXT2_SEEK_CUR 1
119#define EXT2_SEEK_END 2
120
121/*
Theodore Ts'o3839e651997-04-26 13:21:57 +0000122 * Flags for the ext2_filsys structure
123 */
124
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000125#define EXT2_FLAG_RW 0x01
126#define EXT2_FLAG_CHANGED 0x02
127#define EXT2_FLAG_DIRTY 0x04
128#define EXT2_FLAG_VALID 0x08
129#define EXT2_FLAG_IB_DIRTY 0x10
130#define EXT2_FLAG_BB_DIRTY 0x20
Theodore Ts'o5c576471997-04-29 15:29:49 +0000131#define EXT2_FLAG_SWAP_BYTES 0x40
132#define EXT2_FLAG_SWAP_BYTES_READ 0x80
133#define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
134#define EXT2_FLAG_MASTER_SB_ONLY 0x200
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000135#define EXT2_FLAG_FORCE 0x400
Theodore Ts'o3839e651997-04-26 13:21:57 +0000136
Theodore Ts'o7f88b041997-04-26 14:48:50 +0000137/*
138 * Special flag in the ext2 inode i_flag field that means that this is
139 * a new inode. (So that ext2_write_inode() can clear extra fields.)
140 */
141#define EXT2_NEW_INODE_FL 0x80000000
142
Theodore Ts'o3839e651997-04-26 13:21:57 +0000143struct struct_ext2_filsys {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +0000144 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000145 io_channel io;
146 int flags;
147 char * device_name;
148 struct ext2_super_block * super;
149 int blocksize;
150 int fragsize;
151 unsigned long group_desc_count;
152 unsigned long desc_blocks;
153 struct ext2_group_desc * group_desc;
154 int inode_blocks_per_group;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000155 ext2fs_inode_bitmap inode_map;
156 ext2fs_block_bitmap block_map;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000157 errcode_t (*get_blocks)(ext2_filsys fs, ino_t ino, blk_t *blocks);
158 errcode_t (*check_directory)(ext2_filsys fs, ino_t ino);
159 errcode_t (*write_bitmaps)(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000160 errcode_t (*read_inode)(ext2_filsys fs, ino_t ino,
161 struct ext2_inode *inode);
162 errcode_t (*write_inode)(ext2_filsys fs, ino_t ino,
163 struct ext2_inode *inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000164 badblocks_list badblocks;
165 ext2_dblist dblist;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000166 __u32 stride; /* for mke2fs */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000167 /*
168 * Reserved for future expansion
169 */
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000170 __u32 reserved[11];
Theodore Ts'o3839e651997-04-26 13:21:57 +0000171
172 /*
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000173 * Reserved for the use of the calling application.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000174 */
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000175 void * private;
176
177 /*
178 * Inode cache
179 */
180 struct ext2_inode_cache *icache;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000181};
182
Theodore Ts'of3db3561997-04-26 13:34:30 +0000183#include "ext2fs/bitops.h"
Theodore Ts'od40259f1997-10-20 00:44:26 +0000184
Theodore Ts'o3839e651997-04-26 13:21:57 +0000185/*
186 * Return flags for the block iterator functions
187 */
188#define BLOCK_CHANGED 1
189#define BLOCK_ABORT 2
190#define BLOCK_ERROR 4
191
192/*
193 * Block interate flags
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000194 *
195 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
196 * function should be called on blocks where the block number is zero.
197 * This is used by ext2fs_expand_dir() to be able to add a new block
198 * to an inode. It can also be used for programs that want to be able
199 * to deal with files that contain "holes".
200 *
201 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
202 * indirect, doubly indirect, etc. blocks should be called after all
203 * of the blocks containined in the indirect blocks are processed.
204 * This is useful if you are going to be deallocating blocks from an
205 * inode.
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000206 *
207 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
208 * called for data blocks only.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000209 */
210#define BLOCK_FLAG_APPEND 1
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000211#define BLOCK_FLAG_HOLE 1
Theodore Ts'o3839e651997-04-26 13:21:57 +0000212#define BLOCK_FLAG_DEPTH_TRAVERSE 2
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000213#define BLOCK_FLAG_DATA_ONLY 4
214
215/*
216 * Magic "block count" return values for the block iterator function.
217 */
218#define BLOCK_COUNT_IND (-1)
219#define BLOCK_COUNT_DIND (-2)
220#define BLOCK_COUNT_TIND (-3)
221#define BLOCK_COUNT_TRANSLATOR (-4)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000222
223/*
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000224 * Flags for ext2fs_move_blocks
225 */
226#define EXT2_BMOVE_GET_DBLIST 0x0001
Theodore Ts'o36f21431997-06-14 07:25:40 +0000227#define EXT2_BMOVE_DEBUG 0x0002
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000228
229/*
Theodore Ts'o3839e651997-04-26 13:21:57 +0000230 * Return flags for the directory iterator functions
231 */
232#define DIRENT_CHANGED 1
233#define DIRENT_ABORT 2
234#define DIRENT_ERROR 3
235
236/*
237 * Directory iterator flags
238 */
239
240#define DIRENT_FLAG_INCLUDE_EMPTY 1
241
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000242
243#define DIRENT_DOT_FILE 1
244#define DIRENT_DOT_DOT_FILE 2
245#define DIRENT_OTHER_FILE 3
246
Theodore Ts'o3839e651997-04-26 13:21:57 +0000247/*
248 * Inode scan definitions
249 */
Theodore Ts'of3db3561997-04-26 13:34:30 +0000250typedef struct ext2_struct_inode_scan *ext2_inode_scan;
251
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000252/*
253 * ext2fs_scan flags
254 */
255#define EXT2_SF_CHK_BADBLOCKS 0x0001
256#define EXT2_SF_BAD_INODE_BLK 0x0002
257#define EXT2_SF_BAD_EXTRA_BYTES 0x0004
258#define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
Theodore Ts'o3839e651997-04-26 13:21:57 +0000259
Theodore Ts'of3db3561997-04-26 13:34:30 +0000260/*
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000261 * ext2fs_check_if_mounted flags
262 */
263#define EXT2_MF_MOUNTED 1
264#define EXT2_MF_ISROOT 2
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000265#define EXT2_MF_READONLY 4
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000266
267/*
268 * Ext2/linux mode flags. We define them here so that we don't need
269 * to depend on the OS's sys/stat.h, since we may be compiling on a
270 * non-Linux system.
271 */
272#define LINUX_S_IFMT 00170000
273#define LINUX_S_IFSOCK 0140000
274#define LINUX_S_IFLNK 0120000
275#define LINUX_S_IFREG 0100000
276#define LINUX_S_IFBLK 0060000
277#define LINUX_S_IFDIR 0040000
278#define LINUX_S_IFCHR 0020000
279#define LINUX_S_IFIFO 0010000
280#define LINUX_S_ISUID 0004000
281#define LINUX_S_ISGID 0002000
282#define LINUX_S_ISVTX 0001000
283
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000284#define LINUX_S_IRWXU 00700
285#define LINUX_S_IRUSR 00400
286#define LINUX_S_IWUSR 00200
287#define LINUX_S_IXUSR 00100
288
289#define LINUX_S_IRWXG 00070
290#define LINUX_S_IRGRP 00040
291#define LINUX_S_IWGRP 00020
292#define LINUX_S_IXGRP 00010
293
294#define LINUX_S_IRWXO 00007
295#define LINUX_S_IROTH 00004
296#define LINUX_S_IWOTH 00002
297#define LINUX_S_IXOTH 00001
298
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000299#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
300#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
301#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
302#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
303#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
304#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
305#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
306
307/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000308 * ext2_icount_t abstraction
309 */
310#define EXT2_ICOUNT_OPT_INCREMENT 0x01
311
312typedef struct ext2_icount *ext2_icount_t;
313
314/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000315 * Flags for ext2fs_bmap
316 */
317#define BMAP_ALLOC 1
318
319/*
Theodore Ts'of3db3561997-04-26 13:34:30 +0000320 * For checking structure magic numbers...
321 */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000322
Theodore Ts'of3db3561997-04-26 13:34:30 +0000323#define EXT2_CHECK_MAGIC(struct, code) \
324 if ((struct)->magic != (code)) return (code)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000325
326
327/*
328 * The ext2fs library private definition of the ext2 superblock, so we
329 * don't have to depend on the kernel's definition of the superblock,
330 * which might not have the latest features.
331 */
332struct ext2fs_sb {
333 __u32 s_inodes_count; /* Inodes count */
334 __u32 s_blocks_count; /* Blocks count */
335 __u32 s_r_blocks_count; /* Reserved blocks count */
336 __u32 s_free_blocks_count; /* Free blocks count */
337 __u32 s_free_inodes_count; /* Free inodes count */
338 __u32 s_first_data_block; /* First Data Block */
339 __u32 s_log_block_size; /* Block size */
340 __s32 s_log_frag_size; /* Fragment size */
341 __u32 s_blocks_per_group; /* # Blocks per group */
342 __u32 s_frags_per_group; /* # Fragments per group */
343 __u32 s_inodes_per_group; /* # Inodes per group */
344 __u32 s_mtime; /* Mount time */
345 __u32 s_wtime; /* Write time */
346 __u16 s_mnt_count; /* Mount count */
347 __s16 s_max_mnt_count; /* Maximal mount count */
348 __u16 s_magic; /* Magic signature */
349 __u16 s_state; /* File system state */
350 __u16 s_errors; /* Behaviour when detecting errors */
351 __u16 s_minor_rev_level; /* minor revision level */
352 __u32 s_lastcheck; /* time of last check */
353 __u32 s_checkinterval; /* max. time between checks */
354 __u32 s_creator_os; /* OS */
355 __u32 s_rev_level; /* Revision level */
356 __u16 s_def_resuid; /* Default uid for reserved blocks */
357 __u16 s_def_resgid; /* Default gid for reserved blocks */
358 /*
359 * These fields are for EXT2_DYNAMIC_REV superblocks only.
360 *
361 * Note: the difference between the compatible feature set and
362 * the incompatible feature set is that if there is a bit set
363 * in the incompatible feature set that the kernel doesn't
364 * know about, it should refuse to mount the filesystem.
365 *
366 * e2fsck's requirements are more strict; if it doesn't know
367 * about a feature in either the compatible or incompatible
368 * feature set, it must abort and not try to meddle with
369 * things it doesn't understand...
370 */
371 __u32 s_first_ino; /* First non-reserved inode */
372 __u16 s_inode_size; /* size of inode structure */
373 __u16 s_block_group_nr; /* block group # of this superblock */
374 __u32 s_feature_compat; /* compatible feature set */
375 __u32 s_feature_incompat; /* incompatible feature set */
376 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
377 __u8 s_uuid[16]; /* 128-bit uuid for volume */
378 char s_volume_name[16]; /* volume name */
379 char s_last_mounted[64]; /* directory where last mounted */
380 __u32 s_reserved[206]; /* Padding to the end of the block */
381};
Theodore Ts'o521e3681997-04-29 17:48:10 +0000382
383/*
384 * Feature set definitions (that might not be in ext2_fs.h
385 * (was EXT2_COMPAT_SPARSE_SUPER)
386 */
387#ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
388#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
389#endif
390
391#define EXT2_LIB_FEATURE_COMPAT_SUPP 0
392#define EXT2_LIB_FEATURE_INCOMPAT_SUPP 0
393#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
394
Theodore Ts'o3839e651997-04-26 13:21:57 +0000395/*
396 * function prototypes
397 */
398
399/* alloc.c */
400extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000401 ext2fs_inode_bitmap map, ino_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000402extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000403 ext2fs_block_bitmap map, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000404extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000405 blk_t finish, int num,
406 ext2fs_block_bitmap map,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000407 blk_t *ret);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000408extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
409 char *block_buf, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000410
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000411/* alloc_tables.c */
412extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
413extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, int group,
414 ext2fs_block_bitmap bmap);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000415
Theodore Ts'o3839e651997-04-26 13:21:57 +0000416/* badblocks.c */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000417extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
418 int size);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000419extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
420 blk_t blk);
421extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
422 blk_t blk);
423extern errcode_t
424 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
425 ext2_badblocks_iterate *ret);
426extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
427 blk_t *blk);
428extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000429extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
430 ext2_badblocks_list *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000431
432/* bb_compat */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000433extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000434extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
435extern int badblocks_list_test(badblocks_list bb, blk_t blk);
436extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
437 badblocks_iterate *ret);
438extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
439extern void badblocks_list_iterate_end(badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000440extern void badblocks_list_free(badblocks_list bb);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000441
442/* bb_inode.c */
443extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000444 ext2_badblocks_list bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000445
446/* bitmaps.c */
447extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
448extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
449extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
450extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000451extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
452 __u32 end,
453 __u32 real_end,
454 const char *descr,
455 ext2fs_generic_bitmap *ret);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000456extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
457 const char *descr,
458 ext2fs_block_bitmap *ret);
459extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
460 const char *descr,
461 ext2fs_inode_bitmap *ret);
462extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
463 ino_t end, ino_t *oend);
464extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
465 blk_t end, blk_t *oend);
466extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
467extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000468extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
469extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
470
471/* block.c */
472extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
473 ino_t ino,
474 int flags,
475 char *block_buf,
476 int (*func)(ext2_filsys fs,
477 blk_t *blocknr,
478 int blockcnt,
479 void *private),
480 void *private);
481
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000482errcode_t ext2fs_block_iterate2(ext2_filsys fs,
483 ino_t ino,
484 int flags,
485 char *block_buf,
486 int (*func)(ext2_filsys fs,
487 blk_t *blocknr,
488 int blockcnt,
489 blk_t ref_blk,
490 int ref_offset,
491 void *private),
492 void *private);
493
Theodore Ts'o30fab291997-10-25 22:37:42 +0000494/* bmap.c */
495extern errcode_t ext2fs_bmap(ext2_filsys fs, ino_t ino,
496 struct ext2_inode *inode,
497 char *block_buf, int bmap_flags,
498 blk_t block, blk_t *phys_blk);
499
500
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000501/* bmove.c */
502extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
503 ext2fs_block_bitmap reserve,
Theodore Ts'o9941fb71997-06-11 22:27:41 +0000504 ext2fs_block_bitmap alloc_map,
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000505 int flags);
506
Theodore Ts'of3db3561997-04-26 13:34:30 +0000507/* check_desc.c */
508extern errcode_t ext2fs_check_desc(ext2_filsys fs);
509
Theodore Ts'o3839e651997-04-26 13:21:57 +0000510/* closefs.c */
511extern errcode_t ext2fs_close(ext2_filsys fs);
512extern errcode_t ext2fs_flush(ext2_filsys fs);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000513extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000514
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000515/* cmp_bitmaps.c */
516extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
517 ext2fs_block_bitmap bm2);
518extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
519 ext2fs_inode_bitmap bm2);
520
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000521/* dblist.c */
522
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000523extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs);
524extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
525extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino,
526 blk_t blk, int blockcnt);
527extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
528 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
529 void *private),
530 void *private);
531extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino,
532 blk_t blk, int blockcnt);
533extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
534 ext2_dblist *dest);
Theodore Ts'o549860c1997-06-17 03:55:00 +0000535extern int ext2fs_dblist_count(ext2_dblist dblist);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000536
537/* dblist_dir.c */
538extern errcode_t
539 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
540 int flags,
541 char *block_buf,
542 int (*func)(ino_t dir,
543 int entry,
544 struct ext2_dir_entry *dirent,
545 int offset,
546 int blocksize,
547 char *buf,
548 void *private),
549 void *private);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000550
551/* dirblock.c */
552extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
553 void *buf);
554extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
555 void *buf);
556
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000557/* dir_iterate.c */
558extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
559 ino_t dir,
560 int flags,
561 char *block_buf,
562 int (*func)(struct ext2_dir_entry *dirent,
563 int offset,
564 int blocksize,
565 char *buf,
566 void *private),
567 void *private);
568 /* private to library */
569extern int ext2fs_process_dir_block(ext2_filsys fs,
570 blk_t *blocknr,
571 int blockcnt,
572 void *private);
573
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000574/* dupfs.c */
575extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000576
Theodore Ts'o3839e651997-04-26 13:21:57 +0000577/* expanddir.c */
578extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir);
579
Theodore Ts'o30fab291997-10-25 22:37:42 +0000580/* fileio.c */
581extern errcode_t ext2fs_file_open(ext2_filsys fs, ino_t ino,
582 int flags, ext2_file_t *ret);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000583extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000584extern errcode_t ext2fs_file_close(ext2_file_t file);
585extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000586 unsigned int wanted, unsigned int *got);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000587extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000588 unsigned int nbytes, unsigned int *written);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000589extern errcode_t ext2fs_file_llseek(ext2_file_t file, ext2_off_t offset,
590 int whence, ext2_off_t *ret_pos);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000591extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
592extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000593
Theodore Ts'o3839e651997-04-26 13:21:57 +0000594/* freefs.c */
595extern void ext2fs_free(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000596extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000597extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
598extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000599extern void ext2fs_free_dblist(ext2_dblist dblist);
600extern void ext2fs_badblocks_list_free(badblocks_list bb);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000601
602/* getsize.c */
603extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
604 blk_t *retblocks);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000605
606/* initialize.c */
607extern errcode_t ext2fs_initialize(const char *name, int flags,
608 struct ext2_super_block *param,
609 io_manager manager, ext2_filsys *ret_fs);
610
611/* inode.c */
612extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
613 ext2_inode_scan *ret_scan);
614extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
615extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino,
616 struct ext2_inode *inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000617extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
618 int group);
619extern void ext2fs_set_inode_callback
620 (ext2_inode_scan scan,
621 errcode_t (*done_group)(ext2_filsys fs,
622 ext2_inode_scan scan,
623 dgrp_t group,
624 void * private),
625 void *done_group_data);
626extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
627 int clear_flags);
628extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000629 struct ext2_inode * inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000630extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000631 struct ext2_inode * inode);
632extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks);
633extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino);
634
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000635/* icount.c */
636extern void ext2fs_free_icount(ext2_icount_t icount);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000637extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
638 ext2_icount_t hint, ext2_icount_t *ret);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000639extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
640 ext2_icount_t *ret);
641extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino,
642 __u16 *ret);
643extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
644 __u16 *ret);
645extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
646 __u16 *ret);
647extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
648 __u16 count);
649extern ino_t ext2fs_get_icount_size(ext2_icount_t icount);
Theodore Ts'o521e3681997-04-29 17:48:10 +0000650errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000651
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000652/* ismounted.c */
653extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
654
Theodore Ts'o3839e651997-04-26 13:21:57 +0000655/* namei.c */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000656extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name,
657 int namelen, char *buf, ino_t *inode);
658extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd,
659 const char *name, ino_t *inode);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000660errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd,
661 const char *name, ino_t *inode);
662extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd,
663 ino_t inode, ino_t *res_inode);
664
665/* native.c */
666int ext2fs_native_flag(void);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000667
668/* newdir.c */
669extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino,
670 ino_t parent_ino, char **block);
671
672/* mkdir.c */
673extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum,
674 const char *name);
675
676/* openfs.c */
677extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
678 int block_size, io_manager manager,
679 ext2_filsys *ret_fs);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000680
681/* get_pathname.c */
682extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino,
683 char **name);
684
685/* link.c */
686errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name,
687 ino_t ino, int flags);
688errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name,
689 ino_t ino, int flags);
690
691/* read_bb.c */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000692extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
693 ext2_badblocks_list *bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000694
695/* read_bb_file.c */
696extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000697 ext2_badblocks_list *bb_list,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000698 void (*invalid)(ext2_filsys fs,
699 blk_t blk));
700
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000701/* rs_bitmap.c */
702extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
703 __u32 new_real_end,
704 ext2fs_generic_bitmap bmap);
705extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
706 ext2fs_inode_bitmap bmap);
707extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
708 ext2fs_block_bitmap bmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000709extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
710 ext2fs_generic_bitmap *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000711
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000712/* swapfs.c */
713extern void ext2fs_swap_super(struct ext2_super_block * super);
714extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000715extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
716 struct ext2_inode *f, int hostorder);
717
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000718/* valid_blk.c */
Theodore Ts'o521e3681997-04-29 17:48:10 +0000719extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
720
721/* version.c */
722extern int ext2fs_parse_version_string(const char *ver_string);
723extern int ext2fs_get_library_version(const char **ver_string,
724 const char **date_string);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000725
Theodore Ts'o3839e651997-04-26 13:21:57 +0000726/* inline functions */
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000727extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000728extern errcode_t ext2fs_free_mem(void **ptr);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000729extern errcode_t ext2fs_resize_mem(unsigned long size, void **ptr);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000730extern void ext2fs_mark_super_dirty(ext2_filsys fs);
731extern void ext2fs_mark_changed(ext2_filsys fs);
732extern int ext2fs_test_changed(ext2_filsys fs);
733extern void ext2fs_mark_valid(ext2_filsys fs);
734extern void ext2fs_unmark_valid(ext2_filsys fs);
735extern int ext2fs_test_valid(ext2_filsys fs);
736extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
737extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
738extern int ext2fs_test_ib_dirty(ext2_filsys fs);
739extern int ext2fs_test_bb_dirty(ext2_filsys fs);
740extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
741extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino);
742
743/*
744 * The actual inlined functions definitions themselves...
745 *
746 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
747 * functions at all!
748 */
749#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
750#ifdef INCLUDE_INLINE_FUNCS
751#define _INLINE_ extern
752#else
753#define _INLINE_ extern __inline__
754#endif
755
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000756#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
757/*
758 * Allocate memory
759 */
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000760_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000761{
762 *ptr = malloc(size);
763 if (!*ptr)
Theodore Ts'o291c9041997-10-31 06:17:08 +0000764 return EXT2_ET_NO_MEMORY;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000765 return 0;
766}
767
768/*
769 * Free memory
770 */
771_INLINE_ errcode_t ext2fs_free_mem(void **ptr)
772{
773 free(*ptr);
774 *ptr = 0;
775 return 0;
776}
777
778/*
779 * Resize memory
780 */
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000781_INLINE_ errcode_t ext2fs_resize_mem(unsigned long size, void **ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000782{
783 void *p;
784
785 p = realloc(*ptr, size);
786 if (!p)
Theodore Ts'o291c9041997-10-31 06:17:08 +0000787 return EXT2_ET_NO_MEMORY;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000788 *ptr = p;
789 return 0;
790}
791#endif /* Custom memory routines */
792
Theodore Ts'o3839e651997-04-26 13:21:57 +0000793/*
794 * Mark a filesystem superblock as dirty
795 */
796_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
797{
798 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
799}
800
801/*
802 * Mark a filesystem as changed
803 */
804_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
805{
806 fs->flags |= EXT2_FLAG_CHANGED;
807}
808
809/*
810 * Check to see if a filesystem has changed
811 */
812_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
813{
814 return (fs->flags & EXT2_FLAG_CHANGED);
815}
816
817/*
818 * Mark a filesystem as valid
819 */
820_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
821{
822 fs->flags |= EXT2_FLAG_VALID;
823}
824
825/*
826 * Mark a filesystem as NOT valid
827 */
828_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
829{
830 fs->flags &= ~EXT2_FLAG_VALID;
831}
832
833/*
834 * Check to see if a filesystem is valid
835 */
836_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
837{
838 return (fs->flags & EXT2_FLAG_VALID);
839}
840
841/*
842 * Mark the inode bitmap as dirty
843 */
844_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
845{
846 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
847}
848
849/*
850 * Mark the block bitmap as dirty
851 */
852_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
853{
854 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
855}
856
857/*
858 * Check to see if a filesystem's inode bitmap is dirty
859 */
860_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
861{
862 return (fs->flags & EXT2_FLAG_IB_DIRTY);
863}
864
865/*
866 * Check to see if a filesystem's block bitmap is dirty
867 */
868_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
869{
870 return (fs->flags & EXT2_FLAG_BB_DIRTY);
871}
872
873/*
874 * Return the group # of a block
875 */
876_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
877{
878 return (blk - fs->super->s_first_data_block) /
879 fs->super->s_blocks_per_group;
880}
881
882/*
883 * Return the group # of an inode number
884 */
885_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino)
886{
887 return (ino - 1) / fs->super->s_inodes_per_group;
888}
889#undef _INLINE_
890#endif
891