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