]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
7b718769 NS |
3 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
1da177e4 LT |
5 | */ |
6 | #ifndef __XFS_BTREE_H__ | |
7 | #define __XFS_BTREE_H__ | |
8 | ||
9 | struct xfs_buf; | |
1da177e4 LT |
10 | struct xfs_inode; |
11 | struct xfs_mount; | |
12 | struct xfs_trans; | |
13 | ||
a8272ce0 DC |
14 | extern kmem_zone_t *xfs_btree_cur_zone; |
15 | ||
de227dd9 CH |
16 | /* |
17 | * Generic key, ptr and record wrapper structures. | |
18 | * | |
19 | * These are disk format structures, and are converted where necessary | |
20 | * by the btree specific code that needs to interpret them. | |
21 | */ | |
22 | union xfs_btree_ptr { | |
23 | __be32 s; /* short form ptr */ | |
24 | __be64 l; /* long form ptr */ | |
25 | }; | |
26 | ||
2c813ad6 | 27 | /* |
a1d46cff DW |
28 | * The in-core btree key. Overlapping btrees actually store two keys |
29 | * per pointer, so we reserve enough memory to hold both. The __*bigkey | |
30 | * items should never be accessed directly. | |
2c813ad6 | 31 | */ |
a1d46cff | 32 | union xfs_btree_key { |
2c813ad6 DW |
33 | struct xfs_bmbt_key bmbt; |
34 | xfs_bmdr_key_t bmbr; /* bmbt root block */ | |
35 | xfs_alloc_key_t alloc; | |
36 | struct xfs_inobt_key inobt; | |
a1d46cff DW |
37 | struct xfs_rmap_key rmap; |
38 | struct xfs_rmap_key __rmap_bigkey[2]; | |
1946b91c | 39 | struct xfs_refcount_key refc; |
2c813ad6 DW |
40 | }; |
41 | ||
de227dd9 | 42 | union xfs_btree_rec { |
035e00ac DW |
43 | struct xfs_bmbt_rec bmbt; |
44 | xfs_bmdr_rec_t bmbr; /* bmbt root block */ | |
45 | struct xfs_alloc_rec alloc; | |
46 | struct xfs_inobt_rec inobt; | |
47 | struct xfs_rmap_rec rmap; | |
1946b91c | 48 | struct xfs_refcount_rec refc; |
de227dd9 CH |
49 | }; |
50 | ||
a4fbe6ab DC |
51 | /* |
52 | * This nonsense is to make -wlint happy. | |
53 | */ | |
54 | #define XFS_LOOKUP_EQ ((xfs_lookup_t)XFS_LOOKUP_EQi) | |
55 | #define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi) | |
56 | #define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi) | |
57 | ||
58 | #define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi) | |
59 | #define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi) | |
60 | #define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi) | |
61 | #define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi) | |
aafc3c24 | 62 | #define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi) |
b8704944 | 63 | #define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi) |
46eeb521 | 64 | #define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi) |
a4fbe6ab | 65 | |
c8ce540d | 66 | uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum); |
af7d20fd | 67 | |
1da177e4 LT |
68 | /* |
69 | * For logging record fields. | |
70 | */ | |
21b5c978 DC |
71 | #define XFS_BB_MAGIC (1 << 0) |
72 | #define XFS_BB_LEVEL (1 << 1) | |
73 | #define XFS_BB_NUMRECS (1 << 2) | |
74 | #define XFS_BB_LEFTSIB (1 << 3) | |
75 | #define XFS_BB_RIGHTSIB (1 << 4) | |
76 | #define XFS_BB_BLKNO (1 << 5) | |
77 | #define XFS_BB_LSN (1 << 6) | |
78 | #define XFS_BB_UUID (1 << 7) | |
79 | #define XFS_BB_OWNER (1 << 8) | |
1da177e4 LT |
80 | #define XFS_BB_NUM_BITS 5 |
81 | #define XFS_BB_ALL_BITS ((1 << XFS_BB_NUM_BITS) - 1) | |
21b5c978 | 82 | #define XFS_BB_NUM_BITS_CRC 9 |
ee1a47ab | 83 | #define XFS_BB_ALL_BITS_CRC ((1 << XFS_BB_NUM_BITS_CRC) - 1) |
1da177e4 | 84 | |
854929f0 DC |
85 | /* |
86 | * Generic stats interface | |
87 | */ | |
ff6d6af2 | 88 | #define XFS_BTREE_STATS_INC(cur, stat) \ |
11ef38af DC |
89 | XFS_STATS_INC_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat) |
90 | #define XFS_BTREE_STATS_ADD(cur, stat, val) \ | |
91 | XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val) | |
1da177e4 | 92 | |
df3954ff | 93 | #define XFS_BTREE_MAXLEVELS 9 /* max of all btrees */ |
1da177e4 | 94 | |
561f7d17 | 95 | struct xfs_btree_ops { |
65f1eaea CH |
96 | /* size of the key and record structures */ |
97 | size_t key_len; | |
98 | size_t rec_len; | |
99 | ||
561f7d17 CH |
100 | /* cursor operations */ |
101 | struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *); | |
4b22a571 CH |
102 | void (*update_cursor)(struct xfs_btree_cur *src, |
103 | struct xfs_btree_cur *dst); | |
8c4ed633 | 104 | |
344207ce CH |
105 | /* update btree root pointer */ |
106 | void (*set_root)(struct xfs_btree_cur *cur, | |
c0e59e1a | 107 | union xfs_btree_ptr *nptr, int level_change); |
344207ce | 108 | |
f5eb8e7c CH |
109 | /* block allocation / freeing */ |
110 | int (*alloc_block)(struct xfs_btree_cur *cur, | |
111 | union xfs_btree_ptr *start_bno, | |
112 | union xfs_btree_ptr *new_bno, | |
6f8950cd | 113 | int *stat); |
d4b3a4b7 | 114 | int (*free_block)(struct xfs_btree_cur *cur, struct xfs_buf *bp); |
f5eb8e7c | 115 | |
278d0ca1 CH |
116 | /* update last record information */ |
117 | void (*update_lastrec)(struct xfs_btree_cur *cur, | |
118 | struct xfs_btree_block *block, | |
119 | union xfs_btree_rec *rec, | |
120 | int ptr, int reason); | |
121 | ||
ce5e42db | 122 | /* records in block/level */ |
91cca5df | 123 | int (*get_minrecs)(struct xfs_btree_cur *cur, int level); |
ce5e42db CH |
124 | int (*get_maxrecs)(struct xfs_btree_cur *cur, int level); |
125 | ||
4b22a571 CH |
126 | /* records on disk. Matter for the root in inode case. */ |
127 | int (*get_dmaxrecs)(struct xfs_btree_cur *cur, int level); | |
128 | ||
fe033cc8 CH |
129 | /* init values of btree structures */ |
130 | void (*init_key_from_rec)(union xfs_btree_key *key, | |
131 | union xfs_btree_rec *rec); | |
4b22a571 CH |
132 | void (*init_rec_from_cur)(struct xfs_btree_cur *cur, |
133 | union xfs_btree_rec *rec); | |
fe033cc8 CH |
134 | void (*init_ptr_from_cur)(struct xfs_btree_cur *cur, |
135 | union xfs_btree_ptr *ptr); | |
2c813ad6 DW |
136 | void (*init_high_key_from_rec)(union xfs_btree_key *key, |
137 | union xfs_btree_rec *rec); | |
fe033cc8 CH |
138 | |
139 | /* difference between key value and cursor value */ | |
c8ce540d | 140 | int64_t (*key_diff)(struct xfs_btree_cur *cur, |
fe033cc8 CH |
141 | union xfs_btree_key *key); |
142 | ||
2c813ad6 DW |
143 | /* |
144 | * Difference between key2 and key1 -- positive if key1 > key2, | |
145 | * negative if key1 < key2, and zero if equal. | |
146 | */ | |
c8ce540d | 147 | int64_t (*diff_two_keys)(struct xfs_btree_cur *cur, |
2c813ad6 DW |
148 | union xfs_btree_key *key1, |
149 | union xfs_btree_key *key2); | |
150 | ||
1813dd64 | 151 | const struct xfs_buf_ops *buf_ops; |
b0f539de | 152 | |
4a26e66e CH |
153 | /* check that k1 is lower than k2 */ |
154 | int (*keys_inorder)(struct xfs_btree_cur *cur, | |
155 | union xfs_btree_key *k1, | |
156 | union xfs_btree_key *k2); | |
157 | ||
158 | /* check that r1 is lower than r2 */ | |
159 | int (*recs_inorder)(struct xfs_btree_cur *cur, | |
160 | union xfs_btree_rec *r1, | |
161 | union xfs_btree_rec *r2); | |
561f7d17 CH |
162 | }; |
163 | ||
278d0ca1 CH |
164 | /* |
165 | * Reasons for the update_lastrec method to be called. | |
166 | */ | |
167 | #define LASTREC_UPDATE 0 | |
4b22a571 | 168 | #define LASTREC_INSREC 1 |
91cca5df | 169 | #define LASTREC_DELREC 2 |
278d0ca1 CH |
170 | |
171 | ||
105f7d83 DW |
172 | union xfs_btree_irec { |
173 | struct xfs_alloc_rec_incore a; | |
174 | struct xfs_bmbt_irec b; | |
175 | struct xfs_inobt_rec_incore i; | |
4b8ed677 | 176 | struct xfs_rmap_irec r; |
1946b91c DW |
177 | struct xfs_refcount_irec rc; |
178 | }; | |
179 | ||
180 | /* Per-AG btree private information. */ | |
181 | union xfs_btree_cur_private { | |
182 | struct { | |
183 | unsigned long nr_ops; /* # record updates */ | |
184 | int shape_changes; /* # of extent splits */ | |
185 | } refc; | |
105f7d83 DW |
186 | }; |
187 | ||
1da177e4 LT |
188 | /* |
189 | * Btree cursor structure. | |
190 | * This collects all information needed by the btree code in one place. | |
191 | */ | |
192 | typedef struct xfs_btree_cur | |
193 | { | |
194 | struct xfs_trans *bc_tp; /* transaction we're in, if any */ | |
195 | struct xfs_mount *bc_mp; /* file system mount struct */ | |
561f7d17 | 196 | const struct xfs_btree_ops *bc_ops; |
8186e517 | 197 | uint bc_flags; /* btree features - below */ |
105f7d83 | 198 | union xfs_btree_irec bc_rec; /* current insert/search record value */ |
1da177e4 LT |
199 | struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS]; /* buf ptr per level */ |
200 | int bc_ptrs[XFS_BTREE_MAXLEVELS]; /* key/record # */ | |
c8ce540d | 201 | uint8_t bc_ra[XFS_BTREE_MAXLEVELS]; /* readahead bits */ |
1da177e4 LT |
202 | #define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */ |
203 | #define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */ | |
c8ce540d DW |
204 | uint8_t bc_nlevels; /* number of levels in the tree */ |
205 | uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */ | |
1da177e4 | 206 | xfs_btnum_t bc_btnum; /* identifies which btree type */ |
11ef38af | 207 | int bc_statoff; /* offset of btre stats array */ |
1da177e4 | 208 | union { |
169d6227 CH |
209 | struct { /* needed for BNO, CNT, INO */ |
210 | struct xfs_buf *agbp; /* agf/agi buffer pointer */ | |
1da177e4 | 211 | xfs_agnumber_t agno; /* ag number */ |
1946b91c | 212 | union xfs_btree_cur_private priv; |
1da177e4 LT |
213 | } a; |
214 | struct { /* needed for BMAP */ | |
215 | struct xfs_inode *ip; /* pointer to our inode */ | |
1da177e4 LT |
216 | int allocated; /* count of alloced */ |
217 | short forksize; /* fork's inode space */ | |
218 | char whichfork; /* data or attr fork */ | |
219 | char flags; /* flags */ | |
99c794c6 BF |
220 | #define XFS_BTCUR_BPRV_WASDEL (1<<0) /* was delayed */ |
221 | #define XFS_BTCUR_BPRV_INVALID_OWNER (1<<1) /* for ext swap */ | |
1da177e4 | 222 | } b; |
1da177e4 LT |
223 | } bc_private; /* per-btree type data */ |
224 | } xfs_btree_cur_t; | |
225 | ||
8186e517 | 226 | /* cursor flags */ |
e99ab90d | 227 | #define XFS_BTREE_LONG_PTRS (1<<0) /* pointers are 64bits long */ |
8186e517 | 228 | #define XFS_BTREE_ROOT_IN_INODE (1<<1) /* root may be variable size */ |
278d0ca1 | 229 | #define XFS_BTREE_LASTREC_UPDATE (1<<2) /* track last rec externally */ |
ee1a47ab | 230 | #define XFS_BTREE_CRC_BLOCKS (1<<3) /* uses extended btree blocks */ |
2c813ad6 | 231 | #define XFS_BTREE_OVERLAPPING (1<<4) /* overlapping intervals */ |
8186e517 CH |
232 | |
233 | ||
1da177e4 LT |
234 | #define XFS_BTREE_NOERROR 0 |
235 | #define XFS_BTREE_ERROR 1 | |
236 | ||
237 | /* | |
238 | * Convert from buffer to btree block header. | |
239 | */ | |
62926044 | 240 | #define XFS_BUF_TO_BLOCK(bp) ((struct xfs_btree_block *)((bp)->b_addr)) |
1da177e4 | 241 | |
52c732ee DW |
242 | /* |
243 | * Internal long and short btree block checks. They return NULL if the | |
244 | * block is ok or the address of the failed check otherwise. | |
245 | */ | |
246 | xfs_failaddr_t __xfs_btree_check_lblock(struct xfs_btree_cur *cur, | |
247 | struct xfs_btree_block *block, int level, struct xfs_buf *bp); | |
248 | xfs_failaddr_t __xfs_btree_check_sblock(struct xfs_btree_cur *cur, | |
249 | struct xfs_btree_block *block, int level, struct xfs_buf *bp); | |
1da177e4 | 250 | |
1da177e4 | 251 | /* |
a23f6ef8 | 252 | * Check that block header is ok. |
1da177e4 | 253 | */ |
a23f6ef8 CH |
254 | int |
255 | xfs_btree_check_block( | |
256 | struct xfs_btree_cur *cur, /* btree cursor */ | |
257 | struct xfs_btree_block *block, /* generic btree block pointer */ | |
1da177e4 LT |
258 | int level, /* level of the btree block */ |
259 | struct xfs_buf *bp); /* buffer containing block, if any */ | |
260 | ||
261 | /* | |
a23f6ef8 | 262 | * Check that (long) pointer is ok. |
1da177e4 | 263 | */ |
f135761a | 264 | bool /* error (0 or EFSCORRUPTED) */ |
1da177e4 | 265 | xfs_btree_check_lptr( |
a23f6ef8 | 266 | struct xfs_btree_cur *cur, /* btree cursor */ |
f135761a DW |
267 | xfs_fsblock_t fsbno, /* btree block disk address */ |
268 | int level); /* btree block level */ | |
269 | ||
270 | /* | |
271 | * Check that (short) pointer is ok. | |
272 | */ | |
273 | bool /* error (0 or EFSCORRUPTED) */ | |
274 | xfs_btree_check_sptr( | |
275 | struct xfs_btree_cur *cur, /* btree cursor */ | |
276 | xfs_agblock_t agbno, /* btree block disk address */ | |
1da177e4 LT |
277 | int level); /* btree block level */ |
278 | ||
1da177e4 LT |
279 | /* |
280 | * Delete the btree cursor. | |
281 | */ | |
282 | void | |
283 | xfs_btree_del_cursor( | |
284 | xfs_btree_cur_t *cur, /* btree cursor */ | |
285 | int error); /* del because of error */ | |
286 | ||
287 | /* | |
288 | * Duplicate the btree cursor. | |
289 | * Allocate a new one, copy the record, re-get the buffers. | |
290 | */ | |
291 | int /* error */ | |
292 | xfs_btree_dup_cursor( | |
293 | xfs_btree_cur_t *cur, /* input cursor */ | |
294 | xfs_btree_cur_t **ncur);/* output cursor */ | |
295 | ||
1da177e4 LT |
296 | /* |
297 | * Get a buffer for the block, return it with no data read. | |
298 | * Long-form addressing. | |
299 | */ | |
300 | struct xfs_buf * /* buffer for fsbno */ | |
301 | xfs_btree_get_bufl( | |
302 | struct xfs_mount *mp, /* file system mount point */ | |
303 | struct xfs_trans *tp, /* transaction pointer */ | |
304 | xfs_fsblock_t fsbno, /* file system block number */ | |
305 | uint lock); /* lock flags for get_buf */ | |
306 | ||
307 | /* | |
308 | * Get a buffer for the block, return it with no data read. | |
309 | * Short-form addressing. | |
310 | */ | |
311 | struct xfs_buf * /* buffer for agno/agbno */ | |
312 | xfs_btree_get_bufs( | |
313 | struct xfs_mount *mp, /* file system mount point */ | |
314 | struct xfs_trans *tp, /* transaction pointer */ | |
315 | xfs_agnumber_t agno, /* allocation group number */ | |
316 | xfs_agblock_t agbno, /* allocation group block number */ | |
317 | uint lock); /* lock flags for get_buf */ | |
318 | ||
1da177e4 LT |
319 | /* |
320 | * Check for the cursor referring to the last block at the given level. | |
321 | */ | |
322 | int /* 1=is last block, 0=not last block */ | |
323 | xfs_btree_islastblock( | |
324 | xfs_btree_cur_t *cur, /* btree cursor */ | |
325 | int level); /* level to check */ | |
326 | ||
1da177e4 LT |
327 | /* |
328 | * Compute first and last byte offsets for the fields given. | |
329 | * Interprets the offsets table, which contains struct field offsets. | |
330 | */ | |
331 | void | |
332 | xfs_btree_offsets( | |
c8ce540d | 333 | int64_t fields, /* bitmask of fields */ |
1da177e4 LT |
334 | const short *offsets,/* table of field offsets */ |
335 | int nbits, /* number of bits to inspect */ | |
336 | int *first, /* output: first byte offset */ | |
337 | int *last); /* output: last byte offset */ | |
338 | ||
339 | /* | |
340 | * Get a buffer for the block, return it read in. | |
341 | * Long-form addressing. | |
342 | */ | |
343 | int /* error */ | |
344 | xfs_btree_read_bufl( | |
345 | struct xfs_mount *mp, /* file system mount point */ | |
346 | struct xfs_trans *tp, /* transaction pointer */ | |
347 | xfs_fsblock_t fsbno, /* file system block number */ | |
348 | uint lock, /* lock flags for read_buf */ | |
349 | struct xfs_buf **bpp, /* buffer for fsbno */ | |
3d3e6f64 | 350 | int refval, /* ref count value for buffer */ |
1813dd64 | 351 | const struct xfs_buf_ops *ops); |
1da177e4 | 352 | |
1da177e4 LT |
353 | /* |
354 | * Read-ahead the block, don't wait for it, don't return a buffer. | |
355 | * Long-form addressing. | |
356 | */ | |
357 | void /* error */ | |
358 | xfs_btree_reada_bufl( | |
359 | struct xfs_mount *mp, /* file system mount point */ | |
360 | xfs_fsblock_t fsbno, /* file system block number */ | |
3d3e6f64 | 361 | xfs_extlen_t count, /* count of filesystem blocks */ |
1813dd64 | 362 | const struct xfs_buf_ops *ops); |
1da177e4 LT |
363 | |
364 | /* | |
365 | * Read-ahead the block, don't wait for it, don't return a buffer. | |
366 | * Short-form addressing. | |
367 | */ | |
368 | void /* error */ | |
369 | xfs_btree_reada_bufs( | |
370 | struct xfs_mount *mp, /* file system mount point */ | |
371 | xfs_agnumber_t agno, /* allocation group number */ | |
372 | xfs_agblock_t agbno, /* allocation group block number */ | |
3d3e6f64 | 373 | xfs_extlen_t count, /* count of filesystem blocks */ |
1813dd64 | 374 | const struct xfs_buf_ops *ops); |
1da177e4 | 375 | |
b64f3a39 DC |
376 | /* |
377 | * Initialise a new btree block header | |
378 | */ | |
379 | void | |
380 | xfs_btree_init_block( | |
381 | struct xfs_mount *mp, | |
382 | struct xfs_buf *bp, | |
b6f41e44 | 383 | xfs_btnum_t btnum, |
b64f3a39 DC |
384 | __u16 level, |
385 | __u16 numrecs, | |
ee1a47ab | 386 | __u64 owner, |
b64f3a39 | 387 | unsigned int flags); |
65f1eaea | 388 | |
ee1a47ab CH |
389 | void |
390 | xfs_btree_init_block_int( | |
391 | struct xfs_mount *mp, | |
392 | struct xfs_btree_block *buf, | |
393 | xfs_daddr_t blkno, | |
b6f41e44 | 394 | xfs_btnum_t btnum, |
ee1a47ab CH |
395 | __u16 level, |
396 | __u16 numrecs, | |
397 | __u64 owner, | |
398 | unsigned int flags); | |
399 | ||
637aa50f CH |
400 | /* |
401 | * Common btree core entry points. | |
402 | */ | |
403 | int xfs_btree_increment(struct xfs_btree_cur *, int, int *); | |
8df4da4a | 404 | int xfs_btree_decrement(struct xfs_btree_cur *, int, int *); |
fe033cc8 | 405 | int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *); |
278d0ca1 | 406 | int xfs_btree_update(struct xfs_btree_cur *, union xfs_btree_rec *); |
ea77b0a6 | 407 | int xfs_btree_new_iroot(struct xfs_btree_cur *, int *, int *); |
4b22a571 | 408 | int xfs_btree_insert(struct xfs_btree_cur *, int *); |
91cca5df | 409 | int xfs_btree_delete(struct xfs_btree_cur *, int *); |
8cc938fe | 410 | int xfs_btree_get_rec(struct xfs_btree_cur *, union xfs_btree_rec **, int *); |
c8ce540d | 411 | int xfs_btree_change_owner(struct xfs_btree_cur *cur, uint64_t new_owner, |
638f4416 | 412 | struct list_head *buffer_list); |
637aa50f | 413 | |
ee1a47ab CH |
414 | /* |
415 | * btree block CRC helpers | |
416 | */ | |
417 | void xfs_btree_lblock_calc_crc(struct xfs_buf *); | |
418 | bool xfs_btree_lblock_verify_crc(struct xfs_buf *); | |
419 | void xfs_btree_sblock_calc_crc(struct xfs_buf *); | |
420 | bool xfs_btree_sblock_verify_crc(struct xfs_buf *); | |
421 | ||
fd6bcc5b CH |
422 | /* |
423 | * Internal btree helpers also used by xfs_bmap.c. | |
424 | */ | |
425 | void xfs_btree_log_block(struct xfs_btree_cur *, struct xfs_buf *, int); | |
426 | void xfs_btree_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int, int); | |
427 | ||
65f1eaea CH |
428 | /* |
429 | * Helpers. | |
430 | */ | |
637aa50f CH |
431 | static inline int xfs_btree_get_numrecs(struct xfs_btree_block *block) |
432 | { | |
433 | return be16_to_cpu(block->bb_numrecs); | |
434 | } | |
435 | ||
9eaead51 | 436 | static inline void xfs_btree_set_numrecs(struct xfs_btree_block *block, |
c8ce540d | 437 | uint16_t numrecs) |
9eaead51 CH |
438 | { |
439 | block->bb_numrecs = cpu_to_be16(numrecs); | |
440 | } | |
441 | ||
65f1eaea CH |
442 | static inline int xfs_btree_get_level(struct xfs_btree_block *block) |
443 | { | |
444 | return be16_to_cpu(block->bb_level); | |
445 | } | |
446 | ||
1da177e4 LT |
447 | |
448 | /* | |
449 | * Min and max functions for extlen, agblock, fileoff, and filblks types. | |
450 | */ | |
54aa8e26 DC |
451 | #define XFS_EXTLEN_MIN(a,b) min_t(xfs_extlen_t, (a), (b)) |
452 | #define XFS_EXTLEN_MAX(a,b) max_t(xfs_extlen_t, (a), (b)) | |
453 | #define XFS_AGBLOCK_MIN(a,b) min_t(xfs_agblock_t, (a), (b)) | |
454 | #define XFS_AGBLOCK_MAX(a,b) max_t(xfs_agblock_t, (a), (b)) | |
455 | #define XFS_FILEOFF_MIN(a,b) min_t(xfs_fileoff_t, (a), (b)) | |
456 | #define XFS_FILEOFF_MAX(a,b) max_t(xfs_fileoff_t, (a), (b)) | |
457 | #define XFS_FILBLKS_MIN(a,b) min_t(xfs_filblks_t, (a), (b)) | |
458 | #define XFS_FILBLKS_MAX(a,b) max_t(xfs_filblks_t, (a), (b)) | |
a844f451 | 459 | |
a6a781a5 DW |
460 | xfs_failaddr_t xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp); |
461 | xfs_failaddr_t xfs_btree_sblock_verify(struct xfs_buf *bp, | |
462 | unsigned int max_recs); | |
463 | xfs_failaddr_t xfs_btree_lblock_v5hdr_verify(struct xfs_buf *bp, | |
464 | uint64_t owner); | |
465 | xfs_failaddr_t xfs_btree_lblock_verify(struct xfs_buf *bp, | |
466 | unsigned int max_recs); | |
8368a601 | 467 | |
a1f69417 | 468 | uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len); |
14861c47 | 469 | unsigned long long xfs_btree_calc_size(uint *limits, unsigned long long len); |
c5ab131b | 470 | |
105f7d83 DW |
471 | /* return codes */ |
472 | #define XFS_BTREE_QUERY_RANGE_CONTINUE 0 /* keep iterating */ | |
473 | #define XFS_BTREE_QUERY_RANGE_ABORT 1 /* stop iterating */ | |
474 | typedef int (*xfs_btree_query_range_fn)(struct xfs_btree_cur *cur, | |
475 | union xfs_btree_rec *rec, void *priv); | |
476 | ||
477 | int xfs_btree_query_range(struct xfs_btree_cur *cur, | |
478 | union xfs_btree_irec *low_rec, union xfs_btree_irec *high_rec, | |
479 | xfs_btree_query_range_fn fn, void *priv); | |
e9a2599a DW |
480 | int xfs_btree_query_all(struct xfs_btree_cur *cur, xfs_btree_query_range_fn fn, |
481 | void *priv); | |
105f7d83 | 482 | |
28a89567 DW |
483 | typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level, |
484 | void *data); | |
485 | int xfs_btree_visit_blocks(struct xfs_btree_cur *cur, | |
486 | xfs_btree_visit_blocks_fn fn, void *data); | |
487 | ||
c611cc03 DW |
488 | int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks); |
489 | ||
26788097 DW |
490 | union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n, |
491 | struct xfs_btree_block *block); | |
492 | union xfs_btree_key *xfs_btree_key_addr(struct xfs_btree_cur *cur, int n, | |
493 | struct xfs_btree_block *block); | |
494 | union xfs_btree_key *xfs_btree_high_key_addr(struct xfs_btree_cur *cur, int n, | |
495 | struct xfs_btree_block *block); | |
496 | union xfs_btree_ptr *xfs_btree_ptr_addr(struct xfs_btree_cur *cur, int n, | |
497 | struct xfs_btree_block *block); | |
498 | int xfs_btree_lookup_get_block(struct xfs_btree_cur *cur, int level, | |
499 | union xfs_btree_ptr *pp, struct xfs_btree_block **blkp); | |
500 | struct xfs_btree_block *xfs_btree_get_block(struct xfs_btree_cur *cur, | |
501 | int level, struct xfs_buf **bpp); | |
cc3e0948 DW |
502 | bool xfs_btree_ptr_is_null(struct xfs_btree_cur *cur, union xfs_btree_ptr *ptr); |
503 | int64_t xfs_btree_diff_two_ptrs(struct xfs_btree_cur *cur, | |
504 | const union xfs_btree_ptr *a, | |
505 | const union xfs_btree_ptr *b); | |
506 | void xfs_btree_get_sibling(struct xfs_btree_cur *cur, | |
507 | struct xfs_btree_block *block, | |
508 | union xfs_btree_ptr *ptr, int lr); | |
2fdbec5c DW |
509 | void xfs_btree_get_keys(struct xfs_btree_cur *cur, |
510 | struct xfs_btree_block *block, union xfs_btree_key *key); | |
511 | union xfs_btree_key *xfs_btree_high_key_from_key(struct xfs_btree_cur *cur, | |
512 | union xfs_btree_key *key); | |
ce1d802e DW |
513 | int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low, |
514 | union xfs_btree_irec *high, bool *exists); | |
08daa3cc | 515 | bool xfs_btree_has_more_records(struct xfs_btree_cur *cur); |
26788097 | 516 | |
1da177e4 | 517 | #endif /* __XFS_BTREE_H__ */ |