blob: fd99c3eb75a00d3f8303498f3a9daa007d7fc430 [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'o54434922003-12-07 01:28:50 -050015#ifdef __GNUC__
16#define EXT2FS_ATTR(x) __attribute__(x)
17#else
18#define EXT2FS_ATTR(x)
19#endif
20
Theodore Ts'ofa7ef712000-05-19 02:11:41 +000021#ifdef __cplusplus
22extern "C" {
23#endif
24
Theodore Ts'o3839e651997-04-26 13:21:57 +000025/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000026 * Non-GNU C compilers won't necessarily understand inline
27 */
Theodore Ts'o76f875d1998-04-27 01:41:13 +000028#if (!defined(__GNUC__) && !defined(__WATCOMC__))
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000029#define NO_INLINE_FUNCS
30#endif
31
32/*
Theodore Ts'o5df55d72001-06-11 07:00:04 +000033 * Build in support for byte-swapping filesystems if we the feature
34 * has been configured or if we're being built on a CPU architecture
35 * with a non-native byte order.
36 */
37#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
38#define EXT2FS_ENABLE_SWAPFS
39#endif
40
41/*
Theodore Ts'o3839e651997-04-26 13:21:57 +000042 * Where the master copy of the superblock is located, and how big
43 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
44 * the size of the superblock structure is not necessarily trustworthy
45 * (some versions have the padding set up so that the superblock is
46 * 1032 bytes long).
47 */
48#define SUPERBLOCK_OFFSET 1024
49#define SUPERBLOCK_SIZE 1024
50
Theodore Ts'of3db3561997-04-26 13:34:30 +000051/*
52 * The last ext2fs revision level that this version of the library is
53 * able to support.
54 */
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000055#define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
Theodore Ts'of3db3561997-04-26 13:34:30 +000056
Theodore Ts'od40259f1997-10-20 00:44:26 +000057#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000058#include <sys/types.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000059#endif
60
Theodore Ts'o3e699062002-10-13 23:56:28 -040061#include <stdio.h>
Theodore Ts'o5be8dc21997-12-01 18:24:10 +000062#include <stdlib.h>
Theodore Ts'oa82a5702005-11-14 14:49:15 -050063#include <string.h>
Theodore Ts'o5953b9d1998-02-01 13:23:02 +000064
65#if EXT2_FLAT_INCLUDES
66#include "e2_types.h"
Theodore Ts'o3e699062002-10-13 23:56:28 -040067#include "ext2_fs.h"
Theodore Ts'o5953b9d1998-02-01 13:23:02 +000068#else
Theodore Ts'o797f5ef2001-06-01 23:49:46 +000069#include <ext2fs/ext2_types.h>
Theodore Ts'o3e699062002-10-13 23:56:28 -040070#include <ext2fs/ext2_fs.h>
Theodore Ts'oe589f672000-04-03 13:45:40 +000071#endif /* EXT2_FLAT_INCLUDES */
Theodore Ts'o50e1e101997-04-26 13:58:21 +000072
Theodore Ts'o31dbecd2001-01-11 04:54:39 +000073typedef __u32 ext2_ino_t;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000074typedef __u32 blk_t;
Theodore Ts'o2eb374c1998-09-03 01:22:57 +000075typedef __u32 dgrp_t;
Theodore Ts'o30fab291997-10-25 22:37:42 +000076typedef __u32 ext2_off_t;
Theodore Ts'o03673db1998-06-10 20:39:43 +000077typedef __s64 e2_blkcnt_t;
Theodore Ts'o52783e02002-03-11 15:04:45 -050078typedef __u32 ext2_dirhash_t;
Theodore Ts'o3839e651997-04-26 13:21:57 +000079
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000080#if EXT2_FLAT_INCLUDES
81#include "com_err.h"
82#include "ext2_io.h"
83#include "ext2_err.h"
84#else
Theodore Ts'o7c2d2562001-05-21 02:54:21 +000085#include <et/com_err.h>
86#include <ext2fs/ext2_io.h>
87#include <ext2fs/ext2_err.h>
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000088#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000089
Theodore Ts'o4c77fe51998-04-30 17:35:59 +000090/*
91 * Portability help for Microsoft Visual C++
92 */
93#ifdef _MSC_VER
94#define EXT2_QSORT_TYPE int __cdecl
95#else
96#define EXT2_QSORT_TYPE int
97#endif
98
Theodore Ts'of3db3561997-04-26 13:34:30 +000099typedef struct struct_ext2_filsys *ext2_filsys;
100
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000101struct ext2fs_struct_generic_bitmap {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +0000102 errcode_t magic;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000103 ext2_filsys fs;
104 __u32 start, end;
105 __u32 real_end;
106 char * description;
107 char * bitmap;
108 errcode_t base_error_code;
109 __u32 reserved[7];
Theodore Ts'of3db3561997-04-26 13:34:30 +0000110};
111
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000112#define EXT2FS_MARK_ERROR 0
113#define EXT2FS_UNMARK_ERROR 1
114#define EXT2FS_TEST_ERROR 2
Theodore Ts'of3db3561997-04-26 13:34:30 +0000115
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000116typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000117typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000118typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000119
Theodore Ts'o7f88b041997-04-26 14:48:50 +0000120#ifdef EXT2_DYNAMIC_REV
121#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
122#else
123#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
124#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
125#endif
126
Theodore Ts'o3839e651997-04-26 13:21:57 +0000127/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000128 * badblocks list definitions
129 */
130
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400131typedef struct ext2_struct_u32_list *ext2_badblocks_list;
132typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
133
134typedef struct ext2_struct_u32_list *ext2_u32_list;
135typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000136
137/* old */
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400138typedef struct ext2_struct_u32_list *badblocks_list;
139typedef struct ext2_struct_u32_iterate *badblocks_iterate;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000140
141#define BADBLOCKS_FLAG_DIRTY 1
142
143/*
144 * ext2_dblist structure and abstractions (see dblist.c)
145 */
146struct ext2_db_entry {
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000147 ext2_ino_t ino;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000148 blk_t blk;
149 int blockcnt;
150};
151
152typedef struct ext2_struct_dblist *ext2_dblist;
153
154#define DBLIST_ABORT 1
155
156/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000157 * ext2_fileio definitions
158 */
159
160#define EXT2_FILE_WRITE 0x0001
161#define EXT2_FILE_CREATE 0x0002
162
163#define EXT2_FILE_MASK 0x00FF
164
165#define EXT2_FILE_BUF_DIRTY 0x4000
166#define EXT2_FILE_BUF_VALID 0x2000
167
168typedef struct ext2_file *ext2_file_t;
169
170#define EXT2_SEEK_SET 0
171#define EXT2_SEEK_CUR 1
172#define EXT2_SEEK_END 2
173
174/*
Theodore Ts'oa1128472001-01-16 06:56:14 +0000175 * Flags for the ext2_filsys structure and for ext2fs_open()
Theodore Ts'o3839e651997-04-26 13:21:57 +0000176 */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000177#define EXT2_FLAG_RW 0x01
178#define EXT2_FLAG_CHANGED 0x02
179#define EXT2_FLAG_DIRTY 0x04
180#define EXT2_FLAG_VALID 0x08
181#define EXT2_FLAG_IB_DIRTY 0x10
182#define EXT2_FLAG_BB_DIRTY 0x20
Theodore Ts'o5c576471997-04-29 15:29:49 +0000183#define EXT2_FLAG_SWAP_BYTES 0x40
184#define EXT2_FLAG_SWAP_BYTES_READ 0x80
185#define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
186#define EXT2_FLAG_MASTER_SB_ONLY 0x200
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000187#define EXT2_FLAG_FORCE 0x400
Theodore Ts'o43ec8732001-01-03 14:56:46 +0000188#define EXT2_FLAG_SUPER_ONLY 0x800
Theodore Ts'oa1128472001-01-16 06:56:14 +0000189#define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
Theodore Ts'oa78926e2001-05-03 04:02:29 +0000190#define EXT2_FLAG_IMAGE_FILE 0x2000
Theodore Ts'o3839e651997-04-26 13:21:57 +0000191
Theodore Ts'o7f88b041997-04-26 14:48:50 +0000192/*
193 * Special flag in the ext2 inode i_flag field that means that this is
194 * a new inode. (So that ext2_write_inode() can clear extra fields.)
195 */
196#define EXT2_NEW_INODE_FL 0x80000000
197
Theodore Ts'o4e246702000-12-09 14:39:16 +0000198/*
199 * Flags for mkjournal
200 *
201 * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
202 */
203#define EXT2_MKJOURNAL_V1_SUPER 0x0000001
204
Theodore Ts'o3839e651997-04-26 13:21:57 +0000205struct struct_ext2_filsys {
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +0000206 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000207 io_channel io;
208 int flags;
209 char * device_name;
210 struct ext2_super_block * super;
Theodore Ts'o54434922003-12-07 01:28:50 -0500211 unsigned int blocksize;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000212 int fragsize;
Theodore Ts'o2eb374c1998-09-03 01:22:57 +0000213 dgrp_t group_desc_count;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000214 unsigned long desc_blocks;
215 struct ext2_group_desc * group_desc;
216 int inode_blocks_per_group;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000217 ext2fs_inode_bitmap inode_map;
218 ext2fs_block_bitmap block_map;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000219 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
220 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000221 errcode_t (*write_bitmaps)(ext2_filsys fs);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000222 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000223 struct ext2_inode *inode);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000224 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000225 struct ext2_inode *inode);
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400226 ext2_badblocks_list badblocks;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000227 ext2_dblist dblist;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000228 __u32 stride; /* for mke2fs */
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000229 struct ext2_super_block * orig_super;
Theodore Ts'oa78926e2001-05-03 04:02:29 +0000230 struct ext2_image_hdr * image_header;
Theodore Ts'o6a525062001-12-24 09:40:00 -0500231 __u32 umask;
Theodore Ts'o9b9a7802005-12-10 21:50:30 -0500232 time_t now;
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000233 /*
234 * Reserved for future expansion
235 */
Theodore Ts'o32138182005-09-24 20:14:51 -0400236 __u32 reserved[7];
Theodore Ts'o3839e651997-04-26 13:21:57 +0000237
238 /*
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000239 * Reserved for the use of the calling application.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000240 */
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000241 void * priv_data;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000242
243 /*
244 * Inode cache
245 */
246 struct ext2_inode_cache *icache;
Theodore Ts'o1ad54a92004-07-28 21:11:48 -0400247 io_channel image_io;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000248};
249
Theodore Ts'o5953b9d1998-02-01 13:23:02 +0000250#if EXT2_FLAT_INCLUDES
251#include "e2_bitops.h"
252#else
Theodore Ts'o7c2d2562001-05-21 02:54:21 +0000253#include <ext2fs/bitops.h>
Theodore Ts'o5953b9d1998-02-01 13:23:02 +0000254#endif
Theodore Ts'od40259f1997-10-20 00:44:26 +0000255
Theodore Ts'o3839e651997-04-26 13:21:57 +0000256/*
257 * Return flags for the block iterator functions
258 */
259#define BLOCK_CHANGED 1
260#define BLOCK_ABORT 2
261#define BLOCK_ERROR 4
262
263/*
264 * Block interate flags
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000265 *
266 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
267 * function should be called on blocks where the block number is zero.
268 * This is used by ext2fs_expand_dir() to be able to add a new block
269 * to an inode. It can also be used for programs that want to be able
270 * to deal with files that contain "holes".
271 *
272 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
273 * indirect, doubly indirect, etc. blocks should be called after all
274 * of the blocks containined in the indirect blocks are processed.
275 * This is useful if you are going to be deallocating blocks from an
276 * inode.
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000277 *
278 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
279 * called for data blocks only.
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000280 *
281 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
Theodore Ts'o36a43d61998-03-24 16:17:51 +0000282 * ext2fs_block_iterate2 that large files won't be accepted.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000283 */
284#define BLOCK_FLAG_APPEND 1
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000285#define BLOCK_FLAG_HOLE 1
Theodore Ts'o3839e651997-04-26 13:21:57 +0000286#define BLOCK_FLAG_DEPTH_TRAVERSE 2
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000287#define BLOCK_FLAG_DATA_ONLY 4
288
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000289#define BLOCK_FLAG_NO_LARGE 0x1000
290
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000291/*
292 * Magic "block count" return values for the block iterator function.
293 */
294#define BLOCK_COUNT_IND (-1)
295#define BLOCK_COUNT_DIND (-2)
296#define BLOCK_COUNT_TIND (-3)
297#define BLOCK_COUNT_TRANSLATOR (-4)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000298
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000299#if 0
Theodore Ts'o3839e651997-04-26 13:21:57 +0000300/*
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000301 * Flags for ext2fs_move_blocks
302 */
303#define EXT2_BMOVE_GET_DBLIST 0x0001
Theodore Ts'o36f21431997-06-14 07:25:40 +0000304#define EXT2_BMOVE_DEBUG 0x0002
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000305#endif
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000306
307/*
Theodore Ts'of9190c82002-03-12 01:05:06 -0500308 * Flags for directory block reading and writing functions
309 */
310#define EXT2_DIRBLOCK_V2_STRUCT 0x0001
311
312/*
Theodore Ts'o3839e651997-04-26 13:21:57 +0000313 * Return flags for the directory iterator functions
314 */
315#define DIRENT_CHANGED 1
316#define DIRENT_ABORT 2
317#define DIRENT_ERROR 3
318
319/*
320 * Directory iterator flags
321 */
322
323#define DIRENT_FLAG_INCLUDE_EMPTY 1
Theodore Ts'o8bd0c952002-01-03 03:29:19 -0500324#define DIRENT_FLAG_INCLUDE_REMOVED 2
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000325
326#define DIRENT_DOT_FILE 1
327#define DIRENT_DOT_DOT_FILE 2
328#define DIRENT_OTHER_FILE 3
Theodore Ts'o8bd0c952002-01-03 03:29:19 -0500329#define DIRENT_DELETED_FILE 4
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000330
Theodore Ts'o3839e651997-04-26 13:21:57 +0000331/*
332 * Inode scan definitions
333 */
Theodore Ts'of3db3561997-04-26 13:34:30 +0000334typedef struct ext2_struct_inode_scan *ext2_inode_scan;
335
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000336/*
337 * ext2fs_scan flags
338 */
339#define EXT2_SF_CHK_BADBLOCKS 0x0001
340#define EXT2_SF_BAD_INODE_BLK 0x0002
341#define EXT2_SF_BAD_EXTRA_BYTES 0x0004
342#define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
Theodore Ts'o3839e651997-04-26 13:21:57 +0000343
Theodore Ts'of3db3561997-04-26 13:34:30 +0000344/*
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000345 * ext2fs_check_if_mounted flags
346 */
347#define EXT2_MF_MOUNTED 1
348#define EXT2_MF_ISROOT 2
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000349#define EXT2_MF_READONLY 4
Theodore Ts'o07cefe72001-12-24 15:20:22 -0500350#define EXT2_MF_SWAP 8
Theodore Ts'o2fa8f372005-06-05 16:05:22 -0400351#define EXT2_MF_BUSY 16
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000352
353/*
354 * Ext2/linux mode flags. We define them here so that we don't need
355 * to depend on the OS's sys/stat.h, since we may be compiling on a
356 * non-Linux system.
357 */
358#define LINUX_S_IFMT 00170000
359#define LINUX_S_IFSOCK 0140000
360#define LINUX_S_IFLNK 0120000
361#define LINUX_S_IFREG 0100000
362#define LINUX_S_IFBLK 0060000
363#define LINUX_S_IFDIR 0040000
364#define LINUX_S_IFCHR 0020000
365#define LINUX_S_IFIFO 0010000
366#define LINUX_S_ISUID 0004000
367#define LINUX_S_ISGID 0002000
368#define LINUX_S_ISVTX 0001000
369
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000370#define LINUX_S_IRWXU 00700
371#define LINUX_S_IRUSR 00400
372#define LINUX_S_IWUSR 00200
373#define LINUX_S_IXUSR 00100
374
375#define LINUX_S_IRWXG 00070
376#define LINUX_S_IRGRP 00040
377#define LINUX_S_IWGRP 00020
378#define LINUX_S_IXGRP 00010
379
380#define LINUX_S_IRWXO 00007
381#define LINUX_S_IROTH 00004
382#define LINUX_S_IWOTH 00002
383#define LINUX_S_IXOTH 00001
384
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000385#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
386#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
387#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
388#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
389#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
390#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
391#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
392
393/*
Theodore Ts'o819157d2003-01-22 18:25:39 -0500394 * ext2 size of an inode
395 */
396#define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
397
398/*
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000399 * ext2_icount_t abstraction
400 */
401#define EXT2_ICOUNT_OPT_INCREMENT 0x01
402
403typedef struct ext2_icount *ext2_icount_t;
404
405/*
Theodore Ts'o30fab291997-10-25 22:37:42 +0000406 * Flags for ext2fs_bmap
407 */
Theodore Ts'o1d667532004-12-23 13:55:34 -0500408#define BMAP_ALLOC 0x0001
409#define BMAP_SET 0x0002
Theodore Ts'o30fab291997-10-25 22:37:42 +0000410
411/*
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000412 * Flags for imager.c functions
413 */
414#define IMAGER_FLAG_INODEMAP 1
415#define IMAGER_FLAG_SPARSEWRITE 2
416
417/*
Theodore Ts'of3db3561997-04-26 13:34:30 +0000418 * For checking structure magic numbers...
419 */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000420
Theodore Ts'of3db3561997-04-26 13:34:30 +0000421#define EXT2_CHECK_MAGIC(struct, code) \
422 if ((struct)->magic != (code)) return (code)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000423
424
425/*
Theodore Ts'oe5b38a52001-01-01 16:17:12 +0000426 * For ext2 compression support
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000427 */
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000428#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
429#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
430
Theodore Ts'o521e3681997-04-29 17:48:10 +0000431/*
Theodore Ts'o426d7342001-01-13 01:29:05 +0000432 * Features supported by this version of the library
Theodore Ts'o521e3681997-04-29 17:48:10 +0000433 */
Theodore Ts'o3a5f8ea1999-09-14 20:21:26 +0000434#define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
435 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
Theodore Ts'o342d8472001-07-02 11:54:09 -0400436 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
Theodore Ts'od323f8f2004-12-15 14:39:16 -0500437 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
Theodore Ts'o52783e02002-03-11 15:04:45 -0500438 EXT2_FEATURE_COMPAT_DIR_INDEX|\
Theodore Ts'o342d8472001-07-02 11:54:09 -0400439 EXT2_FEATURE_COMPAT_EXT_ATTR)
Theodore Ts'o2fe1efe2000-12-31 13:39:17 +0000440
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000441/* This #ifdef is temporary until compression is fully supported */
442#ifdef ENABLE_COMPRESSION
Theodore Ts'oe589f672000-04-03 13:45:40 +0000443#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
444/* If the below warning bugs you, then have
445 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
446 environment at configure time. */
Theodore Ts'ocdaf1fa2001-01-05 22:23:22 +0000447 #warning "Compression support is experimental"
Theodore Ts'oe589f672000-04-03 13:45:40 +0000448#endif
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000449#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000450 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
Theodore Ts'oa1128472001-01-16 06:56:14 +0000451 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'oc046ac72002-10-20 00:38:57 -0400452 EXT2_FEATURE_INCOMPAT_META_BG|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000453 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000454#else
Theodore Ts'oab146762000-07-07 04:37:35 +0000455#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
Theodore Ts'oa1128472001-01-16 06:56:14 +0000456 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
Theodore Ts'oc046ac72002-10-20 00:38:57 -0400457 EXT2_FEATURE_INCOMPAT_META_BG|\
Theodore Ts'oab146762000-07-07 04:37:35 +0000458 EXT3_FEATURE_INCOMPAT_RECOVER)
Theodore Ts'o5a63dd22000-02-11 15:44:08 +0000459#endif
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000460#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
461 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000462/*
463 * function prototypes
464 */
465
466/* alloc.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000467extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
468 ext2fs_inode_bitmap map, ext2_ino_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000469extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000470 ext2fs_block_bitmap map, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000471extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
Theodore Ts'of3db3561997-04-26 13:34:30 +0000472 blk_t finish, int num,
473 ext2fs_block_bitmap map,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000474 blk_t *ret);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000475extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
476 char *block_buf, blk_t *ret);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000477
Theodore Ts'oef344e12003-11-21 09:02:21 -0500478/* alloc_sb.c */
479extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
480 dgrp_t group,
481 ext2fs_block_bitmap bmap);
482
Theodore Ts'o8bd0c952002-01-03 03:29:19 -0500483/* alloc_stats.c */
484void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
Theodore Ts'o7f961d42002-02-03 01:28:52 -0500485void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
486 int inuse, int isdir);
Theodore Ts'o8bd0c952002-01-03 03:29:19 -0500487void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
488
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000489/* alloc_tables.c */
490extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
Theodore Ts'o2eb374c1998-09-03 01:22:57 +0000491extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000492 ext2fs_block_bitmap bmap);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000493
Theodore Ts'o3839e651997-04-26 13:21:57 +0000494/* badblocks.c */
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400495extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
496extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
Theodore Ts'o54434922003-12-07 01:28:50 -0500497extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400498extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
499extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
500 ext2_u32_iterate *ret);
501extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
502extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
503extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
504extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
505
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000506extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
507 int size);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000508extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
509 blk_t blk);
510extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
511 blk_t blk);
Theodore Ts'o7d7bdd52003-06-24 17:34:02 -0400512extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
513extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000514extern errcode_t
515 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
516 ext2_badblocks_iterate *ret);
517extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
518 blk_t *blk);
519extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000520extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
521 ext2_badblocks_list *dest);
Theodore Ts'o57dca852000-07-04 19:20:25 +0000522extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
523 ext2_badblocks_list bb2);
Theodore Ts'o220c0042003-03-14 00:59:42 -0500524extern int ext2fs_u32_list_count(ext2_u32_list bb);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000525
526/* bb_compat */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000527extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000528extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
529extern int badblocks_list_test(badblocks_list bb, blk_t blk);
530extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
531 badblocks_iterate *ret);
532extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
533extern void badblocks_list_iterate_end(badblocks_iterate iter);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000534extern void badblocks_list_free(badblocks_list bb);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000535
536/* bb_inode.c */
537extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000538 ext2_badblocks_list bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000539
540/* bitmaps.c */
541extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
542extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
543extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
544extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000545extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
546 __u32 end,
547 __u32 real_end,
548 const char *descr,
549 ext2fs_generic_bitmap *ret);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000550extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
551 const char *descr,
552 ext2fs_block_bitmap *ret);
553extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
554 const char *descr,
555 ext2fs_inode_bitmap *ret);
556extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000557 ext2_ino_t end, ext2_ino_t *oend);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000558extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
559 blk_t end, blk_t *oend);
560extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
561extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000562extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
563extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
564
565/* block.c */
566extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000567 ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000568 int flags,
569 char *block_buf,
570 int (*func)(ext2_filsys fs,
571 blk_t *blocknr,
572 int blockcnt,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000573 void *priv_data),
574 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000575errcode_t ext2fs_block_iterate2(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000576 ext2_ino_t ino,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000577 int flags,
578 char *block_buf,
579 int (*func)(ext2_filsys fs,
580 blk_t *blocknr,
Theodore Ts'o03673db1998-06-10 20:39:43 +0000581 e2_blkcnt_t blockcnt,
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000582 blk_t ref_blk,
583 int ref_offset,
584 void *priv_data),
585 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000586
Theodore Ts'o30fab291997-10-25 22:37:42 +0000587/* bmap.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000588extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o30fab291997-10-25 22:37:42 +0000589 struct ext2_inode *inode,
590 char *block_buf, int bmap_flags,
591 blk_t block, blk_t *phys_blk);
592
593
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000594#if 0
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000595/* bmove.c */
596extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
597 ext2fs_block_bitmap reserve,
Theodore Ts'o9941fb71997-06-11 22:27:41 +0000598 ext2fs_block_bitmap alloc_map,
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000599 int flags);
Theodore Ts'o4a31c481998-03-30 01:27:25 +0000600#endif
Theodore Ts'o1e1da291997-06-09 14:51:29 +0000601
Theodore Ts'of3db3561997-04-26 13:34:30 +0000602/* check_desc.c */
603extern errcode_t ext2fs_check_desc(ext2_filsys fs);
604
Theodore Ts'o3839e651997-04-26 13:21:57 +0000605/* closefs.c */
606extern errcode_t ext2fs_close(ext2_filsys fs);
607extern errcode_t ext2fs_flush(ext2_filsys fs);
Theodore Ts'o1b4cd9c2004-12-15 18:06:52 -0500608extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
Theodore Ts'oef344e12003-11-21 09:02:21 -0500609extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
610 dgrp_t group,
611 blk_t *ret_super_blk,
612 blk_t *ret_old_desc_blk,
613 blk_t *ret_new_desc_blk,
614 int *ret_meta_bg);
Theodore Ts'o1b4cd9c2004-12-15 18:06:52 -0500615extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000616
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000617/* cmp_bitmaps.c */
618extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
619 ext2fs_block_bitmap bm2);
620extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
621 ext2fs_inode_bitmap bm2);
622
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000623/* dblist.c */
624
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000625extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000626extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000627extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000628 blk_t blk, int blockcnt);
Theodore Ts'oea1959f2002-08-31 02:32:41 -0400629extern void ext2fs_dblist_sort(ext2_dblist dblist,
630 EXT2_QSORT_TYPE (*sortfunc)(const void *,
631 const void *));
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000632extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
633 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000634 void *priv_data),
635 void *priv_data);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000636extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000637 blk_t blk, int blockcnt);
638extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
639 ext2_dblist *dest);
Theodore Ts'o549860c1997-06-17 03:55:00 +0000640extern int ext2fs_dblist_count(ext2_dblist dblist);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000641
642/* dblist_dir.c */
643extern errcode_t
644 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
645 int flags,
646 char *block_buf,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000647 int (*func)(ext2_ino_t dir,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000648 int entry,
649 struct ext2_dir_entry *dirent,
650 int offset,
651 int blocksize,
652 char *buf,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000653 void *priv_data),
654 void *priv_data);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000655
656/* dirblock.c */
657extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
658 void *buf);
Theodore Ts'of9190c82002-03-12 01:05:06 -0500659extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
660 void *buf, int flags);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000661extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
662 void *buf);
Theodore Ts'of9190c82002-03-12 01:05:06 -0500663extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
664 void *buf, int flags);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000665
Theodore Ts'o52783e02002-03-11 15:04:45 -0500666/* dirhash.c */
667extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
Theodore Ts'ob33278c2002-08-17 10:52:51 -0400668 const __u32 *seed,
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400669 ext2_dirhash_t *ret_hash,
670 ext2_dirhash_t *ret_minor_hash);
Theodore Ts'o52783e02002-03-11 15:04:45 -0500671
672
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000673/* dir_iterate.c */
674extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000675 ext2_ino_t dir,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000676 int flags,
677 char *block_buf,
678 int (*func)(struct ext2_dir_entry *dirent,
679 int offset,
680 int blocksize,
681 char *buf,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000682 void *priv_data),
683 void *priv_data);
Theodore Ts'o8bd0c952002-01-03 03:29:19 -0500684extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
685 ext2_ino_t dir,
686 int flags,
687 char *block_buf,
688 int (*func)(ext2_ino_t dir,
689 int entry,
690 struct ext2_dir_entry *dirent,
691 int offset,
692 int blocksize,
693 char *buf,
694 void *priv_data),
695 void *priv_data);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000696
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000697/* dupfs.c */
698extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000699
Theodore Ts'o3839e651997-04-26 13:21:57 +0000700/* expanddir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000701extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000702
Theodore Ts'o342d8472001-07-02 11:54:09 -0400703/* ext_attr.c */
Theodore Ts'o342d8472001-07-02 11:54:09 -0400704extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
Theodore Ts'o0684a4f2002-08-17 10:19:44 -0400705extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
706 void *buf);
707extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
708 char *block_buf,
709 int adjust, __u32 *newcount);
710
Theodore Ts'o30fab291997-10-25 22:37:42 +0000711/* fileio.c */
Theodore Ts'oa435ec32003-08-21 00:40:26 -0400712extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
713 struct ext2_inode *inode,
714 int flags, ext2_file_t *ret);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000715extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o30fab291997-10-25 22:37:42 +0000716 int flags, ext2_file_t *ret);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000717extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000718extern errcode_t ext2fs_file_close(ext2_file_t file);
Theodore Ts'of12e2852002-02-20 01:06:25 -0500719extern errcode_t ext2fs_file_flush(ext2_file_t file);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000720extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000721 unsigned int wanted, unsigned int *got);
Theodore Ts'of12e2852002-02-20 01:06:25 -0500722extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000723 unsigned int nbytes, unsigned int *written);
Theodore Ts'o819157d2003-01-22 18:25:39 -0500724extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
725 int whence, __u64 *ret_pos);
Theodore Ts'o674a4ee1998-03-23 02:06:52 +0000726extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
727 int whence, ext2_off_t *ret_pos);
Theodore Ts'o819157d2003-01-22 18:25:39 -0500728errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
Theodore Ts'o79a90bd1997-11-03 19:16:55 +0000729extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
730extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
Theodore Ts'o30fab291997-10-25 22:37:42 +0000731
Theodore Ts'ode23aa12000-08-19 17:00:47 +0000732/* finddev.c */
733extern char *ext2fs_find_block_device(dev_t device);
734
Theodore Ts'o4d0f3e12001-01-11 15:48:50 +0000735/* flushb.c */
736extern errcode_t ext2fs_sync_device(int fd, int flushb);
737
Theodore Ts'o3839e651997-04-26 13:21:57 +0000738/* freefs.c */
739extern void ext2fs_free(ext2_filsys fs);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000740extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000741extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
742extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000743extern void ext2fs_free_dblist(ext2_dblist dblist);
Theodore Ts'ob7a00562002-07-20 00:28:07 -0400744extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
745extern void ext2fs_u32_list_free(ext2_u32_list bb);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000746
747/* getsize.c */
748extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
749 blk_t *retblocks);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000750
Theodore Ts'o93d5c382003-05-21 17:28:29 -0400751/* getsectsize.c */
752errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
753
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000754/* imager.c */
755extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
756extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
757extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
758extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
759extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
760extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
761
Theodore Ts'odc8ce342005-01-06 00:04:24 -0500762/* ind_block.c */
763errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
764errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
765
Theodore Ts'o3839e651997-04-26 13:21:57 +0000766/* initialize.c */
767extern errcode_t ext2fs_initialize(const char *name, int flags,
768 struct ext2_super_block *param,
769 io_manager manager, ext2_filsys *ret_fs);
770
Theodore Ts'of12e2852002-02-20 01:06:25 -0500771/* icount.c */
772extern void ext2fs_free_icount(ext2_icount_t icount);
Theodore Ts'o54434922003-12-07 01:28:50 -0500773extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
774 unsigned int size,
Theodore Ts'of12e2852002-02-20 01:06:25 -0500775 ext2_icount_t hint, ext2_icount_t *ret);
Theodore Ts'o54434922003-12-07 01:28:50 -0500776extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
777 unsigned int size,
Theodore Ts'of12e2852002-02-20 01:06:25 -0500778 ext2_icount_t *ret);
779extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
780 __u16 *ret);
781extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
782 __u16 *ret);
783extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
784 __u16 *ret);
785extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
786 __u16 count);
787extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
788errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
789
Theodore Ts'o3839e651997-04-26 13:21:57 +0000790/* inode.c */
Theodore Ts'o72ed1262000-11-12 19:32:20 +0000791extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
Theodore Ts'o73311962005-01-25 23:42:56 -0500792extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
793 ext2_ino_t *ino,
794 struct ext2_inode *inode,
795 int bufsize);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000796extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
797 ext2_inode_scan *ret_scan);
798extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000799extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000800 struct ext2_inode *inode);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000801extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
802 int group);
803extern void ext2fs_set_inode_callback
804 (ext2_inode_scan scan,
805 errcode_t (*done_group)(ext2_filsys fs,
806 ext2_inode_scan scan,
807 dgrp_t group,
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +0000808 void * priv_data),
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000809 void *done_group_data);
810extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
811 int clear_flags);
Theodore Ts'o73311962005-01-25 23:42:56 -0500812extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
813 struct ext2_inode * inode,
814 int bufsize);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000815extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000816 struct ext2_inode * inode);
Theodore Ts'o73311962005-01-25 23:42:56 -0500817extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
818 struct ext2_inode * inode,
819 int bufsize);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000820extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000821 struct ext2_inode * inode);
Theodore Ts'o030970e2005-03-20 20:05:22 -0500822extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
823 struct ext2_inode * inode);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000824extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
825extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000826
Theodore Ts'of12e2852002-02-20 01:06:25 -0500827/* inode_io.c */
828extern io_manager inode_io_manager;
Theodore Ts'o546a1ff2002-03-07 23:52:56 -0500829extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
830 char **name);
Theodore Ts'oa435ec32003-08-21 00:40:26 -0400831extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
832 struct ext2_inode *inode,
833 char **name);
Theodore Ts'of12e2852002-02-20 01:06:25 -0500834
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000835/* ismounted.c */
836extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
Theodore Ts'o43ec8732001-01-03 14:56:46 +0000837extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
838 char *mtpt, int mtlen);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000839
Theodore Ts'o3839e651997-04-26 13:21:57 +0000840/* namei.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000841extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
842 int namelen, char *buf, ext2_ino_t *inode);
843extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
844 const char *name, ext2_ino_t *inode);
845errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
846 const char *name, ext2_ino_t *inode);
847extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
848 ext2_ino_t inode, ext2_ino_t *res_inode);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000849
850/* native.c */
851int ext2fs_native_flag(void);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000852
853/* newdir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000854extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
855 ext2_ino_t parent_ino, char **block);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000856
857/* mkdir.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000858extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000859 const char *name);
860
Theodore Ts'od3cd93c2000-10-24 18:33:16 +0000861/* mkjournal.c */
Theodore Ts'oa1128472001-01-16 06:56:14 +0000862extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
863 __u32 size, int flags,
864 char **ret_jsb);
865extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
866 ext2_filsys journal_dev);
Theodore Ts'o31a17b32001-01-03 13:04:12 +0000867extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
868 int flags);
Theodore Ts'od3cd93c2000-10-24 18:33:16 +0000869
Theodore Ts'o3839e651997-04-26 13:21:57 +0000870/* openfs.c */
871extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
Theodore Ts'o54434922003-12-07 01:28:50 -0500872 unsigned int block_size, io_manager manager,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000873 ext2_filsys *ret_fs);
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500874extern errcode_t ext2fs_open2(const char *name, const char *io_options,
875 int flags, int superblock,
876 unsigned int block_size, io_manager manager,
877 ext2_filsys *ret_fs);
Theodore Ts'oc046ac72002-10-20 00:38:57 -0400878extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
879 dgrp_t i);
Theodore Ts'o1ad54a92004-07-28 21:11:48 -0400880errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
881errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
882errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000883
884/* get_pathname.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000885extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000886 char **name);
887
888/* link.c */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000889errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
890 ext2_ino_t ino, int flags);
891errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
892 ext2_ino_t ino, int flags);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000893
894/* read_bb.c */
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000895extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
896 ext2_badblocks_list *bb_list);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000897
898/* read_bb_file.c */
Theodore Ts'o57dca852000-07-04 19:20:25 +0000899extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
900 ext2_badblocks_list *bb_list,
Theodore Ts'o50cd7e02002-07-14 16:00:50 -0400901 void *priv_data,
Theodore Ts'o57dca852000-07-04 19:20:25 +0000902 void (*invalid)(ext2_filsys fs,
903 blk_t blk,
904 char *badstr,
Theodore Ts'o50cd7e02002-07-14 16:00:50 -0400905 void *priv_data));
Theodore Ts'o3839e651997-04-26 13:21:57 +0000906extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000907 ext2_badblocks_list *bb_list,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000908 void (*invalid)(ext2_filsys fs,
909 blk_t blk));
910
Theodore Ts'od323f8f2004-12-15 14:39:16 -0500911/* res_gdt.c */
912extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
913
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000914/* rs_bitmap.c */
915extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
916 __u32 new_real_end,
917 ext2fs_generic_bitmap bmap);
918extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
919 ext2fs_inode_bitmap bmap);
920extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
921 ext2fs_block_bitmap bmap);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000922extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
923 ext2fs_generic_bitmap *dest);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000924
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000925/* swapfs.c */
Theodore Ts'o73311962005-01-25 23:42:56 -0500926extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
927 int has_header);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000928extern void ext2fs_swap_super(struct ext2_super_block * super);
929extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
Theodore Ts'o73311962005-01-25 23:42:56 -0500930extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
931 struct ext2_inode_large *f, int hostorder,
932 int bufsize);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000933extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
934 struct ext2_inode *f, int hostorder);
935
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000936/* valid_blk.c */
Theodore Ts'o521e3681997-04-29 17:48:10 +0000937extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
938
939/* version.c */
940extern int ext2fs_parse_version_string(const char *ver_string);
941extern int ext2fs_get_library_version(const char **ver_string,
942 const char **date_string);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000943
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000944/* write_bb_file.c */
945extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
946 unsigned int flags,
947 FILE *f);
948
949
Theodore Ts'o3839e651997-04-26 13:21:57 +0000950/* inline functions */
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400951extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
952extern errcode_t ext2fs_free_mem(void *ptr);
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000953extern errcode_t ext2fs_resize_mem(unsigned long old_size,
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400954 unsigned long size, void *ptr);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000955extern void ext2fs_mark_super_dirty(ext2_filsys fs);
956extern void ext2fs_mark_changed(ext2_filsys fs);
957extern int ext2fs_test_changed(ext2_filsys fs);
958extern void ext2fs_mark_valid(ext2_filsys fs);
959extern void ext2fs_unmark_valid(ext2_filsys fs);
960extern int ext2fs_test_valid(ext2_filsys fs);
961extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
962extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
963extern int ext2fs_test_ib_dirty(ext2_filsys fs);
964extern int ext2fs_test_bb_dirty(ext2_filsys fs);
965extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000966extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
Theodore Ts'o0684a4f2002-08-17 10:19:44 -0400967extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
968 struct ext2_inode *inode);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000969
970/*
971 * The actual inlined functions definitions themselves...
972 *
973 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
974 * functions at all!
975 */
976#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
977#ifdef INCLUDE_INLINE_FUNCS
978#define _INLINE_ extern
979#else
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000980#ifdef __GNUC__
Theodore Ts'o3839e651997-04-26 13:21:57 +0000981#define _INLINE_ extern __inline__
Theodore Ts'o76f875d1998-04-27 01:41:13 +0000982#else /* For Watcom C */
983#define _INLINE_ extern inline
984#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +0000985#endif
986
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000987#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
Matthias Andree68a7f952005-09-06 05:59:52 -0400988#include <string.h>
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000989/*
990 * Allocate memory
991 */
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400992_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000993{
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400994 void **pp = (void **)ptr;
995
996 *pp = malloc(size);
997 if (!*pp)
Theodore Ts'o291c9041997-10-31 06:17:08 +0000998 return EXT2_ET_NO_MEMORY;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000999 return 0;
1000}
1001
1002/*
1003 * Free memory
1004 */
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -04001005_INLINE_ errcode_t ext2fs_free_mem(void *ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +00001006{
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -04001007 void **pp = (void **)ptr;
1008
1009 free(*pp);
1010 *pp = 0;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +00001011 return 0;
1012}
1013
1014/*
1015 * Resize memory
1016 */
Theodore Ts'oe47fd842004-02-21 21:04:30 -05001017_INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -04001018 unsigned long size, void *ptr)
Theodore Ts'o7b4e4531997-10-26 03:41:24 +00001019{
1020 void *p;
1021
Stephen Tweedie39c191f2005-06-27 11:47:21 -04001022 /* Use "memcpy" for pointer assignments here to avoid problems
1023 * with C99 strict type aliasing rules. */
1024 memcpy(&p, ptr, sizeof (p));
1025 p = realloc(p, size);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +00001026 if (!p)
Theodore Ts'o291c9041997-10-31 06:17:08 +00001027 return EXT2_ET_NO_MEMORY;
Stephen Tweedie39c191f2005-06-27 11:47:21 -04001028 memcpy(ptr, &p, sizeof (p));
Theodore Ts'o7b4e4531997-10-26 03:41:24 +00001029 return 0;
1030}
1031#endif /* Custom memory routines */
1032
Theodore Ts'o3839e651997-04-26 13:21:57 +00001033/*
1034 * Mark a filesystem superblock as dirty
1035 */
1036_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1037{
1038 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1039}
1040
1041/*
1042 * Mark a filesystem as changed
1043 */
1044_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1045{
1046 fs->flags |= EXT2_FLAG_CHANGED;
1047}
1048
1049/*
1050 * Check to see if a filesystem has changed
1051 */
1052_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1053{
1054 return (fs->flags & EXT2_FLAG_CHANGED);
1055}
1056
1057/*
1058 * Mark a filesystem as valid
1059 */
1060_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1061{
1062 fs->flags |= EXT2_FLAG_VALID;
1063}
1064
1065/*
1066 * Mark a filesystem as NOT valid
1067 */
1068_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1069{
1070 fs->flags &= ~EXT2_FLAG_VALID;
1071}
1072
1073/*
1074 * Check to see if a filesystem is valid
1075 */
1076_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1077{
1078 return (fs->flags & EXT2_FLAG_VALID);
1079}
1080
1081/*
1082 * Mark the inode bitmap as dirty
1083 */
1084_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1085{
1086 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1087}
1088
1089/*
1090 * Mark the block bitmap as dirty
1091 */
1092_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1093{
1094 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1095}
1096
1097/*
1098 * Check to see if a filesystem's inode bitmap is dirty
1099 */
1100_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1101{
1102 return (fs->flags & EXT2_FLAG_IB_DIRTY);
1103}
1104
1105/*
1106 * Check to see if a filesystem's block bitmap is dirty
1107 */
1108_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1109{
1110 return (fs->flags & EXT2_FLAG_BB_DIRTY);
1111}
1112
1113/*
1114 * Return the group # of a block
1115 */
1116_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1117{
1118 return (blk - fs->super->s_first_data_block) /
1119 fs->super->s_blocks_per_group;
1120}
1121
1122/*
1123 * Return the group # of an inode number
1124 */
Theodore Ts'o31dbecd2001-01-11 04:54:39 +00001125_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
Theodore Ts'o3839e651997-04-26 13:21:57 +00001126{
1127 return (ino - 1) / fs->super->s_inodes_per_group;
1128}
Theodore Ts'o0684a4f2002-08-17 10:19:44 -04001129
1130_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1131 struct ext2_inode *inode)
1132{
1133 return inode->i_blocks -
1134 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1135}
Theodore Ts'o3839e651997-04-26 13:21:57 +00001136#undef _INLINE_
1137#endif
1138
Theodore Ts'ofa7ef712000-05-19 02:11:41 +00001139#ifdef __cplusplus
1140}
1141#endif
1142
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +00001143#endif /* _EXT2FS_EXT2FS_H */