2 * Copyright (c) 2003,2004 Cluster File Systems, Inc, info@clusterfs.com
3 * Written by Alex Tomas <alex@clusterfs.com>
6 * This file may be redistributed under the terms of the GNU Library
7 * General Public License, version 2.
11 #ifndef _LINUX_EXT3_EXTENTS
12 #define _LINUX_EXT3_EXTENTS
15 * ext3_inode has i_block array (total 60 bytes)
16 * first 4 bytes are used to store:
17 * - tree depth (0 mean there is no tree yet. all extents in the inode)
18 * - number of alive extents in the inode
22 * this is extent on-disk structure
23 * it's used at the bottom of the tree
26 __u32 ee_block; /* first logical block extent covers */
27 __u16 ee_len; /* number of blocks covered by extent */
28 __u16 ee_start_hi; /* high 16 bits of physical block */
29 __u32 ee_start; /* low 32 bigs of physical block */
33 * this is index on-disk structure
34 * it's used at all the levels, but the bottom
36 struct ext3_extent_idx {
37 __u32 ei_block; /* index covers logical blocks from 'block' */
38 __u32 ei_leaf; /* pointer to the physical block of the next *
39 * level. leaf or next index could bet here */
40 __u16 ei_leaf_hi; /* high 16 bits of physical block */
45 * each block (leaves and indexes), even inode-stored has header
47 struct ext3_extent_header {
48 __u16 eh_magic; /* probably will support different formats */
49 __u16 eh_entries; /* number of valid entries */
50 __u16 eh_max; /* capacity of store in entries */
51 __u16 eh_depth; /* has tree real underlaying blocks? */
52 __u32 eh_generation; /* generation of the tree */
55 #define EXT3_EXT_MAGIC 0xf30a
58 * array of ext3_ext_path contains path to some extent
59 * creation/lookup routines use it for traversal/splitting/etc
60 * truncate uses it to simulate recursive walking
62 struct ext3_ext_path {
65 struct ext3_extent *p_ext;
66 struct ext3_extent_idx *p_idx;
67 struct ext3_extent_header *p_hdr;
68 struct buffer_head *p_bh;
72 * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
73 * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
74 * MSB of ee_len field in the extent datastructure to signify if this
75 * particular extent is an initialized extent or an uninitialized (i.e.
77 * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
78 * uninitialized extent.
79 * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
80 * uninitialized one. In other words, if MSB of ee_len is set, it is an
81 * uninitialized extent with only one special scenario when ee_len = 0x8000.
82 * In this case we can not have an uninitialized extent of zero length and
83 * thus we make it as a special case of initialized extent with 0x8000 length.
84 * This way we get better extent-to-group alignment for initialized extents.
85 * Hence, the maximum number of blocks we can have in an *initialized*
86 * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
88 #define EXT_INIT_MAX_LEN (1UL << 15)
89 #define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1)
91 #define EXT_FIRST_EXTENT(__hdr__) \
92 ((struct ext3_extent *) (((char *) (__hdr__)) + \
93 sizeof(struct ext3_extent_header)))
94 #define EXT_FIRST_INDEX(__hdr__) \
95 ((struct ext3_extent_idx *) (((char *) (__hdr__)) + \
96 sizeof(struct ext3_extent_header)))
97 #define EXT_HAS_FREE_INDEX(__path__) \
98 (ext2fs_le16_to_cpu((__path__)->p_hdr->eh_entries) < \
99 ext2fs_le16_to_cpu((__path__)->p_hdr->eh_max))
100 #define EXT_LAST_EXTENT(__hdr__) \
101 (EXT_FIRST_EXTENT((__hdr__)) + \
102 ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
103 #define EXT_LAST_INDEX(__hdr__) \
104 (EXT_FIRST_INDEX((__hdr__)) + \
105 ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
106 #define EXT_MAX_EXTENT(__hdr__) \
107 (EXT_FIRST_EXTENT((__hdr__)) + \
108 ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
109 #define EXT_MAX_INDEX(__hdr__) \
110 (EXT_FIRST_INDEX((__hdr__)) + \
111 ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
113 #endif /* _LINUX_EXT3_EXTENTS */