ext2_extents.h revision 314937
1153577Sjhb/*-
2153577Sjhb * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org>
3153577Sjhb * All rights reserved.
4153577Sjhb *
5153577Sjhb * Redistribution and use in source and binary forms, with or without
6153577Sjhb * modification, are permitted provided that the following conditions
7153577Sjhb * are met:
8153577Sjhb * 1. Redistributions of source code must retain the above copyright
9153577Sjhb *    notice, this list of conditions and the following disclaimer.
10153577Sjhb * 2. Redistributions in binary form must reproduce the above copyright
11153577Sjhb *    notice, this list of conditions and the following disclaimer in the
12153577Sjhb *    documentation and/or other materials provided with the distribution.
13153577Sjhb *
14153577Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15153577Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16153577Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17153577Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18153577Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19153577Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20153577Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21153577Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22153577Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23153577Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24153577Sjhb * SUCH DAMAGE.
25153577Sjhb *
26153577Sjhb * $FreeBSD: stable/10/sys/fs/ext2fs/ext2_extents.h 314937 2017-03-09 02:47:01Z pfg $
27153577Sjhb */
28153577Sjhb#ifndef _FS_EXT2FS_EXT2_EXTENTS_H_
29153577Sjhb#define	_FS_EXT2FS_EXT2_EXTENTS_H_
30153577Sjhb
31153577Sjhb#include <sys/types.h>
32153577Sjhb
33153577Sjhb#define	EXT4_EXT_MAGIC  0xf30a
34153577Sjhb
35153577Sjhb#define	EXT4_EXT_CACHE_NO	0
36153577Sjhb#define	EXT4_EXT_CACHE_GAP	1
37153577Sjhb#define	EXT4_EXT_CACHE_IN	2
38153577Sjhb
39153577Sjhb/*
40153577Sjhb * Ext4 file system extent on disk.
41153577Sjhb */
42153577Sjhbstruct ext4_extent {
43153577Sjhb	uint32_t e_blk;	/* first logical block */
44153577Sjhb	uint16_t e_len;	/* number of blocks */
45153577Sjhb	uint16_t e_start_hi;	/* high 16 bits of physical block */
46153577Sjhb	uint32_t e_start_lo;	/* low 32 bits of physical block */
47153577Sjhb};
48153577Sjhb
49183095Sjhb/*
50183095Sjhb * Extent index on disk.
51183095Sjhb */
52183095Sjhbstruct ext4_extent_index {
53153577Sjhb	uint32_t ei_blk;	/* indexes logical blocks */
54153577Sjhb	uint32_t ei_leaf_lo;	/* points to physical block of the
55153577Sjhb				 * next level */
56153577Sjhb	uint16_t ei_leaf_hi;	/* high 16 bits of physical block */
57153577Sjhb	uint16_t ei_unused;
58153577Sjhb};
59153577Sjhb
60153577Sjhb/*
61153577Sjhb * Extent tree header.
62153577Sjhb */
63153577Sjhbstruct ext4_extent_header {
64153577Sjhb	uint16_t eh_magic;		/* magic number: 0xf30a */
65153577Sjhb	uint16_t eh_ecount;		/* number of valid entries */
66153577Sjhb	uint16_t eh_max;		/* capacity of store in entries */
67153577Sjhb	uint16_t eh_depth;		/* the depth of extent tree */
68153646Sjhb	uint32_t eh_gen;		/* generation of extent tree */
69153577Sjhb};
70153577Sjhb
71153577Sjhb/*
72153577Sjhb * Save cached extent.
73153577Sjhb */
74153577Sjhbstruct ext4_extent_cache {
75153577Sjhb	daddr_t	ec_start;		/* extent start */
76153577Sjhb	uint32_t ec_blk;		/* logical block */
77153577Sjhb	uint32_t ec_len;
78153577Sjhb	uint32_t ec_type;
79153577Sjhb};
80153577Sjhb
81153577Sjhb/*
82153577Sjhb * Save path to some extent.
83153577Sjhb */
84153577Sjhbstruct ext4_extent_path {
85153577Sjhb	uint16_t ep_depth;
86153577Sjhb	struct buf *ep_bp;
87153577Sjhb	int ep_is_sparse;
88153577Sjhb	union {
89153577Sjhb		struct ext4_extent ep_sparse_ext;
90153577Sjhb		struct ext4_extent *ep_ext;
91153577Sjhb	};
92153577Sjhb	struct ext4_extent_index *ep_index;
93153577Sjhb	struct ext4_extent_header *ep_header;
94153577Sjhb};
95153577Sjhb
96153577Sjhbstruct inode;
97153577Sjhbstruct m_ext2fs;
98153577Sjhbint	ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *);
99153577Sjhbvoid	ext4_ext_put_cache(struct inode *, struct ext4_extent *, int);
100153577Sjhbstruct ext4_extent_path *
101153577Sjhbext4_ext_find_extent(struct m_ext2fs *fs,
102153577Sjhb    struct inode *, daddr_t, struct ext4_extent_path *);
103153577Sjhb
104153577Sjhb#endif	/* !_FS_EXT2FS_EXT2_EXTENTS_H_ */
105153577Sjhb