Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ext2fs.h --- ext2fs |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 3 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. |
| 5 | * |
| 6 | * %Begin-Header% |
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame^] | 7 | * This file may be redistributed under the terms of the GNU Library |
| 8 | * General Public License, version 2. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Theodore Ts'o | 9abd2ce | 1998-02-16 22:00:37 +0000 | [diff] [blame] | 12 | #ifndef _EXT2FS_EXT2FS_H |
| 13 | #define _EXT2FS_EXT2FS_H |
| 14 | |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 15 | #ifdef __GNUC__ |
| 16 | #define EXT2FS_ATTR(x) __attribute__(x) |
| 17 | #else |
| 18 | #define EXT2FS_ATTR(x) |
| 19 | #endif |
| 20 | |
Theodore Ts'o | fa7ef71 | 2000-05-19 02:11:41 +0000 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 25 | /* |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 26 | * Non-GNU C compilers won't necessarily understand inline |
| 27 | */ |
Theodore Ts'o | 76f875d | 1998-04-27 01:41:13 +0000 | [diff] [blame] | 28 | #if (!defined(__GNUC__) && !defined(__WATCOMC__)) |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 29 | #define NO_INLINE_FUNCS |
| 30 | #endif |
| 31 | |
| 32 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 33 | * Where the master copy of the superblock is located, and how big |
| 34 | * superblocks are supposed to be. We define SUPERBLOCK_SIZE because |
| 35 | * the size of the superblock structure is not necessarily trustworthy |
| 36 | * (some versions have the padding set up so that the superblock is |
| 37 | * 1032 bytes long). |
| 38 | */ |
| 39 | #define SUPERBLOCK_OFFSET 1024 |
| 40 | #define SUPERBLOCK_SIZE 1024 |
| 41 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 42 | /* |
| 43 | * The last ext2fs revision level that this version of the library is |
| 44 | * able to support. |
| 45 | */ |
Theodore Ts'o | e5b38a5 | 2001-01-01 16:17:12 +0000 | [diff] [blame] | 46 | #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 47 | |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 48 | #ifdef HAVE_SYS_TYPES_H |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 49 | #include <sys/types.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 52 | #include <stdio.h> |
Theodore Ts'o | 5be8dc2 | 1997-12-01 18:24:10 +0000 | [diff] [blame] | 53 | #include <stdlib.h> |
Theodore Ts'o | a82a570 | 2005-11-14 14:49:15 -0500 | [diff] [blame] | 54 | #include <string.h> |
Theodore Ts'o | 5953b9d | 1998-02-01 13:23:02 +0000 | [diff] [blame] | 55 | |
| 56 | #if EXT2_FLAT_INCLUDES |
| 57 | #include "e2_types.h" |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 58 | #include "ext2_fs.h" |
Theodore Ts'o | 89dd657 | 2006-11-12 22:54:35 -0500 | [diff] [blame] | 59 | #include "ext3_extents.h" |
Theodore Ts'o | 5953b9d | 1998-02-01 13:23:02 +0000 | [diff] [blame] | 60 | #else |
Theodore Ts'o | 797f5ef | 2001-06-01 23:49:46 +0000 | [diff] [blame] | 61 | #include <ext2fs/ext2_types.h> |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 62 | #include <ext2fs/ext2_fs.h> |
Theodore Ts'o | 89dd657 | 2006-11-12 22:54:35 -0500 | [diff] [blame] | 63 | #include <ext2fs/ext3_extents.h> |
Theodore Ts'o | e589f67 | 2000-04-03 13:45:40 +0000 | [diff] [blame] | 64 | #endif /* EXT2_FLAT_INCLUDES */ |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 65 | |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 66 | typedef __u32 ext2_ino_t; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 67 | typedef __u32 blk_t; |
Theodore Ts'o | eac91b3 | 2007-10-14 11:23:20 -0400 | [diff] [blame] | 68 | typedef __u64 blk64_t; |
Theodore Ts'o | 2eb374c | 1998-09-03 01:22:57 +0000 | [diff] [blame] | 69 | typedef __u32 dgrp_t; |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 70 | typedef __u32 ext2_off_t; |
Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 71 | typedef __s64 e2_blkcnt_t; |
Theodore Ts'o | 52783e0 | 2002-03-11 15:04:45 -0500 | [diff] [blame] | 72 | typedef __u32 ext2_dirhash_t; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 73 | |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 74 | #if EXT2_FLAT_INCLUDES |
| 75 | #include "com_err.h" |
| 76 | #include "ext2_io.h" |
| 77 | #include "ext2_err.h" |
Andreas Dilger | fefaef3 | 2008-02-02 01:16:32 -0700 | [diff] [blame] | 78 | #include "ext2_ext_attr.h" |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 79 | #else |
Theodore Ts'o | 7c2d256 | 2001-05-21 02:54:21 +0000 | [diff] [blame] | 80 | #include <et/com_err.h> |
| 81 | #include <ext2fs/ext2_io.h> |
| 82 | #include <ext2fs/ext2_err.h> |
Andreas Dilger | fefaef3 | 2008-02-02 01:16:32 -0700 | [diff] [blame] | 83 | #include <ext2fs/ext2_ext_attr.h> |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 84 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 85 | |
Theodore Ts'o | 4c77fe5 | 1998-04-30 17:35:59 +0000 | [diff] [blame] | 86 | /* |
| 87 | * Portability help for Microsoft Visual C++ |
| 88 | */ |
| 89 | #ifdef _MSC_VER |
| 90 | #define EXT2_QSORT_TYPE int __cdecl |
| 91 | #else |
| 92 | #define EXT2_QSORT_TYPE int |
| 93 | #endif |
| 94 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 95 | typedef struct struct_ext2_filsys *ext2_filsys; |
| 96 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 97 | #define EXT2FS_MARK_ERROR 0 |
| 98 | #define EXT2FS_UNMARK_ERROR 1 |
| 99 | #define EXT2FS_TEST_ERROR 2 |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 100 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 101 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 102 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 103 | typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 104 | |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 105 | #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) |
Andreas Dilger | 067911a | 2006-07-15 22:08:20 -0400 | [diff] [blame] | 106 | |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 107 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 108 | /* |
Andreas Dilger | 067911a | 2006-07-15 22:08:20 -0400 | [diff] [blame] | 109 | * Badblocks list definitions |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 110 | */ |
| 111 | |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 112 | typedef struct ext2_struct_u32_list *ext2_badblocks_list; |
| 113 | typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate; |
| 114 | |
| 115 | typedef struct ext2_struct_u32_list *ext2_u32_list; |
| 116 | typedef struct ext2_struct_u32_iterate *ext2_u32_iterate; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 117 | |
| 118 | /* old */ |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 119 | typedef struct ext2_struct_u32_list *badblocks_list; |
| 120 | typedef struct ext2_struct_u32_iterate *badblocks_iterate; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 121 | |
| 122 | #define BADBLOCKS_FLAG_DIRTY 1 |
| 123 | |
| 124 | /* |
| 125 | * ext2_dblist structure and abstractions (see dblist.c) |
| 126 | */ |
| 127 | struct ext2_db_entry { |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 128 | ext2_ino_t ino; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 129 | blk_t blk; |
| 130 | int blockcnt; |
| 131 | }; |
| 132 | |
| 133 | typedef struct ext2_struct_dblist *ext2_dblist; |
| 134 | |
| 135 | #define DBLIST_ABORT 1 |
| 136 | |
| 137 | /* |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 138 | * ext2_fileio definitions |
| 139 | */ |
| 140 | |
| 141 | #define EXT2_FILE_WRITE 0x0001 |
| 142 | #define EXT2_FILE_CREATE 0x0002 |
| 143 | |
| 144 | #define EXT2_FILE_MASK 0x00FF |
| 145 | |
| 146 | #define EXT2_FILE_BUF_DIRTY 0x4000 |
| 147 | #define EXT2_FILE_BUF_VALID 0x2000 |
| 148 | |
| 149 | typedef struct ext2_file *ext2_file_t; |
| 150 | |
| 151 | #define EXT2_SEEK_SET 0 |
| 152 | #define EXT2_SEEK_CUR 1 |
| 153 | #define EXT2_SEEK_END 2 |
| 154 | |
| 155 | /* |
Theodore Ts'o | a112847 | 2001-01-16 06:56:14 +0000 | [diff] [blame] | 156 | * Flags for the ext2_filsys structure and for ext2fs_open() |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 157 | */ |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 158 | #define EXT2_FLAG_RW 0x01 |
| 159 | #define EXT2_FLAG_CHANGED 0x02 |
| 160 | #define EXT2_FLAG_DIRTY 0x04 |
| 161 | #define EXT2_FLAG_VALID 0x08 |
| 162 | #define EXT2_FLAG_IB_DIRTY 0x10 |
| 163 | #define EXT2_FLAG_BB_DIRTY 0x20 |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 164 | #define EXT2_FLAG_SWAP_BYTES 0x40 |
| 165 | #define EXT2_FLAG_SWAP_BYTES_READ 0x80 |
| 166 | #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100 |
| 167 | #define EXT2_FLAG_MASTER_SB_ONLY 0x200 |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 168 | #define EXT2_FLAG_FORCE 0x400 |
Theodore Ts'o | 43ec873 | 2001-01-03 14:56:46 +0000 | [diff] [blame] | 169 | #define EXT2_FLAG_SUPER_ONLY 0x800 |
Theodore Ts'o | a112847 | 2001-01-16 06:56:14 +0000 | [diff] [blame] | 170 | #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000 |
Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 171 | #define EXT2_FLAG_IMAGE_FILE 0x2000 |
Theodore Ts'o | 39c47ce | 2006-03-18 19:16:10 -0500 | [diff] [blame] | 172 | #define EXT2_FLAG_EXCLUSIVE 0x4000 |
Theodore Ts'o | cf8272e | 2006-11-12 23:26:46 -0500 | [diff] [blame] | 173 | #define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000 |
Theodore Ts'o | ab52e12 | 2008-02-26 20:45:36 -0500 | [diff] [blame] | 174 | #define EXT2_FLAG_NOFREE_ON_ERROR 0x10000 |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 175 | |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 176 | /* |
| 177 | * Special flag in the ext2 inode i_flag field that means that this is |
| 178 | * a new inode. (So that ext2_write_inode() can clear extra fields.) |
| 179 | */ |
| 180 | #define EXT2_NEW_INODE_FL 0x80000000 |
| 181 | |
Theodore Ts'o | 4e24670 | 2000-12-09 14:39:16 +0000 | [diff] [blame] | 182 | /* |
| 183 | * Flags for mkjournal |
| 184 | * |
| 185 | * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock |
| 186 | */ |
| 187 | #define EXT2_MKJOURNAL_V1_SUPER 0x0000001 |
| 188 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 189 | struct struct_ext2_filsys { |
Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 190 | errcode_t magic; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 191 | io_channel io; |
| 192 | int flags; |
| 193 | char * device_name; |
| 194 | struct ext2_super_block * super; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 195 | unsigned int blocksize; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 196 | int fragsize; |
Theodore Ts'o | 2eb374c | 1998-09-03 01:22:57 +0000 | [diff] [blame] | 197 | dgrp_t group_desc_count; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 198 | unsigned long desc_blocks; |
| 199 | struct ext2_group_desc * group_desc; |
| 200 | int inode_blocks_per_group; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 201 | ext2fs_inode_bitmap inode_map; |
| 202 | ext2fs_block_bitmap block_map; |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 203 | errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks); |
| 204 | errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 205 | errcode_t (*write_bitmaps)(ext2_filsys fs); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 206 | errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 207 | struct ext2_inode *inode); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 208 | errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 209 | struct ext2_inode *inode); |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 210 | ext2_badblocks_list badblocks; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 211 | ext2_dblist dblist; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 212 | __u32 stride; /* for mke2fs */ |
Theodore Ts'o | c180ac8 | 2000-10-26 20:24:43 +0000 | [diff] [blame] | 213 | struct ext2_super_block * orig_super; |
Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 214 | struct ext2_image_hdr * image_header; |
Theodore Ts'o | 6a52506 | 2001-12-24 09:40:00 -0500 | [diff] [blame] | 215 | __u32 umask; |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 216 | time_t now; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 217 | /* |
| 218 | * Reserved for future expansion |
| 219 | */ |
Theodore Ts'o | 3213818 | 2005-09-24 20:14:51 -0400 | [diff] [blame] | 220 | __u32 reserved[7]; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 221 | |
| 222 | /* |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 223 | * Reserved for the use of the calling application. |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 224 | */ |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 225 | void * priv_data; |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * Inode cache |
| 229 | */ |
| 230 | struct ext2_inode_cache *icache; |
Theodore Ts'o | 1ad54a9 | 2004-07-28 21:11:48 -0400 | [diff] [blame] | 231 | io_channel image_io; |
Theodore Ts'o | f5c562e | 2008-06-02 17:21:37 -0400 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * More callback functions |
| 235 | */ |
| 236 | errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal, |
| 237 | blk64_t *ret); |
| 238 | void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
Theodore Ts'o | 5953b9d | 1998-02-01 13:23:02 +0000 | [diff] [blame] | 241 | #if EXT2_FLAT_INCLUDES |
| 242 | #include "e2_bitops.h" |
| 243 | #else |
Theodore Ts'o | 7c2d256 | 2001-05-21 02:54:21 +0000 | [diff] [blame] | 244 | #include <ext2fs/bitops.h> |
Theodore Ts'o | 5953b9d | 1998-02-01 13:23:02 +0000 | [diff] [blame] | 245 | #endif |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 246 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 247 | /* |
| 248 | * Return flags for the block iterator functions |
| 249 | */ |
| 250 | #define BLOCK_CHANGED 1 |
| 251 | #define BLOCK_ABORT 2 |
| 252 | #define BLOCK_ERROR 4 |
| 253 | |
| 254 | /* |
| 255 | * Block interate flags |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 256 | * |
| 257 | * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator |
| 258 | * function should be called on blocks where the block number is zero. |
| 259 | * This is used by ext2fs_expand_dir() to be able to add a new block |
| 260 | * to an inode. It can also be used for programs that want to be able |
| 261 | * to deal with files that contain "holes". |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 262 | * |
Theodore Ts'o | 7447921 | 2006-03-18 08:26:36 -0500 | [diff] [blame] | 263 | * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for |
| 264 | * the indirect, doubly indirect, etc. blocks should be called after |
| 265 | * all of the blocks containined in the indirect blocks are processed. |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 266 | * This is useful if you are going to be deallocating blocks from an |
| 267 | * inode. |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 268 | * |
| 269 | * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be |
| 270 | * called for data blocks only. |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 271 | * |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 272 | * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not |
Theodore Ts'o | 357d186 | 2008-02-02 21:26:54 -0500 | [diff] [blame] | 273 | * modify returned block number. |
| 274 | * |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 275 | * BLOCK_FLAG_NO_LARGE is for internal use only. It informs |
Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 276 | * ext2fs_block_iterate2 that large files won't be accepted. |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 277 | */ |
| 278 | #define BLOCK_FLAG_APPEND 1 |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 279 | #define BLOCK_FLAG_HOLE 1 |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 280 | #define BLOCK_FLAG_DEPTH_TRAVERSE 2 |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 281 | #define BLOCK_FLAG_DATA_ONLY 4 |
Theodore Ts'o | 357d186 | 2008-02-02 21:26:54 -0500 | [diff] [blame] | 282 | #define BLOCK_FLAG_READ_ONLY 8 |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 283 | |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 284 | #define BLOCK_FLAG_NO_LARGE 0x1000 |
| 285 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 286 | /* |
| 287 | * Magic "block count" return values for the block iterator function. |
| 288 | */ |
| 289 | #define BLOCK_COUNT_IND (-1) |
| 290 | #define BLOCK_COUNT_DIND (-2) |
| 291 | #define BLOCK_COUNT_TIND (-3) |
| 292 | #define BLOCK_COUNT_TRANSLATOR (-4) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 293 | |
Theodore Ts'o | 4a31c48 | 1998-03-30 01:27:25 +0000 | [diff] [blame] | 294 | #if 0 |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 295 | /* |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 296 | * Flags for ext2fs_move_blocks |
| 297 | */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 298 | #define EXT2_BMOVE_GET_DBLIST 0x0001 |
Theodore Ts'o | 36f2143 | 1997-06-14 07:25:40 +0000 | [diff] [blame] | 299 | #define EXT2_BMOVE_DEBUG 0x0002 |
Theodore Ts'o | 4a31c48 | 1998-03-30 01:27:25 +0000 | [diff] [blame] | 300 | #endif |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 301 | |
| 302 | /* |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 303 | * Generic (non-filesystem layout specific) extents structure |
| 304 | */ |
| 305 | |
| 306 | #define EXT2_EXTENT_FLAGS_LEAF 0x0001 |
| 307 | #define EXT2_EXTENT_FLAGS_UNINIT 0x0002 |
| 308 | #define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004 |
| 309 | |
| 310 | struct ext2fs_extent { |
| 311 | blk64_t e_pblk; /* first physical block */ |
| 312 | blk64_t e_lblk; /* first logical block extent covers */ |
| 313 | __u32 e_len; /* number of blocks covered by extent */ |
| 314 | __u32 e_flags; /* extent flags */ |
| 315 | }; |
| 316 | |
| 317 | typedef struct ext2_extent_handle *ext2_extent_handle_t; |
| 318 | typedef struct ext2_extent_path *ext2_extent_path_t; |
| 319 | |
| 320 | /* |
| 321 | * Flags used by ext2fs_extent_get() |
| 322 | */ |
| 323 | #define EXT2_EXTENT_CURRENT 0x0000 |
| 324 | #define EXT2_EXTENT_MOVE_MASK 0x000F |
| 325 | #define EXT2_EXTENT_ROOT 0x0001 |
| 326 | #define EXT2_EXTENT_LAST_LEAF 0x0002 |
| 327 | #define EXT2_EXTENT_FIRST_SIB 0x0003 |
| 328 | #define EXT2_EXTENT_LAST_SIB 0x0004 |
| 329 | #define EXT2_EXTENT_NEXT_SIB 0x0005 |
| 330 | #define EXT2_EXTENT_PREV_SIB 0x0006 |
| 331 | #define EXT2_EXTENT_NEXT_LEAF 0x0007 |
| 332 | #define EXT2_EXTENT_PREV_LEAF 0x0008 |
| 333 | #define EXT2_EXTENT_NEXT 0x0009 |
| 334 | #define EXT2_EXTENT_PREV 0x000A |
| 335 | #define EXT2_EXTENT_UP 0x000B |
| 336 | #define EXT2_EXTENT_DOWN 0x000C |
| 337 | #define EXT2_EXTENT_DOWN_AND_LAST 0x000D |
| 338 | |
| 339 | /* |
| 340 | * Flags used by ext2fs_extent_insert() |
| 341 | */ |
Eric Sandeen | 01229db | 2008-05-20 10:15:27 -0500 | [diff] [blame] | 342 | #define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */ |
| 343 | #define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */ |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 344 | |
| 345 | /* |
Eric Sandeen | c802ad9 | 2008-05-20 16:13:41 -0500 | [diff] [blame] | 346 | * Flags used by ext2fs_extent_delete() |
| 347 | */ |
| 348 | #define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extnt gone */ |
| 349 | |
| 350 | /* |
Eric Sandeen | f4e9963 | 2008-05-20 10:17:46 -0500 | [diff] [blame] | 351 | * Flags used by ext2fs_extent_set_bmap() |
| 352 | */ |
| 353 | #define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001 |
| 354 | |
| 355 | /* |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 356 | * Data structure returned by ext2fs_extent_get_info() |
| 357 | */ |
| 358 | struct ext2_extent_info { |
| 359 | int curr_entry; |
| 360 | int curr_level; |
| 361 | int num_entries; |
| 362 | int max_entries; |
| 363 | int max_depth; |
| 364 | int bytes_avail; |
| 365 | blk64_t max_lblk; |
| 366 | blk64_t max_pblk; |
| 367 | __u32 max_len; |
| 368 | __u32 max_uninit_len; |
| 369 | }; |
| 370 | |
| 371 | /* |
Theodore Ts'o | f9190c8 | 2002-03-12 01:05:06 -0500 | [diff] [blame] | 372 | * Flags for directory block reading and writing functions |
| 373 | */ |
| 374 | #define EXT2_DIRBLOCK_V2_STRUCT 0x0001 |
| 375 | |
| 376 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 377 | * Return flags for the directory iterator functions |
| 378 | */ |
| 379 | #define DIRENT_CHANGED 1 |
| 380 | #define DIRENT_ABORT 2 |
| 381 | #define DIRENT_ERROR 3 |
| 382 | |
| 383 | /* |
| 384 | * Directory iterator flags |
| 385 | */ |
| 386 | |
| 387 | #define DIRENT_FLAG_INCLUDE_EMPTY 1 |
Theodore Ts'o | 8bd0c95 | 2002-01-03 03:29:19 -0500 | [diff] [blame] | 388 | #define DIRENT_FLAG_INCLUDE_REMOVED 2 |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 389 | |
| 390 | #define DIRENT_DOT_FILE 1 |
| 391 | #define DIRENT_DOT_DOT_FILE 2 |
| 392 | #define DIRENT_OTHER_FILE 3 |
Theodore Ts'o | 8bd0c95 | 2002-01-03 03:29:19 -0500 | [diff] [blame] | 393 | #define DIRENT_DELETED_FILE 4 |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 394 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 395 | /* |
| 396 | * Inode scan definitions |
| 397 | */ |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 398 | typedef struct ext2_struct_inode_scan *ext2_inode_scan; |
| 399 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 400 | /* |
| 401 | * ext2fs_scan flags |
| 402 | */ |
| 403 | #define EXT2_SF_CHK_BADBLOCKS 0x0001 |
| 404 | #define EXT2_SF_BAD_INODE_BLK 0x0002 |
| 405 | #define EXT2_SF_BAD_EXTRA_BYTES 0x0004 |
| 406 | #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008 |
Theodore Ts'o | f5fa200 | 2006-05-08 20:17:26 -0400 | [diff] [blame] | 407 | #define EXT2_SF_DO_LAZY 0x0010 |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 408 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 409 | /* |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 410 | * ext2fs_check_if_mounted flags |
| 411 | */ |
| 412 | #define EXT2_MF_MOUNTED 1 |
| 413 | #define EXT2_MF_ISROOT 2 |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 414 | #define EXT2_MF_READONLY 4 |
Theodore Ts'o | 07cefe7 | 2001-12-24 15:20:22 -0500 | [diff] [blame] | 415 | #define EXT2_MF_SWAP 8 |
Theodore Ts'o | 2fa8f37 | 2005-06-05 16:05:22 -0400 | [diff] [blame] | 416 | #define EXT2_MF_BUSY 16 |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 417 | |
| 418 | /* |
| 419 | * Ext2/linux mode flags. We define them here so that we don't need |
| 420 | * to depend on the OS's sys/stat.h, since we may be compiling on a |
| 421 | * non-Linux system. |
| 422 | */ |
| 423 | #define LINUX_S_IFMT 00170000 |
| 424 | #define LINUX_S_IFSOCK 0140000 |
| 425 | #define LINUX_S_IFLNK 0120000 |
| 426 | #define LINUX_S_IFREG 0100000 |
| 427 | #define LINUX_S_IFBLK 0060000 |
| 428 | #define LINUX_S_IFDIR 0040000 |
| 429 | #define LINUX_S_IFCHR 0020000 |
| 430 | #define LINUX_S_IFIFO 0010000 |
| 431 | #define LINUX_S_ISUID 0004000 |
| 432 | #define LINUX_S_ISGID 0002000 |
| 433 | #define LINUX_S_ISVTX 0001000 |
| 434 | |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 435 | #define LINUX_S_IRWXU 00700 |
| 436 | #define LINUX_S_IRUSR 00400 |
| 437 | #define LINUX_S_IWUSR 00200 |
| 438 | #define LINUX_S_IXUSR 00100 |
| 439 | |
| 440 | #define LINUX_S_IRWXG 00070 |
| 441 | #define LINUX_S_IRGRP 00040 |
| 442 | #define LINUX_S_IWGRP 00020 |
| 443 | #define LINUX_S_IXGRP 00010 |
| 444 | |
| 445 | #define LINUX_S_IRWXO 00007 |
| 446 | #define LINUX_S_IROTH 00004 |
| 447 | #define LINUX_S_IWOTH 00002 |
| 448 | #define LINUX_S_IXOTH 00001 |
| 449 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 450 | #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK) |
| 451 | #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG) |
| 452 | #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR) |
| 453 | #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR) |
| 454 | #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK) |
| 455 | #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO) |
| 456 | #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK) |
| 457 | |
| 458 | /* |
Theodore Ts'o | 819157d | 2003-01-22 18:25:39 -0500 | [diff] [blame] | 459 | * ext2 size of an inode |
| 460 | */ |
| 461 | #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32)) |
| 462 | |
| 463 | /* |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 464 | * ext2_icount_t abstraction |
| 465 | */ |
| 466 | #define EXT2_ICOUNT_OPT_INCREMENT 0x01 |
| 467 | |
| 468 | typedef struct ext2_icount *ext2_icount_t; |
| 469 | |
| 470 | /* |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 471 | * Flags for ext2fs_bmap |
| 472 | */ |
Theodore Ts'o | 1d66753 | 2004-12-23 13:55:34 -0500 | [diff] [blame] | 473 | #define BMAP_ALLOC 0x0001 |
| 474 | #define BMAP_SET 0x0002 |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 475 | |
| 476 | /* |
Theodore Ts'o | cc9bf5d | 2008-02-18 14:59:45 -0500 | [diff] [blame] | 477 | * Returned flags from ext2fs_bmap |
| 478 | */ |
| 479 | #define BMAP_RET_UNINIT 0x0001 |
| 480 | |
| 481 | /* |
Theodore Ts'o | 72ed126 | 2000-11-12 19:32:20 +0000 | [diff] [blame] | 482 | * Flags for imager.c functions |
| 483 | */ |
| 484 | #define IMAGER_FLAG_INODEMAP 1 |
| 485 | #define IMAGER_FLAG_SPARSEWRITE 2 |
| 486 | |
| 487 | /* |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 488 | * For checking structure magic numbers... |
| 489 | */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 490 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 491 | #define EXT2_CHECK_MAGIC(struct, code) \ |
| 492 | if ((struct)->magic != (code)) return (code) |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 493 | |
| 494 | |
| 495 | /* |
Theodore Ts'o | e5b38a5 | 2001-01-01 16:17:12 +0000 | [diff] [blame] | 496 | * For ext2 compression support |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 497 | */ |
Valerie Clement | 5d38ef1 | 2007-08-30 17:33:40 +0200 | [diff] [blame] | 498 | #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1) |
Theodore Ts'o | 5a63dd2 | 2000-02-11 15:44:08 +0000 | [diff] [blame] | 499 | #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR) |
| 500 | |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 501 | /* |
Theodore Ts'o | 426d734 | 2001-01-13 01:29:05 +0000 | [diff] [blame] | 502 | * Features supported by this version of the library |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 503 | */ |
Theodore Ts'o | 3a5f8ea | 1999-09-14 20:21:26 +0000 | [diff] [blame] | 504 | #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\ |
| 505 | EXT2_FEATURE_COMPAT_IMAGIC_INODES|\ |
Theodore Ts'o | 342d847 | 2001-07-02 11:54:09 -0400 | [diff] [blame] | 506 | EXT3_FEATURE_COMPAT_HAS_JOURNAL|\ |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 507 | EXT2_FEATURE_COMPAT_RESIZE_INODE|\ |
Theodore Ts'o | 52783e0 | 2002-03-11 15:04:45 -0500 | [diff] [blame] | 508 | EXT2_FEATURE_COMPAT_DIR_INDEX|\ |
Theodore Ts'o | 342d847 | 2001-07-02 11:54:09 -0400 | [diff] [blame] | 509 | EXT2_FEATURE_COMPAT_EXT_ATTR) |
Theodore Ts'o | 2fe1efe | 2000-12-31 13:39:17 +0000 | [diff] [blame] | 510 | |
Theodore Ts'o | 5a63dd2 | 2000-02-11 15:44:08 +0000 | [diff] [blame] | 511 | /* This #ifdef is temporary until compression is fully supported */ |
| 512 | #ifdef ENABLE_COMPRESSION |
Theodore Ts'o | e589f67 | 2000-04-03 13:45:40 +0000 | [diff] [blame] | 513 | #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL |
| 514 | /* If the below warning bugs you, then have |
| 515 | `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your |
| 516 | environment at configure time. */ |
Theodore Ts'o | cdaf1fa | 2001-01-05 22:23:22 +0000 | [diff] [blame] | 517 | #warning "Compression support is experimental" |
Theodore Ts'o | e589f67 | 2000-04-03 13:45:40 +0000 | [diff] [blame] | 518 | #endif |
Theodore Ts'o | 5a63dd2 | 2000-02-11 15:44:08 +0000 | [diff] [blame] | 519 | #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ |
Theodore Ts'o | ab14676 | 2000-07-07 04:37:35 +0000 | [diff] [blame] | 520 | EXT2_FEATURE_INCOMPAT_COMPRESSION|\ |
Theodore Ts'o | a112847 | 2001-01-16 06:56:14 +0000 | [diff] [blame] | 521 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\ |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 522 | EXT2_FEATURE_INCOMPAT_META_BG|\ |
Jose R. Santos | c2d4300 | 2007-08-13 23:32:57 -0500 | [diff] [blame] | 523 | EXT3_FEATURE_INCOMPAT_RECOVER|\ |
Theodore Ts'o | 15d482b | 2007-08-20 21:31:11 -0400 | [diff] [blame] | 524 | EXT3_FEATURE_INCOMPAT_EXTENTS|\ |
Jose R. Santos | c2d4300 | 2007-08-13 23:32:57 -0500 | [diff] [blame] | 525 | EXT4_FEATURE_INCOMPAT_FLEX_BG) |
Theodore Ts'o | 5a63dd2 | 2000-02-11 15:44:08 +0000 | [diff] [blame] | 526 | #else |
Theodore Ts'o | ab14676 | 2000-07-07 04:37:35 +0000 | [diff] [blame] | 527 | #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ |
Theodore Ts'o | a112847 | 2001-01-16 06:56:14 +0000 | [diff] [blame] | 528 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\ |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 529 | EXT2_FEATURE_INCOMPAT_META_BG|\ |
Jose R. Santos | c2d4300 | 2007-08-13 23:32:57 -0500 | [diff] [blame] | 530 | EXT3_FEATURE_INCOMPAT_RECOVER|\ |
Theodore Ts'o | 15d482b | 2007-08-20 21:31:11 -0400 | [diff] [blame] | 531 | EXT3_FEATURE_INCOMPAT_EXTENTS|\ |
Jose R. Santos | c2d4300 | 2007-08-13 23:32:57 -0500 | [diff] [blame] | 532 | EXT4_FEATURE_INCOMPAT_FLEX_BG) |
Theodore Ts'o | 5a63dd2 | 2000-02-11 15:44:08 +0000 | [diff] [blame] | 533 | #endif |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 534 | #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ |
Theodore Ts'o | 1ca1059 | 2008-04-09 11:39:11 -0400 | [diff] [blame] | 535 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\ |
Andreas Dilger | a7c9cb7 | 2008-02-02 01:25:03 -0700 | [diff] [blame] | 536 | EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ |
Jose R. Santos | d4f34d4 | 2007-10-21 21:03:25 -0500 | [diff] [blame] | 537 | EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ |
Theodore Ts'o | 2be8fe4 | 2008-07-10 10:49:59 -0400 | [diff] [blame] | 538 | EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\ |
Jose R. Santos | d4f34d4 | 2007-10-21 21:03:25 -0500 | [diff] [blame] | 539 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM) |
Theodore Ts'o | cf8272e | 2006-11-12 23:26:46 -0500 | [diff] [blame] | 540 | |
| 541 | /* |
| 542 | * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed |
| 543 | * to ext2fs_openfs() |
| 544 | */ |
Theodore Ts'o | 1ca1059 | 2008-04-09 11:39:11 -0400 | [diff] [blame] | 545 | #define EXT2_LIB_SOFTSUPP_INCOMPAT (0) |
Theodore Ts'o | 2be8fe4 | 2008-07-10 10:49:59 -0400 | [diff] [blame] | 546 | #define EXT2_LIB_SOFTSUPP_RO_COMPAT (0) |
Theodore Ts'o | cf8272e | 2006-11-12 23:26:46 -0500 | [diff] [blame] | 547 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 548 | /* |
| 549 | * function prototypes |
| 550 | */ |
| 551 | |
| 552 | /* alloc.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 553 | extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode, |
| 554 | ext2fs_inode_bitmap map, ext2_ino_t *ret); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 555 | extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 556 | ext2fs_block_bitmap map, blk_t *ret); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 557 | extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 558 | blk_t finish, int num, |
| 559 | ext2fs_block_bitmap map, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 560 | blk_t *ret); |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 561 | extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, |
| 562 | char *block_buf, blk_t *ret); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 563 | extern void ext2fs_set_alloc_block_callback(ext2_filsys fs, |
Theodore Ts'o | f5c562e | 2008-06-02 17:21:37 -0400 | [diff] [blame] | 564 | errcode_t (*func)(ext2_filsys fs, |
| 565 | blk64_t goal, |
| 566 | blk64_t *ret), |
| 567 | errcode_t (**old)(ext2_filsys fs, |
| 568 | blk64_t goal, |
| 569 | blk64_t *ret)); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 570 | |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 571 | /* alloc_sb.c */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 572 | extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs, |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 573 | dgrp_t group, |
| 574 | ext2fs_block_bitmap bmap); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 575 | extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs, |
Theodore Ts'o | f5c562e | 2008-06-02 17:21:37 -0400 | [diff] [blame] | 576 | void (*func)(ext2_filsys fs, |
| 577 | blk64_t blk, |
| 578 | int inuse), |
| 579 | void (**old)(ext2_filsys fs, |
| 580 | blk64_t blk, |
| 581 | int inuse)); |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 582 | |
Theodore Ts'o | 8bd0c95 | 2002-01-03 03:29:19 -0500 | [diff] [blame] | 583 | /* alloc_stats.c */ |
| 584 | void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse); |
Theodore Ts'o | 7f961d4 | 2002-02-03 01:28:52 -0500 | [diff] [blame] | 585 | void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino, |
| 586 | int inuse, int isdir); |
Theodore Ts'o | 8bd0c95 | 2002-01-03 03:29:19 -0500 | [diff] [blame] | 587 | void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse); |
| 588 | |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 589 | /* alloc_tables.c */ |
| 590 | extern errcode_t ext2fs_allocate_tables(ext2_filsys fs); |
Theodore Ts'o | 2eb374c | 1998-09-03 01:22:57 +0000 | [diff] [blame] | 591 | extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 592 | ext2fs_block_bitmap bmap); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 593 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 594 | /* badblocks.c */ |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 595 | extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size); |
| 596 | extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 597 | extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk); |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 598 | extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk); |
| 599 | extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb, |
| 600 | ext2_u32_iterate *ret); |
| 601 | extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk); |
| 602 | extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter); |
| 603 | extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest); |
| 604 | extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2); |
| 605 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 606 | extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, |
| 607 | int size); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 608 | extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, |
| 609 | blk_t blk); |
| 610 | extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb, |
| 611 | blk_t blk); |
Theodore Ts'o | 7d7bdd5 | 2003-06-24 17:34:02 -0400 | [diff] [blame] | 612 | extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk); |
| 613 | extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 614 | extern errcode_t |
| 615 | ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb, |
| 616 | ext2_badblocks_iterate *ret); |
| 617 | extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter, |
| 618 | blk_t *blk); |
| 619 | extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 620 | extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, |
| 621 | ext2_badblocks_list *dest); |
Theodore Ts'o | 57dca85 | 2000-07-04 19:20:25 +0000 | [diff] [blame] | 622 | extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1, |
| 623 | ext2_badblocks_list bb2); |
Theodore Ts'o | 220c004 | 2003-03-14 00:59:42 -0500 | [diff] [blame] | 624 | extern int ext2fs_u32_list_count(ext2_u32_list bb); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 625 | |
| 626 | /* bb_compat */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 627 | extern errcode_t badblocks_list_create(badblocks_list *ret, int size); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 628 | extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk); |
| 629 | extern int badblocks_list_test(badblocks_list bb, blk_t blk); |
| 630 | extern errcode_t badblocks_list_iterate_begin(badblocks_list bb, |
| 631 | badblocks_iterate *ret); |
| 632 | extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk); |
| 633 | extern void badblocks_list_iterate_end(badblocks_iterate iter); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 634 | extern void badblocks_list_free(badblocks_list bb); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 635 | |
| 636 | /* bb_inode.c */ |
| 637 | extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 638 | ext2_badblocks_list bb_list); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 639 | |
| 640 | /* bitmaps.c */ |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 641 | extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap); |
| 642 | extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap); |
Theodore Ts'o | f1f115a | 2007-07-23 04:32:48 -0400 | [diff] [blame] | 643 | extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, |
| 644 | ext2fs_generic_bitmap *dest); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 645 | extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs); |
| 646 | extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs); |
| 647 | extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs); |
| 648 | extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 649 | extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, |
| 650 | const char *descr, |
| 651 | ext2fs_block_bitmap *ret); |
| 652 | extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, |
| 653 | const char *descr, |
| 654 | ext2fs_inode_bitmap *ret); |
| 655 | extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 656 | ext2_ino_t end, ext2_ino_t *oend); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 657 | extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, |
| 658 | blk_t end, blk_t *oend); |
| 659 | extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap); |
| 660 | extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 661 | extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs); |
| 662 | extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs); |
Theodore Ts'o | 50448d3 | 2007-07-22 23:42:14 -0400 | [diff] [blame] | 663 | extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, |
| 664 | ext2fs_inode_bitmap bmap); |
| 665 | extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, |
| 666 | ext2fs_block_bitmap bmap); |
| 667 | extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, |
| 668 | ext2fs_block_bitmap bm2); |
| 669 | extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, |
| 670 | ext2fs_inode_bitmap bm2); |
Theodore Ts'o | f1f115a | 2007-07-23 04:32:48 -0400 | [diff] [blame] | 671 | extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, |
| 672 | ext2_ino_t start, unsigned int num, |
| 673 | void *in); |
| 674 | extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, |
| 675 | ext2_ino_t start, unsigned int num, |
| 676 | void *out); |
| 677 | extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, |
| 678 | blk_t start, unsigned int num, |
| 679 | void *in); |
| 680 | extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, |
| 681 | blk_t start, unsigned int num, |
| 682 | void *out); |
Theodore Ts'o | 50448d3 | 2007-07-22 23:42:14 -0400 | [diff] [blame] | 683 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 684 | |
| 685 | /* block.c */ |
| 686 | extern errcode_t ext2fs_block_iterate(ext2_filsys fs, |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 687 | ext2_ino_t ino, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 688 | int flags, |
| 689 | char *block_buf, |
| 690 | int (*func)(ext2_filsys fs, |
| 691 | blk_t *blocknr, |
| 692 | int blockcnt, |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 693 | void *priv_data), |
| 694 | void *priv_data); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 695 | errcode_t ext2fs_block_iterate2(ext2_filsys fs, |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 696 | ext2_ino_t ino, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 697 | int flags, |
| 698 | char *block_buf, |
| 699 | int (*func)(ext2_filsys fs, |
| 700 | blk_t *blocknr, |
Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 701 | e2_blkcnt_t blockcnt, |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 702 | blk_t ref_blk, |
| 703 | int ref_offset, |
| 704 | void *priv_data), |
| 705 | void *priv_data); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 706 | |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 707 | /* bmap.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 708 | extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 709 | struct ext2_inode *inode, |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 710 | char *block_buf, int bmap_flags, |
| 711 | blk_t block, blk_t *phys_blk); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 712 | extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | cc9bf5d | 2008-02-18 14:59:45 -0500 | [diff] [blame] | 713 | struct ext2_inode *inode, |
| 714 | char *block_buf, int bmap_flags, blk64_t block, |
| 715 | int *ret_flags, blk64_t *phys_blk); |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 716 | |
Theodore Ts'o | 4a31c48 | 1998-03-30 01:27:25 +0000 | [diff] [blame] | 717 | #if 0 |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 718 | /* bmove.c */ |
| 719 | extern errcode_t ext2fs_move_blocks(ext2_filsys fs, |
| 720 | ext2fs_block_bitmap reserve, |
Theodore Ts'o | 9941fb7 | 1997-06-11 22:27:41 +0000 | [diff] [blame] | 721 | ext2fs_block_bitmap alloc_map, |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 722 | int flags); |
Theodore Ts'o | 4a31c48 | 1998-03-30 01:27:25 +0000 | [diff] [blame] | 723 | #endif |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 724 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 725 | /* check_desc.c */ |
| 726 | extern errcode_t ext2fs_check_desc(ext2_filsys fs); |
| 727 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 728 | /* closefs.c */ |
| 729 | extern errcode_t ext2fs_close(ext2_filsys fs); |
| 730 | extern errcode_t ext2fs_flush(ext2_filsys fs); |
Theodore Ts'o | 1b4cd9c | 2004-12-15 18:06:52 -0500 | [diff] [blame] | 731 | extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 732 | extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 733 | dgrp_t group, |
| 734 | blk_t *ret_super_blk, |
| 735 | blk_t *ret_old_desc_blk, |
| 736 | blk_t *ret_new_desc_blk, |
| 737 | int *ret_meta_bg); |
Theodore Ts'o | 1b4cd9c | 2004-12-15 18:06:52 -0500 | [diff] [blame] | 738 | extern void ext2fs_update_dynamic_rev(ext2_filsys fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 739 | |
Jose R. Santos | ca2634a | 2007-10-21 21:03:19 -0500 | [diff] [blame] | 740 | /* csum.c */ |
| 741 | extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group); |
| 742 | extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group); |
Andreas Dilger | f628ace | 2008-03-31 10:50:19 -0400 | [diff] [blame] | 743 | extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs); |
Jose R. Santos | ca2634a | 2007-10-21 21:03:19 -0500 | [diff] [blame] | 744 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 745 | /* dblist.c */ |
| 746 | |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 747 | extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 748 | extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 749 | extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 750 | blk_t blk, int blockcnt); |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 751 | extern void ext2fs_dblist_sort(ext2_dblist dblist, |
| 752 | EXT2_QSORT_TYPE (*sortfunc)(const void *, |
| 753 | const void *)); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 754 | extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, |
| 755 | int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 756 | void *priv_data), |
| 757 | void *priv_data); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 758 | extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 759 | blk_t blk, int blockcnt); |
| 760 | extern errcode_t ext2fs_copy_dblist(ext2_dblist src, |
| 761 | ext2_dblist *dest); |
Theodore Ts'o | 549860c | 1997-06-17 03:55:00 +0000 | [diff] [blame] | 762 | extern int ext2fs_dblist_count(ext2_dblist dblist); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 763 | extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, |
Theodore Ts'o | 52b1dd5 | 2008-03-13 00:34:16 -0400 | [diff] [blame] | 764 | struct ext2_db_entry **entry); |
| 765 | extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 766 | |
| 767 | /* dblist_dir.c */ |
| 768 | extern errcode_t |
| 769 | ext2fs_dblist_dir_iterate(ext2_dblist dblist, |
| 770 | int flags, |
| 771 | char *block_buf, |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 772 | int (*func)(ext2_ino_t dir, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 773 | int entry, |
| 774 | struct ext2_dir_entry *dirent, |
| 775 | int offset, |
| 776 | int blocksize, |
| 777 | char *buf, |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 778 | void *priv_data), |
| 779 | void *priv_data); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 780 | |
| 781 | /* dirblock.c */ |
| 782 | extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, |
| 783 | void *buf); |
Theodore Ts'o | f9190c8 | 2002-03-12 01:05:06 -0500 | [diff] [blame] | 784 | extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block, |
| 785 | void *buf, int flags); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 786 | extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, |
| 787 | void *buf); |
Theodore Ts'o | f9190c8 | 2002-03-12 01:05:06 -0500 | [diff] [blame] | 788 | extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, |
| 789 | void *buf, int flags); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 790 | |
Theodore Ts'o | 52783e0 | 2002-03-11 15:04:45 -0500 | [diff] [blame] | 791 | /* dirhash.c */ |
| 792 | extern errcode_t ext2fs_dirhash(int version, const char *name, int len, |
Theodore Ts'o | b33278c | 2002-08-17 10:52:51 -0400 | [diff] [blame] | 793 | const __u32 *seed, |
Theodore Ts'o | 503f9e7 | 2002-06-26 16:52:10 -0400 | [diff] [blame] | 794 | ext2_dirhash_t *ret_hash, |
| 795 | ext2_dirhash_t *ret_minor_hash); |
Theodore Ts'o | 52783e0 | 2002-03-11 15:04:45 -0500 | [diff] [blame] | 796 | |
| 797 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 798 | /* dir_iterate.c */ |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 799 | extern errcode_t ext2fs_get_rec_len(ext2_filsys fs, |
| 800 | struct ext2_dir_entry *dirent, |
| 801 | unsigned int *rec_len); |
| 802 | extern errcode_t ext2fs_set_rec_len(ext2_filsys fs, |
| 803 | unsigned int len, |
| 804 | struct ext2_dir_entry *dirent); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 805 | extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 806 | ext2_ino_t dir, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 807 | int flags, |
| 808 | char *block_buf, |
| 809 | int (*func)(struct ext2_dir_entry *dirent, |
| 810 | int offset, |
| 811 | int blocksize, |
| 812 | char *buf, |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 813 | void *priv_data), |
| 814 | void *priv_data); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 815 | extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs, |
Theodore Ts'o | 8bd0c95 | 2002-01-03 03:29:19 -0500 | [diff] [blame] | 816 | ext2_ino_t dir, |
| 817 | int flags, |
| 818 | char *block_buf, |
| 819 | int (*func)(ext2_ino_t dir, |
| 820 | int entry, |
| 821 | struct ext2_dir_entry *dirent, |
| 822 | int offset, |
| 823 | int blocksize, |
| 824 | char *buf, |
| 825 | void *priv_data), |
| 826 | void *priv_data); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 827 | |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 828 | /* dupfs.c */ |
| 829 | extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 830 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 831 | /* expanddir.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 832 | extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 833 | |
Theodore Ts'o | 342d847 | 2001-07-02 11:54:09 -0400 | [diff] [blame] | 834 | /* ext_attr.c */ |
Andreas Dilger | fefaef3 | 2008-02-02 01:16:32 -0700 | [diff] [blame] | 835 | extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry, |
| 836 | void *data); |
Theodore Ts'o | 342d847 | 2001-07-02 11:54:09 -0400 | [diff] [blame] | 837 | extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 838 | extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, |
| 839 | void *buf); |
| 840 | extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk, |
| 841 | char *block_buf, |
| 842 | int adjust, __u32 *newcount); |
| 843 | |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 844 | /* extent.c */ |
| 845 | extern errcode_t ext2fs_extent_header_verify(void *ptr, int size); |
| 846 | extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino, |
| 847 | ext2_extent_handle_t *handle); |
number9652 | 84b239a | 2009-05-19 13:34:12 -0700 | [diff] [blame] | 848 | extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, |
| 849 | struct ext2_inode *inode, |
| 850 | ext2_extent_handle_t *ret_handle); |
Theodore Ts'o | 2d328bb | 2008-03-17 23:17:13 -0400 | [diff] [blame] | 851 | extern void ext2fs_extent_free(ext2_extent_handle_t handle); |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 852 | extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, |
| 853 | int flags, struct ext2fs_extent *extent); |
| 854 | extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags, |
| 855 | struct ext2fs_extent *extent); |
| 856 | extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, |
| 857 | struct ext2fs_extent *extent); |
Eric Sandeen | f4e9963 | 2008-05-20 10:17:46 -0500 | [diff] [blame] | 858 | extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, |
| 859 | blk64_t logical, blk64_t physical, |
| 860 | int flags); |
Theodore Ts'o | 3eb07f6 | 2007-10-14 23:04:58 -0400 | [diff] [blame] | 861 | extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags); |
| 862 | extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, |
| 863 | struct ext2_extent_info *info); |
| 864 | extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, |
| 865 | blk64_t blk); |
| 866 | |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 867 | /* fileio.c */ |
Theodore Ts'o | a435ec3 | 2003-08-21 00:40:26 -0400 | [diff] [blame] | 868 | extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, |
| 869 | struct ext2_inode *inode, |
| 870 | int flags, ext2_file_t *ret); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 871 | extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 872 | int flags, ext2_file_t *ret); |
Theodore Ts'o | 79a90bd | 1997-11-03 19:16:55 +0000 | [diff] [blame] | 873 | extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file); |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 874 | extern errcode_t ext2fs_file_close(ext2_file_t file); |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 875 | extern errcode_t ext2fs_file_flush(ext2_file_t file); |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 876 | extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf, |
Theodore Ts'o | 79a90bd | 1997-11-03 19:16:55 +0000 | [diff] [blame] | 877 | unsigned int wanted, unsigned int *got); |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 878 | extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, |
Theodore Ts'o | 79a90bd | 1997-11-03 19:16:55 +0000 | [diff] [blame] | 879 | unsigned int nbytes, unsigned int *written); |
Theodore Ts'o | 819157d | 2003-01-22 18:25:39 -0500 | [diff] [blame] | 880 | extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset, |
| 881 | int whence, __u64 *ret_pos); |
Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 882 | extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, |
| 883 | int whence, ext2_off_t *ret_pos); |
Theodore Ts'o | 819157d | 2003-01-22 18:25:39 -0500 | [diff] [blame] | 884 | errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size); |
Theodore Ts'o | 79a90bd | 1997-11-03 19:16:55 +0000 | [diff] [blame] | 885 | extern ext2_off_t ext2fs_file_get_size(ext2_file_t file); |
| 886 | extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size); |
Theodore Ts'o | 30fab29 | 1997-10-25 22:37:42 +0000 | [diff] [blame] | 887 | |
Theodore Ts'o | de23aa1 | 2000-08-19 17:00:47 +0000 | [diff] [blame] | 888 | /* finddev.c */ |
| 889 | extern char *ext2fs_find_block_device(dev_t device); |
| 890 | |
Theodore Ts'o | 4d0f3e1 | 2001-01-11 15:48:50 +0000 | [diff] [blame] | 891 | /* flushb.c */ |
| 892 | extern errcode_t ext2fs_sync_device(int fd, int flushb); |
| 893 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 894 | /* freefs.c */ |
| 895 | extern void ext2fs_free(ext2_filsys fs); |
Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 896 | extern void ext2fs_free_dblist(ext2_dblist dblist); |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 897 | extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb); |
| 898 | extern void ext2fs_u32_list_free(ext2_u32_list bb); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 899 | |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 900 | /* gen_bitmap.c */ |
| 901 | extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 902 | extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs, |
| 903 | __u32 start, __u32 end, |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 904 | __u32 real_end, |
| 905 | const char *descr, char *init_map, |
| 906 | ext2fs_generic_bitmap *ret); |
| 907 | extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start, |
| 908 | __u32 end, |
| 909 | __u32 real_end, |
| 910 | const char *descr, |
| 911 | ext2fs_generic_bitmap *ret); |
| 912 | extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src, |
| 913 | ext2fs_generic_bitmap *dest); |
| 914 | extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap); |
| 915 | extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 916 | errcode_t magic, |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 917 | errcode_t neq, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 918 | ext2_ino_t end, |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 919 | ext2_ino_t *oend); |
| 920 | extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map); |
Theodore Ts'o | 50448d3 | 2007-07-22 23:42:14 -0400 | [diff] [blame] | 921 | extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic, |
| 922 | __u32 new_end, |
| 923 | __u32 new_real_end, |
| 924 | ext2fs_generic_bitmap bmap); |
| 925 | extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq, |
| 926 | ext2fs_generic_bitmap bm1, |
| 927 | ext2fs_generic_bitmap bm2); |
Theodore Ts'o | f1f115a | 2007-07-23 04:32:48 -0400 | [diff] [blame] | 928 | extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap, |
| 929 | errcode_t magic, |
| 930 | __u32 start, __u32 num, |
| 931 | void *out); |
| 932 | extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, |
| 933 | errcode_t magic, |
| 934 | __u32 start, __u32 num, |
| 935 | void *in); |
Theodore Ts'o | a0553c9 | 2007-07-22 22:59:50 -0400 | [diff] [blame] | 936 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 937 | /* getsize.c */ |
| 938 | extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, |
| 939 | blk_t *retblocks); |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 940 | extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize, |
| 941 | blk64_t *retblocks); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 942 | |
Theodore Ts'o | 93d5c38 | 2003-05-21 17:28:29 -0400 | [diff] [blame] | 943 | /* getsectsize.c */ |
| 944 | errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize); |
| 945 | |
Theodore Ts'o | 1ca1059 | 2008-04-09 11:39:11 -0400 | [diff] [blame] | 946 | /* i_block.c */ |
| 947 | errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode, |
| 948 | blk64_t num_blocks); |
| 949 | errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode, |
| 950 | blk64_t num_blocks); |
| 951 | errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b); |
| 952 | |
Theodore Ts'o | 72ed126 | 2000-11-12 19:32:20 +0000 | [diff] [blame] | 953 | /* imager.c */ |
| 954 | extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags); |
| 955 | extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags); |
| 956 | extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags); |
| 957 | extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags); |
| 958 | extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags); |
| 959 | extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags); |
| 960 | |
Theodore Ts'o | dc8ce34 | 2005-01-06 00:04:24 -0500 | [diff] [blame] | 961 | /* ind_block.c */ |
| 962 | errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf); |
| 963 | errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf); |
| 964 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 965 | /* initialize.c */ |
| 966 | extern errcode_t ext2fs_initialize(const char *name, int flags, |
| 967 | struct ext2_super_block *param, |
| 968 | io_manager manager, ext2_filsys *ret_fs); |
| 969 | |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 970 | /* icount.c */ |
| 971 | extern void ext2fs_free_icount(ext2_icount_t icount); |
Theodore Ts'o | 1b9d8cb | 2007-04-06 14:30:39 -0400 | [diff] [blame] | 972 | extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir, |
| 973 | int flags, ext2_icount_t *ret); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 974 | extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 975 | unsigned int size, |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 976 | ext2_icount_t hint, ext2_icount_t *ret); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 977 | extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 978 | unsigned int size, |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 979 | ext2_icount_t *ret); |
| 980 | extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino, |
| 981 | __u16 *ret); |
| 982 | extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, |
| 983 | __u16 *ret); |
| 984 | extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, |
| 985 | __u16 *ret); |
| 986 | extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, |
| 987 | __u16 count); |
| 988 | extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount); |
| 989 | errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); |
| 990 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 991 | /* inode.c */ |
Theodore Ts'o | 72ed126 | 2000-11-12 19:32:20 +0000 | [diff] [blame] | 992 | extern errcode_t ext2fs_flush_icache(ext2_filsys fs); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 993 | extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 994 | ext2_ino_t *ino, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 995 | struct ext2_inode *inode, |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 996 | int bufsize); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 997 | extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, |
| 998 | ext2_inode_scan *ret_scan); |
| 999 | extern void ext2fs_close_inode_scan(ext2_inode_scan scan); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1000 | extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1001 | struct ext2_inode *inode); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1002 | extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, |
| 1003 | int group); |
| 1004 | extern void ext2fs_set_inode_callback |
| 1005 | (ext2_inode_scan scan, |
| 1006 | errcode_t (*done_group)(ext2_filsys fs, |
| 1007 | ext2_inode_scan scan, |
| 1008 | dgrp_t group, |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 1009 | void * priv_data), |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1010 | void *done_group_data); |
| 1011 | extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, |
| 1012 | int clear_flags); |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1013 | extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1014 | struct ext2_inode * inode, |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1015 | int bufsize); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1016 | extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1017 | struct ext2_inode * inode); |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1018 | extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1019 | struct ext2_inode * inode, |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1020 | int bufsize); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1021 | extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1022 | struct ext2_inode * inode); |
Theodore Ts'o | 030970e | 2005-03-20 20:05:22 -0500 | [diff] [blame] | 1023 | extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino, |
| 1024 | struct ext2_inode * inode); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1025 | extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks); |
| 1026 | extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1027 | |
Theodore Ts'o | f12e285 | 2002-02-20 01:06:25 -0500 | [diff] [blame] | 1028 | /* inode_io.c */ |
| 1029 | extern io_manager inode_io_manager; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1030 | extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino, |
Theodore Ts'o | 546a1ff | 2002-03-07 23:52:56 -0500 | [diff] [blame] | 1031 | char **name); |
Theodore Ts'o | a435ec3 | 2003-08-21 00:40:26 -0400 | [diff] [blame] | 1032 | extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino, |
| 1033 | struct ext2_inode *inode, |
| 1034 | char **name); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1035 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1036 | /* ismounted.c */ |
| 1037 | extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); |
Theodore Ts'o | 43ec873 | 2001-01-03 14:56:46 +0000 | [diff] [blame] | 1038 | extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, |
| 1039 | char *mtpt, int mtlen); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1040 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1041 | /* namei.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1042 | extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name, |
| 1043 | int namelen, char *buf, ext2_ino_t *inode); |
| 1044 | extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, |
| 1045 | const char *name, ext2_ino_t *inode); |
| 1046 | errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, |
| 1047 | const char *name, ext2_ino_t *inode); |
| 1048 | extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, |
| 1049 | ext2_ino_t inode, ext2_ino_t *res_inode); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1050 | |
| 1051 | /* native.c */ |
| 1052 | int ext2fs_native_flag(void); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1053 | |
| 1054 | /* newdir.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1055 | extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, |
| 1056 | ext2_ino_t parent_ino, char **block); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1057 | |
| 1058 | /* mkdir.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1059 | extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1060 | const char *name); |
| 1061 | |
Theodore Ts'o | d3cd93c | 2000-10-24 18:33:16 +0000 | [diff] [blame] | 1062 | /* mkjournal.c */ |
Theodore Ts'o | c860850 | 2008-04-27 16:10:32 -0400 | [diff] [blame] | 1063 | extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, |
| 1064 | blk_t *ret_blk, int *ret_count); |
Theodore Ts'o | a112847 | 2001-01-16 06:56:14 +0000 | [diff] [blame] | 1065 | extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, |
| 1066 | __u32 size, int flags, |
| 1067 | char **ret_jsb); |
| 1068 | extern errcode_t ext2fs_add_journal_device(ext2_filsys fs, |
| 1069 | ext2_filsys journal_dev); |
Theodore Ts'o | 31a17b3 | 2001-01-03 13:04:12 +0000 | [diff] [blame] | 1070 | extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, |
| 1071 | int flags); |
Theodore Ts'o | 56d1236 | 2007-06-21 11:59:06 -0400 | [diff] [blame] | 1072 | extern int ext2fs_default_journal_size(__u64 blocks); |
Theodore Ts'o | d3cd93c | 2000-10-24 18:33:16 +0000 | [diff] [blame] | 1073 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1074 | /* openfs.c */ |
| 1075 | extern errcode_t ext2fs_open(const char *name, int flags, int superblock, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1076 | unsigned int block_size, io_manager manager, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1077 | ext2_filsys *ret_fs); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1078 | extern errcode_t ext2fs_open2(const char *name, const char *io_options, |
| 1079 | int flags, int superblock, |
Theodore Ts'o | 2e8ca9a | 2004-11-30 14:07:11 -0500 | [diff] [blame] | 1080 | unsigned int block_size, io_manager manager, |
| 1081 | ext2_filsys *ret_fs); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1082 | extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 1083 | dgrp_t i); |
Theodore Ts'o | 1ad54a9 | 2004-07-28 21:11:48 -0400 | [diff] [blame] | 1084 | errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io); |
| 1085 | errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io); |
| 1086 | errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1087 | |
| 1088 | /* get_pathname.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1089 | extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1090 | char **name); |
| 1091 | |
| 1092 | /* link.c */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1093 | errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name, |
| 1094 | ext2_ino_t ino, int flags); |
| 1095 | errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name, |
| 1096 | ext2_ino_t ino, int flags); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* read_bb.c */ |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1099 | extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, |
| 1100 | ext2_badblocks_list *bb_list); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1101 | |
| 1102 | /* read_bb_file.c */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1103 | extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, |
Theodore Ts'o | 57dca85 | 2000-07-04 19:20:25 +0000 | [diff] [blame] | 1104 | ext2_badblocks_list *bb_list, |
Theodore Ts'o | 50cd7e0 | 2002-07-14 16:00:50 -0400 | [diff] [blame] | 1105 | void *priv_data, |
Theodore Ts'o | 57dca85 | 2000-07-04 19:20:25 +0000 | [diff] [blame] | 1106 | void (*invalid)(ext2_filsys fs, |
| 1107 | blk_t blk, |
| 1108 | char *badstr, |
Theodore Ts'o | 50cd7e0 | 2002-07-14 16:00:50 -0400 | [diff] [blame] | 1109 | void *priv_data)); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1110 | extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1111 | ext2_badblocks_list *bb_list, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1112 | void (*invalid)(ext2_filsys fs, |
| 1113 | blk_t blk)); |
| 1114 | |
Theodore Ts'o | d323f8f | 2004-12-15 14:39:16 -0500 | [diff] [blame] | 1115 | /* res_gdt.c */ |
| 1116 | extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs); |
| 1117 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1118 | /* swapfs.c */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1119 | extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize, |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1120 | int has_header); |
Andreas Dilger | fefaef3 | 2008-02-02 01:16:32 -0700 | [diff] [blame] | 1121 | extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header, |
| 1122 | struct ext2_ext_attr_header *from_hdr); |
| 1123 | extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry, |
| 1124 | struct ext2_ext_attr_entry *from_entry); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1125 | extern void ext2fs_swap_super(struct ext2_super_block * super); |
| 1126 | extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp); |
Theodore Ts'o | 7331196 | 2005-01-25 23:42:56 -0500 | [diff] [blame] | 1127 | extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, |
| 1128 | struct ext2_inode_large *f, int hostorder, |
| 1129 | int bufsize); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1130 | extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, |
| 1131 | struct ext2_inode *f, int hostorder); |
| 1132 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1133 | /* valid_blk.c */ |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1134 | extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); |
| 1135 | |
| 1136 | /* version.c */ |
| 1137 | extern int ext2fs_parse_version_string(const char *ver_string); |
| 1138 | extern int ext2fs_get_library_version(const char **ver_string, |
| 1139 | const char **date_string); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1140 | |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1141 | /* write_bb_file.c */ |
| 1142 | extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, |
| 1143 | unsigned int flags, |
| 1144 | FILE *f); |
| 1145 | |
| 1146 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1147 | /* inline functions */ |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1148 | extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr); |
Theodore Ts'o | ee01079 | 2007-11-09 19:01:06 -0500 | [diff] [blame] | 1149 | extern errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr); |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1150 | extern errcode_t ext2fs_free_mem(void *ptr); |
Theodore Ts'o | 76f875d | 1998-04-27 01:41:13 +0000 | [diff] [blame] | 1151 | extern errcode_t ext2fs_resize_mem(unsigned long old_size, |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1152 | unsigned long size, void *ptr); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1153 | extern void ext2fs_mark_super_dirty(ext2_filsys fs); |
| 1154 | extern void ext2fs_mark_changed(ext2_filsys fs); |
| 1155 | extern int ext2fs_test_changed(ext2_filsys fs); |
| 1156 | extern void ext2fs_mark_valid(ext2_filsys fs); |
| 1157 | extern void ext2fs_unmark_valid(ext2_filsys fs); |
| 1158 | extern int ext2fs_test_valid(ext2_filsys fs); |
| 1159 | extern void ext2fs_mark_ib_dirty(ext2_filsys fs); |
| 1160 | extern void ext2fs_mark_bb_dirty(ext2_filsys fs); |
| 1161 | extern int ext2fs_test_ib_dirty(ext2_filsys fs); |
| 1162 | extern int ext2fs_test_bb_dirty(ext2_filsys fs); |
| 1163 | extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1164 | extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino); |
Eric Sandeen | abf2343 | 2006-09-12 14:56:16 -0400 | [diff] [blame] | 1165 | extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group); |
| 1166 | extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1167 | extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, |
| 1168 | struct ext2_inode *inode); |
Theodore Ts'o | 69022e0 | 2006-08-30 01:57:00 -0400 | [diff] [blame] | 1169 | extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1170 | |
| 1171 | /* |
| 1172 | * The actual inlined functions definitions themselves... |
| 1173 | * |
| 1174 | * If NO_INLINE_FUNCS is defined, then we won't try to do inline |
| 1175 | * functions at all! |
| 1176 | */ |
| 1177 | #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) |
| 1178 | #ifdef INCLUDE_INLINE_FUNCS |
| 1179 | #define _INLINE_ extern |
| 1180 | #else |
Theodore Ts'o | 76f875d | 1998-04-27 01:41:13 +0000 | [diff] [blame] | 1181 | #ifdef __GNUC__ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1182 | #define _INLINE_ extern __inline__ |
Theodore Ts'o | 76f875d | 1998-04-27 01:41:13 +0000 | [diff] [blame] | 1183 | #else /* For Watcom C */ |
| 1184 | #define _INLINE_ extern inline |
| 1185 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1186 | #endif |
| 1187 | |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1188 | #ifndef EXT2_CUSTOM_MEMORY_ROUTINES |
Matthias Andree | 68a7f95 | 2005-09-06 05:59:52 -0400 | [diff] [blame] | 1189 | #include <string.h> |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1190 | /* |
| 1191 | * Allocate memory |
| 1192 | */ |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1193 | _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1194 | { |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1195 | void *pp; |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1196 | |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1197 | pp = malloc(size); |
| 1198 | if (!pp) |
Theodore Ts'o | 291c904 | 1997-10-31 06:17:08 +0000 | [diff] [blame] | 1199 | return EXT2_ET_NO_MEMORY; |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1200 | memcpy(ptr, &pp, sizeof (pp)); |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
Theodore Ts'o | e5aace9 | 2007-12-27 10:08:13 -0500 | [diff] [blame] | 1203 | |
Theodore Ts'o | ee01079 | 2007-11-09 19:01:06 -0500 | [diff] [blame] | 1204 | _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr) |
| 1205 | { |
| 1206 | if (count && (-1UL)/count<size) |
| 1207 | return EXT2_ET_NO_MEMORY; //maybe define EXT2_ET_OVERFLOW ? |
| 1208 | return ext2fs_get_mem(count*size, ptr); |
| 1209 | } |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1210 | |
| 1211 | /* |
| 1212 | * Free memory |
| 1213 | */ |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1214 | _INLINE_ errcode_t ext2fs_free_mem(void *ptr) |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1215 | { |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1216 | void *p; |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1217 | |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1218 | memcpy(&p, ptr, sizeof(p)); |
| 1219 | free(p); |
| 1220 | p = 0; |
| 1221 | memcpy(ptr, &p, sizeof(p)); |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1222 | return 0; |
| 1223 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1224 | |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1225 | /* |
| 1226 | * Resize memory |
| 1227 | */ |
Theodore Ts'o | e47fd84 | 2004-02-21 21:04:30 -0500 | [diff] [blame] | 1228 | _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size, |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1229 | unsigned long size, void *ptr) |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1230 | { |
| 1231 | void *p; |
| 1232 | |
Stephen Tweedie | 39c191f | 2005-06-27 11:47:21 -0400 | [diff] [blame] | 1233 | /* Use "memcpy" for pointer assignments here to avoid problems |
| 1234 | * with C99 strict type aliasing rules. */ |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1235 | memcpy(&p, ptr, sizeof(p)); |
Stephen Tweedie | 39c191f | 2005-06-27 11:47:21 -0400 | [diff] [blame] | 1236 | p = realloc(p, size); |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1237 | if (!p) |
Theodore Ts'o | 291c904 | 1997-10-31 06:17:08 +0000 | [diff] [blame] | 1238 | return EXT2_ET_NO_MEMORY; |
Theodore Ts'o | 2694f31 | 2006-11-14 00:34:34 -0500 | [diff] [blame] | 1239 | memcpy(ptr, &p, sizeof(p)); |
Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 1240 | return 0; |
| 1241 | } |
| 1242 | #endif /* Custom memory routines */ |
| 1243 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1244 | /* |
| 1245 | * Mark a filesystem superblock as dirty |
| 1246 | */ |
| 1247 | _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs) |
| 1248 | { |
| 1249 | fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; |
| 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * Mark a filesystem as changed |
| 1254 | */ |
| 1255 | _INLINE_ void ext2fs_mark_changed(ext2_filsys fs) |
| 1256 | { |
| 1257 | fs->flags |= EXT2_FLAG_CHANGED; |
| 1258 | } |
| 1259 | |
| 1260 | /* |
| 1261 | * Check to see if a filesystem has changed |
| 1262 | */ |
| 1263 | _INLINE_ int ext2fs_test_changed(ext2_filsys fs) |
| 1264 | { |
| 1265 | return (fs->flags & EXT2_FLAG_CHANGED); |
| 1266 | } |
| 1267 | |
| 1268 | /* |
| 1269 | * Mark a filesystem as valid |
| 1270 | */ |
| 1271 | _INLINE_ void ext2fs_mark_valid(ext2_filsys fs) |
| 1272 | { |
| 1273 | fs->flags |= EXT2_FLAG_VALID; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * Mark a filesystem as NOT valid |
| 1278 | */ |
| 1279 | _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs) |
| 1280 | { |
| 1281 | fs->flags &= ~EXT2_FLAG_VALID; |
| 1282 | } |
| 1283 | |
| 1284 | /* |
| 1285 | * Check to see if a filesystem is valid |
| 1286 | */ |
| 1287 | _INLINE_ int ext2fs_test_valid(ext2_filsys fs) |
| 1288 | { |
| 1289 | return (fs->flags & EXT2_FLAG_VALID); |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * Mark the inode bitmap as dirty |
| 1294 | */ |
| 1295 | _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs) |
| 1296 | { |
| 1297 | fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; |
| 1298 | } |
| 1299 | |
| 1300 | /* |
| 1301 | * Mark the block bitmap as dirty |
| 1302 | */ |
| 1303 | _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs) |
| 1304 | { |
| 1305 | fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; |
| 1306 | } |
| 1307 | |
| 1308 | /* |
| 1309 | * Check to see if a filesystem's inode bitmap is dirty |
| 1310 | */ |
| 1311 | _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs) |
| 1312 | { |
| 1313 | return (fs->flags & EXT2_FLAG_IB_DIRTY); |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | * Check to see if a filesystem's block bitmap is dirty |
| 1318 | */ |
| 1319 | _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) |
| 1320 | { |
| 1321 | return (fs->flags & EXT2_FLAG_BB_DIRTY); |
| 1322 | } |
| 1323 | |
| 1324 | /* |
| 1325 | * Return the group # of a block |
| 1326 | */ |
| 1327 | _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) |
| 1328 | { |
| 1329 | return (blk - fs->super->s_first_data_block) / |
| 1330 | fs->super->s_blocks_per_group; |
| 1331 | } |
| 1332 | |
| 1333 | /* |
| 1334 | * Return the group # of an inode number |
| 1335 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 1336 | _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1337 | { |
| 1338 | return (ino - 1) / fs->super->s_inodes_per_group; |
| 1339 | } |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1340 | |
Eric Sandeen | abf2343 | 2006-09-12 14:56:16 -0400 | [diff] [blame] | 1341 | /* |
| 1342 | * Return the first block (inclusive) in a group |
| 1343 | */ |
| 1344 | _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group) |
| 1345 | { |
| 1346 | return fs->super->s_first_data_block + |
| 1347 | (group * fs->super->s_blocks_per_group); |
| 1348 | } |
| 1349 | |
| 1350 | /* |
| 1351 | * Return the last block (inclusive) in a group |
| 1352 | */ |
| 1353 | _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group) |
| 1354 | { |
| 1355 | return (group == fs->group_desc_count - 1 ? |
| 1356 | fs->super->s_blocks_count - 1 : |
| 1357 | ext2fs_group_first_block(fs, group) + |
| 1358 | (fs->super->s_blocks_per_group - 1)); |
| 1359 | } |
| 1360 | |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1361 | _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs, |
| 1362 | struct ext2_inode *inode) |
| 1363 | { |
| 1364 | return inode->i_blocks - |
| 1365 | (inode->i_file_acl ? fs->blocksize >> 9 : 0); |
| 1366 | } |
Theodore Ts'o | 69022e0 | 2006-08-30 01:57:00 -0400 | [diff] [blame] | 1367 | |
| 1368 | /* |
| 1369 | * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b) |
| 1370 | */ |
| 1371 | _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b) |
| 1372 | { |
| 1373 | if (!a) |
| 1374 | return 0; |
| 1375 | return ((a - 1) / b) + 1; |
| 1376 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1377 | #undef _INLINE_ |
| 1378 | #endif |
| 1379 | |
Theodore Ts'o | fa7ef71 | 2000-05-19 02:11:41 +0000 | [diff] [blame] | 1380 | #ifdef __cplusplus |
| 1381 | } |
| 1382 | #endif |
| 1383 | |
Theodore Ts'o | 9abd2ce | 1998-02-16 22:00:37 +0000 | [diff] [blame] | 1384 | #endif /* _EXT2FS_EXT2FS_H */ |