]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmapbt.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / bmapbt.c
1 /*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "type.h"
35 #include "faddr.h"
36 #include "fprint.h"
37 #include "field.h"
38 #include "bmapbt.h"
39 #include "print.h"
40 #include "bit.h"
41 #include "init.h"
42
43 static int bmapbta_key_count(void *obj, int startoff);
44 static int bmapbta_key_offset(void *obj, int startoff, int idx);
45 static int bmapbta_ptr_count(void *obj, int startoff);
46 static int bmapbta_ptr_offset(void *obj, int startoff, int idx);
47 static int bmapbta_rec_count(void *obj, int startoff);
48 static int bmapbta_rec_offset(void *obj, int startoff, int idx);
49 static int bmapbtd_key_count(void *obj, int startoff);
50 static int bmapbtd_key_offset(void *obj, int startoff, int idx);
51 static int bmapbtd_ptr_count(void *obj, int startoff);
52 static int bmapbtd_ptr_offset(void *obj, int startoff, int idx);
53 static int bmapbtd_rec_count(void *obj, int startoff);
54 static int bmapbtd_rec_offset(void *obj, int startoff, int idx);
55
56 const field_t bmapbta_hfld[] = {
57 { "", FLDT_BMAPBTA, OI(0), C1, 0, TYP_NONE },
58 { NULL }
59 };
60 const field_t bmapbtd_hfld[] = {
61 { "", FLDT_BMAPBTD, OI(0), C1, 0, TYP_NONE },
62 { NULL }
63 };
64
65 #define OFF(f) bitize(offsetof(xfs_bmbt_block_t, bb_ ## f))
66 const field_t bmapbta_flds[] = {
67 { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
68 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
69 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
70 { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTA },
71 { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTA },
72 { "recs", FLDT_BMAPBTAREC, bmapbta_rec_offset, bmapbta_rec_count,
73 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
74 { "keys", FLDT_BMAPBTAKEY, bmapbta_key_offset, bmapbta_key_count,
75 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
76 { "ptrs", FLDT_BMAPBTAPTR, bmapbta_ptr_offset, bmapbta_ptr_count,
77 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA },
78 { NULL }
79 };
80 const field_t bmapbtd_flds[] = {
81 { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
82 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
83 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
84 { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTD },
85 { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTD },
86 { "recs", FLDT_BMAPBTDREC, bmapbtd_rec_offset, bmapbtd_rec_count,
87 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
88 { "keys", FLDT_BMAPBTDKEY, bmapbtd_key_offset, bmapbtd_key_count,
89 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
90 { "ptrs", FLDT_BMAPBTDPTR, bmapbtd_ptr_offset, bmapbtd_ptr_count,
91 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD },
92 { NULL }
93 };
94
95 #define KOFF(f) bitize(offsetof(xfs_bmbt_key_t, br_ ## f))
96 const field_t bmapbta_key_flds[] = {
97 { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_ATTR },
98 { NULL }
99 };
100 const field_t bmapbtd_key_flds[] = {
101 { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_INODATA },
102 { NULL }
103 };
104
105 const field_t bmapbta_rec_flds[] = {
106 { "startoff", FLDT_CFILEOFFA, OI(BMBT_STARTOFF_BITOFF), C1, 0,
107 TYP_ATTR },
108 { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0,
109 TYP_ATTR },
110 { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0,
111 TYP_NONE },
112 { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0,
113 TYP_NONE },
114 { NULL }
115 };
116 const field_t bmapbtd_rec_flds[] = {
117 { "startoff", FLDT_CFILEOFFD, OI(BMBT_STARTOFF_BITOFF), C1, 0,
118 TYP_INODATA },
119 { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0,
120 TYP_INODATA },
121 { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0,
122 TYP_NONE },
123 { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0,
124 TYP_NONE },
125 { NULL }
126 };
127
128 static int
129 bmapbta_key_count(
130 void *obj,
131 int startoff)
132 {
133 xfs_bmbt_block_t *block;
134
135 ASSERT(startoff == 0);
136 block = obj;
137 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
138 return 0;
139 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
140 }
141
142 static int
143 bmapbta_key_offset(
144 void *obj,
145 int startoff,
146 int idx)
147 {
148 xfs_bmbt_block_t *block;
149 xfs_bmbt_key_t *kp;
150
151 ASSERT(startoff == 0);
152 block = obj;
153 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
154 kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
155 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
156 return bitize((int)((char *)kp - (char *)block));
157 }
158
159 static int
160 bmapbta_ptr_count(
161 void *obj,
162 int startoff)
163 {
164 xfs_bmbt_block_t *block;
165
166 ASSERT(startoff == 0);
167 block = obj;
168 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
169 return 0;
170 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
171 }
172
173 static int
174 bmapbta_ptr_offset(
175 void *obj,
176 int startoff,
177 int idx)
178 {
179 xfs_bmbt_block_t *block;
180 xfs_bmbt_ptr_t *pp;
181
182 ASSERT(startoff == 0);
183 block = obj;
184 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
185 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
186 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
187 return bitize((int)((char *)pp - (char *)block));
188 }
189
190 static int
191 bmapbta_rec_count(
192 void *obj,
193 int startoff)
194 {
195 xfs_bmbt_block_t *block;
196
197 ASSERT(startoff == 0);
198 block = obj;
199 if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
200 return 0;
201 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
202 }
203
204 static int
205 bmapbta_rec_offset(
206 void *obj,
207 int startoff,
208 int idx)
209 {
210 xfs_bmbt_block_t *block;
211 xfs_bmbt_rec_t *rp;
212
213 ASSERT(startoff == 0);
214 block = obj;
215 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
216 rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
217 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 1));
218 return bitize((int)((char *)rp - (char *)block));
219 }
220
221 int
222 bmapbta_size(
223 void *obj,
224 int startoff,
225 int idx)
226 {
227 return bitize(mp->m_sb.sb_blocksize);
228 }
229
230 static int
231 bmapbtd_key_count(
232 void *obj,
233 int startoff)
234 {
235 xfs_bmbt_block_t *block;
236
237 ASSERT(startoff == 0);
238 block = obj;
239 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
240 return 0;
241 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
242 }
243
244 static int
245 bmapbtd_key_offset(
246 void *obj,
247 int startoff,
248 int idx)
249 {
250 xfs_bmbt_block_t *block;
251 xfs_bmbt_key_t *kp;
252
253 ASSERT(startoff == 0);
254 block = obj;
255 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
256 kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
257 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
258 return bitize((int)((char *)kp - (char *)block));
259 }
260
261 static int
262 bmapbtd_ptr_count(
263 void *obj,
264 int startoff)
265 {
266 xfs_bmbt_block_t *block;
267
268 ASSERT(startoff == 0);
269 block = obj;
270 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
271 return 0;
272 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
273 }
274
275 static int
276 bmapbtd_ptr_offset(
277 void *obj,
278 int startoff,
279 int idx)
280 {
281 xfs_bmbt_block_t *block;
282 xfs_bmbt_ptr_t *pp;
283
284 ASSERT(startoff == 0);
285 block = obj;
286 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
287 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
288 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
289 return bitize((int)((char *)pp - (char *)block));
290 }
291
292 static int
293 bmapbtd_rec_count(
294 void *obj,
295 int startoff)
296 {
297 xfs_bmbt_block_t *block;
298
299 ASSERT(startoff == 0);
300 block = obj;
301 if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
302 return 0;
303 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
304 }
305
306 static int
307 bmapbtd_rec_offset(
308 void *obj,
309 int startoff,
310 int idx)
311 {
312 xfs_bmbt_block_t *block;
313 xfs_bmbt_rec_t *rp;
314
315 ASSERT(startoff == 0);
316 block = obj;
317 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
318 rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
319 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 1));
320 return bitize((int)((char *)rp - (char *)block));
321 }
322
323 int
324 bmapbtd_size(
325 void *obj,
326 int startoff,
327 int idx)
328 {
329 return bitize(mp->m_sb.sb_blocksize);
330 }