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