]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmroot.c
misc: fix libxfs api violations
[thirdparty/xfsprogs-dev.git] / db / bmroot.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "libxfs.h"
20 #include "type.h"
21 #include "faddr.h"
22 #include "fprint.h"
23 #include "field.h"
24 #include "bmroot.h"
25 #include "io.h"
26 #include "print.h"
27 #include "bit.h"
28 #include "init.h"
29
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);
38
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 },
47 { NULL }
48 };
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 },
56 { NULL }
57 };
58
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 },
62 { NULL }
63 };
64 const field_t bmrootd_key_flds[] = {
65 { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_NONE },
66 { NULL }
67 };
68
69 static int
70 bmroota_key_count(
71 void *obj,
72 int startoff)
73 {
74 xfs_bmdr_block_t *block;
75 #ifdef DEBUG
76 xfs_dinode_t *dip = obj;
77 #endif
78
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);
85 }
86
87 static int
88 bmroota_key_offset(
89 void *obj,
90 int startoff,
91 int idx)
92 {
93 xfs_bmdr_block_t *block;
94 #ifdef DEBUG
95 xfs_dinode_t *dip = obj;
96 #endif
97 xfs_bmdr_key_t *kp;
98
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));
106 }
107
108 static int
109 bmroota_ptr_count(
110 void *obj,
111 int startoff)
112 {
113 xfs_bmdr_block_t *block;
114 #ifdef DEBUG
115 xfs_dinode_t *dip = obj;
116 #endif
117
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);
124 }
125
126 static int
127 bmroota_ptr_offset(
128 void *obj,
129 int startoff,
130 int idx)
131 {
132 xfs_bmdr_block_t *block;
133 xfs_dinode_t *dip;
134 xfs_bmdr_ptr_t *pp;
135
136 ASSERT(bitoffs(startoff) == 0);
137 ASSERT(obj == iocur_top->data);
138 dip = obj;
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));
145 }
146
147 int
148 bmroota_size(
149 void *obj,
150 int startoff,
151 int idx)
152 {
153 xfs_dinode_t *dip;
154 #ifdef DEBUG
155 xfs_bmdr_block_t *block;
156 #endif
157
158 ASSERT(bitoffs(startoff) == 0);
159 ASSERT(obj == iocur_top->data);
160 ASSERT(idx == 0);
161 dip = obj;
162 #ifdef DEBUG
163 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
164 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
165 #endif
166 return bitize((int)XFS_DFORK_ASIZE(dip, mp));
167 }
168
169 static int
170 bmrootd_key_count(
171 void *obj,
172 int startoff)
173 {
174 xfs_bmdr_block_t *block;
175 #ifdef DEBUG
176 xfs_dinode_t *dip = obj;
177 #endif
178
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);
185 }
186
187 static int
188 bmrootd_key_offset(
189 void *obj,
190 int startoff,
191 int idx)
192 {
193 xfs_bmdr_block_t *block;
194 xfs_bmdr_key_t *kp;
195
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));
202 }
203
204 static int
205 bmrootd_ptr_count(
206 void *obj,
207 int startoff)
208 {
209 xfs_bmdr_block_t *block;
210 #ifdef DEBUG
211 xfs_dinode_t *dip = obj;
212 #endif
213
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);
220 }
221
222 static int
223 bmrootd_ptr_offset(
224 void *obj,
225 int startoff,
226 int idx)
227 {
228 xfs_bmdr_block_t *block;
229 xfs_bmdr_ptr_t *pp;
230 xfs_dinode_t *dip;
231
232 ASSERT(bitoffs(startoff) == 0);
233 ASSERT(obj == iocur_top->data);
234 dip = obj;
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));
240 }
241
242 int
243 bmrootd_size(
244 void *obj,
245 int startoff,
246 int idx)
247 {
248 xfs_dinode_t *dip;
249
250 ASSERT(bitoffs(startoff) == 0);
251 ASSERT(obj == iocur_top->data);
252 ASSERT(idx == 0);
253 dip = obj;
254 return bitize((int)XFS_DFORK_DSIZE(dip, mp));
255 }