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;
279 * Reserved for future expansion
284 * Reserved for the use of the calling application.
291 struct ext2_inode_cache *icache;
295 * More callback functions
297 errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
299 errcode_t (*get_alloc_block2)(ext2_filsys fs, blk64_t goal,
300 blk64_t *ret, struct blk_alloc_ctx *ctx);
301 void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
304 * Buffers for Multiple mount protection(MMP) block.
311 * Time at which e2fsck last updated the MMP block.
313 long mmp_last_written;
315 /* progress operation functions */
316 struct ext2fs_progress_ops *progress_ops;
318 /* Precomputed FS UUID checksum for seeding other checksums */
321 io_channel journal_io;
324 /* New block range allocation hooks */
325 errcode_t (*new_range)(ext2_filsys fs, int flags, blk64_t goal,
326 blk64_t len, blk64_t *pblk, blk64_t *plen);
327 void (*block_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
330 /* hashmap for SHA of data blocks */
331 struct ext2fs_hashmap* block_sha_map;
333 const struct ext2fs_nls_table *encoding;
336 #if EXT2_FLAT_INCLUDES
337 #include "e2_bitops.h"
339 #include <ext2fs/bitops.h>
343 * 64-bit bitmap backend types
345 #define EXT2FS_BMAP64_BITARRAY 1
346 #define EXT2FS_BMAP64_RBTREE 2
347 #define EXT2FS_BMAP64_AUTODIR 3
350 * Return flags for the block iterator functions
352 #define BLOCK_CHANGED 1
353 #define BLOCK_ABORT 2
354 #define BLOCK_ERROR 4
355 #define BLOCK_INLINE_DATA_CHANGED 8
358 * Block interate flags
360 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
361 * function should be called on blocks where the block number is zero.
362 * This is used by ext2fs_expand_dir() to be able to add a new block
363 * to an inode. It can also be used for programs that want to be able
364 * to deal with files that contain "holes".
366 * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
367 * the indirect, doubly indirect, etc. blocks should be called after
368 * all of the blocks contained in the indirect blocks are processed.
369 * This is useful if you are going to be deallocating blocks from an
372 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
373 * called for data blocks only.
375 * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
376 * modify returned block number.
378 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
379 * ext2fs_block_iterate2 that large files won't be accepted.
381 #define BLOCK_FLAG_APPEND 1
382 #define BLOCK_FLAG_HOLE 1
383 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
384 #define BLOCK_FLAG_DATA_ONLY 4
385 #define BLOCK_FLAG_READ_ONLY 8
387 #define BLOCK_FLAG_NO_LARGE 0x1000
390 * Magic "block count" return values for the block iterator function.
392 #define BLOCK_COUNT_IND (-1)
393 #define BLOCK_COUNT_DIND (-2)
394 #define BLOCK_COUNT_TIND (-3)
395 #define BLOCK_COUNT_TRANSLATOR (-4)
397 #define BLOCK_ALLOC_UNKNOWN 0
398 #define BLOCK_ALLOC_DATA 1
399 #define BLOCK_ALLOC_METADATA 2
401 struct blk_alloc_ctx {
403 struct ext2_inode *inode;
410 * Flags for ext2fs_move_blocks
412 #define EXT2_BMOVE_GET_DBLIST 0x0001
413 #define EXT2_BMOVE_DEBUG 0x0002
417 * Generic (non-filesystem layout specific) extents structure
420 #define EXT2_EXTENT_FLAGS_LEAF 0x0001
421 #define EXT2_EXTENT_FLAGS_UNINIT 0x0002
422 #define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004
424 struct ext2fs_extent {
425 blk64_t e_pblk; /* first physical block */
426 blk64_t e_lblk; /* first logical block extent covers */
427 __u32 e_len; /* number of blocks covered by extent */
428 __u32 e_flags; /* extent flags */
431 typedef struct ext2_extent_handle *ext2_extent_handle_t;
432 typedef struct ext2_extent_path *ext2_extent_path_t;
435 * Flags used by ext2fs_extent_get()
437 #define EXT2_EXTENT_CURRENT 0x0000
438 #define EXT2_EXTENT_MOVE_MASK 0x000F
439 #define EXT2_EXTENT_ROOT 0x0001
440 #define EXT2_EXTENT_LAST_LEAF 0x0002
441 #define EXT2_EXTENT_FIRST_SIB 0x0003
442 #define EXT2_EXTENT_LAST_SIB 0x0004
443 #define EXT2_EXTENT_NEXT_SIB 0x0005
444 #define EXT2_EXTENT_PREV_SIB 0x0006
445 #define EXT2_EXTENT_NEXT_LEAF 0x0007
446 #define EXT2_EXTENT_PREV_LEAF 0x0008
447 #define EXT2_EXTENT_NEXT 0x0009
448 #define EXT2_EXTENT_PREV 0x000A
449 #define EXT2_EXTENT_UP 0x000B
450 #define EXT2_EXTENT_DOWN 0x000C
451 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
454 * Flags used by ext2fs_extent_insert()
456 #define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */
457 #define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */
460 * Flags used by ext2fs_extent_delete()
462 #define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extent gone */
465 * Flags used by ext2fs_extent_set_bmap()
467 #define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001
470 * Data structure returned by ext2fs_extent_get_info()
472 struct ext2_extent_info {
482 __u32 max_uninit_len;
486 * Flags for directory block reading and writing functions
488 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
491 * Return flags for the directory iterator functions
493 #define DIRENT_CHANGED 1
494 #define DIRENT_ABORT 2
495 #define DIRENT_ERROR 3
498 * Directory iterator flags
501 #define DIRENT_FLAG_INCLUDE_EMPTY 1
502 #define DIRENT_FLAG_INCLUDE_REMOVED 2
503 #define DIRENT_FLAG_INCLUDE_CSUM 4
504 #define DIRENT_FLAG_INCLUDE_INLINE_DATA 8
506 #define DIRENT_DOT_FILE 1
507 #define DIRENT_DOT_DOT_FILE 2
508 #define DIRENT_OTHER_FILE 3
509 #define DIRENT_DELETED_FILE 4
510 #define DIRENT_CHECKSUM 5
513 * Inode scan definitions
515 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
520 #define EXT2_SF_CHK_BADBLOCKS 0x0001
521 #define EXT2_SF_BAD_INODE_BLK 0x0002
522 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
523 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
524 #define EXT2_SF_DO_LAZY 0x0010
525 #define EXT2_SF_WARN_GARBAGE_INODES 0x0020
528 * ext2fs_check_if_mounted flags
530 #define EXT2_MF_MOUNTED 1
531 #define EXT2_MF_ISROOT 2
532 #define EXT2_MF_READONLY 4
533 #define EXT2_MF_SWAP 8
534 #define EXT2_MF_BUSY 16
537 * Ext2/linux mode flags. We define them here so that we don't need
538 * to depend on the OS's sys/stat.h, since we may be compiling on a
541 #define LINUX_S_IFMT 00170000
542 #define LINUX_S_IFSOCK 0140000
543 #define LINUX_S_IFLNK 0120000
544 #define LINUX_S_IFREG 0100000
545 #define LINUX_S_IFBLK 0060000
546 #define LINUX_S_IFDIR 0040000
547 #define LINUX_S_IFCHR 0020000
548 #define LINUX_S_IFIFO 0010000
549 #define LINUX_S_ISUID 0004000
550 #define LINUX_S_ISGID 0002000
551 #define LINUX_S_ISVTX 0001000
553 #define LINUX_S_IRWXU 00700
554 #define LINUX_S_IRUSR 00400
555 #define LINUX_S_IWUSR 00200
556 #define LINUX_S_IXUSR 00100
558 #define LINUX_S_IRWXG 00070
559 #define LINUX_S_IRGRP 00040
560 #define LINUX_S_IWGRP 00020
561 #define LINUX_S_IXGRP 00010
563 #define LINUX_S_IRWXO 00007
564 #define LINUX_S_IROTH 00004
565 #define LINUX_S_IWOTH 00002
566 #define LINUX_S_IXOTH 00001
568 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
569 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
570 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
571 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
572 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
573 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
574 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
577 * ext2 size of an inode
579 #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
582 * ext2_icount_t abstraction
584 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
585 #define EXT2_ICOUNT_OPT_FULLMAP 0x02
587 typedef struct ext2_icount *ext2_icount_t;
590 * Flags for ext2fs_bmap
592 #define BMAP_ALLOC 0x0001
593 #define BMAP_SET 0x0002
594 #define BMAP_UNINIT 0x0004
595 #define BMAP_ZERO 0x0008
598 * Returned flags from ext2fs_bmap
600 #define BMAP_RET_UNINIT 0x0001
603 * Flags for ext2fs_read_inode2
605 #define READ_INODE_NOCSUM 0x0001
608 * Flags for ext2fs_write_inode2
610 #define WRITE_INODE_NOCSUM 0x0001
613 * Flags for imager.c functions
615 #define IMAGER_FLAG_INODEMAP 1
616 #define IMAGER_FLAG_SPARSEWRITE 2
619 * For checking structure magic numbers...
622 #define EXT2_CHECK_MAGIC(struct, code) \
623 if ((struct)->magic != (code)) return (code)
626 * Features supported by this version of the library
628 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
629 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
630 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
631 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
632 EXT2_FEATURE_COMPAT_DIR_INDEX|\
633 EXT2_FEATURE_COMPAT_EXT_ATTR|\
634 EXT4_FEATURE_COMPAT_SPARSE_SUPER2|\
635 EXT4_FEATURE_COMPAT_FAST_COMMIT|\
636 EXT4_FEATURE_COMPAT_STABLE_INODES)
639 #define EXT4_LIB_INCOMPAT_MMP EXT4_FEATURE_INCOMPAT_MMP
641 #define EXT4_LIB_INCOMPAT_MMP (0)
644 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
645 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
646 EXT2_FEATURE_INCOMPAT_META_BG|\
647 EXT3_FEATURE_INCOMPAT_RECOVER|\
648 EXT3_FEATURE_INCOMPAT_EXTENTS|\
649 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
650 EXT4_FEATURE_INCOMPAT_EA_INODE|\
651 EXT4_LIB_INCOMPAT_MMP|\
652 EXT4_FEATURE_INCOMPAT_64BIT|\
653 EXT4_FEATURE_INCOMPAT_INLINE_DATA|\
654 EXT4_FEATURE_INCOMPAT_ENCRYPT|\
655 EXT4_FEATURE_INCOMPAT_CASEFOLD|\
656 EXT4_FEATURE_INCOMPAT_CSUM_SEED|\
657 EXT4_FEATURE_INCOMPAT_LARGEDIR)
659 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
660 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
661 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
662 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
663 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
664 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
665 EXT4_FEATURE_RO_COMPAT_BIGALLOC|\
666 EXT4_FEATURE_RO_COMPAT_QUOTA|\
667 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
668 EXT4_FEATURE_RO_COMPAT_READONLY |\
669 EXT4_FEATURE_RO_COMPAT_PROJECT |\
670 EXT4_FEATURE_RO_COMPAT_SHARED_BLOCKS |\
671 EXT4_FEATURE_RO_COMPAT_VERITY)
674 * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
677 #define EXT2_LIB_SOFTSUPP_INCOMPAT (0)
678 #define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_REPLICA)
681 /* Translate a block number to a cluster number */
682 #define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits)
683 #define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1)
684 #define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits)
685 /* Translate a cluster number to a block number */
686 #define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits)
687 /* Translate # of blks to # of clusters */
688 #define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
689 (fs)->cluster_ratio_bits)
691 #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
692 typedef struct stat64 ext2fs_struct_stat;
694 typedef struct stat ext2fs_struct_stat;
698 * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
699 * avoid the fsync call.
701 #define EXT2_FLAG_FLUSH_NO_SYNC 1
704 * Modify and iterate extended attributes
706 struct ext2_xattr_handle;
707 #define XATTR_ABORT 1
708 #define XATTR_CHANGED 2
711 * flags for ext2fs_rw_bitmaps()
713 #define EXT2FS_BITMAPS_WRITE 0x0001
714 #define EXT2FS_BITMAPS_BLOCK 0x0002
715 #define EXT2FS_BITMAPS_INODE 0x0004
716 #define EXT2FS_BITMAPS_VALID_FLAGS 0x0007
719 * function prototypes
721 static inline int ext2fs_has_group_desc_csum(ext2_filsys fs)
723 return ext2fs_has_feature_metadata_csum(fs->super) ||
724 ext2fs_has_feature_gdt_csum(fs->super);
727 /* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */
728 static inline int ext2fs_needs_large_file_feature(unsigned long long file_size)
730 return file_size >= 0x80000000ULL;
734 extern void ext2fs_clear_block_uninit(ext2_filsys fs, dgrp_t group);
735 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
736 ext2fs_inode_bitmap map, ext2_ino_t *ret);
737 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
738 ext2fs_block_bitmap map, blk_t *ret);
739 extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
740 ext2fs_block_bitmap map, blk64_t *ret);
741 extern errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,
742 ext2fs_block_bitmap map, blk64_t *ret,
743 struct blk_alloc_ctx *ctx);
744 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
745 blk_t finish, int num,
746 ext2fs_block_bitmap map,
748 extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start,
749 blk64_t finish, int num,
750 ext2fs_block_bitmap map,
752 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
753 char *block_buf, blk_t *ret);
754 extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal,
755 char *block_buf, blk64_t *ret);
756 extern errcode_t ext2fs_alloc_block3(ext2_filsys fs, blk64_t goal,
757 char *block_buf, blk64_t *ret,
758 struct blk_alloc_ctx *ctx);
760 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
761 errcode_t (*func)(ext2_filsys fs,
764 errcode_t (**old)(ext2_filsys fs,
767 blk64_t ext2fs_find_inode_goal(ext2_filsys fs, ext2_ino_t ino,
768 struct ext2_inode *inode, blk64_t lblk);
769 extern void ext2fs_set_new_range_callback(ext2_filsys fs,
770 errcode_t (*func)(ext2_filsys fs, int flags, blk64_t goal,
771 blk64_t len, blk64_t *pblk, blk64_t *plen),
772 errcode_t (**old)(ext2_filsys fs, int flags, blk64_t goal,
773 blk64_t len, blk64_t *pblk, blk64_t *plen));
774 extern void ext2fs_set_block_alloc_stats_range_callback(ext2_filsys fs,
775 void (*func)(ext2_filsys fs, blk64_t blk,
776 blk_t num, int inuse),
777 void (**old)(ext2_filsys fs, blk64_t blk,
778 blk_t num, int inuse));
779 #define EXT2_NEWRANGE_FIXED_GOAL (0x1)
780 #define EXT2_NEWRANGE_MIN_LENGTH (0x2)
781 #define EXT2_NEWRANGE_ALL_FLAGS (0x3)
782 errcode_t ext2fs_new_range(ext2_filsys fs, int flags, blk64_t goal,
783 blk64_t len, ext2fs_block_bitmap map, blk64_t *pblk,
785 #define EXT2_ALLOCRANGE_FIXED_GOAL (0x1)
786 #define EXT2_ALLOCRANGE_ZERO_BLOCKS (0x2)
787 #define EXT2_ALLOCRANGE_ALL_FLAGS (0x3)
788 errcode_t ext2fs_alloc_range(ext2_filsys fs, int flags, blk64_t goal,
789 blk_t len, blk64_t *ret);
792 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
794 ext2fs_block_bitmap bmap);
795 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
796 void (*func)(ext2_filsys fs,
799 void (**old)(ext2_filsys fs,
804 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
805 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
806 int inuse, int isdir);
807 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
808 void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
809 void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
810 blk_t num, int inuse);
813 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
814 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
815 ext2fs_block_bitmap bmap);
818 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
819 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
820 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
821 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
822 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
823 ext2_u32_iterate *ret);
824 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
825 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
826 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
827 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
829 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
831 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
833 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
835 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
836 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
838 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
839 ext2_badblocks_iterate *ret);
840 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
842 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
843 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
844 ext2_badblocks_list *dest);
845 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
846 ext2_badblocks_list bb2);
847 extern int ext2fs_u32_list_count(ext2_u32_list bb);
850 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
851 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
852 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
853 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
854 badblocks_iterate *ret);
855 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
856 extern void badblocks_list_iterate_end(badblocks_iterate iter);
857 extern void badblocks_list_free(badblocks_list bb);
860 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
861 ext2_badblocks_list bb_list);
864 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
865 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
866 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
867 ext2fs_generic_bitmap *dest);
868 errcode_t ext2fs_merge_bitmap(ext2fs_generic_bitmap src,
869 ext2fs_generic_bitmap dest,
870 ext2fs_generic_bitmap dup,
871 ext2fs_generic_bitmap dup_allowed);
872 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
874 ext2fs_block_bitmap *ret);
875 extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
877 ext2fs_block_bitmap *ret);
878 extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap);
879 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
881 ext2fs_inode_bitmap *ret);
882 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
883 ext2_ino_t end, ext2_ino_t *oend);
884 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
885 blk_t end, blk_t *oend);
886 extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
887 blk64_t end, blk64_t *oend);
888 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
889 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
890 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
891 ext2fs_inode_bitmap bmap);
892 extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end,
894 ext2fs_inode_bitmap bmap);
895 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
896 ext2fs_block_bitmap bmap);
897 extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end,
899 ext2fs_block_bitmap bmap);
900 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
901 ext2fs_block_bitmap bm2);
902 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
903 ext2fs_inode_bitmap bm2);
904 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
905 ext2_ino_t start, unsigned int num,
907 extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
908 __u64 start, size_t num,
910 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
911 ext2_ino_t start, unsigned int num,
913 extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
914 __u64 start, size_t num,
916 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
917 blk_t start, unsigned int num,
919 extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
920 blk64_t start, size_t num,
922 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
923 blk_t start, unsigned int num,
925 extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
926 blk64_t start, size_t num,
930 extern __u32 ext2fs_inode_bitmap_checksum(ext2_filsys fs, dgrp_t group);
931 extern __u32 ext2fs_block_bitmap_checksum(ext2_filsys fs, dgrp_t group);
932 extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
933 extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
934 extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
935 extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
936 extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
937 struct ext2_inode *inode);
938 extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
939 struct ext2_inode *inode);
940 extern blk64_t ext2fs_get_stat_i_blocks(ext2_filsys fs,
941 struct ext2_inode *inode);
942 extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super);
943 extern void ext2fs_blocks_count_set(struct ext2_super_block *super,
945 extern void ext2fs_blocks_count_add(struct ext2_super_block *super,
947 extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super);
948 extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super,
950 extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super,
952 extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super);
953 extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super,
955 extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super,
957 /* Block group descriptor accessor functions */
958 extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
959 struct opaque_ext2_group_desc *gdp,
961 extern blk64_t ext2fs_block_bitmap_csum(ext2_filsys fs, dgrp_t group);
962 extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group);
963 extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
965 extern __u32 ext2fs_inode_bitmap_csum(ext2_filsys fs, dgrp_t group);
966 extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group);
967 extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
969 extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group);
970 extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group,
972 extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group);
973 extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group,
975 extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group);
976 extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group,
978 extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group);
979 extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group,
981 extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
982 extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
984 extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
985 extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
986 extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
987 extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
988 extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
989 extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
990 extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
991 extern blk64_t ext2fs_file_acl_block(ext2_filsys fs,
992 const struct ext2_inode *inode);
993 extern void ext2fs_file_acl_block_set(ext2_filsys fs,
994 struct ext2_inode *inode, blk64_t blk);
995 extern errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode,
999 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
1003 int (*func)(ext2_filsys fs,
1008 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
1012 int (*func)(ext2_filsys fs,
1014 e2_blkcnt_t blockcnt,
1019 errcode_t ext2fs_block_iterate3(ext2_filsys fs,
1023 int (*func)(ext2_filsys fs,
1025 e2_blkcnt_t blockcnt,
1032 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
1033 struct ext2_inode *inode,
1034 char *block_buf, int bmap_flags,
1035 blk_t block, blk_t *phys_blk);
1036 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
1037 struct ext2_inode *inode,
1038 char *block_buf, int bmap_flags, blk64_t block,
1039 int *ret_flags, blk64_t *phys_blk);
1040 errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino,
1041 struct ext2_inode *inode, blk64_t lblk,
1046 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
1047 ext2fs_block_bitmap reserve,
1048 ext2fs_block_bitmap alloc_map,
1053 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
1056 extern errcode_t ext2fs_close(ext2_filsys fs);
1057 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
1058 extern errcode_t ext2fs_close_free(ext2_filsys *fs);
1059 extern errcode_t ext2fs_flush(ext2_filsys fs);
1060 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
1061 extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
1062 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
1064 blk64_t *ret_super_blk,
1065 blk64_t *ret_old_desc_blk,
1066 blk64_t *ret_new_desc_blk,
1067 blk_t *ret_used_blks);
1068 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
1070 blk_t *ret_super_blk,
1071 blk_t *ret_old_desc_blk,
1072 blk_t *ret_new_desc_blk,
1074 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
1077 extern __u32 ext2fs_crc32_be(__u32 crc, unsigned char const *p, size_t len);
1078 extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
1081 extern void ext2fs_init_csum_seed(ext2_filsys fs);
1082 extern errcode_t ext2fs_mmp_csum_set(ext2_filsys fs, struct mmp_struct *mmp);
1083 extern int ext2fs_mmp_csum_verify(ext2_filsys, struct mmp_struct *mmp);
1084 extern int ext2fs_verify_csum_type(ext2_filsys fs, struct ext2_super_block *sb);
1085 extern errcode_t ext2fs_superblock_csum_set(ext2_filsys fs,
1086 struct ext2_super_block *sb);
1087 extern int ext2fs_superblock_csum_verify(ext2_filsys fs,
1088 struct ext2_super_block *sb);
1089 extern errcode_t ext2fs_ext_attr_block_csum_set(ext2_filsys fs,
1090 ext2_ino_t inum, blk64_t block,
1091 struct ext2_ext_attr_header *hdr);
1092 extern int ext2fs_ext_attr_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1094 struct ext2_ext_attr_header *hdr);
1095 #define EXT2_DIRENT_TAIL(block, blocksize) \
1096 ((struct ext2_dir_entry_tail *)(((char *)(block)) + \
1097 (blocksize) - sizeof(struct ext2_dir_entry_tail)))
1099 extern void ext2fs_initialize_dirent_tail(ext2_filsys fs,
1100 struct ext2_dir_entry_tail *t);
1101 extern int ext2fs_dirent_has_tail(ext2_filsys fs,
1102 struct ext2_dir_entry *dirent);
1103 extern int ext2fs_dirent_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1104 struct ext2_dir_entry *dirent);
1105 extern int ext2fs_dir_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1106 struct ext2_dir_entry *dirent);
1107 extern errcode_t ext2fs_dir_block_csum_set(ext2_filsys fs, ext2_ino_t inum,
1108 struct ext2_dir_entry *dirent);
1109 extern errcode_t ext2fs_get_dx_countlimit(ext2_filsys fs,
1110 struct ext2_dir_entry *dirent,
1111 struct ext2_dx_countlimit **cc,
1113 extern errcode_t ext2fs_dx_csum(ext2_filsys fs, ext2_ino_t inum,
1114 struct ext2_dir_entry *dirent,
1115 __u32 *crc, struct ext2_dx_tail **ret_t);
1116 extern errcode_t ext2fs_extent_block_csum_set(ext2_filsys fs,
1118 struct ext3_extent_header *eh);
1119 extern int ext2fs_extent_block_csum_verify(ext2_filsys fs,
1121 struct ext3_extent_header *eh);
1122 extern errcode_t ext2fs_block_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1123 char *bitmap, int size);
1124 extern int ext2fs_block_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1125 char *bitmap, int size);
1126 extern errcode_t ext2fs_inode_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1127 char *bitmap, int size);
1128 extern int ext2fs_inode_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1129 char *bitmap, int size);
1130 extern errcode_t ext2fs_inode_csum_set(ext2_filsys fs, ext2_ino_t inum,
1131 struct ext2_inode_large *inode);
1132 extern int ext2fs_inode_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1133 struct ext2_inode_large *inode);
1134 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
1135 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
1136 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
1137 extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
1140 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
1141 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1142 blk_t blk, int blockcnt);
1143 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1144 blk64_t blk, e2_blkcnt_t blockcnt);
1145 extern void ext2fs_dblist_sort(ext2_dblist dblist,
1146 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1148 extern void ext2fs_dblist_sort2(ext2_dblist dblist,
1149 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1151 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
1152 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
1155 extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
1156 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1159 extern errcode_t ext2fs_dblist_iterate3(ext2_dblist dblist,
1160 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1162 unsigned long long start,
1163 unsigned long long count,
1165 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1166 blk_t blk, int blockcnt);
1167 extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1168 blk64_t blk, e2_blkcnt_t blockcnt);
1169 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
1171 extern int ext2fs_dblist_count(ext2_dblist dblist);
1172 extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist);
1173 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
1174 struct ext2_db_entry **entry);
1175 extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
1176 struct ext2_db_entry2 **entry);
1177 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
1181 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
1184 int (*func)(ext2_ino_t dir,
1186 struct ext2_dir_entry *dirent,
1194 /* digest_encode.c */
1195 #define EXT2FS_DIGEST_SIZE EXT2FS_SHA256_LENGTH
1196 extern int ext2fs_digest_encode(const char *src, int len, char *dst);
1197 extern int ext2fs_digest_decode(const char *src, int len, char *dst);
1201 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
1203 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
1204 void *buf, int flags);
1205 extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
1206 void *buf, int flags);
1207 extern errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block,
1208 void *buf, int flags, ext2_ino_t ino);
1209 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
1211 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
1212 void *buf, int flags);
1213 extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
1214 void *buf, int flags);
1215 extern errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block,
1216 void *buf, int flags, ext2_ino_t ino);
1219 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
1221 ext2_dirhash_t *ret_hash,
1222 ext2_dirhash_t *ret_minor_hash);
1224 extern errcode_t ext2fs_dirhash2(int version, const char *name, int len,
1225 const struct ext2fs_nls_table *charset,
1228 ext2_dirhash_t *ret_hash,
1229 ext2_dirhash_t *ret_minor_hash);
1232 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
1233 struct ext2_dir_entry *dirent,
1234 unsigned int *rec_len);
1235 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
1237 struct ext2_dir_entry *dirent);
1238 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
1242 int (*func)(struct ext2_dir_entry *dirent,
1248 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
1252 int (*func)(ext2_ino_t dir,
1254 struct ext2_dir_entry *dirent,
1262 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
1265 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
1268 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
1270 extern errcode_t ext2fs_ext_attr_hash_entry2(ext2_filsys fs,
1271 struct ext2_ext_attr_entry *entry,
1272 void *data, __u32 *hash);
1273 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
1274 extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block,
1276 extern errcode_t ext2fs_read_ext_attr3(ext2_filsys fs, blk64_t block,
1277 void *buf, ext2_ino_t inum);
1278 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
1280 extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block,
1282 extern errcode_t ext2fs_write_ext_attr3(ext2_filsys fs, blk64_t block,
1283 void *buf, ext2_ino_t inum);
1284 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
1286 int adjust, __u32 *newcount);
1287 extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
1289 int adjust, __u32 *newcount);
1290 extern errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk,
1292 int adjust, __u32 *newcount,
1294 errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle);
1295 errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle);
1296 errcode_t ext2fs_xattrs_iterate(struct ext2_xattr_handle *h,
1297 int (*func)(char *name, char *value,
1298 size_t value_len, void *data),
1300 errcode_t ext2fs_xattr_get(struct ext2_xattr_handle *h, const char *key,
1301 void **value, size_t *value_len);
1302 errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *handle,
1306 errcode_t ext2fs_xattr_remove(struct ext2_xattr_handle *handle,
1308 errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
1309 struct ext2_xattr_handle **handle);
1310 errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle);
1311 errcode_t ext2fs_free_ext_attr(ext2_filsys fs, ext2_ino_t ino,
1312 struct ext2_inode_large *inode);
1313 errcode_t ext2fs_xattrs_count(struct ext2_xattr_handle *handle, size_t *count);
1314 errcode_t ext2fs_xattr_inode_max_size(ext2_filsys fs, ext2_ino_t ino,
1316 #define XATTR_HANDLE_FLAG_RAW 0x0001
1317 errcode_t ext2fs_xattrs_flags(struct ext2_xattr_handle *handle,
1318 unsigned int *new_flags, unsigned int *old_flags);
1319 extern void ext2fs_ext_attr_block_rehash(struct ext2_ext_attr_header *header,
1320 struct ext2_ext_attr_entry *end);
1321 extern __u32 ext2fs_get_ea_inode_hash(struct ext2_inode *inode);
1322 extern void ext2fs_set_ea_inode_hash(struct ext2_inode *inode, __u32 hash);
1323 extern __u64 ext2fs_get_ea_inode_ref(struct ext2_inode *inode);
1324 extern void ext2fs_set_ea_inode_ref(struct ext2_inode *inode, __u64 ref_count);
1327 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
1328 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
1329 ext2_extent_handle_t *handle);
1330 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
1331 struct ext2_inode *inode,
1332 ext2_extent_handle_t *ret_handle);
1333 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
1334 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
1335 int flags, struct ext2fs_extent *extent);
1336 extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
1337 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
1338 struct ext2fs_extent *extent);
1339 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
1340 struct ext2fs_extent *extent);
1341 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
1342 blk64_t logical, blk64_t physical,
1344 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
1345 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
1346 struct ext2_extent_info *info);
1347 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
1349 extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
1350 int leaf_level, blk64_t blk);
1351 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
1352 extern size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle);
1353 extern errcode_t ext2fs_fix_extents_checksums(ext2_filsys fs, ext2_ino_t ino,
1354 struct ext2_inode *inode);
1355 extern errcode_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
1356 struct ext2_inode *inode, blk64_t *ret_count);
1357 extern errcode_t ext2fs_decode_extent(struct ext2fs_extent *to, void *from,
1361 #define EXT2_FALLOCATE_ZERO_BLOCKS (0x1)
1362 #define EXT2_FALLOCATE_FORCE_INIT (0x2)
1363 #define EXT2_FALLOCATE_FORCE_UNINIT (0x4)
1364 #define EXT2_FALLOCATE_INIT_BEYOND_EOF (0x8)
1365 #define EXT2_FALLOCATE_ALL_FLAGS (0xF)
1366 errcode_t ext2fs_fallocate(ext2_filsys fs, int flags, ext2_ino_t ino,
1367 struct ext2_inode *inode, blk64_t goal,
1368 blk64_t start, blk64_t len);
1371 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
1372 struct ext2_inode *inode,
1373 int flags, ext2_file_t *ret);
1374 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
1375 int flags, ext2_file_t *ret);
1376 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
1377 struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);
1378 extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file);
1379 extern errcode_t ext2fs_file_close(ext2_file_t file);
1380 extern errcode_t ext2fs_file_flush(ext2_file_t file);
1381 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
1382 unsigned int wanted, unsigned int *got);
1383 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
1384 unsigned int nbytes, unsigned int *written);
1385 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
1386 int whence, __u64 *ret_pos);
1387 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
1388 int whence, ext2_off_t *ret_pos);
1389 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
1390 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
1391 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
1392 extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size);
1395 extern char *ext2fs_find_block_device(dev_t device);
1398 extern errcode_t ext2fs_sync_device(int fd, int flushb);
1401 extern void ext2fs_free(ext2_filsys fs);
1402 extern void ext2fs_free_dblist(ext2_dblist dblist);
1403 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
1404 extern void ext2fs_u32_list_free(ext2_u32_list bb);
1407 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
1408 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
1409 __u32 start, __u32 end,
1411 const char *descr, char *init_map,
1412 ext2fs_generic_bitmap *ret);
1413 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
1417 ext2fs_generic_bitmap *ret);
1418 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
1419 ext2fs_generic_bitmap *dest);
1420 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
1421 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
1426 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
1427 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
1430 ext2fs_generic_bitmap bmap);
1431 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
1432 ext2fs_generic_bitmap bm1,
1433 ext2fs_generic_bitmap bm2);
1434 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1436 __u32 start, __u32 num,
1438 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1440 __u32 start, __u32 num,
1442 extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap,
1443 __u32 start, __u32 end,
1445 extern errcode_t ext2fs_find_first_set_generic_bitmap(ext2fs_generic_bitmap bitmap,
1446 __u32 start, __u32 end,
1449 /* gen_bitmap64.c */
1450 void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
1451 errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
1452 int type, __u64 start, __u64 end,
1455 ext2fs_generic_bitmap *ret);
1456 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
1457 ext2fs_generic_bitmap *dest);
1458 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
1459 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
1461 __u64 end, __u64 *oend);
1462 void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
1463 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
1465 __u64 new_real_end);
1466 errcode_t ext2fs_merge_generic_bmap(ext2fs_generic_bitmap gen_src,
1467 ext2fs_generic_bitmap gen_dest,
1468 ext2fs_generic_bitmap gen_dup,
1469 ext2fs_generic_bitmap dup_allowed);
1470 errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
1471 ext2fs_generic_bitmap bm1,
1472 ext2fs_generic_bitmap bm2);
1473 errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
1474 __u64 start, unsigned int num,
1476 errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
1477 __u64 start, unsigned int num,
1479 errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
1480 ext2fs_block_bitmap *bitmap);
1481 errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
1482 blk64_t end, blk64_t *out);
1484 /* get_num_dirs.c */
1485 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
1488 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
1490 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
1491 blk64_t *retblocks);
1494 extern int ext2fs_get_dio_alignment(int fd);
1495 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
1496 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
1499 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
1500 blk64_t num_blocks);
1501 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
1502 blk64_t num_blocks);
1503 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
1506 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
1507 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
1508 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
1509 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
1510 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
1511 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
1514 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1515 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1518 extern errcode_t ext2fs_initialize(const char *name, int flags,
1519 struct ext2_super_block *param,
1520 io_manager manager, ext2_filsys *ret_fs);
1521 extern errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs, int super_only);
1524 extern void ext2fs_free_icount(ext2_icount_t icount);
1525 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
1526 int flags, ext2_icount_t *ret);
1527 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
1529 ext2_icount_t hint, ext2_icount_t *ret);
1530 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
1532 ext2_icount_t *ret);
1533 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
1535 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
1537 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
1539 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
1541 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
1542 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
1546 extern errcode_t ext2fs_get_memalign(unsigned long size,
1547 unsigned long align, void *ptr);
1550 extern errcode_t ext2fs_inline_data_init(ext2_filsys fs, ext2_ino_t ino);
1551 extern errcode_t ext2fs_inline_data_size(ext2_filsys fs, ext2_ino_t ino,
1553 extern errcode_t ext2fs_inline_data_get(ext2_filsys fs, ext2_ino_t ino,
1554 struct ext2_inode *inode,
1555 void *buf, size_t *size);
1556 extern errcode_t ext2fs_inline_data_set(ext2_filsys fs, ext2_ino_t ino,
1557 struct ext2_inode *inode,
1558 void *buf, size_t size);
1561 extern errcode_t ext2fs_create_inode_cache(ext2_filsys fs,
1562 unsigned int cache_size);
1563 extern void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
1564 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
1565 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
1567 struct ext2_inode *inode,
1569 #define EXT2_INODE_SCAN_DEFAULT_BUFFER_BLOCKS 8
1570 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
1571 ext2_inode_scan *ret_scan);
1572 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1573 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1574 struct ext2_inode *inode);
1575 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1577 extern void ext2fs_set_inode_callback
1578 (ext2_inode_scan scan,
1579 errcode_t (*done_group)(ext2_filsys fs,
1580 ext2_inode_scan scan,
1583 void *done_group_data);
1584 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1586 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1587 struct ext2_inode * inode,
1589 extern errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
1590 struct ext2_inode * inode);
1591 extern errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
1592 struct ext2_inode * inode,
1593 int bufsize, int flags);
1594 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1595 struct ext2_inode * inode,
1597 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1598 struct ext2_inode * inode);
1599 extern errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
1600 struct ext2_inode * inode,
1601 int bufsize, int flags);
1602 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1603 struct ext2_inode * inode);
1604 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1605 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1608 extern io_manager inode_io_manager;
1609 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1611 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1612 struct ext2_inode *inode,
1616 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1617 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1618 char *mtpt, int mtlen);
1622 * NOTE: This function removes from an inode the blocks "start", "end", and
1623 * every block in between.
1625 extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
1626 struct ext2_inode *inode,
1627 char *block_buf, blk64_t start,
1631 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1632 int namelen, char *buf, ext2_ino_t *inode);
1633 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1634 const char *name, ext2_ino_t *inode);
1635 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1636 const char *name, ext2_ino_t *inode);
1637 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1638 ext2_ino_t inode, ext2_ino_t *res_inode);
1641 int ext2fs_native_flag(void);
1644 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1645 ext2_ino_t parent_ino, char **block);
1646 extern errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino,
1647 ext2_ino_t parent_ino, __u32 *iblock);
1650 extern const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding);
1651 extern int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table,
1652 char *s, size_t len, char **pos);
1653 extern int ext2fs_casefold_cmp(const struct ext2fs_nls_table *table,
1654 const unsigned char *str1, size_t len1,
1655 const unsigned char *str2, size_t len2);
1658 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1662 struct ext2fs_journal_params {
1663 blk_t num_journal_blocks;
1664 blk_t num_fc_blocks;
1666 extern errcode_t ext2fs_get_journal_params(
1667 struct ext2fs_journal_params *params, ext2_filsys fs);
1668 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1669 blk_t *ret_blk, int *ret_count);
1670 extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
1671 blk64_t *ret_blk, int *ret_count);
1672 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1673 __u32 num_blocks, int flags,
1675 extern errcode_t ext2fs_create_journal_superblock2(ext2_filsys fs,
1676 struct ext2fs_journal_params *params,
1677 int flags, char **ret_jsb);
1678 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1679 ext2_filsys journal_dev);
1680 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,
1682 extern errcode_t ext2fs_add_journal_inode2(ext2_filsys fs, blk_t num_blocks,
1683 blk64_t goal, int flags);
1684 extern errcode_t ext2fs_add_journal_inode3(ext2_filsys fs,
1685 struct ext2fs_journal_params *params,
1686 blk64_t goal, int flags);
1687 extern int ext2fs_default_journal_size(__u64 num_blocks);
1688 extern int ext2fs_journal_sb_start(int blocksize);
1691 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1692 unsigned int block_size, io_manager manager,
1693 ext2_filsys *ret_fs);
1694 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1695 int flags, int superblock,
1696 unsigned int block_size, io_manager manager,
1697 ext2_filsys *ret_fs);
1698 errcode_t ext2fs_open_channel(ext2_filsys fs, const char *io_options,
1699 io_manager manager, int flags,
1702 * The dgrp_t argument to these two functions is not actually a group number
1703 * but a block number offset within a group table! Convert with the formula
1704 * (group_number / groups_per_block).
1706 extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs,
1707 blk64_t group_block, dgrp_t i);
1708 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1710 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1711 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1712 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1714 /* get_pathname.c */
1715 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1719 #define EXT2FS_UNLINK_FORCE 0x1 /* Forcefully unlink even if
1720 * the inode number doesn't
1723 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1724 ext2_ino_t ino, int flags);
1725 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1726 ext2_ino_t ino, int flags);
1729 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
1730 const char *name, const char *target);
1731 int ext2fs_is_fast_symlink(struct ext2_inode *inode);
1734 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1735 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1736 errcode_t ext2fs_mmp_clear(ext2_filsys fs);
1737 errcode_t ext2fs_mmp_init(ext2_filsys fs);
1738 errcode_t ext2fs_mmp_start(ext2_filsys fs);
1739 errcode_t ext2fs_mmp_update(ext2_filsys fs);
1740 errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately);
1741 errcode_t ext2fs_mmp_stop(ext2_filsys fs);
1742 unsigned ext2fs_mmp_new_seq(void);
1745 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1746 ext2_badblocks_list *bb_list);
1748 /* read_bb_file.c */
1749 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1750 ext2_badblocks_list *bb_list,
1752 void (*invalid)(ext2_filsys fs,
1756 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1757 ext2_badblocks_list *bb_list,
1758 void (*invalid)(ext2_filsys fs,
1762 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1765 extern errcode_t ext2fs_rw_bitmaps(ext2_filsys fs, int flags, int num_threads);
1766 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
1767 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
1768 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
1769 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
1770 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
1771 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
1774 #define EXT2FS_SHA256_LENGTH 32
1776 extern void ext2fs_sha256(const unsigned char *in, unsigned long in_size,
1777 unsigned char out[EXT2FS_SHA256_LENGTH]);
1781 #define EXT2FS_SHA512_LENGTH 64
1782 extern void ext2fs_sha512(const unsigned char *in, unsigned long in_size,
1783 unsigned char out[EXT2FS_SHA512_LENGTH]);
1786 extern errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf, size_t size,
1788 extern errcode_t ext2fs_dirent_swab_in(ext2_filsys fs, char *buf, int flags);
1789 extern errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf, size_t size,
1791 extern errcode_t ext2fs_dirent_swab_out(ext2_filsys fs, char *buf, int flags);
1792 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1794 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1795 struct ext2_ext_attr_header *from_hdr);
1796 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1797 struct ext2_ext_attr_entry *from_entry);
1798 extern void ext2fs_swap_super(struct ext2_super_block * super);
1799 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1800 extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp);
1801 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1802 struct ext2_inode_large *f, int hostorder,
1804 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1805 struct ext2_inode *f, int hostorder);
1806 extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
1809 extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
1810 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
1811 extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
1814 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1815 extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs,
1816 struct ext2_inode *inode);
1819 extern int ext2fs_parse_version_string(const char *ver_string);
1820 extern int ext2fs_get_library_version(const char **ver_string,
1821 const char **date_string);
1823 /* write_bb_file.c */
1824 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1829 /* inline functions */
1830 #ifdef NO_INLINE_FUNCS
1831 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1832 extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr);
1833 extern errcode_t ext2fs_get_array(unsigned long count,
1834 unsigned long size, void *ptr);
1835 extern errcode_t ext2fs_get_arrayzero(unsigned long count,
1836 unsigned long size, void *ptr);
1837 extern errcode_t ext2fs_free_mem(void *ptr);
1838 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1839 unsigned long size, void *ptr);
1840 extern errcode_t ext2fs_resize_array(unsigned long old_count, unsigned long count,
1841 unsigned long size, void *ptr);
1842 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1843 extern void ext2fs_mark_changed(ext2_filsys fs);
1844 extern int ext2fs_test_changed(ext2_filsys fs);
1845 extern void ext2fs_mark_valid(ext2_filsys fs);
1846 extern void ext2fs_unmark_valid(ext2_filsys fs);
1847 extern int ext2fs_test_valid(ext2_filsys fs);
1848 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1849 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1850 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1851 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1852 extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1853 extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1854 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1855 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1856 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1857 struct ext2_inode *inode);
1858 extern int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks);
1859 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1860 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
1861 extern int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry);
1862 extern void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len);
1863 extern int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry);
1864 extern void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type);
1865 extern struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode);
1866 extern const struct ext2_inode *ext2fs_const_inode(const struct ext2_inode_large * large_inode);
1871 * The actual inlined functions definitions themselves...
1873 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1876 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1877 #ifdef INCLUDE_INLINE_FUNCS
1878 #define _INLINE_ extern
1880 #if (__STDC_VERSION__ >= 199901L)
1881 #define _INLINE_ inline
1884 #define _INLINE_ extern __inline__
1885 #else /* For Watcom C */
1886 #define _INLINE_ extern inline
1887 #endif /* __GNUC__ */
1888 #endif /* __STDC_VERSION__ >= 199901L */
1891 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1894 * Allocate memory. The 'ptr' arg must point to a pointer.
1896 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1902 return EXT2_ET_NO_MEMORY;
1903 memcpy(ptr, &pp, sizeof (pp));
1907 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
1913 return EXT2_ET_NO_MEMORY;
1914 memset(pp, 0, size);
1915 memcpy(ptr, &pp, sizeof(pp));
1919 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size,
1922 if (count && (~0UL)/count < size)
1923 return EXT2_ET_NO_MEMORY;
1924 return ext2fs_get_mem(count*size, ptr);
1927 _INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
1928 unsigned long size, void *ptr)
1930 if (count && (~0UL)/count < size)
1931 return EXT2_ET_NO_MEMORY;
1933 return ext2fs_get_memzero((size_t)count * size, ptr);
1937 * Free memory. The 'ptr' arg must point to a pointer.
1939 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1943 memcpy(&p, ptr, sizeof(p));
1946 memcpy(ptr, &p, sizeof(p));
1951 * Resize memory. The 'ptr' arg must point to a pointer.
1953 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1954 unsigned long size, void *ptr)
1958 /* Use "memcpy" for pointer assignments here to avoid problems
1959 * with C99 strict type aliasing rules. */
1960 memcpy(&p, ptr, sizeof(p));
1961 p = realloc(p, size);
1963 return EXT2_ET_NO_MEMORY;
1964 memcpy(ptr, &p, sizeof(p));
1969 * Resize array. The 'ptr' arg must point to a pointer.
1971 _INLINE_ errcode_t ext2fs_resize_array(unsigned long size,
1972 unsigned long old_count,
1973 unsigned long count, void *ptr)
1975 unsigned long old_size;
1978 if (count && (~0UL)/count < size)
1979 return EXT2_ET_NO_MEMORY;
1982 old_size = size * old_count;
1983 retval = ext2fs_resize_mem(old_size, size, ptr);
1987 if (size > old_size) {
1990 memcpy(&p, ptr, sizeof(p));
1991 memset((char *)p + old_size, 0, size - old_size);
1992 memcpy(ptr, &p, sizeof(p));
1997 #endif /* Custom memory routines */
2000 * Mark a filesystem superblock as dirty
2002 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
2004 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
2008 * Mark a filesystem as changed
2010 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
2012 fs->flags |= EXT2_FLAG_CHANGED;
2016 * Check to see if a filesystem has changed
2018 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
2020 return (fs->flags & EXT2_FLAG_CHANGED);
2024 * Mark a filesystem as valid
2026 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
2028 fs->flags |= EXT2_FLAG_VALID;
2032 * Mark a filesystem as NOT valid
2034 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
2036 fs->flags &= ~EXT2_FLAG_VALID;
2040 * Check to see if a filesystem is valid
2042 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
2044 return (fs->flags & EXT2_FLAG_VALID);
2048 * Mark the inode bitmap as dirty
2050 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
2052 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
2056 * Mark the block bitmap as dirty
2058 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
2060 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
2064 * Check to see if a filesystem's inode bitmap is dirty
2066 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
2068 return (fs->flags & EXT2_FLAG_IB_DIRTY);
2072 * Check to see if a filesystem's block bitmap is dirty
2074 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
2076 return (fs->flags & EXT2_FLAG_BB_DIRTY);
2080 * Return the group # of a block
2082 _INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
2084 return ext2fs_group_of_blk2(fs, blk);
2087 * Return the group # of an inode number
2089 _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
2091 return (ino - 1) / fs->super->s_inodes_per_group;
2095 * Return the first block (inclusive) in a group
2097 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
2099 return (blk_t) ext2fs_group_first_block2(fs, group);
2103 * Return the last block (inclusive) in a group
2105 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
2107 return (blk_t) ext2fs_group_last_block2(fs, group);
2110 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
2111 struct ext2_inode *inode)
2113 return (blk_t) ext2fs_inode_data_blocks2(fs, inode);
2116 _INLINE_ int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks)
2120 if ((EXT2_SB(fs->super)->s_feature_ro_compat &
2121 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) != 0)
2122 csum_size = sizeof(struct ext2_dx_tail);
2123 return blocks * ((fs->blocksize - (8 + csum_size)) /
2124 sizeof(struct ext2_dx_entry));
2128 * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
2130 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
2134 return ((a - 1) / b) + 1;
2137 _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b)
2141 return ((a - 1) / b) + 1;
2144 _INLINE_ int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry)
2146 return entry->name_len & 0xff;
2149 _INLINE_ void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len)
2151 entry->name_len = (entry->name_len & 0xff00) | (len & 0xff);
2154 _INLINE_ int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry)
2156 return entry->name_len >> 8;
2159 _INLINE_ void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type)
2161 entry->name_len = (entry->name_len & 0xff) | (type << 8);
2164 _INLINE_ struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode)
2166 /* It is always safe to convert large inode to a small inode */
2167 return (struct ext2_inode *) large_inode;
2170 _INLINE_ const struct ext2_inode *
2171 ext2fs_const_inode(const struct ext2_inode_large * large_inode)
2173 /* It is always safe to convert large inode to a small inode */
2174 return (const struct ext2_inode *) large_inode;
2180 /* htree levels for ext4 */
2181 #define EXT4_HTREE_LEVEL_COMPAT 2
2182 #define EXT4_HTREE_LEVEL 3
2184 static inline unsigned int ext2_dir_htree_level(ext2_filsys fs)
2186 if (ext2fs_has_feature_largedir(fs->super))
2187 return EXT4_HTREE_LEVEL;
2189 return EXT4_HTREE_LEVEL_COMPAT;
2196 #endif /* _EXT2FS_EXT2FS_H */