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