119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * ext2fsP.h --- private header file for ext2 library
3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o *
419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1997 Theodore Ts'o.
519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header%
7543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o * This file may be redistributed under the terms of the GNU Library
8543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o * General Public License, version 2.
919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header%
1019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
1119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
1219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#include "ext2fs.h"
1319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
14e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define EXT2FS_MAX_NESTED_LINKS  8
15e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
1619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Badblocks list
1819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
19b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'ostruct ext2_struct_u32_list {
2019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	magic;
2119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	num;
2219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	size;
23b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'o	__u32	*list;
2419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int	badblocks_flags;
2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
2619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
27b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'ostruct ext2_struct_u32_iterate {
28b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'o	int			magic;
29b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'o	ext2_u32_list		bb;
30b7a00563b22b0ea47ddc7117508c0b8e0d65df43Theodore Ts'o	int			ptr;
3119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
3519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Directory block iterator definition
3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct ext2_struct_dblist {
3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int			magic;
3919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	ext2_filsys		fs;
40e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned long long	size;
41e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned long long	count;
4219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int			sorted;
43e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	struct ext2_db_entry2 *	list;
4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
4719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * For directory iterators
4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct dir_context {
5031dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	ext2_ino_t		dir;
5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	int		flags;
5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char		*buf;
538bd0c95908baa3af706b9e731daff9472bec74c9Theodore Ts'o	int (*func)(ext2_ino_t	dir,
548bd0c95908baa3af706b9e731daff9472bec74c9Theodore Ts'o		    int	entry,
558bd0c95908baa3af706b9e731daff9472bec74c9Theodore Ts'o		    struct ext2_dir_entry *dirent,
5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		    int	offset,
5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		    int	blocksize,
5819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o		    char	*buf,
59b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o		    void	*priv_data);
60b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o	void		*priv_data;
6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t	errcode;
6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
64a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o/*
65a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o * Inode cache structure
66a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o */
67a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'ostruct ext2_inode_cache {
68a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	void *				buffer;
69e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	blk64_t				buffer_blk;
70a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	int				cache_last;
71a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	int				cache_size;
72a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	int				refcount;
73a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o	struct ext2_inode_cache_ent	*cache;
74a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o};
75a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o
76a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'ostruct ext2_inode_cache_ent {
7731dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	ext2_ino_t		ino;
7831dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	struct ext2_inode	inode;
79a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o};
8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/* Function prototypes */
8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8336a43d675ef61d0f5d5b2ad62d2e670c408d14acTheodore Ts'oextern int ext2fs_process_dir_block(ext2_filsys  	fs,
84e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				    blk64_t		*blocknr,
8503673dbb04a3458ce78a394f27d17d434b51a714Theodore Ts'o				    e2_blkcnt_t		blockcnt,
86e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				    blk64_t		ref_block,
8736a43d675ef61d0f5d5b2ad62d2e670c408d14acTheodore Ts'o				    int			ref_offset,
8836a43d675ef61d0f5d5b2ad62d2e670c408d14acTheodore Ts'o				    void		*priv_data);
8936a43d675ef61d0f5d5b2ad62d2e670c408d14acTheodore Ts'o
90e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/* Generic numeric progress meter */
91e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
92e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct ext2fs_numeric_progress_struct {
93e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	__u64		max;
94e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	int		log_max;
95e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	int		skip_progress;
96e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall};
97e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
98e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern void ext2fs_numeric_progress_init(ext2_filsys fs,
99e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					 struct ext2fs_numeric_progress_struct * progress,
100e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					 const char *label, __u64 max);
101e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern void ext2fs_numeric_progress_update(ext2_filsys fs,
102e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   struct ext2fs_numeric_progress_struct * progress,
103e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   __u64 val);
104e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern void ext2fs_numeric_progress_close(ext2_filsys fs,
105e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					  struct ext2fs_numeric_progress_struct * progress,
106e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					  const char *message);
107e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
108e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/*
109e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall * 64-bit bitmap support
110e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall */
111e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
112e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
113e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   int type, __u64 start, __u64 end,
114e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   __u64 real_end,
115e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   const char * description,
116e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					   ext2fs_generic_bitmap *bmap);
117e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
118e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
119e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
120e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
121e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					  ext2fs_generic_bitmap *dest);
122e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
123e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
124e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					    __u64 new_end,
125e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					    __u64 new_real_end);
126e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
127e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       errcode_t neq,
128e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       __u64 end, __u64 *oend);
129e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,
130e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				    __u64 arg);
131e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,
132e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				      __u64 arg);
133e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,
134e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				    __u64 arg);
135e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bitmap,
136e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       __u64 start, unsigned int num,
137e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       void *in);
138e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bitmap,
139e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       __u64 start, unsigned int num,
140e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					       void *out);
141e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap,const char *func);
142e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
143e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern int ext2fs_mem_is_zero(const char *mem, size_t len);
1441e7451493ed67ae94ba5c1d2bed059527bc9848dDarrick J. Wong
145e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallextern int ext2fs_file_block_offset_too_big(ext2_filsys fs,
146e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					    struct ext2_inode *inode,
147e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					    blk64_t offset);
148