1254260Spfg/*-
2254260Spfg * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org>
3254260Spfg * All rights reserved.
4254260Spfg *
5254260Spfg * Redistribution and use in source and binary forms, with or without
6254260Spfg * modification, are permitted provided that the following conditions
7254260Spfg * are met:
8254260Spfg * 1. Redistributions of source code must retain the above copyright
9254260Spfg *    notice, this list of conditions and the following disclaimer.
10254260Spfg * 2. Redistributions in binary form must reproduce the above copyright
11254260Spfg *    notice, this list of conditions and the following disclaimer in the
12254260Spfg *    documentation and/or other materials provided with the distribution.
13254260Spfg *
14254260Spfg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15254260Spfg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16254260Spfg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17254260Spfg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18254260Spfg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19254260Spfg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20254260Spfg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21254260Spfg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22254260Spfg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23254260Spfg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24254260Spfg * SUCH DAMAGE.
25254260Spfg *
26254260Spfg * $FreeBSD: stable/10/sys/fs/ext2fs/ext2_extents.h 317532 2017-04-27 23:14:01Z pfg $
27254260Spfg */
28254260Spfg#ifndef _FS_EXT2FS_EXT2_EXTENTS_H_
29262723Spfg#define	_FS_EXT2FS_EXT2_EXTENTS_H_
30254260Spfg
31254260Spfg#include <sys/types.h>
32254260Spfg
33262723Spfg#define	EXT4_EXT_MAGIC  0xf30a
34254260Spfg
35262723Spfg#define	EXT4_EXT_CACHE_NO	0
36262723Spfg#define	EXT4_EXT_CACHE_GAP	1
37262723Spfg#define	EXT4_EXT_CACHE_IN	2
38254260Spfg
39254260Spfg/*
40254260Spfg * Ext4 file system extent on disk.
41254260Spfg */
42254260Spfgstruct ext4_extent {
43254260Spfg	uint32_t e_blk;	/* first logical block */
44254260Spfg	uint16_t e_len;	/* number of blocks */
45254260Spfg	uint16_t e_start_hi;	/* high 16 bits of physical block */
46254260Spfg	uint32_t e_start_lo;	/* low 32 bits of physical block */
47254260Spfg};
48254260Spfg
49254260Spfg/*
50254260Spfg * Extent index on disk.
51254260Spfg */
52254260Spfgstruct ext4_extent_index {
53254260Spfg	uint32_t ei_blk;	/* indexes logical blocks */
54254260Spfg	uint32_t ei_leaf_lo;	/* points to physical block of the
55254260Spfg				 * next level */
56254260Spfg	uint16_t ei_leaf_hi;	/* high 16 bits of physical block */
57254260Spfg	uint16_t ei_unused;
58254260Spfg};
59254260Spfg
60254260Spfg/*
61254260Spfg * Extent tree header.
62254260Spfg */
63254260Spfgstruct ext4_extent_header {
64311232Spfg	uint16_t eh_magic;		/* magic number: 0xf30a */
65311232Spfg	uint16_t eh_ecount;		/* number of valid entries */
66311232Spfg	uint16_t eh_max;		/* capacity of store in entries */
67311232Spfg	uint16_t eh_depth;		/* the depth of extent tree */
68311232Spfg	uint32_t eh_gen;		/* generation of extent tree */
69254260Spfg};
70254260Spfg
71254260Spfg/*
72254260Spfg * Save cached extent.
73254260Spfg */
74254260Spfgstruct ext4_extent_cache {
75311232Spfg	daddr_t	ec_start;		/* extent start */
76311232Spfg	uint32_t ec_blk;		/* logical block */
77254260Spfg	uint32_t ec_len;
78254260Spfg	uint32_t ec_type;
79254260Spfg};
80254260Spfg
81254260Spfg/*
82254260Spfg * Save path to some extent.
83254260Spfg */
84254260Spfgstruct ext4_extent_path {
85254260Spfg	uint16_t ep_depth;
86254260Spfg	struct buf *ep_bp;
87317532Spfg	struct ext4_extent *ep_ext;
88254260Spfg	struct ext4_extent_index *ep_index;
89254260Spfg	struct ext4_extent_header *ep_header;
90254260Spfg};
91254260Spfg
92254260Spfgstruct inode;
93254260Spfgstruct m_ext2fs;
94254260Spfgint	ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *);
95254260Spfgvoid	ext4_ext_put_cache(struct inode *, struct ext4_extent *, int);
96311232Spfgstruct ext4_extent_path *
97311232Spfgext4_ext_find_extent(struct m_ext2fs *fs,
98254260Spfg    struct inode *, daddr_t, struct ext4_extent_path *);
99254260Spfg
100311232Spfg#endif	/* !_FS_EXT2FS_EXT2_EXTENTS_H_ */
101