]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/bmroot.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / bmroot.c
CommitLineData
2bd0ea18 1/*
0d3e0b37 2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
dfc130f3 3 *
2bd0ea18
NS
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
dfc130f3 7 *
2bd0ea18
NS
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dfc130f3 11 *
2bd0ea18
NS
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
dfc130f3 18 *
2bd0ea18
NS
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
dfc130f3 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
dfc130f3
RC
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include <libxfs.h>
2bd0ea18
NS
34#include "type.h"
35#include "faddr.h"
36#include "fprint.h"
37#include "field.h"
38#include "bmroot.h"
39#include "io.h"
40#include "print.h"
41#include "bit.h"
4ca431fc 42#include "init.h"
2bd0ea18
NS
43
44static int bmroota_key_count(void *obj, int startoff);
45static int bmroota_key_offset(void *obj, int startoff, int idx);
46static int bmroota_ptr_count(void *obj, int startoff);
47static int bmroota_ptr_offset(void *obj, int startoff, int idx);
48static int bmrootd_key_count(void *obj, int startoff);
49static int bmrootd_key_offset(void *obj, int startoff, int idx);
50static int bmrootd_ptr_count(void *obj, int startoff);
51static int bmrootd_ptr_offset(void *obj, int startoff, int idx);
52
53#define OFF(f) bitize(offsetof(xfs_bmdr_block_t, bb_ ## f))
54const field_t bmroota_flds[] = {
55 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
56 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
57 { "keys", FLDT_BMROOTAKEY, bmroota_key_offset, bmroota_key_count,
58 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
59 { "ptrs", FLDT_BMROOTAPTR, bmroota_ptr_offset, bmroota_ptr_count,
60 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA },
61 { NULL }
62};
63const field_t bmrootd_flds[] = {
64 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
65 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
66 { "keys", FLDT_BMROOTDKEY, bmrootd_key_offset, bmrootd_key_count,
67 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
68 { "ptrs", FLDT_BMROOTDPTR, bmrootd_ptr_offset, bmrootd_ptr_count,
69 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD },
70 { NULL }
71};
72
73#define KOFF(f) bitize(offsetof(xfs_bmdr_key_t, br_ ## f))
74const field_t bmroota_key_flds[] = {
75 { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_NONE },
76 { NULL }
77};
78const field_t bmrootd_key_flds[] = {
79 { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_NONE },
80 { NULL }
81};
82
83static int
84bmroota_key_count(
85 void *obj,
86 int startoff)
87{
88 xfs_bmdr_block_t *block;
89#ifdef DEBUG
90 xfs_dinode_t *dip = obj;
91#endif
92
93 ASSERT(bitoffs(startoff) == 0);
94 ASSERT(obj == iocur_top->data);
95 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
96 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
97 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
98 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
99}
100
101static int
102bmroota_key_offset(
103 void *obj,
104 int startoff,
105 int idx)
106{
107 xfs_bmdr_block_t *block;
108 /* REFERENCED */
109 xfs_dinode_t *dip;
110 xfs_bmdr_key_t *kp;
111
112 ASSERT(bitoffs(startoff) == 0);
113 ASSERT(obj == iocur_top->data);
114 dip = obj;
115 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
116 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
117 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
118 kp = XFS_BTREE_KEY_ADDR(iocur_top->len, xfs_bmdr, block, idx,
119 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_ASIZE(dip, mp), xfs_bmdr, 0));
120 return bitize((int)((char *)kp - (char *)block));
121}
122
123static int
124bmroota_ptr_count(
125 void *obj,
126 int startoff)
127{
128 xfs_bmdr_block_t *block;
129#ifdef DEBUG
130 xfs_dinode_t *dip = obj;
131#endif
132
133 ASSERT(bitoffs(startoff) == 0);
134 ASSERT(obj == iocur_top->data);
135 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
136 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
137 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
138 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
139}
140
141static int
142bmroota_ptr_offset(
143 void *obj,
144 int startoff,
145 int idx)
146{
147 xfs_bmdr_block_t *block;
148 xfs_dinode_t *dip;
149 xfs_bmdr_ptr_t *pp;
150
151 ASSERT(bitoffs(startoff) == 0);
152 ASSERT(obj == iocur_top->data);
153 dip = obj;
154 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
155 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
156 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
157 pp = XFS_BTREE_PTR_ADDR(iocur_top->len, xfs_bmdr, block, idx,
158 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_ASIZE(dip, mp), xfs_bmdr, 0));
159 return bitize((int)((char *)pp - (char *)block));
160}
161
162int
163bmroota_size(
164 void *obj,
165 int startoff,
166 int idx)
167{
168 xfs_dinode_t *dip;
169#ifdef DEBUG
170 xfs_bmdr_block_t *block;
171#endif
172
173 ASSERT(bitoffs(startoff) == 0);
174 ASSERT(obj == iocur_top->data);
175 ASSERT(idx == 0);
176 dip = obj;
177#ifdef DEBUG
178 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
179 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
180#endif
181 return bitize((int)XFS_DFORK_ASIZE(dip, mp));
182}
183
184static int
185bmrootd_key_count(
186 void *obj,
187 int startoff)
188{
189 xfs_bmdr_block_t *block;
190#ifdef DEBUG
191 xfs_dinode_t *dip = obj;
192#endif
193
194 ASSERT(bitoffs(startoff) == 0);
195 ASSERT(obj == iocur_top->data);
196 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
197 ASSERT((char *)block == XFS_DFORK_DPTR(dip));
198 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
199 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
200}
201
202static int
203bmrootd_key_offset(
204 void *obj,
205 int startoff,
206 int idx)
207{
208 xfs_bmdr_block_t *block;
209 xfs_bmdr_key_t *kp;
210 xfs_dinode_t *dip;
211
212 ASSERT(bitoffs(startoff) == 0);
213 ASSERT(obj == iocur_top->data);
214 dip = obj;
215 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
216 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
217 kp = XFS_BTREE_KEY_ADDR(iocur_top->len, xfs_bmdr, block, idx,
218 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_DSIZE(dip, mp), xfs_bmdr, 0));
219 return bitize((int)((char *)kp - (char *)block));
220}
221
222static int
223bmrootd_ptr_count(
224 void *obj,
225 int startoff)
226{
227 xfs_bmdr_block_t *block;
228#ifdef DEBUG
229 xfs_dinode_t *dip = obj;
230#endif
231
232 ASSERT(bitoffs(startoff) == 0);
233 ASSERT(obj == iocur_top->data);
234 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
235 ASSERT((char *)block == XFS_DFORK_DPTR(dip));
236 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
237 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
238}
239
240static int
241bmrootd_ptr_offset(
242 void *obj,
243 int startoff,
244 int idx)
245{
246 xfs_bmdr_block_t *block;
247 xfs_bmdr_ptr_t *pp;
248 xfs_dinode_t *dip;
249
250 ASSERT(bitoffs(startoff) == 0);
251 ASSERT(obj == iocur_top->data);
252 dip = obj;
253 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
254 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
255 pp = XFS_BTREE_PTR_ADDR(iocur_top->len, xfs_bmdr, block, idx,
256 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_DSIZE(dip, mp), xfs_bmdr, 0));
257 return bitize((int)((char *)pp - (char *)block));
258}
259
260int
261bmrootd_size(
262 void *obj,
263 int startoff,
264 int idx)
265{
266 xfs_dinode_t *dip;
267
268 ASSERT(bitoffs(startoff) == 0);
269 ASSERT(obj == iocur_top->data);
270 ASSERT(idx == 0);
271 dip = obj;
272 return bitize((int)XFS_DFORK_DSIZE(dip, mp));
273}