ext2fs.h revision 72ed12648368b3f3ea14e8102e20bf5d3a3be6d3
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 __cplusplus 16extern "C" { 17#endif 18 19/* 20 * Non-GNU C compilers won't necessarily understand inline 21 */ 22#if (!defined(__GNUC__) && !defined(__WATCOMC__)) 23#define NO_INLINE_FUNCS 24#endif 25 26/* 27 * Where the master copy of the superblock is located, and how big 28 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because 29 * the size of the superblock structure is not necessarily trustworthy 30 * (some versions have the padding set up so that the superblock is 31 * 1032 bytes long). 32 */ 33#define SUPERBLOCK_OFFSET 1024 34#define SUPERBLOCK_SIZE 1024 35 36/* 37 * The last ext2fs revision level that this version of the library is 38 * able to support. 39 */ 40#define EXT2_LIB_CURRENT_REV 0 41 42#ifdef HAVE_SYS_TYPES_H 43#include <sys/types.h> 44#endif 45 46#include <stdlib.h> 47 48#if EXT2_FLAT_INCLUDES 49#include "e2_types.h" 50#else 51#include <asm/types.h> 52#if !defined(__GNUC__) || defined(__STRICT_ANSI__) /* asm/types.h already defines __s64 and __u64 otherwise */ 53#if SIZEOF_LONG == 8 54typedef __signed__ long __s64; 55typedef unsigned long __u64; 56#elif SIZEOF_LONG_LONG == 8 || \ 57 defined(__GNUC__) && (((~0UL) == 0xffffffff) || defined(__i386__)) 58typedef __signed__ long long __s64; 59typedef unsigned long long __u64; 60#endif /* SIZEOF_LONG == 8 */ 61#endif 62#endif /* EXT2_FLAT_INCLUDES */ 63 64typedef __u32 blk_t; 65typedef __u32 dgrp_t; 66typedef __u32 ext2_off_t; 67typedef __s64 e2_blkcnt_t; 68 69#if EXT2_FLAT_INCLUDES 70#include "com_err.h" 71#include "ext2_io.h" 72#include "ext2_err.h" 73#else 74#include "et/com_err.h" 75#include "ext2fs/ext2_io.h" 76#include "ext2fs/ext2_err.h" 77#endif 78 79/* 80 * Portability help for Microsoft Visual C++ 81 */ 82#ifdef _MSC_VER 83#define EXT2_QSORT_TYPE int __cdecl 84#else 85#define EXT2_QSORT_TYPE int 86#endif 87 88typedef struct struct_ext2_filsys *ext2_filsys; 89 90struct ext2fs_struct_generic_bitmap { 91 errcode_t magic; 92 ext2_filsys fs; 93 __u32 start, end; 94 __u32 real_end; 95 char * description; 96 char * bitmap; 97 errcode_t base_error_code; 98 __u32 reserved[7]; 99}; 100 101#define EXT2FS_MARK_ERROR 0 102#define EXT2FS_UNMARK_ERROR 1 103#define EXT2FS_TEST_ERROR 2 104 105typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap; 106typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap; 107typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap; 108 109#ifdef EXT2_DYNAMIC_REV 110#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) 111#else 112#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO 113#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) 114#endif 115 116/* 117 * badblocks list definitions 118 */ 119 120typedef struct ext2_struct_badblocks_list *ext2_badblocks_list; 121typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate; 122 123/* old */ 124typedef struct ext2_struct_badblocks_list *badblocks_list; 125typedef struct ext2_struct_badblocks_iterate *badblocks_iterate; 126 127#define BADBLOCKS_FLAG_DIRTY 1 128 129/* 130 * ext2_dblist structure and abstractions (see dblist.c) 131 */ 132struct ext2_db_entry { 133 ino_t ino; 134 blk_t blk; 135 int blockcnt; 136}; 137 138typedef struct ext2_struct_dblist *ext2_dblist; 139 140#define DBLIST_ABORT 1 141 142/* 143 * ext2_fileio definitions 144 */ 145 146#define EXT2_FILE_WRITE 0x0001 147#define EXT2_FILE_CREATE 0x0002 148 149#define EXT2_FILE_MASK 0x00FF 150 151#define EXT2_FILE_BUF_DIRTY 0x4000 152#define EXT2_FILE_BUF_VALID 0x2000 153 154typedef struct ext2_file *ext2_file_t; 155 156#define EXT2_SEEK_SET 0 157#define EXT2_SEEK_CUR 1 158#define EXT2_SEEK_END 2 159 160/* 161 * Flags for the ext2_filsys structure 162 */ 163 164#define EXT2_FLAG_RW 0x01 165#define EXT2_FLAG_CHANGED 0x02 166#define EXT2_FLAG_DIRTY 0x04 167#define EXT2_FLAG_VALID 0x08 168#define EXT2_FLAG_IB_DIRTY 0x10 169#define EXT2_FLAG_BB_DIRTY 0x20 170#define EXT2_FLAG_SWAP_BYTES 0x40 171#define EXT2_FLAG_SWAP_BYTES_READ 0x80 172#define EXT2_FLAG_SWAP_BYTES_WRITE 0x100 173#define EXT2_FLAG_MASTER_SB_ONLY 0x200 174#define EXT2_FLAG_FORCE 0x400 175 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 182struct struct_ext2_filsys { 183 errcode_t magic; 184 io_channel io; 185 int flags; 186 char * device_name; 187 struct ext2_super_block * super; 188 int blocksize; 189 int fragsize; 190 dgrp_t group_desc_count; 191 unsigned long desc_blocks; 192 struct ext2_group_desc * group_desc; 193 int inode_blocks_per_group; 194 ext2fs_inode_bitmap inode_map; 195 ext2fs_block_bitmap block_map; 196 errcode_t (*get_blocks)(ext2_filsys fs, ino_t ino, blk_t *blocks); 197 errcode_t (*check_directory)(ext2_filsys fs, ino_t ino); 198 errcode_t (*write_bitmaps)(ext2_filsys fs); 199 errcode_t (*read_inode)(ext2_filsys fs, ino_t ino, 200 struct ext2_inode *inode); 201 errcode_t (*write_inode)(ext2_filsys fs, ino_t ino, 202 struct ext2_inode *inode); 203 badblocks_list badblocks; 204 ext2_dblist dblist; 205 __u32 stride; /* for mke2fs */ 206 struct ext2_super_block * orig_super; 207 /* 208 * Reserved for future expansion 209 */ 210 __u32 reserved[10]; 211 212 /* 213 * Reserved for the use of the calling application. 214 */ 215 void * priv_data; 216 217 /* 218 * Inode cache 219 */ 220 struct ext2_inode_cache *icache; 221}; 222 223#if EXT2_FLAT_INCLUDES 224#include "e2_bitops.h" 225#else 226#include "ext2fs/bitops.h" 227#endif 228 229/* 230 * Return flags for the block iterator functions 231 */ 232#define BLOCK_CHANGED 1 233#define BLOCK_ABORT 2 234#define BLOCK_ERROR 4 235 236/* 237 * Block interate flags 238 * 239 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator 240 * function should be called on blocks where the block number is zero. 241 * This is used by ext2fs_expand_dir() to be able to add a new block 242 * to an inode. It can also be used for programs that want to be able 243 * to deal with files that contain "holes". 244 * 245 * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the 246 * indirect, doubly indirect, etc. blocks should be called after all 247 * of the blocks containined in the indirect blocks are processed. 248 * This is useful if you are going to be deallocating blocks from an 249 * inode. 250 * 251 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be 252 * called for data blocks only. 253 * 254 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs 255 * ext2fs_block_iterate2 that large files won't be accepted. 256 */ 257#define BLOCK_FLAG_APPEND 1 258#define BLOCK_FLAG_HOLE 1 259#define BLOCK_FLAG_DEPTH_TRAVERSE 2 260#define BLOCK_FLAG_DATA_ONLY 4 261 262#define BLOCK_FLAG_NO_LARGE 0x1000 263 264/* 265 * Magic "block count" return values for the block iterator function. 266 */ 267#define BLOCK_COUNT_IND (-1) 268#define BLOCK_COUNT_DIND (-2) 269#define BLOCK_COUNT_TIND (-3) 270#define BLOCK_COUNT_TRANSLATOR (-4) 271 272#if 0 273/* 274 * Flags for ext2fs_move_blocks 275 */ 276#define EXT2_BMOVE_GET_DBLIST 0x0001 277#define EXT2_BMOVE_DEBUG 0x0002 278#endif 279 280/* 281 * Return flags for the directory iterator functions 282 */ 283#define DIRENT_CHANGED 1 284#define DIRENT_ABORT 2 285#define DIRENT_ERROR 3 286 287/* 288 * Directory iterator flags 289 */ 290 291#define DIRENT_FLAG_INCLUDE_EMPTY 1 292 293 294#define DIRENT_DOT_FILE 1 295#define DIRENT_DOT_DOT_FILE 2 296#define DIRENT_OTHER_FILE 3 297 298/* 299 * Inode scan definitions 300 */ 301typedef struct ext2_struct_inode_scan *ext2_inode_scan; 302 303/* 304 * ext2fs_scan flags 305 */ 306#define EXT2_SF_CHK_BADBLOCKS 0x0001 307#define EXT2_SF_BAD_INODE_BLK 0x0002 308#define EXT2_SF_BAD_EXTRA_BYTES 0x0004 309#define EXT2_SF_SKIP_MISSING_ITABLE 0x0008 310 311/* 312 * ext2fs_check_if_mounted flags 313 */ 314#define EXT2_MF_MOUNTED 1 315#define EXT2_MF_ISROOT 2 316#define EXT2_MF_READONLY 4 317 318/* 319 * Ext2/linux mode flags. We define them here so that we don't need 320 * to depend on the OS's sys/stat.h, since we may be compiling on a 321 * non-Linux system. 322 */ 323#define LINUX_S_IFMT 00170000 324#define LINUX_S_IFSOCK 0140000 325#define LINUX_S_IFLNK 0120000 326#define LINUX_S_IFREG 0100000 327#define LINUX_S_IFBLK 0060000 328#define LINUX_S_IFDIR 0040000 329#define LINUX_S_IFCHR 0020000 330#define LINUX_S_IFIFO 0010000 331#define LINUX_S_ISUID 0004000 332#define LINUX_S_ISGID 0002000 333#define LINUX_S_ISVTX 0001000 334 335#define LINUX_S_IRWXU 00700 336#define LINUX_S_IRUSR 00400 337#define LINUX_S_IWUSR 00200 338#define LINUX_S_IXUSR 00100 339 340#define LINUX_S_IRWXG 00070 341#define LINUX_S_IRGRP 00040 342#define LINUX_S_IWGRP 00020 343#define LINUX_S_IXGRP 00010 344 345#define LINUX_S_IRWXO 00007 346#define LINUX_S_IROTH 00004 347#define LINUX_S_IWOTH 00002 348#define LINUX_S_IXOTH 00001 349 350#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK) 351#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG) 352#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR) 353#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR) 354#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK) 355#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO) 356#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK) 357 358/* 359 * ext2_icount_t abstraction 360 */ 361#define EXT2_ICOUNT_OPT_INCREMENT 0x01 362 363typedef struct ext2_icount *ext2_icount_t; 364 365/* 366 * Flags for ext2fs_bmap 367 */ 368#define BMAP_ALLOC 1 369 370/* 371 * Flags for imager.c functions 372 */ 373#define IMAGER_FLAG_INODEMAP 1 374#define IMAGER_FLAG_SPARSEWRITE 2 375 376/* 377 * For checking structure magic numbers... 378 */ 379 380#define EXT2_CHECK_MAGIC(struct, code) \ 381 if ((struct)->magic != (code)) return (code) 382 383 384/* 385 * The ext2fs library private definition of the ext2 superblock, so we 386 * don't have to depend on the kernel's definition of the superblock, 387 * which might not have the latest features. 388 */ 389struct ext2fs_sb { 390 __u32 s_inodes_count; /* Inodes count */ 391 __u32 s_blocks_count; /* Blocks count */ 392 __u32 s_r_blocks_count; /* Reserved blocks count */ 393 __u32 s_free_blocks_count; /* Free blocks count */ 394 __u32 s_free_inodes_count; /* Free inodes count */ 395 __u32 s_first_data_block; /* First Data Block */ 396 __u32 s_log_block_size; /* Block size */ 397 __s32 s_log_frag_size; /* Fragment size */ 398 __u32 s_blocks_per_group; /* # Blocks per group */ 399 __u32 s_frags_per_group; /* # Fragments per group */ 400 __u32 s_inodes_per_group; /* # Inodes per group */ 401 __u32 s_mtime; /* Mount time */ 402 __u32 s_wtime; /* Write time */ 403 __u16 s_mnt_count; /* Mount count */ 404 __s16 s_max_mnt_count; /* Maximal mount count */ 405 __u16 s_magic; /* Magic signature */ 406 __u16 s_state; /* File system state */ 407 __u16 s_errors; /* Behaviour when detecting errors */ 408 __u16 s_minor_rev_level; /* minor revision level */ 409 __u32 s_lastcheck; /* time of last check */ 410 __u32 s_checkinterval; /* max. time between checks */ 411 __u32 s_creator_os; /* OS */ 412 __u32 s_rev_level; /* Revision level */ 413 __u16 s_def_resuid; /* Default uid for reserved blocks */ 414 __u16 s_def_resgid; /* Default gid for reserved blocks */ 415 /* 416 * These fields are for EXT2_DYNAMIC_REV superblocks only. 417 * 418 * Note: the difference between the compatible feature set and 419 * the incompatible feature set is that if there is a bit set 420 * in the incompatible feature set that the kernel doesn't 421 * know about, it should refuse to mount the filesystem. 422 * 423 * e2fsck's requirements are more strict; if it doesn't know 424 * about a feature in either the compatible or incompatible 425 * feature set, it must abort and not try to meddle with 426 * things it doesn't understand... 427 */ 428 __u32 s_first_ino; /* First non-reserved inode */ 429 __u16 s_inode_size; /* size of inode structure */ 430 __u16 s_block_group_nr; /* block group # of this superblock */ 431 __u32 s_feature_compat; /* compatible feature set */ 432 __u32 s_feature_incompat; /* incompatible feature set */ 433 __u32 s_feature_ro_compat; /* readonly-compatible feature set */ 434 __u8 s_uuid[16]; /* 128-bit uuid for volume */ 435 char s_volume_name[16]; /* volume name */ 436 char s_last_mounted[64]; /* directory where last mounted */ 437 __u32 s_algorithm_usage_bitmap; /* For compression */ 438 /* 439 * Performance hints. Directory preallocation should only 440 * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on. 441 */ 442 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 443 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 444 __u16 s_padding1; 445 /* 446 * Journaling support. 447 */ 448 __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 449 __u32 s_journal_inum; /* inode number of journal file */ 450 __u32 s_journal_dev; /* device number of journal file */ 451 __u32 s_last_orphan; /* start of list of inodes to delete */ 452 453 __u32 s_reserved[197]; /* Padding to the end of the block */ 454}; 455 456#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff) 457#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR) 458 459/* 460 * Feature set definitions (that might not be in ext2_fs.h 461 */ 462 463#ifndef EXT2_FEATURE_COMPAT_DIR_PREALLOC 464#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 465#endif 466 467#ifndef EXT2_FEATURE_COMPAT_IMAGIC_INODES /* for AFS, etc. */ 468#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 469#define EXT2_IMAGIC_FL 0x00002000 470#endif 471 472#ifndef EXT3_FEATURE_COMPAT_HAS_JOURNAL 473#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 474#endif 475 476#ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 477#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 478#endif 479 480#ifndef EXT2_FEATURE_RO_COMPAT_LARGE_FILE 481#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 482#define i_size_high i_dir_acl 483#endif 484 485#ifndef EXT2_FEATURE_RO_COMPAT_BTREE_DIR 486#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 487#endif 488 489#ifndef EXT2_FEATURE_INCOMPAT_COMPRESSION 490#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 491#endif 492 493#ifndef EXT2_FEATURE_INCOMPAT_FILETYPE 494#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 495#endif 496 497#ifndef EXT3_FEATURE_INCOMPAT_RECOVER 498#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 499#endif 500 501#define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\ 502 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\ 503 EXT3_FEATURE_COMPAT_HAS_JOURNAL) 504/* This #ifdef is temporary until compression is fully supported */ 505#ifdef ENABLE_COMPRESSION 506#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL 507/* If the below warning bugs you, then have 508 `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your 509 environment at configure time. */ 510#warning "Compression support is experimental" 511#endif 512#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ 513 EXT2_FEATURE_INCOMPAT_COMPRESSION|\ 514 EXT3_FEATURE_INCOMPAT_RECOVER) 515#else 516#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ 517 EXT3_FEATURE_INCOMPAT_RECOVER) 518#endif 519#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ 520 EXT2_FEATURE_RO_COMPAT_LARGE_FILE) 521/* 522 * function prototypes 523 */ 524 525/* alloc.c */ 526extern errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode, 527 ext2fs_inode_bitmap map, ino_t *ret); 528extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, 529 ext2fs_block_bitmap map, blk_t *ret); 530extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, 531 blk_t finish, int num, 532 ext2fs_block_bitmap map, 533 blk_t *ret); 534extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, 535 char *block_buf, blk_t *ret); 536 537/* alloc_tables.c */ 538extern errcode_t ext2fs_allocate_tables(ext2_filsys fs); 539extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, 540 ext2fs_block_bitmap bmap); 541 542/* badblocks.c */ 543extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, 544 int size); 545extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, 546 blk_t blk); 547extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb, 548 blk_t blk); 549extern errcode_t 550 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb, 551 ext2_badblocks_iterate *ret); 552extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter, 553 blk_t *blk); 554extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter); 555extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, 556 ext2_badblocks_list *dest); 557extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1, 558 ext2_badblocks_list bb2); 559 560/* bb_compat */ 561extern errcode_t badblocks_list_create(badblocks_list *ret, int size); 562extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk); 563extern int badblocks_list_test(badblocks_list bb, blk_t blk); 564extern errcode_t badblocks_list_iterate_begin(badblocks_list bb, 565 badblocks_iterate *ret); 566extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk); 567extern void badblocks_list_iterate_end(badblocks_iterate iter); 568extern void badblocks_list_free(badblocks_list bb); 569 570/* bb_inode.c */ 571extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs, 572 ext2_badblocks_list bb_list); 573 574/* bitmaps.c */ 575extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs); 576extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs); 577extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs); 578extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); 579extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start, 580 __u32 end, 581 __u32 real_end, 582 const char *descr, 583 ext2fs_generic_bitmap *ret); 584extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, 585 const char *descr, 586 ext2fs_block_bitmap *ret); 587extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, 588 const char *descr, 589 ext2fs_inode_bitmap *ret); 590extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, 591 ino_t end, ino_t *oend); 592extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, 593 blk_t end, blk_t *oend); 594extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap); 595extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap); 596extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs); 597extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs); 598 599/* block.c */ 600extern errcode_t ext2fs_block_iterate(ext2_filsys fs, 601 ino_t ino, 602 int flags, 603 char *block_buf, 604 int (*func)(ext2_filsys fs, 605 blk_t *blocknr, 606 int blockcnt, 607 void *priv_data), 608 void *priv_data); 609errcode_t ext2fs_block_iterate2(ext2_filsys fs, 610 ino_t ino, 611 int flags, 612 char *block_buf, 613 int (*func)(ext2_filsys fs, 614 blk_t *blocknr, 615 e2_blkcnt_t blockcnt, 616 blk_t ref_blk, 617 int ref_offset, 618 void *priv_data), 619 void *priv_data); 620 621/* bmap.c */ 622extern errcode_t ext2fs_bmap(ext2_filsys fs, ino_t ino, 623 struct ext2_inode *inode, 624 char *block_buf, int bmap_flags, 625 blk_t block, blk_t *phys_blk); 626 627 628#if 0 629/* bmove.c */ 630extern errcode_t ext2fs_move_blocks(ext2_filsys fs, 631 ext2fs_block_bitmap reserve, 632 ext2fs_block_bitmap alloc_map, 633 int flags); 634#endif 635 636/* check_desc.c */ 637extern errcode_t ext2fs_check_desc(ext2_filsys fs); 638 639/* closefs.c */ 640extern errcode_t ext2fs_close(ext2_filsys fs); 641extern errcode_t ext2fs_flush(ext2_filsys fs); 642extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block); 643 644/* cmp_bitmaps.c */ 645extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, 646 ext2fs_block_bitmap bm2); 647extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, 648 ext2fs_inode_bitmap bm2); 649 650/* dblist.c */ 651 652extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ino_t *ret_num_dirs); 653extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist); 654extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino, 655 blk_t blk, int blockcnt); 656extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, 657 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, 658 void *priv_data), 659 void *priv_data); 660extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ino_t ino, 661 blk_t blk, int blockcnt); 662extern errcode_t ext2fs_copy_dblist(ext2_dblist src, 663 ext2_dblist *dest); 664extern int ext2fs_dblist_count(ext2_dblist dblist); 665 666/* dblist_dir.c */ 667extern errcode_t 668 ext2fs_dblist_dir_iterate(ext2_dblist dblist, 669 int flags, 670 char *block_buf, 671 int (*func)(ino_t dir, 672 int entry, 673 struct ext2_dir_entry *dirent, 674 int offset, 675 int blocksize, 676 char *buf, 677 void *priv_data), 678 void *priv_data); 679 680/* dirblock.c */ 681extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, 682 void *buf); 683extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, 684 void *buf); 685 686/* dir_iterate.c */ 687extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, 688 ino_t dir, 689 int flags, 690 char *block_buf, 691 int (*func)(struct ext2_dir_entry *dirent, 692 int offset, 693 int blocksize, 694 char *buf, 695 void *priv_data), 696 void *priv_data); 697 698/* dupfs.c */ 699extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest); 700 701/* expanddir.c */ 702extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir); 703 704/* fileio.c */ 705extern errcode_t ext2fs_file_open(ext2_filsys fs, ino_t ino, 706 int flags, ext2_file_t *ret); 707extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file); 708extern errcode_t ext2fs_file_close(ext2_file_t file); 709extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf, 710 unsigned int wanted, unsigned int *got); 711extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf, 712 unsigned int nbytes, unsigned int *written); 713extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, 714 int whence, ext2_off_t *ret_pos); 715extern ext2_off_t ext2fs_file_get_size(ext2_file_t file); 716extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size); 717 718/* finddev.c */ 719extern char *ext2fs_find_block_device(dev_t device); 720 721/* freefs.c */ 722extern void ext2fs_free(ext2_filsys fs); 723extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap); 724extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap); 725extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap); 726extern void ext2fs_free_dblist(ext2_dblist dblist); 727extern void ext2fs_badblocks_list_free(badblocks_list bb); 728 729/* getsize.c */ 730extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, 731 blk_t *retblocks); 732 733/* imager.c */ 734extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags); 735extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags); 736extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags); 737extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags); 738extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags); 739extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags); 740 741/* initialize.c */ 742extern errcode_t ext2fs_initialize(const char *name, int flags, 743 struct ext2_super_block *param, 744 io_manager manager, ext2_filsys *ret_fs); 745 746/* inode.c */ 747extern errcode_t ext2fs_flush_icache(ext2_filsys fs); 748extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, 749 ext2_inode_scan *ret_scan); 750extern void ext2fs_close_inode_scan(ext2_inode_scan scan); 751extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ino_t *ino, 752 struct ext2_inode *inode); 753extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, 754 int group); 755extern void ext2fs_set_inode_callback 756 (ext2_inode_scan scan, 757 errcode_t (*done_group)(ext2_filsys fs, 758 ext2_inode_scan scan, 759 dgrp_t group, 760 void * priv_data), 761 void *done_group_data); 762extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, 763 int clear_flags); 764extern errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino, 765 struct ext2_inode * inode); 766extern errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino, 767 struct ext2_inode * inode); 768extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ino_t ino, blk_t *blocks); 769extern errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino); 770 771/* icount.c */ 772extern void ext2fs_free_icount(ext2_icount_t icount); 773extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size, 774 ext2_icount_t hint, ext2_icount_t *ret); 775extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size, 776 ext2_icount_t *ret); 777extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino, 778 __u16 *ret); 779extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino, 780 __u16 *ret); 781extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino, 782 __u16 *ret); 783extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino, 784 __u16 count); 785extern ino_t ext2fs_get_icount_size(ext2_icount_t icount); 786errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); 787 788/* ismounted.c */ 789extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); 790 791/* namei.c */ 792extern errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name, 793 int namelen, char *buf, ino_t *inode); 794extern errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd, 795 const char *name, ino_t *inode); 796errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd, 797 const char *name, ino_t *inode); 798extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd, 799 ino_t inode, ino_t *res_inode); 800 801/* native.c */ 802int ext2fs_native_flag(void); 803 804/* newdir.c */ 805extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino, 806 ino_t parent_ino, char **block); 807 808/* mkdir.c */ 809extern errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum, 810 const char *name); 811 812/* mkjournal.c */ 813extern errcode_t ext2fs_add_journal_device(ext2_filsys fs, char *device, 814 blk_t size); 815extern errcode_t ext2fs_add_journal_fs(ext2_filsys fs, blk_t size); 816 817/* openfs.c */ 818extern errcode_t ext2fs_open(const char *name, int flags, int superblock, 819 int block_size, io_manager manager, 820 ext2_filsys *ret_fs); 821 822/* get_pathname.c */ 823extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino, 824 char **name); 825 826/* link.c */ 827errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name, 828 ino_t ino, int flags); 829errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name, 830 ino_t ino, int flags); 831 832/* read_bb.c */ 833extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, 834 ext2_badblocks_list *bb_list); 835 836/* read_bb_file.c */ 837extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, 838 ext2_badblocks_list *bb_list, 839 void *private, 840 void (*invalid)(ext2_filsys fs, 841 blk_t blk, 842 char *badstr, 843 void *private)); 844extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 845 ext2_badblocks_list *bb_list, 846 void (*invalid)(ext2_filsys fs, 847 blk_t blk)); 848 849/* rs_bitmap.c */ 850extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, 851 __u32 new_real_end, 852 ext2fs_generic_bitmap bmap); 853extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, 854 ext2fs_inode_bitmap bmap); 855extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, 856 ext2fs_block_bitmap bmap); 857extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, 858 ext2fs_generic_bitmap *dest); 859 860/* swapfs.c */ 861extern void ext2fs_swap_super(struct ext2_super_block * super); 862extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp); 863extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, 864 struct ext2_inode *f, int hostorder); 865 866/* valid_blk.c */ 867extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); 868 869/* version.c */ 870extern int ext2fs_parse_version_string(const char *ver_string); 871extern int ext2fs_get_library_version(const char **ver_string, 872 const char **date_string); 873 874/* inline functions */ 875extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr); 876extern errcode_t ext2fs_free_mem(void **ptr); 877extern errcode_t ext2fs_resize_mem(unsigned long old_size, 878 unsigned long size, void **ptr); 879extern void ext2fs_mark_super_dirty(ext2_filsys fs); 880extern void ext2fs_mark_changed(ext2_filsys fs); 881extern int ext2fs_test_changed(ext2_filsys fs); 882extern void ext2fs_mark_valid(ext2_filsys fs); 883extern void ext2fs_unmark_valid(ext2_filsys fs); 884extern int ext2fs_test_valid(ext2_filsys fs); 885extern void ext2fs_mark_ib_dirty(ext2_filsys fs); 886extern void ext2fs_mark_bb_dirty(ext2_filsys fs); 887extern int ext2fs_test_ib_dirty(ext2_filsys fs); 888extern int ext2fs_test_bb_dirty(ext2_filsys fs); 889extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); 890extern int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino); 891 892/* 893 * The actual inlined functions definitions themselves... 894 * 895 * If NO_INLINE_FUNCS is defined, then we won't try to do inline 896 * functions at all! 897 */ 898#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) 899#ifdef INCLUDE_INLINE_FUNCS 900#define _INLINE_ extern 901#else 902#ifdef __GNUC__ 903#define _INLINE_ extern __inline__ 904#else /* For Watcom C */ 905#define _INLINE_ extern inline 906#endif 907#endif 908 909#ifndef EXT2_CUSTOM_MEMORY_ROUTINES 910/* 911 * Allocate memory 912 */ 913_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr) 914{ 915 *ptr = malloc(size); 916 if (!*ptr) 917 return EXT2_ET_NO_MEMORY; 918 return 0; 919} 920 921/* 922 * Free memory 923 */ 924_INLINE_ errcode_t ext2fs_free_mem(void **ptr) 925{ 926 free(*ptr); 927 *ptr = 0; 928 return 0; 929} 930 931/* 932 * Resize memory 933 */ 934_INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size, 935 unsigned long size, void **ptr) 936{ 937 void *p; 938 939 p = realloc(*ptr, size); 940 if (!p) 941 return EXT2_ET_NO_MEMORY; 942 *ptr = p; 943 return 0; 944} 945#endif /* Custom memory routines */ 946 947/* 948 * Mark a filesystem superblock as dirty 949 */ 950_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs) 951{ 952 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; 953} 954 955/* 956 * Mark a filesystem as changed 957 */ 958_INLINE_ void ext2fs_mark_changed(ext2_filsys fs) 959{ 960 fs->flags |= EXT2_FLAG_CHANGED; 961} 962 963/* 964 * Check to see if a filesystem has changed 965 */ 966_INLINE_ int ext2fs_test_changed(ext2_filsys fs) 967{ 968 return (fs->flags & EXT2_FLAG_CHANGED); 969} 970 971/* 972 * Mark a filesystem as valid 973 */ 974_INLINE_ void ext2fs_mark_valid(ext2_filsys fs) 975{ 976 fs->flags |= EXT2_FLAG_VALID; 977} 978 979/* 980 * Mark a filesystem as NOT valid 981 */ 982_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs) 983{ 984 fs->flags &= ~EXT2_FLAG_VALID; 985} 986 987/* 988 * Check to see if a filesystem is valid 989 */ 990_INLINE_ int ext2fs_test_valid(ext2_filsys fs) 991{ 992 return (fs->flags & EXT2_FLAG_VALID); 993} 994 995/* 996 * Mark the inode bitmap as dirty 997 */ 998_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs) 999{ 1000 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; 1001} 1002 1003/* 1004 * Mark the block bitmap as dirty 1005 */ 1006_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs) 1007{ 1008 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; 1009} 1010 1011/* 1012 * Check to see if a filesystem's inode bitmap is dirty 1013 */ 1014_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs) 1015{ 1016 return (fs->flags & EXT2_FLAG_IB_DIRTY); 1017} 1018 1019/* 1020 * Check to see if a filesystem's block bitmap is dirty 1021 */ 1022_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) 1023{ 1024 return (fs->flags & EXT2_FLAG_BB_DIRTY); 1025} 1026 1027/* 1028 * Return the group # of a block 1029 */ 1030_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) 1031{ 1032 return (blk - fs->super->s_first_data_block) / 1033 fs->super->s_blocks_per_group; 1034} 1035 1036/* 1037 * Return the group # of an inode number 1038 */ 1039_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ino_t ino) 1040{ 1041 return (ino - 1) / fs->super->s_inodes_per_group; 1042} 1043#undef _INLINE_ 1044#endif 1045 1046#ifdef __cplusplus 1047} 1048#endif 1049 1050#endif /* _EXT2FS_EXT2FS_H */ 1051