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