]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmroot.c
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 static int bmroota_key_count(void *obj
, int startoff
);
31 static int bmroota_key_offset(void *obj
, int startoff
, int idx
);
32 static int bmroota_ptr_count(void *obj
, int startoff
);
33 static int bmroota_ptr_offset(void *obj
, int startoff
, int idx
);
34 static int bmrootd_key_count(void *obj
, int startoff
);
35 static int bmrootd_key_offset(void *obj
, int startoff
, int idx
);
36 static int bmrootd_ptr_count(void *obj
, int startoff
);
37 static int bmrootd_ptr_offset(void *obj
, int startoff
, int idx
);
39 #define OFF(f) bitize(offsetof(xfs_bmdr_block_t, bb_ ## f))
40 const field_t bmroota_flds
[] = {
41 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
42 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
43 { "keys", FLDT_BMROOTAKEY
, bmroota_key_offset
, bmroota_key_count
,
44 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
45 { "ptrs", FLDT_BMROOTAPTR
, bmroota_ptr_offset
, bmroota_ptr_count
,
46 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_BMAPBTA
},
49 const field_t bmrootd_flds
[] = {
50 { "level", FLDT_UINT16D
, OI(OFF(level
)), C1
, 0, TYP_NONE
},
51 { "numrecs", FLDT_UINT16D
, OI(OFF(numrecs
)), C1
, 0, TYP_NONE
},
52 { "keys", FLDT_BMROOTDKEY
, bmrootd_key_offset
, bmrootd_key_count
,
53 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_NONE
},
54 { "ptrs", FLDT_BMROOTDPTR
, bmrootd_ptr_offset
, bmrootd_ptr_count
,
55 FLD_ARRAY
|FLD_ABASE1
|FLD_COUNT
|FLD_OFFSET
, TYP_BMAPBTD
},
59 #define KOFF(f) bitize(offsetof(xfs_bmdr_key_t, br_ ## f))
60 const field_t bmroota_key_flds
[] = {
61 { "startoff", FLDT_DFILOFFA
, OI(KOFF(startoff
)), C1
, 0, TYP_NONE
},
64 const field_t bmrootd_key_flds
[] = {
65 { "startoff", FLDT_DFILOFFD
, OI(KOFF(startoff
)), C1
, 0, TYP_NONE
},
74 xfs_bmdr_block_t
*block
;
76 xfs_dinode_t
*dip
= obj
;
79 ASSERT(bitoffs(startoff
) == 0);
80 ASSERT(obj
== iocur_top
->data
);
81 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
82 ASSERT(XFS_DFORK_Q(dip
) && (char *)block
== XFS_DFORK_APTR(dip
));
83 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
84 return be16_to_cpu(block
->bb_numrecs
);
93 xfs_bmdr_block_t
*block
;
95 xfs_dinode_t
*dip
= obj
;
99 ASSERT(bitoffs(startoff
) == 0);
100 ASSERT(obj
== iocur_top
->data
);
101 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
102 ASSERT(XFS_DFORK_Q(dip
) && (char *)block
== XFS_DFORK_APTR(dip
));
103 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
104 kp
= XFS_BMDR_KEY_ADDR(block
, idx
);
105 return bitize((int)((char *)kp
- (char *)block
));
113 xfs_bmdr_block_t
*block
;
115 xfs_dinode_t
*dip
= obj
;
118 ASSERT(bitoffs(startoff
) == 0);
119 ASSERT(obj
== iocur_top
->data
);
120 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
121 ASSERT(XFS_DFORK_Q(dip
) && (char *)block
== XFS_DFORK_APTR(dip
));
122 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
123 return be16_to_cpu(block
->bb_numrecs
);
132 xfs_bmdr_block_t
*block
;
136 ASSERT(bitoffs(startoff
) == 0);
137 ASSERT(obj
== iocur_top
->data
);
139 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
140 ASSERT(XFS_DFORK_Q(dip
) && (char *)block
== XFS_DFORK_APTR(dip
));
141 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
142 pp
= XFS_BMDR_PTR_ADDR(block
, idx
,
143 libxfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip
, mp
), 0));
144 return bitize((int)((char *)pp
- (char *)block
));
155 xfs_bmdr_block_t
*block
;
158 ASSERT(bitoffs(startoff
) == 0);
159 ASSERT(obj
== iocur_top
->data
);
163 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
164 ASSERT(XFS_DFORK_Q(dip
) && (char *)block
== XFS_DFORK_APTR(dip
));
166 return bitize((int)XFS_DFORK_ASIZE(dip
, mp
));
174 xfs_bmdr_block_t
*block
;
176 xfs_dinode_t
*dip
= obj
;
179 ASSERT(bitoffs(startoff
) == 0);
180 ASSERT(obj
== iocur_top
->data
);
181 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
182 ASSERT((char *)block
== XFS_DFORK_DPTR(dip
));
183 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
184 return be16_to_cpu(block
->bb_numrecs
);
193 xfs_bmdr_block_t
*block
;
196 ASSERT(bitoffs(startoff
) == 0);
197 ASSERT(obj
== iocur_top
->data
);
198 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
199 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
200 kp
= XFS_BMDR_KEY_ADDR(block
, idx
);
201 return bitize((int)((char *)kp
- (char *)block
));
209 xfs_bmdr_block_t
*block
;
211 xfs_dinode_t
*dip
= obj
;
214 ASSERT(bitoffs(startoff
) == 0);
215 ASSERT(obj
== iocur_top
->data
);
216 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
217 ASSERT((char *)block
== XFS_DFORK_DPTR(dip
));
218 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
219 return be16_to_cpu(block
->bb_numrecs
);
228 xfs_bmdr_block_t
*block
;
232 ASSERT(bitoffs(startoff
) == 0);
233 ASSERT(obj
== iocur_top
->data
);
235 block
= (xfs_bmdr_block_t
*)((char *)obj
+ byteize(startoff
));
236 ASSERT(be16_to_cpu(block
->bb_level
) > 0);
237 pp
= XFS_BMDR_PTR_ADDR(block
, idx
,
238 libxfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip
, mp
), 0));
239 return bitize((int)((char *)pp
- (char *)block
));
250 ASSERT(bitoffs(startoff
) == 0);
251 ASSERT(obj
== iocur_top
->data
);
254 return bitize((int)XFS_DFORK_DSIZE(dip
, mp
));