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