]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmroot.c
83507350b760cf7798829e7674aace390c54fdfe
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
18 static int bmroota_key_count(void *obj
, int startoff
);
19 static int bmroota_key_offset(void *obj
, int startoff
, int idx
);
20 static int bmroota_ptr_count(void *obj
, int startoff
);
21 static int bmroota_ptr_offset(void *obj
, int startoff
, int idx
);
22 static int bmrootd_key_count(void *obj
, int startoff
);
23 static int bmrootd_key_offset(void *obj
, int startoff
, int idx
);
24 static int bmrootd_ptr_count(void *obj
, int startoff
);
25 static int bmrootd_ptr_offset(void *obj
, int startoff
, int idx
);
27 static int rtrmaproot_rec_count(void *obj
, int startoff
);
28 static int rtrmaproot_rec_offset(void *obj
, int startoff
, int idx
);
29 static int rtrmaproot_key_count(void *obj
, int startoff
);
30 static int rtrmaproot_key_offset(void *obj
, int startoff
, int idx
);
31 static int rtrmaproot_ptr_count(void *obj
, int startoff
);
32 static int rtrmaproot_ptr_offset(void *obj
, int startoff
, int idx
);
34 static int rtrefcroot_rec_count(void *obj
, int startoff
);
35 static int rtrefcroot_rec_offset(void *obj
, int startoff
, int idx
);
36 static int rtrefcroot_key_count(void *obj
, int startoff
);
37 static int rtrefcroot_key_offset(void *obj
, int startoff
, int idx
);
38 static int rtrefcroot_ptr_count(void *obj
, int startoff
);
39 static int rtrefcroot_ptr_offset(void *obj
, int startoff
, int idx
);
41 #define OFF(f) bitize(offsetof(xfs_bmdr_block_t, bb_ ## f))
42 const field_t bmroota_flds
[] = {
43 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
44 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
45 { "keys", FLDT_BMROOTAKEY
, bmroota_key_offset
, bmroota_key_count
,
46 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
47 { "ptrs", FLDT_BMROOTAPTR
, bmroota_ptr_offset
, bmroota_ptr_count
,
48 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_BMAPBTA
},
51 const field_t bmrootd_flds
[] = {
52 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
53 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
54 { "keys", FLDT_BMROOTDKEY
, bmrootd_key_offset
, bmrootd_key_count
,
55 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
56 { "ptrs", FLDT_BMROOTDPTR
, bmrootd_ptr_offset
, bmrootd_ptr_count
,
57 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_BMAPBTD
},
61 #define KOFF(f) bitize(offsetof(xfs_bmdr_key_t, br_ ## f))
62 const field_t bmroota_key_flds
[] = {
63 { "startoff", FLDT_DFILOFFA
, OI(KOFF(startoff
)), C1
, 0, TYP_NONE
},
66 const field_t bmrootd_key_flds
[] = {
67 { "startoff", FLDT_DFILOFFD
, OI(KOFF(startoff
)), C1
, 0, TYP_NONE
},
71 /* realtime rmap btree root */
72 const field_t rtrmaproot_flds
[] = {
73 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
74 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
75 { "recs", FLDT_RTRMAPBTREC
, rtrmaproot_rec_offset
, rtrmaproot_rec_count
,
76 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
77 { "keys", FLDT_RTRMAPBTKEY
, rtrmaproot_key_offset
, rtrmaproot_key_count
,
78 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
79 { "ptrs", FLDT_RTRMAPBTPTR
, rtrmaproot_ptr_offset
, rtrmaproot_ptr_count
,
80 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_RTRMAPBT
},
84 /* realtime refcount btree root */
85 const field_t rtrefcroot_flds
[] = {
86 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
87 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
88 { "recs", FLDT_RTREFCBTREC
, rtrefcroot_rec_offset
, rtrefcroot_rec_count
,
89 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
90 { "keys", FLDT_RTREFCBTKEY
, rtrefcroot_key_offset
, rtrefcroot_key_count
,
91 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
92 { "ptrs", FLDT_RTREFCBTPTR
, rtrefcroot_ptr_offset
, rtrefcroot_ptr_count
,
93 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_RTREFCBT
},
103 xfs_bmdr_block_t
*block
;
105 struct xfs_dinode
*dip
= obj
;
108 ASSERT(bitoffs(startoff
) == 0);
109 ASSERT(obj
== iocur_top
->data
);
110 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
111 ASSERT(dip
->di_forkoff
!= 0 && (char *)block
== XFS_DFORK_APTR(dip
));
112 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
113 return be16_to_cpu(block
->bb_numrecs
);
122 xfs_bmdr_block_t
*block
;
124 struct xfs_dinode
*dip
= obj
;
128 ASSERT(bitoffs(startoff
) == 0);
129 ASSERT(obj
== iocur_top
->data
);
130 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
131 ASSERT(dip
->di_forkoff
!= 0 && (char *)block
== XFS_DFORK_APTR(dip
));
132 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
133 kp
= xfs_bmdr_key_addr(block
, idx
);
134 return bitize((int)((char *)kp
- (char *)block
));
142 xfs_bmdr_block_t
*block
;
144 struct xfs_dinode
*dip
= obj
;
147 ASSERT(bitoffs(startoff
) == 0);
148 ASSERT(obj
== iocur_top
->data
);
149 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
150 ASSERT(dip
->di_forkoff
!= 0 && (char *)block
== XFS_DFORK_APTR(dip
));
151 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
152 return be16_to_cpu(block
->bb_numrecs
);
161 xfs_bmdr_block_t
*block
;
162 struct xfs_dinode
*dip
;
165 ASSERT(bitoffs(startoff
) == 0);
166 ASSERT(obj
== iocur_top
->data
);
168 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
169 ASSERT(dip
->di_forkoff
!= 0 && (char *)block
== XFS_DFORK_APTR(dip
));
170 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
171 pp
= xfs_bmdr_ptr_addr(block
, idx
,
172 libxfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip
, mp
), 0));
173 return bitize((int)((char *)pp
- (char *)block
));
182 struct xfs_dinode
*dip
;
184 xfs_bmdr_block_t
*block
;
187 ASSERT(bitoffs(startoff
) == 0);
188 ASSERT(obj
== iocur_top
->data
);
192 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
193 ASSERT(dip
->di_forkoff
!= 0 && (char *)block
== XFS_DFORK_APTR(dip
));
195 return bitize((int)XFS_DFORK_ASIZE(dip
, mp
));
203 xfs_bmdr_block_t
*block
;
205 struct xfs_dinode
*dip
= obj
;
208 ASSERT(bitoffs(startoff
) == 0);
209 ASSERT(obj
== iocur_top
->data
);
210 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
211 ASSERT((char *)block
== XFS_DFORK_DPTR(dip
));
212 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
213 return be16_to_cpu(block
->bb_numrecs
);
222 xfs_bmdr_block_t
*block
;
225 ASSERT(bitoffs(startoff
) == 0);
226 ASSERT(obj
== iocur_top
->data
);
227 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
228 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
229 kp
= xfs_bmdr_key_addr(block
, idx
);
230 return bitize((int)((char *)kp
- (char *)block
));
238 xfs_bmdr_block_t
*block
;
240 struct xfs_dinode
*dip
= obj
;
243 ASSERT(bitoffs(startoff
) == 0);
244 ASSERT(obj
== iocur_top
->data
);
245 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
246 ASSERT((char *)block
== XFS_DFORK_DPTR(dip
));
247 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
248 return be16_to_cpu(block
->bb_numrecs
);
257 xfs_bmdr_block_t
*block
;
259 struct xfs_dinode
*dip
;
261 ASSERT(bitoffs(startoff
) == 0);
262 ASSERT(obj
== iocur_top
->data
);
264 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
265 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
266 pp
= xfs_bmdr_ptr_addr(block
, idx
,
267 libxfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip
, mp
), 0));
268 return bitize((int)((char *)pp
- (char *)block
));
277 struct xfs_dinode
*dip
;
279 ASSERT(bitoffs(startoff
) == 0);
280 ASSERT(obj
== iocur_top
->data
);
283 return bitize((int)XFS_DFORK_DSIZE(dip
, mp
));
286 /* realtime rmap root */
288 rtrmaproot_rec_count(
292 struct xfs_dinode
*dip
= obj
;
293 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
295 ASSERT(block
== obj
+ byteize(startoff
));
297 if (be16_to_cpu(block
->bb_level
) > 0)
299 return be16_to_cpu(block
->bb_numrecs
);
303 rtrmaproot_rec_offset(
308 struct xfs_dinode
*dip
= obj
;
309 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
310 struct xfs_rmap_rec
*kp
;
312 ASSERT(block
== obj
+ byteize(startoff
));
313 ASSERT(be16_to_cpu(block
->bb_level
) == 0);
315 kp
= xfs_rtrmap_droot_rec_addr(block
, idx
);
316 return bitize((int)((char *)kp
- (char *)block
));
320 rtrmaproot_key_count(
324 struct xfs_dinode
*dip
= obj
;
325 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
327 ASSERT(block
== obj
+ byteize(startoff
));
329 if (be16_to_cpu(block
->bb_level
) == 0)
331 return be16_to_cpu(block
->bb_numrecs
);
335 rtrmaproot_key_offset(
340 struct xfs_dinode
*dip
= obj
;
341 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
342 struct xfs_rmap_key
*kp
;
344 ASSERT(block
== obj
+ byteize(startoff
));
345 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
347 kp
= xfs_rtrmap_droot_key_addr(block
, idx
);
348 return bitize((int)((char *)kp
- (char *)block
));
352 rtrmaproot_ptr_count(
356 struct xfs_dinode
*dip
= obj
;
357 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
359 ASSERT(block
== obj
+ byteize(startoff
));
361 if (be16_to_cpu(block
->bb_level
) == 0)
363 return be16_to_cpu(block
->bb_numrecs
);
367 rtrmaproot_ptr_offset(
372 struct xfs_dinode
*dip
= obj
;
373 struct xfs_rtrmap_root
*block
= XFS_DFORK_DPTR(dip
);
374 xfs_rtrmap_ptr_t
*pp
;
377 ASSERT(block
== obj
+ byteize(startoff
));
378 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
380 dmxr
= libxfs_rtrmapbt_droot_maxrecs(XFS_DFORK_DSIZE(dip
, mp
), false);
381 pp
= xfs_rtrmap_droot_ptr_addr(block
, idx
, dmxr
);
382 return bitize((int)((char *)pp
- (char *)block
));
391 struct xfs_dinode
*dip
;
393 ASSERT(bitoffs(startoff
) == 0);
394 ASSERT(obj
== iocur_top
->data
);
397 return bitize((int)XFS_DFORK_DSIZE(dip
, mp
));
400 /* realtime refcount root */
402 rtrefcroot_rec_count(
406 struct xfs_dinode
*dip
= obj
;
407 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
409 ASSERT(block
== obj
+ byteize(startoff
));
411 if (be16_to_cpu(block
->bb_level
) > 0)
413 return be16_to_cpu(block
->bb_numrecs
);
417 rtrefcroot_rec_offset(
422 struct xfs_dinode
*dip
= obj
;
423 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
424 struct xfs_refcount_rec
*kp
;
426 ASSERT(block
== obj
+ byteize(startoff
));
427 ASSERT(be16_to_cpu(block
->bb_level
) == 0);
429 kp
= xfs_rtrefcount_droot_rec_addr(block
, idx
);
430 return bitize((int)((char *)kp
- (char *)block
));
434 rtrefcroot_key_count(
438 struct xfs_dinode
*dip
= obj
;
439 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
441 ASSERT(block
== obj
+ byteize(startoff
));
443 if (be16_to_cpu(block
->bb_level
) == 0)
445 return be16_to_cpu(block
->bb_numrecs
);
449 rtrefcroot_key_offset(
454 struct xfs_dinode
*dip
= obj
;
455 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
456 struct xfs_refcount_key
*kp
;
458 ASSERT(block
== obj
+ byteize(startoff
));
459 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
461 kp
= xfs_rtrefcount_droot_key_addr(block
, idx
);
462 return bitize((int)((char *)kp
- (char *)block
));
466 rtrefcroot_ptr_count(
470 struct xfs_dinode
*dip
= obj
;
471 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
473 ASSERT(block
== obj
+ byteize(startoff
));
475 if (be16_to_cpu(block
->bb_level
) == 0)
477 return be16_to_cpu(block
->bb_numrecs
);
481 rtrefcroot_ptr_offset(
486 struct xfs_dinode
*dip
= obj
;
487 struct xfs_rtrefcount_root
*block
= XFS_DFORK_DPTR(dip
);
488 xfs_rtrefcount_ptr_t
*pp
;
491 ASSERT(block
== obj
+ byteize(startoff
));
492 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
494 dmxr
= libxfs_rtrefcountbt_droot_maxrecs(XFS_DFORK_DSIZE(dip
, mp
),
496 pp
= xfs_rtrefcount_droot_ptr_addr(block
, idx
, dmxr
);
497 return bitize((int)((char *)pp
- (char *)block
));
506 struct xfs_dinode
*dip
;
508 ASSERT(bitoffs(startoff
) == 0);
509 ASSERT(obj
== iocur_top
->data
);
512 return bitize((int)XFS_DFORK_DSIZE(dip
, mp
));