]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmroot.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / db / bmroot.c
1 /*
2 * Copyright (c) 2000 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 "data.h"
35 #include "type.h"
36 #include "faddr.h"
37 #include "fprint.h"
38 #include "field.h"
39 #include "bmroot.h"
40 #include "io.h"
41 #include "print.h"
42 #include "bit.h"
43 #include "mount.h"
44
45 static int bmroota_key_count(void *obj, int startoff);
46 static int bmroota_key_offset(void *obj, int startoff, int idx);
47 static int bmroota_ptr_count(void *obj, int startoff);
48 static int bmroota_ptr_offset(void *obj, int startoff, int idx);
49 static int bmrootd_key_count(void *obj, int startoff);
50 static int bmrootd_key_offset(void *obj, int startoff, int idx);
51 static int bmrootd_ptr_count(void *obj, int startoff);
52 static int bmrootd_ptr_offset(void *obj, int startoff, int idx);
53
54 #define OFF(f) bitize(offsetof(xfs_bmdr_block_t, bb_ ## f))
55 const field_t bmroota_flds[] = {
56 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
57 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
58 { "keys", FLDT_BMROOTAKEY, bmroota_key_offset, bmroota_key_count,
59 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
60 { "ptrs", FLDT_BMROOTAPTR, bmroota_ptr_offset, bmroota_ptr_count,
61 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA },
62 { NULL }
63 };
64 const field_t bmrootd_flds[] = {
65 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
66 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
67 { "keys", FLDT_BMROOTDKEY, bmrootd_key_offset, bmrootd_key_count,
68 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
69 { "ptrs", FLDT_BMROOTDPTR, bmrootd_ptr_offset, bmrootd_ptr_count,
70 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD },
71 { NULL }
72 };
73
74 #define KOFF(f) bitize(offsetof(xfs_bmdr_key_t, br_ ## f))
75 const field_t bmroota_key_flds[] = {
76 { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_NONE },
77 { NULL }
78 };
79 const field_t bmrootd_key_flds[] = {
80 { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_NONE },
81 { NULL }
82 };
83
84 static int
85 bmroota_key_count(
86 void *obj,
87 int startoff)
88 {
89 xfs_bmdr_block_t *block;
90 #ifdef DEBUG
91 xfs_dinode_t *dip = obj;
92 #endif
93
94 ASSERT(bitoffs(startoff) == 0);
95 ASSERT(obj == iocur_top->data);
96 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
97 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
98 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
99 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
100 }
101
102 static int
103 bmroota_key_offset(
104 void *obj,
105 int startoff,
106 int idx)
107 {
108 xfs_bmdr_block_t *block;
109 /* REFERENCED */
110 xfs_dinode_t *dip;
111 xfs_bmdr_key_t *kp;
112
113 ASSERT(bitoffs(startoff) == 0);
114 ASSERT(obj == iocur_top->data);
115 dip = obj;
116 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
117 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
118 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
119 kp = XFS_BTREE_KEY_ADDR(iocur_top->len, xfs_bmdr, block, idx,
120 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_ASIZE(dip, mp), xfs_bmdr, 0));
121 return bitize((int)((char *)kp - (char *)block));
122 }
123
124 static int
125 bmroota_ptr_count(
126 void *obj,
127 int startoff)
128 {
129 xfs_bmdr_block_t *block;
130 #ifdef DEBUG
131 xfs_dinode_t *dip = obj;
132 #endif
133
134 ASSERT(bitoffs(startoff) == 0);
135 ASSERT(obj == iocur_top->data);
136 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
137 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
138 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
139 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
140 }
141
142 static int
143 bmroota_ptr_offset(
144 void *obj,
145 int startoff,
146 int idx)
147 {
148 xfs_bmdr_block_t *block;
149 xfs_dinode_t *dip;
150 xfs_bmdr_ptr_t *pp;
151
152 ASSERT(bitoffs(startoff) == 0);
153 ASSERT(obj == iocur_top->data);
154 dip = obj;
155 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
156 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
157 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
158 pp = XFS_BTREE_PTR_ADDR(iocur_top->len, xfs_bmdr, block, idx,
159 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_ASIZE(dip, mp), xfs_bmdr, 0));
160 return bitize((int)((char *)pp - (char *)block));
161 }
162
163 int
164 bmroota_size(
165 void *obj,
166 int startoff,
167 int idx)
168 {
169 xfs_dinode_t *dip;
170 #ifdef DEBUG
171 xfs_bmdr_block_t *block;
172 #endif
173
174 ASSERT(bitoffs(startoff) == 0);
175 ASSERT(obj == iocur_top->data);
176 ASSERT(idx == 0);
177 dip = obj;
178 #ifdef DEBUG
179 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
180 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
181 #endif
182 return bitize((int)XFS_DFORK_ASIZE(dip, mp));
183 }
184
185 static int
186 bmrootd_key_count(
187 void *obj,
188 int startoff)
189 {
190 xfs_bmdr_block_t *block;
191 #ifdef DEBUG
192 xfs_dinode_t *dip = obj;
193 #endif
194
195 ASSERT(bitoffs(startoff) == 0);
196 ASSERT(obj == iocur_top->data);
197 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
198 ASSERT((char *)block == XFS_DFORK_DPTR(dip));
199 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
200 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
201 }
202
203 static int
204 bmrootd_key_offset(
205 void *obj,
206 int startoff,
207 int idx)
208 {
209 xfs_bmdr_block_t *block;
210 xfs_bmdr_key_t *kp;
211 xfs_dinode_t *dip;
212
213 ASSERT(bitoffs(startoff) == 0);
214 ASSERT(obj == iocur_top->data);
215 dip = obj;
216 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
217 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
218 kp = XFS_BTREE_KEY_ADDR(iocur_top->len, xfs_bmdr, block, idx,
219 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_DSIZE(dip, mp), xfs_bmdr, 0));
220 return bitize((int)((char *)kp - (char *)block));
221 }
222
223 static int
224 bmrootd_ptr_count(
225 void *obj,
226 int startoff)
227 {
228 xfs_bmdr_block_t *block;
229 #ifdef DEBUG
230 xfs_dinode_t *dip = obj;
231 #endif
232
233 ASSERT(bitoffs(startoff) == 0);
234 ASSERT(obj == iocur_top->data);
235 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
236 ASSERT((char *)block == XFS_DFORK_DPTR(dip));
237 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
238 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
239 }
240
241 static int
242 bmrootd_ptr_offset(
243 void *obj,
244 int startoff,
245 int idx)
246 {
247 xfs_bmdr_block_t *block;
248 xfs_bmdr_ptr_t *pp;
249 xfs_dinode_t *dip;
250
251 ASSERT(bitoffs(startoff) == 0);
252 ASSERT(obj == iocur_top->data);
253 dip = obj;
254 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
255 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
256 pp = XFS_BTREE_PTR_ADDR(iocur_top->len, xfs_bmdr, block, idx,
257 XFS_BTREE_BLOCK_MAXRECS(XFS_DFORK_DSIZE(dip, mp), xfs_bmdr, 0));
258 return bitize((int)((char *)pp - (char *)block));
259 }
260
261 int
262 bmrootd_size(
263 void *obj,
264 int startoff,
265 int idx)
266 {
267 xfs_dinode_t *dip;
268
269 ASSERT(bitoffs(startoff) == 0);
270 ASSERT(obj == iocur_top->data);
271 ASSERT(idx == 0);
272 dip = obj;
273 return bitize((int)XFS_DFORK_DSIZE(dip, mp));
274 }