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