]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bmroot.c
Sync up libxfs to latest kernel code
[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 <xfs/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 /* REFERENCED */
95 xfs_dinode_t *dip;
96 xfs_bmdr_key_t *kp;
97
98 ASSERT(bitoffs(startoff) == 0);
99 ASSERT(obj == iocur_top->data);
100 dip = obj;
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 xfs_bmdr_maxrecs(mp, 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 xfs_dinode_t *dip;
196
197 ASSERT(bitoffs(startoff) == 0);
198 ASSERT(obj == iocur_top->data);
199 dip = obj;
200 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
201 ASSERT(be16_to_cpu(block->bb_level) > 0);
202 kp = XFS_BMDR_KEY_ADDR(block, idx);
203 return bitize((int)((char *)kp - (char *)block));
204 }
205
206 static int
207 bmrootd_ptr_count(
208 void *obj,
209 int startoff)
210 {
211 xfs_bmdr_block_t *block;
212 #ifdef DEBUG
213 xfs_dinode_t *dip = obj;
214 #endif
215
216 ASSERT(bitoffs(startoff) == 0);
217 ASSERT(obj == iocur_top->data);
218 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
219 ASSERT((char *)block == XFS_DFORK_DPTR(dip));
220 ASSERT(be16_to_cpu(block->bb_level) > 0);
221 return be16_to_cpu(block->bb_numrecs);
222 }
223
224 static int
225 bmrootd_ptr_offset(
226 void *obj,
227 int startoff,
228 int idx)
229 {
230 xfs_bmdr_block_t *block;
231 xfs_bmdr_ptr_t *pp;
232 xfs_dinode_t *dip;
233
234 ASSERT(bitoffs(startoff) == 0);
235 ASSERT(obj == iocur_top->data);
236 dip = obj;
237 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
238 ASSERT(be16_to_cpu(block->bb_level) > 0);
239 pp = XFS_BMDR_PTR_ADDR(block, idx,
240 xfs_bmdr_maxrecs(mp, XFS_DFORK_DSIZE(dip, mp), 0));
241 return bitize((int)((char *)pp - (char *)block));
242 }
243
244 int
245 bmrootd_size(
246 void *obj,
247 int startoff,
248 int idx)
249 {
250 xfs_dinode_t *dip;
251
252 ASSERT(bitoffs(startoff) == 0);
253 ASSERT(obj == iocur_top->data);
254 ASSERT(idx == 0);
255 dip = obj;
256 return bitize((int)XFS_DFORK_DSIZE(dip, mp));
257 }