]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/bmroot.c
xfs: don't rely on extent indices in xfs_bmap_collapse_extents
[thirdparty/xfsprogs-dev.git] / db / bmroot.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
6b803e5a 19#include "libxfs.h"
2bd0ea18
NS
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"
4ca431fc 28#include "init.h"
2bd0ea18
NS
29
30static int bmroota_key_count(void *obj, int startoff);
31static int bmroota_key_offset(void *obj, int startoff, int idx);
32static int bmroota_ptr_count(void *obj, int startoff);
33static int bmroota_ptr_offset(void *obj, int startoff, int idx);
34static int bmrootd_key_count(void *obj, int startoff);
35static int bmrootd_key_offset(void *obj, int startoff, int idx);
36static int bmrootd_ptr_count(void *obj, int startoff);
37static int bmrootd_ptr_offset(void *obj, int startoff, int idx);
38
39#define OFF(f) bitize(offsetof(xfs_bmdr_block_t, bb_ ## f))
40const 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};
49const 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))
60const field_t bmroota_key_flds[] = {
61 { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_NONE },
62 { NULL }
63};
64const field_t bmrootd_key_flds[] = {
65 { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_NONE },
66 { NULL }
67};
68
69static int
70bmroota_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));
5e656dbb
BN
83 ASSERT(be16_to_cpu(block->bb_level) > 0);
84 return be16_to_cpu(block->bb_numrecs);
2bd0ea18
NS
85}
86
87static int
88bmroota_key_offset(
89 void *obj,
90 int startoff,
91 int idx)
92{
93 xfs_bmdr_block_t *block;
6bddecbc
DC
94#ifdef DEBUG
95 xfs_dinode_t *dip = obj;
96#endif
2bd0ea18
NS
97 xfs_bmdr_key_t *kp;
98
99 ASSERT(bitoffs(startoff) == 0);
100 ASSERT(obj == iocur_top->data);
2bd0ea18
NS
101 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
102 ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
5e656dbb 103 ASSERT(be16_to_cpu(block->bb_level) > 0);
b3563c19 104 kp = XFS_BMDR_KEY_ADDR(block, idx);
2bd0ea18
NS
105 return bitize((int)((char *)kp - (char *)block));
106}
107
108static int
109bmroota_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));
5e656dbb
BN
122 ASSERT(be16_to_cpu(block->bb_level) > 0);
123 return be16_to_cpu(block->bb_numrecs);
2bd0ea18
NS
124}
125
126static int
127bmroota_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));
5e656dbb 141 ASSERT(be16_to_cpu(block->bb_level) > 0);
b3563c19 142 pp = XFS_BMDR_PTR_ADDR(block, idx,
e2f60652 143 libxfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip, mp), 0));
2bd0ea18
NS
144 return bitize((int)((char *)pp - (char *)block));
145}
146
147int
148bmroota_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
169static int
170bmrootd_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));
5e656dbb
BN
183 ASSERT(be16_to_cpu(block->bb_level) > 0);
184 return be16_to_cpu(block->bb_numrecs);
2bd0ea18
NS
185}
186
187static int
188bmrootd_key_offset(
189 void *obj,
190 int startoff,
191 int idx)
192{
193 xfs_bmdr_block_t *block;
194 xfs_bmdr_key_t *kp;
2bd0ea18
NS
195
196 ASSERT(bitoffs(startoff) == 0);
197 ASSERT(obj == iocur_top->data);
2bd0ea18 198 block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
5e656dbb 199 ASSERT(be16_to_cpu(block->bb_level) > 0);
b3563c19 200 kp = XFS_BMDR_KEY_ADDR(block, idx);
2bd0ea18
NS
201 return bitize((int)((char *)kp - (char *)block));
202}
203
204static int
205bmrootd_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));
5e656dbb
BN
218 ASSERT(be16_to_cpu(block->bb_level) > 0);
219 return be16_to_cpu(block->bb_numrecs);
2bd0ea18
NS
220}
221
222static int
223bmrootd_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));
5e656dbb 236 ASSERT(be16_to_cpu(block->bb_level) > 0);
b3563c19 237 pp = XFS_BMDR_PTR_ADDR(block, idx,
e2f60652 238 libxfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip, mp), 0));
2bd0ea18
NS
239 return bitize((int)((char *)pp - (char *)block));
240}
241
242int
243bmrootd_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}