xref: /openbsd/sys/ufs/ext2fs/ext2fs_extents.h (revision ea0c9824)
1*ea0c9824Spelikan /*-
2*ea0c9824Spelikan  * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org>
3*ea0c9824Spelikan  * All rights reserved.
4*ea0c9824Spelikan  *
5*ea0c9824Spelikan  * Redistribution and use in source and binary forms, with or without
6*ea0c9824Spelikan  * modification, are permitted provided that the following conditions
7*ea0c9824Spelikan  * are met:
8*ea0c9824Spelikan  * 1. Redistributions of source code must retain the above copyright
9*ea0c9824Spelikan  *    notice, this list of conditions and the following disclaimer.
10*ea0c9824Spelikan  * 2. Redistributions in binary form must reproduce the above copyright
11*ea0c9824Spelikan  *    notice, this list of conditions and the following disclaimer in the
12*ea0c9824Spelikan  *    documentation and/or other materials provided with the distribution.
13*ea0c9824Spelikan  *
14*ea0c9824Spelikan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*ea0c9824Spelikan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*ea0c9824Spelikan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*ea0c9824Spelikan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*ea0c9824Spelikan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*ea0c9824Spelikan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*ea0c9824Spelikan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*ea0c9824Spelikan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*ea0c9824Spelikan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*ea0c9824Spelikan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*ea0c9824Spelikan  * SUCH DAMAGE.
25*ea0c9824Spelikan  *
26*ea0c9824Spelikan  * $FreeBSD: head/sys/fs/ext2fs/ext2_extents.h 262623 2014-02-28 21:25:32Z pfg $
27*ea0c9824Spelikan  */
28*ea0c9824Spelikan #ifndef _FS_EXT2FS_EXT2_EXTENTS_H_
29*ea0c9824Spelikan #define	_FS_EXT2FS_EXT2_EXTENTS_H_
30*ea0c9824Spelikan 
31*ea0c9824Spelikan #include <sys/types.h>
32*ea0c9824Spelikan 
33*ea0c9824Spelikan #define	EXT4_EXT_MAGIC  0xf30a
34*ea0c9824Spelikan 
35*ea0c9824Spelikan #define	EXT4_EXT_CACHE_NO	0
36*ea0c9824Spelikan #define	EXT4_EXT_CACHE_GAP	1
37*ea0c9824Spelikan #define	EXT4_EXT_CACHE_IN	2
38*ea0c9824Spelikan 
39*ea0c9824Spelikan /*
40*ea0c9824Spelikan  * Ext4 file system extent on disk.
41*ea0c9824Spelikan  */
42*ea0c9824Spelikan struct ext4_extent {
43*ea0c9824Spelikan 	uint32_t e_blk;	/* first logical block */
44*ea0c9824Spelikan 	uint16_t e_len;	/* number of blocks */
45*ea0c9824Spelikan 	uint16_t e_start_hi;	/* high 16 bits of physical block */
46*ea0c9824Spelikan 	uint32_t e_start_lo;	/* low 32 bits of physical block */
47*ea0c9824Spelikan };
48*ea0c9824Spelikan 
49*ea0c9824Spelikan /*
50*ea0c9824Spelikan  * Extent index on disk.
51*ea0c9824Spelikan  */
52*ea0c9824Spelikan struct ext4_extent_index {
53*ea0c9824Spelikan 	uint32_t ei_blk;	/* indexes logical blocks */
54*ea0c9824Spelikan 	uint32_t ei_leaf_lo;	/* points to physical block of the
55*ea0c9824Spelikan 				 * next level */
56*ea0c9824Spelikan 	uint16_t ei_leaf_hi;	/* high 16 bits of physical block */
57*ea0c9824Spelikan 	uint16_t ei_unused;
58*ea0c9824Spelikan };
59*ea0c9824Spelikan 
60*ea0c9824Spelikan /*
61*ea0c9824Spelikan  * Extent tree header.
62*ea0c9824Spelikan  */
63*ea0c9824Spelikan struct ext4_extent_header {
64*ea0c9824Spelikan 	uint16_t eh_magic;	/* magic number: 0xf30a */
65*ea0c9824Spelikan 	uint16_t eh_ecount;	/* number of valid entries */
66*ea0c9824Spelikan 	uint16_t eh_max;	/* capacity of store in entries */
67*ea0c9824Spelikan 	uint16_t eh_depth;	/* the depth of extent tree */
68*ea0c9824Spelikan 	uint32_t eh_gen;	/* generation of extent tree */
69*ea0c9824Spelikan };
70*ea0c9824Spelikan 
71*ea0c9824Spelikan /*
72*ea0c9824Spelikan  * Save cached extent.
73*ea0c9824Spelikan  */
74*ea0c9824Spelikan struct ext4_extent_cache {
75*ea0c9824Spelikan 	daddr_t	ec_start;	/* extent start */
76*ea0c9824Spelikan 	uint32_t ec_blk;	/* logical block */
77*ea0c9824Spelikan 	uint32_t ec_len;
78*ea0c9824Spelikan 	uint32_t ec_type;
79*ea0c9824Spelikan };
80*ea0c9824Spelikan 
81*ea0c9824Spelikan /*
82*ea0c9824Spelikan  * Save path to some extent.
83*ea0c9824Spelikan  */
84*ea0c9824Spelikan struct ext4_extent_path {
85*ea0c9824Spelikan 	uint16_t ep_depth;
86*ea0c9824Spelikan 	struct buf *ep_bp;
87*ea0c9824Spelikan 	struct ext4_extent *ep_ext;
88*ea0c9824Spelikan 	struct ext4_extent_index *ep_index;
89*ea0c9824Spelikan 	struct ext4_extent_header *ep_header;
90*ea0c9824Spelikan };
91*ea0c9824Spelikan 
92*ea0c9824Spelikan struct inode;
93*ea0c9824Spelikan struct m_ext2fs;
94*ea0c9824Spelikan int	ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *);
95*ea0c9824Spelikan void	ext4_ext_put_cache(struct inode *, struct ext4_extent *, int);
96*ea0c9824Spelikan struct ext4_extent_path *ext4_ext_find_extent(struct m_ext2fs *fs,
97*ea0c9824Spelikan     struct inode *, daddr_t, struct ext4_extent_path *);
98*ea0c9824Spelikan 
99*ea0c9824Spelikan #endif /* !_FS_EXT2FS_EXT2_EXTENTS_H_ */
100