4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
12 #ifndef _EXT2FS_EXT2FS_H
13 #define _EXT2FS_EXT2FS_H
16 #define EXT2FS_ATTR(x) __attribute__(x)
18 #define EXT2FS_ATTR(x)
22 #ifdef __has_attribute
23 #if __has_attribute(__nonstring__)
24 #define __nonstring __attribute__((__nonstring__))
27 #endif /* __has_attribute(__nonstring__) */
30 #endif /* __has_attribute */
31 #endif /* __nonstring */
34 #define EXT2FS_NO_TDB_UNUSED
36 #define EXT2FS_NO_TDB_UNUSED EXT2FS_ATTR((unused))
44 * Non-GNU C compilers won't necessarily understand inline
46 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
47 #define NO_INLINE_FUNCS
51 * Where the master copy of the superblock is located, and how big
52 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
53 * the size of the superblock structure is not necessarily trustworthy
54 * (some versions have the padding set up so that the superblock is
57 #define SUPERBLOCK_OFFSET 1024
58 #define SUPERBLOCK_SIZE 1024
60 #define UUID_STR_SIZE 37
63 * The last ext2fs revision level that this version of the library is
66 #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
68 #ifdef HAVE_SYS_TYPES_H
69 #include <sys/types.h>
78 #if EXT2_FLAT_INCLUDES
81 #include "ext3_extents.h"
83 #include <ext2fs/ext2_types.h>
84 #include <ext2fs/ext2_fs.h>
85 #include <ext2fs/ext3_extents.h>
86 #endif /* EXT2_FLAT_INCLUDES */
88 typedef __u32 __bitwise ext2_ino_t;
89 typedef __u32 __bitwise blk_t;
90 typedef __u64 __bitwise blk64_t;
91 typedef __u32 __bitwise dgrp_t;
92 typedef __s32 __bitwise ext2_off_t;
93 typedef __s64 __bitwise ext2_off64_t;
94 typedef __s64 __bitwise e2_blkcnt_t;
95 typedef __u32 __bitwise ext2_dirhash_t;
97 #if EXT2_FLAT_INCLUDES
100 #include "ext2_err.h"
101 #include "ext2_ext_attr.h"
103 #include <et/com_err.h>
104 #include <ext2fs/ext2_io.h>
105 #include <ext2fs/ext2_err.h>
106 #include <ext2fs/ext2_ext_attr.h>
112 * Portability help for Microsoft Visual C++
115 #define EXT2_QSORT_TYPE int __cdecl
117 #define EXT2_QSORT_TYPE int
120 typedef struct struct_ext2_filsys *ext2_filsys;
122 #define EXT2FS_MARK_ERROR 0
123 #define EXT2FS_UNMARK_ERROR 1
124 #define EXT2FS_TEST_ERROR 2
126 struct ext2fs_struct_generic_bitmap_base {
131 typedef struct ext2fs_struct_generic_bitmap_base *ext2fs_generic_bitmap;
132 typedef struct ext2fs_struct_generic_bitmap_base *ext2fs_inode_bitmap;
133 typedef struct ext2fs_struct_generic_bitmap_base *ext2fs_block_bitmap;
135 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
139 * Badblocks list definitions
142 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
143 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
145 typedef struct ext2_struct_u32_list *ext2_u32_list;
146 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
149 typedef struct ext2_struct_u32_list *badblocks_list;
150 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
152 #define BADBLOCKS_FLAG_DIRTY 1
155 * ext2_dblist structure and abstractions (see dblist.c)
157 struct ext2_db_entry2 {
160 e2_blkcnt_t blockcnt;
163 /* Ye Olde 32-bit version */
164 struct ext2_db_entry {
170 typedef struct ext2_struct_dblist *ext2_dblist;
172 #define DBLIST_ABORT 1
175 * ext2_fileio definitions
178 #define EXT2_FILE_WRITE 0x0001
179 #define EXT2_FILE_CREATE 0x0002
181 #define EXT2_FILE_MASK 0x00FF
183 #define EXT2_FILE_BUF_DIRTY 0x4000
184 #define EXT2_FILE_BUF_VALID 0x2000
186 typedef struct ext2_file *ext2_file_t;
188 #define EXT2_SEEK_SET 0
189 #define EXT2_SEEK_CUR 1
190 #define EXT2_SEEK_END 2
193 * Flags for the ext2_filsys structure and for ext2fs_open()
195 #define EXT2_FLAG_RW 0x01
196 #define EXT2_FLAG_CHANGED 0x02
197 #define EXT2_FLAG_DIRTY 0x04
198 #define EXT2_FLAG_VALID 0x08
199 #define EXT2_FLAG_IB_DIRTY 0x10
200 #define EXT2_FLAG_BB_DIRTY 0x20
201 #define EXT2_FLAG_SWAP_BYTES 0x40
202 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
203 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
204 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
205 #define EXT2_FLAG_FORCE 0x400
206 #define EXT2_FLAG_SUPER_ONLY 0x800
207 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
208 #define EXT2_FLAG_IMAGE_FILE 0x2000
209 #define EXT2_FLAG_EXCLUSIVE 0x4000
210 #define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000
211 #define EXT2_FLAG_NOFREE_ON_ERROR 0x10000
212 #define EXT2_FLAG_64BITS 0x20000
213 #define EXT2_FLAG_PRINT_PROGRESS 0x40000
214 #define EXT2_FLAG_DIRECT_IO 0x80000
215 #define EXT2_FLAG_SKIP_MMP 0x100000
216 #define EXT2_FLAG_IGNORE_CSUM_ERRORS 0x200000
217 #define EXT2_FLAG_SHARE_DUP 0x400000
218 #define EXT2_FLAG_IGNORE_SB_ERRORS 0x800000
219 #define EXT2_FLAG_BBITMAP_TAIL_PROBLEM 0x1000000
220 #define EXT2_FLAG_IBITMAP_TAIL_PROBLEM 0x2000000
221 #define EXT2_FLAG_THREADS 0x4000000
222 #define EXT2_FLAG_IGNORE_SWAP_DIRENT 0x8000000
225 * Special flag in the ext2 inode i_flag field that means that this is
226 * a new inode. (So that ext2_write_inode() can clear extra fields.)
228 #define EXT2_NEW_INODE_FL 0x80000000
231 * Flags for mkjournal
233 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001 /* create V1 superblock (deprecated) */
234 #define EXT2_MKJOURNAL_LAZYINIT 0x0000002 /* don't zero journal inode before use*/
235 #define EXT2_MKJOURNAL_NO_MNT_CHECK 0x0000004 /* don't check mount status */
238 * Normal journal area size to fast commit area size ratio. This is used to
239 * set default size of fast commit area.
241 #define EXT2_JOURNAL_TO_FC_BLKS_RATIO 64
243 struct blk_alloc_ctx;
244 struct opaque_ext2_group_desc;
246 struct struct_ext2_filsys {
251 struct ext2_super_block * super;
252 unsigned int blocksize;
254 dgrp_t group_desc_count;
255 unsigned long desc_blocks;
256 struct opaque_ext2_group_desc * group_desc;
257 unsigned int inode_blocks_per_group;
258 ext2fs_inode_bitmap inode_map;
259 ext2fs_block_bitmap block_map;
260 /* XXX FIXME-64: not 64-bit safe, but not used? */
261 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
262 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
263 errcode_t (*write_bitmaps)(ext2_filsys fs);
264 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
265 struct ext2_inode *inode);
266 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
267 struct ext2_inode *inode);
268 ext2_badblocks_list badblocks;
270 __u32 stride; /* for mke2fs */
271 struct ext2_super_block * orig_super;
272 struct ext2_image_hdr * image_header;
275 int cluster_ratio_bits;
276 __u16 default_bitmap_type;
278 __u32 fs_num_threads;
280 * Reserved for future expansion
285 * Reserved for the use of the calling application.
292 struct ext2_inode_cache *icache;
296 * More callback functions
298 errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
300 errcode_t (*get_alloc_block2)(ext2_filsys fs, blk64_t goal,
301 blk64_t *ret, struct blk_alloc_ctx *ctx);
302 void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
305 * Buffers for Multiple mount protection(MMP) block.
312 * Time at which e2fsck last updated the MMP block.
314 long mmp_last_written;
316 /* progress operation functions */
317 struct ext2fs_progress_ops *progress_ops;
319 /* Precomputed FS UUID checksum for seeding other checksums */
322 io_channel journal_io;
325 /* New block range allocation hooks */
326 errcode_t (*new_range)(ext2_filsys fs, int flags, blk64_t goal,
327 blk64_t len, blk64_t *pblk, blk64_t *plen);
328 void (*block_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
331 /* hashmap for SHA of data blocks */
332 struct ext2fs_hashmap* block_sha_map;
334 const struct ext2fs_nls_table *encoding;
337 #if EXT2_FLAT_INCLUDES
338 #include "e2_bitops.h"
340 #include <ext2fs/bitops.h>
344 * 64-bit bitmap backend types
346 #define EXT2FS_BMAP64_BITARRAY 1
347 #define EXT2FS_BMAP64_RBTREE 2
348 #define EXT2FS_BMAP64_AUTODIR 3
351 * Return flags for the block iterator functions
353 #define BLOCK_CHANGED 1
354 #define BLOCK_ABORT 2
355 #define BLOCK_ERROR 4
356 #define BLOCK_INLINE_DATA_CHANGED 8
359 * Block interate flags
361 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
362 * function should be called on blocks where the block number is zero.
363 * This is used by ext2fs_expand_dir() to be able to add a new block
364 * to an inode. It can also be used for programs that want to be able
365 * to deal with files that contain "holes".
367 * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
368 * the indirect, doubly indirect, etc. blocks should be called after
369 * all of the blocks contained in the indirect blocks are processed.
370 * This is useful if you are going to be deallocating blocks from an
373 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
374 * called for data blocks only.
376 * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
377 * modify returned block number.
379 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
380 * ext2fs_block_iterate2 that large files won't be accepted.
382 #define BLOCK_FLAG_APPEND 1
383 #define BLOCK_FLAG_HOLE 1
384 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
385 #define BLOCK_FLAG_DATA_ONLY 4
386 #define BLOCK_FLAG_READ_ONLY 8
388 #define BLOCK_FLAG_NO_LARGE 0x1000
391 * Magic "block count" return values for the block iterator function.
393 #define BLOCK_COUNT_IND (-1)
394 #define BLOCK_COUNT_DIND (-2)
395 #define BLOCK_COUNT_TIND (-3)
396 #define BLOCK_COUNT_TRANSLATOR (-4)
398 #define BLOCK_ALLOC_UNKNOWN 0
399 #define BLOCK_ALLOC_DATA 1
400 #define BLOCK_ALLOC_METADATA 2
402 struct blk_alloc_ctx {
404 struct ext2_inode *inode;
411 * Flags for ext2fs_move_blocks
413 #define EXT2_BMOVE_GET_DBLIST 0x0001
414 #define EXT2_BMOVE_DEBUG 0x0002
418 * Generic (non-filesystem layout specific) extents structure
421 #define EXT2_EXTENT_FLAGS_LEAF 0x0001
422 #define EXT2_EXTENT_FLAGS_UNINIT 0x0002
423 #define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004
425 struct ext2fs_extent {
426 blk64_t e_pblk; /* first physical block */
427 blk64_t e_lblk; /* first logical block extent covers */
428 __u32 e_len; /* number of blocks covered by extent */
429 __u32 e_flags; /* extent flags */
432 typedef struct ext2_extent_handle *ext2_extent_handle_t;
433 typedef struct ext2_extent_path *ext2_extent_path_t;
436 * Flags used by ext2fs_extent_get()
438 #define EXT2_EXTENT_CURRENT 0x0000
439 #define EXT2_EXTENT_MOVE_MASK 0x000F
440 #define EXT2_EXTENT_ROOT 0x0001
441 #define EXT2_EXTENT_LAST_LEAF 0x0002
442 #define EXT2_EXTENT_FIRST_SIB 0x0003
443 #define EXT2_EXTENT_LAST_SIB 0x0004
444 #define EXT2_EXTENT_NEXT_SIB 0x0005
445 #define EXT2_EXTENT_PREV_SIB 0x0006
446 #define EXT2_EXTENT_NEXT_LEAF 0x0007
447 #define EXT2_EXTENT_PREV_LEAF 0x0008
448 #define EXT2_EXTENT_NEXT 0x0009
449 #define EXT2_EXTENT_PREV 0x000A
450 #define EXT2_EXTENT_UP 0x000B
451 #define EXT2_EXTENT_DOWN 0x000C
452 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
455 * Flags used by ext2fs_extent_insert()
457 #define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */
458 #define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */
461 * Flags used by ext2fs_extent_delete()
463 #define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extent gone */
466 * Flags used by ext2fs_extent_set_bmap()
468 #define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001
471 * Data structure returned by ext2fs_extent_get_info()
473 struct ext2_extent_info {
483 __u32 max_uninit_len;
487 * Flags for directory block reading and writing functions
489 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
492 * Return flags for the directory iterator functions
494 #define DIRENT_CHANGED 1
495 #define DIRENT_ABORT 2
496 #define DIRENT_ERROR 3
499 * Directory iterator flags
502 #define DIRENT_FLAG_INCLUDE_EMPTY 1
503 #define DIRENT_FLAG_INCLUDE_REMOVED 2
504 #define DIRENT_FLAG_INCLUDE_CSUM 4
505 #define DIRENT_FLAG_INCLUDE_INLINE_DATA 8
507 #define DIRENT_DOT_FILE 1
508 #define DIRENT_DOT_DOT_FILE 2
509 #define DIRENT_OTHER_FILE 3
510 #define DIRENT_DELETED_FILE 4
511 #define DIRENT_CHECKSUM 5
514 * Inode scan definitions
516 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
521 #define EXT2_SF_CHK_BADBLOCKS 0x0001
522 #define EXT2_SF_BAD_INODE_BLK 0x0002
523 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
524 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
525 #define EXT2_SF_DO_LAZY 0x0010
526 #define EXT2_SF_WARN_GARBAGE_INODES 0x0020
529 * ext2fs_check_if_mounted flags
531 #define EXT2_MF_MOUNTED 1
532 #define EXT2_MF_ISROOT 2
533 #define EXT2_MF_READONLY 4
534 #define EXT2_MF_SWAP 8
535 #define EXT2_MF_BUSY 16
538 * Ext2/linux mode flags. We define them here so that we don't need
539 * to depend on the OS's sys/stat.h, since we may be compiling on a
542 #define LINUX_S_IFMT 00170000
543 #define LINUX_S_IFSOCK 0140000
544 #define LINUX_S_IFLNK 0120000
545 #define LINUX_S_IFREG 0100000
546 #define LINUX_S_IFBLK 0060000
547 #define LINUX_S_IFDIR 0040000
548 #define LINUX_S_IFCHR 0020000
549 #define LINUX_S_IFIFO 0010000
550 #define LINUX_S_ISUID 0004000
551 #define LINUX_S_ISGID 0002000
552 #define LINUX_S_ISVTX 0001000
554 #define LINUX_S_IRWXU 00700
555 #define LINUX_S_IRUSR 00400
556 #define LINUX_S_IWUSR 00200
557 #define LINUX_S_IXUSR 00100
559 #define LINUX_S_IRWXG 00070
560 #define LINUX_S_IRGRP 00040
561 #define LINUX_S_IWGRP 00020
562 #define LINUX_S_IXGRP 00010
564 #define LINUX_S_IRWXO 00007
565 #define LINUX_S_IROTH 00004
566 #define LINUX_S_IWOTH 00002
567 #define LINUX_S_IXOTH 00001
569 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
570 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
571 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
572 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
573 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
574 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
575 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
578 * ext2 size of an inode
580 #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
583 * ext2_icount_t abstraction
585 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
586 #define EXT2_ICOUNT_OPT_FULLMAP 0x02
588 typedef struct ext2_icount *ext2_icount_t;
591 * Flags for ext2fs_bmap
593 #define BMAP_ALLOC 0x0001
594 #define BMAP_SET 0x0002
595 #define BMAP_UNINIT 0x0004
596 #define BMAP_ZERO 0x0008
599 * Returned flags from ext2fs_bmap
601 #define BMAP_RET_UNINIT 0x0001
604 * Flags for ext2fs_read_inode2
606 #define READ_INODE_NOCSUM 0x0001
609 * Flags for ext2fs_write_inode2
611 #define WRITE_INODE_NOCSUM 0x0001
614 * Flags for imager.c functions
616 #define IMAGER_FLAG_INODEMAP 1
617 #define IMAGER_FLAG_SPARSEWRITE 2
620 * For checking structure magic numbers...
623 #define EXT2_CHECK_MAGIC(struct, code) \
624 if ((struct)->magic != (code)) return (code)
627 * Features supported by this version of the library
629 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
630 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
631 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
632 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
633 EXT2_FEATURE_COMPAT_DIR_INDEX|\
634 EXT2_FEATURE_COMPAT_EXT_ATTR|\
635 EXT4_FEATURE_COMPAT_SPARSE_SUPER2|\
636 EXT4_FEATURE_COMPAT_FAST_COMMIT|\
637 EXT4_FEATURE_COMPAT_STABLE_INODES)
640 #define EXT4_LIB_INCOMPAT_MMP EXT4_FEATURE_INCOMPAT_MMP
642 #define EXT4_LIB_INCOMPAT_MMP (0)
645 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
646 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
647 EXT2_FEATURE_INCOMPAT_META_BG|\
648 EXT3_FEATURE_INCOMPAT_RECOVER|\
649 EXT3_FEATURE_INCOMPAT_EXTENTS|\
650 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
651 EXT4_FEATURE_INCOMPAT_EA_INODE|\
652 EXT4_LIB_INCOMPAT_MMP|\
653 EXT4_FEATURE_INCOMPAT_64BIT|\
654 EXT4_FEATURE_INCOMPAT_INLINE_DATA|\
655 EXT4_FEATURE_INCOMPAT_ENCRYPT|\
656 EXT4_FEATURE_INCOMPAT_CASEFOLD|\
657 EXT4_FEATURE_INCOMPAT_CSUM_SEED|\
658 EXT4_FEATURE_INCOMPAT_LARGEDIR)
660 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
661 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
662 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
663 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
664 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
665 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
666 EXT4_FEATURE_RO_COMPAT_BIGALLOC|\
667 EXT4_FEATURE_RO_COMPAT_QUOTA|\
668 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
669 EXT4_FEATURE_RO_COMPAT_READONLY |\
670 EXT4_FEATURE_RO_COMPAT_PROJECT |\
671 EXT4_FEATURE_RO_COMPAT_SHARED_BLOCKS |\
672 EXT4_FEATURE_RO_COMPAT_VERITY)
675 * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
678 #define EXT2_LIB_SOFTSUPP_INCOMPAT (0)
679 #define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_REPLICA)
682 /* Translate a block number to a cluster number */
683 #define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits)
684 #define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1)
685 #define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits)
686 /* Translate a cluster number to a block number */
687 #define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits)
688 /* Translate # of blks to # of clusters */
689 #define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
690 (fs)->cluster_ratio_bits)
692 #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
693 typedef struct stat64 ext2fs_struct_stat;
695 typedef struct stat ext2fs_struct_stat;
699 * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
700 * avoid the fsync call.
702 #define EXT2_FLAG_FLUSH_NO_SYNC 1
705 * Modify and iterate extended attributes
707 struct ext2_xattr_handle;
708 #define XATTR_ABORT 1
709 #define XATTR_CHANGED 2
712 * flags for ext2fs_rw_bitmaps()
714 #define EXT2FS_BITMAPS_WRITE 0x0001
715 #define EXT2FS_BITMAPS_BLOCK 0x0002
716 #define EXT2FS_BITMAPS_INODE 0x0004
717 #define EXT2FS_BITMAPS_VALID_FLAGS 0x0007
720 * function prototypes
722 static inline int ext2fs_has_group_desc_csum(ext2_filsys fs)
724 return ext2fs_has_feature_metadata_csum(fs->super) ||
725 ext2fs_has_feature_gdt_csum(fs->super);
728 /* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */
729 static inline int ext2fs_needs_large_file_feature(unsigned long long file_size)
731 return file_size >= 0x80000000ULL;
735 extern void ext2fs_clear_block_uninit(ext2_filsys fs, dgrp_t group);
736 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
737 ext2fs_inode_bitmap map, ext2_ino_t *ret);
738 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
739 ext2fs_block_bitmap map, blk_t *ret);
740 extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
741 ext2fs_block_bitmap map, blk64_t *ret);
742 extern errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,
743 ext2fs_block_bitmap map, blk64_t *ret,
744 struct blk_alloc_ctx *ctx);
745 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
746 blk_t finish, int num,
747 ext2fs_block_bitmap map,
749 extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start,
750 blk64_t finish, int num,
751 ext2fs_block_bitmap map,
753 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
754 char *block_buf, blk_t *ret);
755 extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal,
756 char *block_buf, blk64_t *ret);
757 extern errcode_t ext2fs_alloc_block3(ext2_filsys fs, blk64_t goal,
758 char *block_buf, blk64_t *ret,
759 struct blk_alloc_ctx *ctx);
761 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
762 errcode_t (*func)(ext2_filsys fs,
765 errcode_t (**old)(ext2_filsys fs,
768 blk64_t ext2fs_find_inode_goal(ext2_filsys fs, ext2_ino_t ino,
769 struct ext2_inode *inode, blk64_t lblk);
770 extern void ext2fs_set_new_range_callback(ext2_filsys fs,
771 errcode_t (*func)(ext2_filsys fs, int flags, blk64_t goal,
772 blk64_t len, blk64_t *pblk, blk64_t *plen),
773 errcode_t (**old)(ext2_filsys fs, int flags, blk64_t goal,
774 blk64_t len, blk64_t *pblk, blk64_t *plen));
775 extern void ext2fs_set_block_alloc_stats_range_callback(ext2_filsys fs,
776 void (*func)(ext2_filsys fs, blk64_t blk,
777 blk_t num, int inuse),
778 void (**old)(ext2_filsys fs, blk64_t blk,
779 blk_t num, int inuse));
780 #define EXT2_NEWRANGE_FIXED_GOAL (0x1)
781 #define EXT2_NEWRANGE_MIN_LENGTH (0x2)
782 #define EXT2_NEWRANGE_ALL_FLAGS (0x3)
783 errcode_t ext2fs_new_range(ext2_filsys fs, int flags, blk64_t goal,
784 blk64_t len, ext2fs_block_bitmap map, blk64_t *pblk,
786 #define EXT2_ALLOCRANGE_FIXED_GOAL (0x1)
787 #define EXT2_ALLOCRANGE_ZERO_BLOCKS (0x2)
788 #define EXT2_ALLOCRANGE_ALL_FLAGS (0x3)
789 errcode_t ext2fs_alloc_range(ext2_filsys fs, int flags, blk64_t goal,
790 blk_t len, blk64_t *ret);
793 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
795 ext2fs_block_bitmap bmap);
796 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
797 void (*func)(ext2_filsys fs,
800 void (**old)(ext2_filsys fs,
805 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
806 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
807 int inuse, int isdir);
808 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
809 void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
810 void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
811 blk_t num, int inuse);
814 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
815 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
816 ext2fs_block_bitmap bmap);
819 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
820 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
821 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
822 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
823 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
824 ext2_u32_iterate *ret);
825 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
826 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
827 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
828 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
830 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
832 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
834 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
836 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
837 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
839 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
840 ext2_badblocks_iterate *ret);
841 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
843 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
844 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
845 ext2_badblocks_list *dest);
846 extern errcode_t ext2fs_badblocks_merge(ext2_badblocks_list src,
847 ext2_badblocks_list dest);
848 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
849 ext2_badblocks_list bb2);
850 extern int ext2fs_u32_list_count(ext2_u32_list bb);
853 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
854 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
855 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
856 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
857 badblocks_iterate *ret);
858 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
859 extern void badblocks_list_iterate_end(badblocks_iterate iter);
860 extern void badblocks_list_free(badblocks_list bb);
863 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
864 ext2_badblocks_list bb_list);
867 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
868 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
869 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
870 ext2fs_generic_bitmap *dest);
871 errcode_t ext2fs_merge_bitmap(ext2fs_generic_bitmap src,
872 ext2fs_generic_bitmap dest,
873 ext2fs_generic_bitmap dup,
874 ext2fs_generic_bitmap dup_allowed);
875 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
877 ext2fs_block_bitmap *ret);
878 extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
880 ext2fs_block_bitmap *ret);
881 extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap);
882 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
884 ext2fs_inode_bitmap *ret);
885 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
886 ext2_ino_t end, ext2_ino_t *oend);
887 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
888 blk_t end, blk_t *oend);
889 extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
890 blk64_t end, blk64_t *oend);
891 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
892 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
893 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
894 ext2fs_inode_bitmap bmap);
895 extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end,
897 ext2fs_inode_bitmap bmap);
898 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
899 ext2fs_block_bitmap bmap);
900 extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end,
902 ext2fs_block_bitmap bmap);
903 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
904 ext2fs_block_bitmap bm2);
905 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
906 ext2fs_inode_bitmap bm2);
907 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
908 ext2_ino_t start, unsigned int num,
910 extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
911 __u64 start, size_t num,
913 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
914 ext2_ino_t start, unsigned int num,
916 extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
917 __u64 start, size_t num,
919 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
920 blk_t start, unsigned int num,
922 extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
923 blk64_t start, size_t num,
925 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
926 blk_t start, unsigned int num,
928 extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
929 blk64_t start, size_t num,
933 extern __u32 ext2fs_inode_bitmap_checksum(ext2_filsys fs, dgrp_t group);
934 extern __u32 ext2fs_block_bitmap_checksum(ext2_filsys fs, dgrp_t group);
935 extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
936 extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
937 extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
938 extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
939 extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
940 struct ext2_inode *inode);
941 extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
942 struct ext2_inode *inode);
943 extern blk64_t ext2fs_get_stat_i_blocks(ext2_filsys fs,
944 struct ext2_inode *inode);
945 extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super);
946 extern void ext2fs_blocks_count_set(struct ext2_super_block *super,
948 extern void ext2fs_blocks_count_add(struct ext2_super_block *super,
950 extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super);
951 extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super,
953 extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super,
955 extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super);
956 extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super,
958 extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super,
960 /* Block group descriptor accessor functions */
961 extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
962 struct opaque_ext2_group_desc *gdp,
964 extern blk64_t ext2fs_block_bitmap_csum(ext2_filsys fs, dgrp_t group);
965 extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group);
966 extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
968 extern __u32 ext2fs_inode_bitmap_csum(ext2_filsys fs, dgrp_t group);
969 extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group);
970 extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
972 extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group);
973 extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group,
975 extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group);
976 extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group,
978 extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group);
979 extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group,
981 extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group);
982 extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group,
984 extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
985 extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
987 extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
988 extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
989 extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
990 extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
991 extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
992 extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
993 extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
994 extern blk64_t ext2fs_file_acl_block(ext2_filsys fs,
995 const struct ext2_inode *inode);
996 extern void ext2fs_file_acl_block_set(ext2_filsys fs,
997 struct ext2_inode *inode, blk64_t blk);
998 extern errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode,
1002 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
1006 int (*func)(ext2_filsys fs,
1011 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
1015 int (*func)(ext2_filsys fs,
1017 e2_blkcnt_t blockcnt,
1022 errcode_t ext2fs_block_iterate3(ext2_filsys fs,
1026 int (*func)(ext2_filsys fs,
1028 e2_blkcnt_t blockcnt,
1035 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
1036 struct ext2_inode *inode,
1037 char *block_buf, int bmap_flags,
1038 blk_t block, blk_t *phys_blk);
1039 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
1040 struct ext2_inode *inode,
1041 char *block_buf, int bmap_flags, blk64_t block,
1042 int *ret_flags, blk64_t *phys_blk);
1043 errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino,
1044 struct ext2_inode *inode, blk64_t lblk,
1049 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
1050 ext2fs_block_bitmap reserve,
1051 ext2fs_block_bitmap alloc_map,
1056 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
1059 extern errcode_t ext2fs_close(ext2_filsys fs);
1060 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
1061 extern errcode_t ext2fs_close_free(ext2_filsys *fs);
1062 extern errcode_t ext2fs_flush(ext2_filsys fs);
1063 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
1064 extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
1065 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
1067 blk64_t *ret_super_blk,
1068 blk64_t *ret_old_desc_blk,
1069 blk64_t *ret_new_desc_blk,
1070 blk_t *ret_used_blks);
1071 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
1073 blk_t *ret_super_blk,
1074 blk_t *ret_old_desc_blk,
1075 blk_t *ret_new_desc_blk,
1077 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
1080 extern __u32 ext2fs_crc32_be(__u32 crc, unsigned char const *p, size_t len);
1081 extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
1084 extern void ext2fs_init_csum_seed(ext2_filsys fs);
1085 extern errcode_t ext2fs_mmp_csum_set(ext2_filsys fs, struct mmp_struct *mmp);
1086 extern int ext2fs_mmp_csum_verify(ext2_filsys, struct mmp_struct *mmp);
1087 extern int ext2fs_verify_csum_type(ext2_filsys fs, struct ext2_super_block *sb);
1088 extern errcode_t ext2fs_superblock_csum_set(ext2_filsys fs,
1089 struct ext2_super_block *sb);
1090 extern int ext2fs_superblock_csum_verify(ext2_filsys fs,
1091 struct ext2_super_block *sb);
1092 extern errcode_t ext2fs_ext_attr_block_csum_set(ext2_filsys fs,
1093 ext2_ino_t inum, blk64_t block,
1094 struct ext2_ext_attr_header *hdr);
1095 extern int ext2fs_ext_attr_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1097 struct ext2_ext_attr_header *hdr);
1098 #define EXT2_DIRENT_TAIL(block, blocksize) \
1099 ((struct ext2_dir_entry_tail *)(((char *)(block)) + \
1100 (blocksize) - sizeof(struct ext2_dir_entry_tail)))
1102 extern void ext2fs_initialize_dirent_tail(ext2_filsys fs,
1103 struct ext2_dir_entry_tail *t);
1104 extern int ext2fs_dirent_has_tail(ext2_filsys fs,
1105 struct ext2_dir_entry *dirent);
1106 extern int ext2fs_dirent_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1107 struct ext2_dir_entry *dirent);
1108 extern int ext2fs_dir_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1109 struct ext2_dir_entry *dirent);
1110 extern errcode_t ext2fs_dir_block_csum_set(ext2_filsys fs, ext2_ino_t inum,
1111 struct ext2_dir_entry *dirent);
1112 extern errcode_t ext2fs_get_dx_countlimit(ext2_filsys fs,
1113 struct ext2_dir_entry *dirent,
1114 struct ext2_dx_countlimit **cc,
1116 extern errcode_t ext2fs_dx_csum(ext2_filsys fs, ext2_ino_t inum,
1117 struct ext2_dir_entry *dirent,
1118 __u32 *crc, struct ext2_dx_tail **ret_t);
1119 extern errcode_t ext2fs_extent_block_csum_set(ext2_filsys fs,
1121 struct ext3_extent_header *eh);
1122 extern int ext2fs_extent_block_csum_verify(ext2_filsys fs,
1124 struct ext3_extent_header *eh);
1125 extern errcode_t ext2fs_block_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1126 char *bitmap, int size);
1127 extern int ext2fs_block_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1128 char *bitmap, int size);
1129 extern errcode_t ext2fs_inode_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1130 char *bitmap, int size);
1131 extern int ext2fs_inode_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1132 char *bitmap, int size);
1133 extern errcode_t ext2fs_inode_csum_set(ext2_filsys fs, ext2_ino_t inum,
1134 struct ext2_inode_large *inode);
1135 extern int ext2fs_inode_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1136 struct ext2_inode_large *inode);
1137 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
1138 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
1139 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
1140 extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
1143 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
1144 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1145 blk_t blk, int blockcnt);
1146 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1147 blk64_t blk, e2_blkcnt_t blockcnt);
1148 extern errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest);
1149 extern void ext2fs_dblist_sort(ext2_dblist dblist,
1150 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1152 extern void ext2fs_dblist_sort2(ext2_dblist dblist,
1153 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1155 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
1156 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
1159 extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
1160 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1163 extern errcode_t ext2fs_dblist_iterate3(ext2_dblist dblist,
1164 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1166 unsigned long long start,
1167 unsigned long long count,
1169 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1170 blk_t blk, int blockcnt);
1171 extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1172 blk64_t blk, e2_blkcnt_t blockcnt);
1173 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
1175 extern int ext2fs_dblist_count(ext2_dblist dblist);
1176 extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist);
1177 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
1178 struct ext2_db_entry **entry);
1179 extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
1180 struct ext2_db_entry2 **entry);
1181 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
1185 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
1188 int (*func)(ext2_ino_t dir,
1190 struct ext2_dir_entry *dirent,
1198 /* digest_encode.c */
1199 #define EXT2FS_DIGEST_SIZE EXT2FS_SHA256_LENGTH
1200 extern int ext2fs_digest_encode(const char *src, int len, char *dst);
1201 extern int ext2fs_digest_decode(const char *src, int len, char *dst);
1205 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
1207 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
1208 void *buf, int flags);
1209 extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
1210 void *buf, int flags);
1211 extern errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block,
1212 void *buf, int flags, ext2_ino_t ino);
1213 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
1215 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
1216 void *buf, int flags);
1217 extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
1218 void *buf, int flags);
1219 extern errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block,
1220 void *buf, int flags, ext2_ino_t ino);
1223 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
1225 ext2_dirhash_t *ret_hash,
1226 ext2_dirhash_t *ret_minor_hash);
1228 extern errcode_t ext2fs_dirhash2(int version, const char *name, int len,
1229 const struct ext2fs_nls_table *charset,
1232 ext2_dirhash_t *ret_hash,
1233 ext2_dirhash_t *ret_minor_hash);
1236 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
1237 struct ext2_dir_entry *dirent,
1238 unsigned int *rec_len);
1239 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
1241 struct ext2_dir_entry *dirent);
1242 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
1246 int (*func)(struct ext2_dir_entry *dirent,
1252 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
1256 int (*func)(ext2_ino_t dir,
1258 struct ext2_dir_entry *dirent,
1266 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
1269 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
1272 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
1274 extern errcode_t ext2fs_ext_attr_hash_entry2(ext2_filsys fs,
1275 struct ext2_ext_attr_entry *entry,
1276 void *data, __u32 *hash);
1277 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
1278 extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block,
1280 extern errcode_t ext2fs_read_ext_attr3(ext2_filsys fs, blk64_t block,
1281 void *buf, ext2_ino_t inum);
1282 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
1284 extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block,
1286 extern errcode_t ext2fs_write_ext_attr3(ext2_filsys fs, blk64_t block,
1287 void *buf, ext2_ino_t inum);
1288 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
1290 int adjust, __u32 *newcount);
1291 extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
1293 int adjust, __u32 *newcount);
1294 extern errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk,
1296 int adjust, __u32 *newcount,
1298 errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle);
1299 errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle);
1300 errcode_t ext2fs_xattrs_iterate(struct ext2_xattr_handle *h,
1301 int (*func)(char *name, char *value,
1302 size_t value_len, void *data),
1304 errcode_t ext2fs_xattr_get(struct ext2_xattr_handle *h, const char *key,
1305 void **value, size_t *value_len);
1306 errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *handle,
1310 errcode_t ext2fs_xattr_remove(struct ext2_xattr_handle *handle,
1312 errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
1313 struct ext2_xattr_handle **handle);
1314 errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle);
1315 errcode_t ext2fs_free_ext_attr(ext2_filsys fs, ext2_ino_t ino,
1316 struct ext2_inode_large *inode);
1317 errcode_t ext2fs_xattrs_count(struct ext2_xattr_handle *handle, size_t *count);
1318 errcode_t ext2fs_xattr_inode_max_size(ext2_filsys fs, ext2_ino_t ino,
1320 #define XATTR_HANDLE_FLAG_RAW 0x0001
1321 errcode_t ext2fs_xattrs_flags(struct ext2_xattr_handle *handle,
1322 unsigned int *new_flags, unsigned int *old_flags);
1323 extern void ext2fs_ext_attr_block_rehash(struct ext2_ext_attr_header *header,
1324 struct ext2_ext_attr_entry *end);
1325 extern __u32 ext2fs_get_ea_inode_hash(struct ext2_inode *inode);
1326 extern void ext2fs_set_ea_inode_hash(struct ext2_inode *inode, __u32 hash);
1327 extern __u64 ext2fs_get_ea_inode_ref(struct ext2_inode *inode);
1328 extern void ext2fs_set_ea_inode_ref(struct ext2_inode *inode, __u64 ref_count);
1331 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
1332 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
1333 ext2_extent_handle_t *handle);
1334 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
1335 struct ext2_inode *inode,
1336 ext2_extent_handle_t *ret_handle);
1337 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
1338 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
1339 int flags, struct ext2fs_extent *extent);
1340 extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
1341 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
1342 struct ext2fs_extent *extent);
1343 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
1344 struct ext2fs_extent *extent);
1345 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
1346 blk64_t logical, blk64_t physical,
1348 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
1349 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
1350 struct ext2_extent_info *info);
1351 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
1353 extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
1354 int leaf_level, blk64_t blk);
1355 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
1356 extern size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle);
1357 extern errcode_t ext2fs_fix_extents_checksums(ext2_filsys fs, ext2_ino_t ino,
1358 struct ext2_inode *inode);
1359 extern errcode_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
1360 struct ext2_inode *inode, blk64_t *ret_count);
1361 extern errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *from,
1365 #define EXT2_FALLOCATE_ZERO_BLOCKS (0x1)
1366 #define EXT2_FALLOCATE_FORCE_INIT (0x2)
1367 #define EXT2_FALLOCATE_FORCE_UNINIT (0x4)
1368 #define EXT2_FALLOCATE_INIT_BEYOND_EOF (0x8)
1369 #define EXT2_FALLOCATE_ALL_FLAGS (0xF)
1370 errcode_t ext2fs_fallocate(ext2_filsys fs, int flags, ext2_ino_t ino,
1371 struct ext2_inode *inode, blk64_t goal,
1372 blk64_t start, blk64_t len);
1375 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
1376 struct ext2_inode *inode,
1377 int flags, ext2_file_t *ret);
1378 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
1379 int flags, ext2_file_t *ret);
1380 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
1381 struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);
1382 extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file);
1383 extern errcode_t ext2fs_file_close(ext2_file_t file);
1384 extern errcode_t ext2fs_file_flush(ext2_file_t file);
1385 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
1386 unsigned int wanted, unsigned int *got);
1387 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
1388 unsigned int nbytes, unsigned int *written);
1389 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
1390 int whence, __u64 *ret_pos);
1391 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
1392 int whence, ext2_off_t *ret_pos);
1393 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
1394 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
1395 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
1396 extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size);
1399 extern char *ext2fs_find_block_device(dev_t device);
1402 extern errcode_t ext2fs_sync_device(int fd, int flushb);
1405 extern void ext2fs_free(ext2_filsys fs);
1406 extern void ext2fs_free_dblist(ext2_dblist dblist);
1407 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
1408 extern void ext2fs_u32_list_free(ext2_u32_list bb);
1411 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
1412 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
1413 __u32 start, __u32 end,
1415 const char *descr, char *init_map,
1416 ext2fs_generic_bitmap *ret);
1417 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
1421 ext2fs_generic_bitmap *ret);
1422 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
1423 ext2fs_generic_bitmap *dest);
1424 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
1425 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
1430 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
1431 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
1434 ext2fs_generic_bitmap bmap);
1435 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
1436 ext2fs_generic_bitmap bm1,
1437 ext2fs_generic_bitmap bm2);
1438 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1440 __u32 start, __u32 num,
1442 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1444 __u32 start, __u32 num,
1446 extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap,
1447 __u32 start, __u32 end,
1449 extern errcode_t ext2fs_find_first_set_generic_bitmap(ext2fs_generic_bitmap bitmap,
1450 __u32 start, __u32 end,
1453 /* gen_bitmap64.c */
1454 void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
1455 errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
1456 int type, __u64 start, __u64 end,
1459 ext2fs_generic_bitmap *ret);
1460 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
1461 ext2fs_generic_bitmap *dest);
1462 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
1463 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
1465 __u64 end, __u64 *oend);
1466 void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
1467 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
1469 __u64 new_real_end);
1470 errcode_t ext2fs_merge_generic_bmap(ext2fs_generic_bitmap gen_src,
1471 ext2fs_generic_bitmap gen_dest,
1472 ext2fs_generic_bitmap gen_dup,
1473 ext2fs_generic_bitmap dup_allowed);
1474 errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
1475 ext2fs_generic_bitmap bm1,
1476 ext2fs_generic_bitmap bm2);
1477 errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
1478 __u64 start, unsigned int num,
1480 errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
1481 __u64 start, unsigned int num,
1483 errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
1484 ext2fs_block_bitmap *bitmap);
1485 errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
1486 blk64_t end, blk64_t *out);
1488 /* get_num_dirs.c */
1489 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
1492 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
1494 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
1495 blk64_t *retblocks);
1498 extern int ext2fs_get_dio_alignment(int fd);
1499 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
1500 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
1503 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
1504 blk64_t num_blocks);
1505 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
1506 blk64_t num_blocks);
1507 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
1510 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
1511 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
1512 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
1513 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
1514 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
1515 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
1518 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1519 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1522 extern errcode_t ext2fs_initialize(const char *name, int flags,
1523 struct ext2_super_block *param,
1524 io_manager manager, ext2_filsys *ret_fs);
1525 extern errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs, int super_only);
1528 extern void ext2fs_free_icount(ext2_icount_t icount);
1529 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
1530 int flags, ext2_icount_t *ret);
1531 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
1533 ext2_icount_t hint, ext2_icount_t *ret);
1534 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
1536 ext2_icount_t *ret);
1537 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
1539 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
1541 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
1543 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
1545 extern errcode_t ext2fs_icount_merge(ext2_icount_t src, ext2_icount_t dest);
1546 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
1547 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
1551 extern errcode_t ext2fs_get_memalign(unsigned long size,
1552 unsigned long align, void *ptr);
1555 extern errcode_t ext2fs_inline_data_init(ext2_filsys fs, ext2_ino_t ino);
1556 extern errcode_t ext2fs_inline_data_size(ext2_filsys fs, ext2_ino_t ino,
1558 extern errcode_t ext2fs_inline_data_get(ext2_filsys fs, ext2_ino_t ino,
1559 struct ext2_inode *inode,
1560 void *buf, size_t *size);
1561 extern errcode_t ext2fs_inline_data_set(ext2_filsys fs, ext2_ino_t ino,
1562 struct ext2_inode *inode,
1563 void *buf, size_t size);
1566 extern errcode_t ext2fs_create_inode_cache(ext2_filsys fs,
1567 unsigned int cache_size);
1568 extern void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
1569 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
1570 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
1572 struct ext2_inode *inode,
1574 #define EXT2_INODE_SCAN_DEFAULT_BUFFER_BLOCKS 8
1575 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
1576 ext2_inode_scan *ret_scan);
1577 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1578 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1579 struct ext2_inode *inode);
1580 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1582 extern void ext2fs_set_inode_callback
1583 (ext2_inode_scan scan,
1584 errcode_t (*done_group)(ext2_filsys fs,
1585 ext2_inode_scan scan,
1588 void *done_group_data);
1589 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1591 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1592 struct ext2_inode * inode,
1594 extern errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
1595 struct ext2_inode * inode);
1596 extern errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
1597 struct ext2_inode * inode,
1598 int bufsize, int flags);
1599 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1600 struct ext2_inode * inode,
1602 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1603 struct ext2_inode * inode);
1604 extern errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
1605 struct ext2_inode * inode,
1606 int bufsize, int flags);
1607 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1608 struct ext2_inode * inode);
1609 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1610 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1613 extern io_manager inode_io_manager;
1614 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1616 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1617 struct ext2_inode *inode,
1621 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1622 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1623 char *mtpt, int mtlen);
1627 * NOTE: This function removes from an inode the blocks "start", "end", and
1628 * every block in between.
1630 extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
1631 struct ext2_inode *inode,
1632 char *block_buf, blk64_t start,
1636 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1637 int namelen, char *buf, ext2_ino_t *inode);
1638 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1639 const char *name, ext2_ino_t *inode);
1640 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1641 const char *name, ext2_ino_t *inode);
1642 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1643 ext2_ino_t inode, ext2_ino_t *res_inode);
1646 int ext2fs_native_flag(void);
1649 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1650 ext2_ino_t parent_ino, char **block);
1651 extern errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino,
1652 ext2_ino_t parent_ino, __u32 *iblock);
1655 extern const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding);
1656 extern int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table,
1657 char *s, size_t len, char **pos);
1658 extern int ext2fs_casefold_cmp(const struct ext2fs_nls_table *table,
1659 const unsigned char *str1, size_t len1,
1660 const unsigned char *str2, size_t len2);
1663 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1667 struct ext2fs_journal_params {
1668 blk_t num_journal_blocks;
1669 blk_t num_fc_blocks;
1671 extern errcode_t ext2fs_get_journal_params(
1672 struct ext2fs_journal_params *params, ext2_filsys fs);
1673 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1674 blk_t *ret_blk, int *ret_count);
1675 extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
1676 blk64_t *ret_blk, int *ret_count);
1677 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1678 __u32 num_blocks, int flags,
1680 extern errcode_t ext2fs_create_journal_superblock2(ext2_filsys fs,
1681 struct ext2fs_journal_params *params,
1682 int flags, char **ret_jsb);
1683 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1684 ext2_filsys journal_dev);
1685 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,
1687 extern errcode_t ext2fs_add_journal_inode2(ext2_filsys fs, blk_t num_blocks,
1688 blk64_t goal, int flags);
1689 extern errcode_t ext2fs_add_journal_inode3(ext2_filsys fs,
1690 struct ext2fs_journal_params *params,
1691 blk64_t goal, int flags);
1692 extern int ext2fs_default_journal_size(__u64 num_blocks);
1693 extern int ext2fs_journal_sb_start(int blocksize);
1696 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1697 unsigned int block_size, io_manager manager,
1698 ext2_filsys *ret_fs);
1699 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1700 int flags, int superblock,
1701 unsigned int block_size, io_manager manager,
1702 ext2_filsys *ret_fs);
1703 errcode_t ext2fs_open_channel(ext2_filsys fs, const char *io_options,
1704 io_manager manager, int flags,
1707 * The dgrp_t argument to these two functions is not actually a group number
1708 * but a block number offset within a group table! Convert with the formula
1709 * (group_number / groups_per_block).
1711 extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs,
1712 blk64_t group_block, dgrp_t i);
1713 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1715 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1716 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1717 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1719 /* get_pathname.c */
1720 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1724 #define EXT2FS_UNLINK_FORCE 0x1 /* Forcefully unlink even if
1725 * the inode number doesn't
1728 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1729 ext2_ino_t ino, int flags);
1730 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1731 ext2_ino_t ino, int flags);
1734 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
1735 const char *name, const char *target);
1736 int ext2fs_is_fast_symlink(struct ext2_inode *inode);
1739 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1740 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1741 errcode_t ext2fs_mmp_clear(ext2_filsys fs);
1742 errcode_t ext2fs_mmp_init(ext2_filsys fs);
1743 errcode_t ext2fs_mmp_start(ext2_filsys fs);
1744 errcode_t ext2fs_mmp_update(ext2_filsys fs);
1745 errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately);
1746 errcode_t ext2fs_mmp_stop(ext2_filsys fs);
1747 unsigned ext2fs_mmp_new_seq(void);
1750 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1751 ext2_badblocks_list *bb_list);
1753 /* read_bb_file.c */
1754 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1755 ext2_badblocks_list *bb_list,
1757 void (*invalid)(ext2_filsys fs,
1761 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1762 ext2_badblocks_list *bb_list,
1763 void (*invalid)(ext2_filsys fs,
1767 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1770 extern errcode_t ext2fs_rw_bitmaps(ext2_filsys fs, int flags, int num_threads);
1771 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
1772 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
1773 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
1774 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
1775 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
1776 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
1779 #define EXT2FS_SHA256_LENGTH 32
1781 extern void ext2fs_sha256(const unsigned char *in, unsigned long in_size,
1782 unsigned char out[EXT2FS_SHA256_LENGTH]);
1786 #define EXT2FS_SHA512_LENGTH 64
1787 extern void ext2fs_sha512(const unsigned char *in, unsigned long in_size,
1788 unsigned char out[EXT2FS_SHA512_LENGTH]);
1791 extern errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf, size_t size,
1793 extern errcode_t ext2fs_dirent_swab_in(ext2_filsys fs, char *buf, int flags);
1794 extern errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf, size_t size,
1796 extern errcode_t ext2fs_dirent_swab_out(ext2_filsys fs, char *buf, int flags);
1797 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1799 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1800 struct ext2_ext_attr_header *from_hdr);
1801 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1802 struct ext2_ext_attr_entry *from_entry);
1803 extern void ext2fs_swap_super(struct ext2_super_block * super);
1804 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1805 extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp);
1806 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1807 struct ext2_inode_large *f, int hostorder,
1809 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1810 struct ext2_inode *f, int hostorder);
1811 extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
1814 extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
1815 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
1816 extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
1819 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1820 extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs,
1821 struct ext2_inode *inode);
1824 extern int ext2fs_parse_version_string(const char *ver_string);
1825 extern int ext2fs_get_library_version(const char **ver_string,
1826 const char **date_string);
1828 /* write_bb_file.c */
1829 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1834 /* inline functions */
1835 #ifdef NO_INLINE_FUNCS
1836 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1837 extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr);
1838 extern errcode_t ext2fs_get_array(unsigned long count,
1839 unsigned long size, void *ptr);
1840 extern errcode_t ext2fs_get_arrayzero(unsigned long count,
1841 unsigned long size, void *ptr);
1842 extern errcode_t ext2fs_free_mem(void *ptr);
1843 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1844 unsigned long size, void *ptr);
1845 extern errcode_t ext2fs_resize_array(unsigned long old_count, unsigned long count,
1846 unsigned long size, void *ptr);
1847 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1848 extern void ext2fs_mark_changed(ext2_filsys fs);
1849 extern int ext2fs_test_changed(ext2_filsys fs);
1850 extern void ext2fs_mark_valid(ext2_filsys fs);
1851 extern void ext2fs_unmark_valid(ext2_filsys fs);
1852 extern int ext2fs_test_valid(ext2_filsys fs);
1853 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1854 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1855 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1856 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1857 extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1858 extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1859 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1860 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1861 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1862 struct ext2_inode *inode);
1863 extern int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks);
1864 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1865 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
1866 extern int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry);
1867 extern void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len);
1868 extern int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry);
1869 extern void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type);
1870 extern struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode);
1871 extern const struct ext2_inode *ext2fs_const_inode(const struct ext2_inode_large * large_inode);
1876 * The actual inlined functions definitions themselves...
1878 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1881 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1882 #ifdef INCLUDE_INLINE_FUNCS
1883 #define _INLINE_ extern
1885 #if (__STDC_VERSION__ >= 199901L)
1886 #define _INLINE_ inline
1889 #define _INLINE_ extern __inline__
1890 #else /* For Watcom C */
1891 #define _INLINE_ extern inline
1892 #endif /* __GNUC__ */
1893 #endif /* __STDC_VERSION__ >= 199901L */
1896 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1899 * Allocate memory. The 'ptr' arg must point to a pointer.
1901 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1907 return EXT2_ET_NO_MEMORY;
1908 memcpy(ptr, &pp, sizeof (pp));
1912 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
1918 return EXT2_ET_NO_MEMORY;
1919 memset(pp, 0, size);
1920 memcpy(ptr, &pp, sizeof(pp));
1924 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size,
1927 if (count && (~0UL)/count < size)
1928 return EXT2_ET_NO_MEMORY;
1929 return ext2fs_get_mem(count*size, ptr);
1932 _INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
1933 unsigned long size, void *ptr)
1935 if (count && (~0UL)/count < size)
1936 return EXT2_ET_NO_MEMORY;
1938 return ext2fs_get_memzero((size_t)count * size, ptr);
1942 * Free memory. The 'ptr' arg must point to a pointer.
1944 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1948 memcpy(&p, ptr, sizeof(p));
1951 memcpy(ptr, &p, sizeof(p));
1956 * Resize memory. The 'ptr' arg must point to a pointer.
1958 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1959 unsigned long size, void *ptr)
1963 /* Use "memcpy" for pointer assignments here to avoid problems
1964 * with C99 strict type aliasing rules. */
1965 memcpy(&p, ptr, sizeof(p));
1966 p = realloc(p, size);
1968 return EXT2_ET_NO_MEMORY;
1969 memcpy(ptr, &p, sizeof(p));
1974 * Resize array. The 'ptr' arg must point to a pointer.
1976 _INLINE_ errcode_t ext2fs_resize_array(unsigned long size,
1977 unsigned long old_count,
1978 unsigned long count, void *ptr)
1980 unsigned long old_size;
1983 if (count && (~0UL)/count < size)
1984 return EXT2_ET_NO_MEMORY;
1987 old_size = size * old_count;
1988 retval = ext2fs_resize_mem(old_size, size, ptr);
1992 if (size > old_size) {
1995 memcpy(&p, ptr, sizeof(p));
1996 memset((char *)p + old_size, 0, size - old_size);
1997 memcpy(ptr, &p, sizeof(p));
2002 #endif /* Custom memory routines */
2005 * Mark a filesystem superblock as dirty
2007 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
2009 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
2013 * Mark a filesystem as changed
2015 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
2017 fs->flags |= EXT2_FLAG_CHANGED;
2021 * Check to see if a filesystem has changed
2023 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
2025 return (fs->flags & EXT2_FLAG_CHANGED);
2029 * Mark a filesystem as valid
2031 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
2033 fs->flags |= EXT2_FLAG_VALID;
2037 * Mark a filesystem as NOT valid
2039 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
2041 fs->flags &= ~EXT2_FLAG_VALID;
2045 * Check to see if a filesystem is valid
2047 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
2049 return (fs->flags & EXT2_FLAG_VALID);
2053 * Mark the inode bitmap as dirty
2055 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
2057 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
2061 * Mark the block bitmap as dirty
2063 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
2065 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
2069 * Check to see if a filesystem's inode bitmap is dirty
2071 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
2073 return (fs->flags & EXT2_FLAG_IB_DIRTY);
2077 * Check to see if a filesystem's block bitmap is dirty
2079 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
2081 return (fs->flags & EXT2_FLAG_BB_DIRTY);
2085 * Return the group # of a block
2087 _INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
2089 return ext2fs_group_of_blk2(fs, blk);
2092 * Return the group # of an inode number
2094 _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
2096 return (ino - 1) / fs->super->s_inodes_per_group;
2100 * Return the first block (inclusive) in a group
2102 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
2104 return (blk_t) ext2fs_group_first_block2(fs, group);
2108 * Return the last block (inclusive) in a group
2110 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
2112 return (blk_t) ext2fs_group_last_block2(fs, group);
2115 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
2116 struct ext2_inode *inode)
2118 return (blk_t) ext2fs_inode_data_blocks2(fs, inode);
2121 _INLINE_ int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks)
2125 if ((EXT2_SB(fs->super)->s_feature_ro_compat &
2126 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) != 0)
2127 csum_size = sizeof(struct ext2_dx_tail);
2128 return blocks * ((fs->blocksize - (8 + csum_size)) /
2129 sizeof(struct ext2_dx_entry));
2133 * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
2135 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
2139 return ((a - 1) / b) + 1;
2142 _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b)
2146 return ((a - 1) / b) + 1;
2149 _INLINE_ int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry)
2151 return entry->name_len & 0xff;
2154 _INLINE_ void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len)
2156 entry->name_len = (entry->name_len & 0xff00) | (len & 0xff);
2159 _INLINE_ int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry)
2161 return entry->name_len >> 8;
2164 _INLINE_ void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type)
2166 entry->name_len = (entry->name_len & 0xff) | (type << 8);
2169 _INLINE_ struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode)
2171 /* It is always safe to convert large inode to a small inode */
2172 return (struct ext2_inode *) large_inode;
2175 _INLINE_ const struct ext2_inode *
2176 ext2fs_const_inode(const struct ext2_inode_large * large_inode)
2178 /* It is always safe to convert large inode to a small inode */
2179 return (const struct ext2_inode *) large_inode;
2182 static dgrp_t ext2fs_get_avg_group(ext2_filsys fs)
2185 dgrp_t average_group;
2186 unsigned flexbg_size;
2188 if (fs->fs_num_threads <= 1)
2189 return fs->group_desc_count;
2191 average_group = fs->group_desc_count / fs->fs_num_threads;
2192 if (average_group <= 1)
2195 if (ext2fs_has_feature_flex_bg(fs->super)) {
2198 flexbg_size = 1 << fs->super->s_log_groups_per_flex;
2199 if (average_group % flexbg_size) {
2200 times = average_group / flexbg_size;
2201 average_group = times * flexbg_size;
2205 return average_group;
2207 return fs->group_desc_count;
2214 /* htree levels for ext4 */
2215 #define EXT4_HTREE_LEVEL_COMPAT 2
2216 #define EXT4_HTREE_LEVEL 3
2218 static inline unsigned int ext2_dir_htree_level(ext2_filsys fs)
2220 if (ext2fs_has_feature_largedir(fs->super))
2221 return EXT4_HTREE_LEVEL;
2223 return EXT4_HTREE_LEVEL_COMPAT;
2230 #endif /* _EXT2FS_EXT2FS_H */