1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef _EXT4_EXTENTS
20#define _EXT4_EXTENTS
21
22#include "ext4.h"
23
24
25
26
27
28
29
30#define AGGRESSIVE_TEST_
31
32
33
34
35
36
37#define EXTENTS_STATS__
38
39
40
41
42
43#define CHECK_BINSEARCH__
44
45
46
47
48#define EXT_DEBUG__
49#ifdef EXT_DEBUG
50#define ext_debug(a...) printk(a)
51#else
52#define ext_debug(a...)
53#endif
54
55
56
57
58
59#define EXT_STATS_
60
61
62
63
64
65
66
67
68
69
70
71
72struct ext4_extent {
73 __le32 ee_block;
74 __le16 ee_len;
75 __le16 ee_start_hi;
76 __le32 ee_start_lo;
77};
78
79
80
81
82
83struct ext4_extent_idx {
84 __le32 ei_block;
85 __le32 ei_leaf_lo;
86
87 __le16 ei_leaf_hi;
88 __u16 ei_unused;
89};
90
91
92
93
94struct ext4_extent_header {
95 __le16 eh_magic;
96 __le16 eh_entries;
97 __le16 eh_max;
98 __le16 eh_depth;
99 __le32 eh_generation;
100};
101
102#define EXT4_EXT_MAGIC cpu_to_le16(0xf30a)
103
104
105
106
107
108
109struct ext4_ext_path {
110 ext4_fsblk_t p_block;
111 __u16 p_depth;
112 struct ext4_extent *p_ext;
113 struct ext4_extent_idx *p_idx;
114 struct ext4_extent_header *p_hdr;
115 struct buffer_head *p_bh;
116};
117
118
119
120
121
122
123
124
125
126
127
128typedef int (*ext_prepare_callback)(struct inode *, ext4_lblk_t,
129 struct ext4_ext_cache *,
130 struct ext4_extent *, void *);
131
132#define EXT_CONTINUE 0
133#define EXT_BREAK 1
134#define EXT_REPEAT 2
135
136
137
138
139
140#define EXT_MAX_BLOCKS 0xffffffff
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159#define EXT_INIT_MAX_LEN (1UL << 15)
160#define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1)
161
162
163#define EXT_FIRST_EXTENT(__hdr__) \
164 ((struct ext4_extent *) (((char *) (__hdr__)) + \
165 sizeof(struct ext4_extent_header)))
166#define EXT_FIRST_INDEX(__hdr__) \
167 ((struct ext4_extent_idx *) (((char *) (__hdr__)) + \
168 sizeof(struct ext4_extent_header)))
169#define EXT_HAS_FREE_INDEX(__path__) \
170 (le16_to_cpu((__path__)->p_hdr->eh_entries) \
171 < le16_to_cpu((__path__)->p_hdr->eh_max))
172#define EXT_LAST_EXTENT(__hdr__) \
173 (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1)
174#define EXT_LAST_INDEX(__hdr__) \
175 (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_entries) - 1)
176#define EXT_MAX_EXTENT(__hdr__) \
177 (EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)
178#define EXT_MAX_INDEX(__hdr__) \
179 (EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)
180
181static inline struct ext4_extent_header *ext_inode_hdr(struct inode *inode)
182{
183 return (struct ext4_extent_header *) EXT4_I(inode)->i_data;
184}
185
186static inline struct ext4_extent_header *ext_block_hdr(struct buffer_head *bh)
187{
188 return (struct ext4_extent_header *) bh->b_data;
189}
190
191static inline unsigned short ext_depth(struct inode *inode)
192{
193 return le16_to_cpu(ext_inode_hdr(inode)->eh_depth);
194}
195
196static inline void
197ext4_ext_invalidate_cache(struct inode *inode)
198{
199 EXT4_I(inode)->i_cached_extent.ec_len = 0;
200}
201
202static inline void ext4_ext_mark_uninitialized(struct ext4_extent *ext)
203{
204
205 BUG_ON((le16_to_cpu(ext->ee_len) & ~EXT_INIT_MAX_LEN) == 0);
206 ext->ee_len |= cpu_to_le16(EXT_INIT_MAX_LEN);
207}
208
209static inline int ext4_ext_is_uninitialized(struct ext4_extent *ext)
210{
211
212 return (le16_to_cpu(ext->ee_len) > EXT_INIT_MAX_LEN);
213}
214
215static inline int ext4_ext_get_actual_len(struct ext4_extent *ext)
216{
217 return (le16_to_cpu(ext->ee_len) <= EXT_INIT_MAX_LEN ?
218 le16_to_cpu(ext->ee_len) :
219 (le16_to_cpu(ext->ee_len) - EXT_INIT_MAX_LEN));
220}
221
222static inline void ext4_ext_mark_initialized(struct ext4_extent *ext)
223{
224 ext->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ext));
225}
226
227
228
229
230
231static inline ext4_fsblk_t ext4_ext_pblock(struct ext4_extent *ex)
232{
233 ext4_fsblk_t block;
234
235 block = le32_to_cpu(ex->ee_start_lo);
236 block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
237 return block;
238}
239
240
241
242
243
244static inline ext4_fsblk_t ext4_idx_pblock(struct ext4_extent_idx *ix)
245{
246 ext4_fsblk_t block;
247
248 block = le32_to_cpu(ix->ei_leaf_lo);
249 block |= ((ext4_fsblk_t) le16_to_cpu(ix->ei_leaf_hi) << 31) << 1;
250 return block;
251}
252
253
254
255
256
257
258static inline void ext4_ext_store_pblock(struct ext4_extent *ex,
259 ext4_fsblk_t pb)
260{
261 ex->ee_start_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
262 ex->ee_start_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) &
263 0xffff);
264}
265
266
267
268
269
270
271static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix,
272 ext4_fsblk_t pb)
273{
274 ix->ei_leaf_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
275 ix->ei_leaf_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) &
276 0xffff);
277}
278
279extern int ext4_ext_calc_metadata_amount(struct inode *inode,
280 ext4_lblk_t lblocks);
281extern int ext4_extent_tree_init(handle_t *, struct inode *);
282extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
283 int num,
284 struct ext4_ext_path *path);
285extern int ext4_can_extents_be_merged(struct inode *inode,
286 struct ext4_extent *ex1,
287 struct ext4_extent *ex2);
288extern int ext4_ext_insert_extent(handle_t *, struct inode *, struct ext4_ext_path *, struct ext4_extent *, int);
289extern struct ext4_ext_path *ext4_ext_find_extent(struct inode *, ext4_lblk_t,
290 struct ext4_ext_path *);
291extern void ext4_ext_drop_refs(struct ext4_ext_path *);
292extern int ext4_ext_check_inode(struct inode *inode);
293#endif
294
295