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