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