]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/faddr.c
xfs_scrub: adapt phase5 to deferred descriptions
[thirdparty/xfsprogs-dev.git] / db / faddr.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
6b803e5a 7#include "libxfs.h"
2bd0ea18 8#include "type.h"
128efca1 9#include "fprint.h"
2bd0ea18 10#include "faddr.h"
128efca1 11#include "field.h"
2bd0ea18
NS
12#include "inode.h"
13#include "io.h"
14#include "bit.h"
15#include "bmap.h"
16#include "output.h"
4ca431fc 17#include "init.h"
2bd0ea18
NS
18
19void
20fa_agblock(
21 void *obj,
22 int bit,
23 typnm_t next)
24{
25 xfs_agblock_t bno;
26
27 if (cur_agno == NULLAGNUMBER) {
9ee7055c 28 dbprintf(_("no current allocation group, cannot set new addr\n"));
2bd0ea18
NS
29 return;
30 }
31 bno = (xfs_agblock_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
32 if (bno == NULLAGBLOCK) {
9ee7055c 33 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
34 return;
35 }
36 ASSERT(typtab[next].typnm == next);
37 set_cur(&typtab[next], XFS_AGB_TO_DADDR(mp, cur_agno, bno), blkbb,
38 DB_RING_ADD, NULL);
39}
40
41/*ARGSUSED*/
42void
43fa_agino(
44 void *obj,
45 int bit,
46 typnm_t next)
47{
48 xfs_agino_t agino;
49
50 if (cur_agno == NULLAGNUMBER) {
9ee7055c 51 dbprintf(_("no current allocation group, cannot set new addr\n"));
2bd0ea18
NS
52 return;
53 }
54 agino = (xfs_agino_t)getbitval(obj, bit, bitsz(agino), BVUNSIGNED);
55 if (agino == NULLAGINO) {
9ee7055c 56 dbprintf(_("null inode number, cannot set new addr\n"));
2bd0ea18
NS
57 return;
58 }
59 set_cur_inode(XFS_AGINO_TO_INO(mp, cur_agno, agino));
60}
61
62/*ARGSUSED*/
63void
64fa_attrblock(
65 void *obj,
66 int bit,
67 typnm_t next)
68{
69 bmap_ext_t bm;
14f8b681 70 uint32_t bno;
5a35bf2c 71 xfs_fsblock_t dfsbno;
2bd0ea18
NS
72 int nex;
73
14f8b681 74 bno = (uint32_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
2bd0ea18 75 if (bno == 0) {
9ee7055c 76 dbprintf(_("null attribute block number, cannot set new addr\n"));
2bd0ea18
NS
77 return;
78 }
79 nex = 1;
80 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
81 if (nex == 0) {
9ee7055c 82 dbprintf(_("attribute block is unmapped\n"));
2bd0ea18
NS
83 return;
84 }
85 dfsbno = bm.startblock + (bno - bm.startoff);
86 ASSERT(typtab[next].typnm == next);
14f8b681 87 set_cur(&typtab[next], (int64_t)XFS_FSB_TO_DADDR(mp, dfsbno), blkbb,
2bd0ea18
NS
88 DB_RING_ADD, NULL);
89}
90
91void
92fa_cfileoffa(
93 void *obj,
94 int bit,
95 typnm_t next)
96{
97 bmap_ext_t bm;
5a35bf2c
DC
98 xfs_fileoff_t bno;
99 xfs_fsblock_t dfsbno;
2bd0ea18
NS
100 int nex;
101
5a35bf2c 102 bno = (xfs_fileoff_t)getbitval(obj, bit, BMBT_STARTOFF_BITLEN,
2bd0ea18 103 BVUNSIGNED);
5a35bf2c 104 if (bno == NULLFILEOFF) {
9ee7055c 105 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
106 return;
107 }
108 nex = 1;
109 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
110 if (nex == 0) {
9ee7055c 111 dbprintf(_("file block is unmapped\n"));
2bd0ea18
NS
112 return;
113 }
114 dfsbno = bm.startblock + (bno - bm.startoff);
115 ASSERT(typtab[next].typnm == next);
116 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), blkbb, DB_RING_ADD,
117 NULL);
118}
119
120void
121fa_cfileoffd(
122 void *obj,
123 int bit,
124 typnm_t next)
125{
126 bbmap_t bbmap;
127 bmap_ext_t *bmp;
5a35bf2c
DC
128 xfs_fileoff_t bno;
129 xfs_fsblock_t dfsbno;
2bd0ea18
NS
130 int nb;
131 int nex;
132
5a35bf2c 133 bno = (xfs_fileoff_t)getbitval(obj, bit, BMBT_STARTOFF_BITLEN,
2bd0ea18 134 BVUNSIGNED);
5a35bf2c 135 if (bno == NULLFILEOFF) {
9ee7055c 136 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
137 return;
138 }
ff105f75 139 nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
2bd0ea18
NS
140 bmp = malloc(nb * sizeof(*bmp));
141 bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
142 if (nex == 0) {
9ee7055c 143 dbprintf(_("file block is unmapped\n"));
2bd0ea18
NS
144 free(bmp);
145 return;
146 }
147 dfsbno = bmp->startblock + (bno - bmp->startoff);
148 ASSERT(typtab[next].typnm == next);
149 if (nex > 1)
150 make_bbmap(&bbmap, nex, bmp);
151 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), nb * blkbb,
152 DB_RING_ADD, nex > 1 ? &bbmap: NULL);
153 free(bmp);
154}
155
156void
157fa_cfsblock(
158 void *obj,
159 int bit,
160 typnm_t next)
161{
5a35bf2c 162 xfs_fsblock_t bno;
cbead9df 163 int nb;
2bd0ea18 164
5a35bf2c 165 bno = (xfs_fsblock_t)getbitval(obj, bit, BMBT_STARTBLOCK_BITLEN,
2bd0ea18 166 BVUNSIGNED);
5a35bf2c 167 if (bno == NULLFSBLOCK) {
9ee7055c 168 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
169 return;
170 }
ff105f75 171 nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
2bd0ea18 172 ASSERT(typtab[next].typnm == next);
cbead9df
NS
173 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, bno), nb * blkbb,
174 DB_RING_ADD, NULL);
2bd0ea18
NS
175}
176
177void
178fa_dfiloffa(
179 void *obj,
180 int bit,
181 typnm_t next)
182{
183 bmap_ext_t bm;
5a35bf2c
DC
184 xfs_fileoff_t bno;
185 xfs_fsblock_t dfsbno;
2bd0ea18
NS
186 int nex;
187
5a35bf2c
DC
188 bno = (xfs_fileoff_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
189 if (bno == NULLFILEOFF) {
9ee7055c 190 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
191 return;
192 }
193 nex = 1;
194 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
195 if (nex == 0) {
9ee7055c 196 dbprintf(_("file block is unmapped\n"));
2bd0ea18
NS
197 return;
198 }
199 dfsbno = bm.startblock + (bno - bm.startoff);
200 ASSERT(typtab[next].typnm == next);
201 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), blkbb, DB_RING_ADD,
202 NULL);
203}
204
205void
206fa_dfiloffd(
207 void *obj,
208 int bit,
209 typnm_t next)
210{
211 bbmap_t bbmap;
212 bmap_ext_t *bmp;
5a35bf2c
DC
213 xfs_fileoff_t bno;
214 xfs_fsblock_t dfsbno;
2bd0ea18
NS
215 int nb;
216 int nex;
217
5a35bf2c
DC
218 bno = (xfs_fileoff_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
219 if (bno == NULLFILEOFF) {
9ee7055c 220 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
221 return;
222 }
ff105f75 223 nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
2bd0ea18
NS
224 bmp = malloc(nb * sizeof(*bmp));
225 bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
226 if (nex == 0) {
9ee7055c 227 dbprintf(_("file block is unmapped\n"));
2bd0ea18
NS
228 free(bmp);
229 return;
230 }
231 dfsbno = bmp->startblock + (bno - bmp->startoff);
232 ASSERT(typtab[next].typnm == next);
233 if (nex > 1)
234 make_bbmap(&bbmap, nex, bmp);
235 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), nb * blkbb,
236 DB_RING_ADD, nex > 1 ? &bbmap : NULL);
237 free(bmp);
238}
239
240void
241fa_dfsbno(
242 void *obj,
243 int bit,
244 typnm_t next)
245{
5a35bf2c 246 xfs_fsblock_t bno;
2bd0ea18 247
5a35bf2c
DC
248 bno = (xfs_fsblock_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
249 if (bno == NULLFSBLOCK) {
9ee7055c 250 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
251 return;
252 }
253 ASSERT(typtab[next].typnm == next);
254 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, bno), blkbb, DB_RING_ADD,
255 NULL);
256}
257
258/*ARGSUSED*/
259void
260fa_dirblock(
261 void *obj,
262 int bit,
263 typnm_t next)
264{
265 bbmap_t bbmap;
266 bmap_ext_t *bmp;
14f8b681 267 uint32_t bno;
5a35bf2c 268 xfs_fsblock_t dfsbno;
2bd0ea18
NS
269 int nex;
270
14f8b681 271 bno = (uint32_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
2bd0ea18 272 if (bno == 0) {
9ee7055c 273 dbprintf(_("null directory block number, cannot set new addr\n"));
2bd0ea18
NS
274 return;
275 }
ff105f75 276 nex = mp->m_dir_geo->fsbcount;
2bd0ea18 277 bmp = malloc(nex * sizeof(*bmp));
ff105f75 278 bmap(bno, mp->m_dir_geo->fsbcount, XFS_DATA_FORK, &nex, bmp);
2bd0ea18 279 if (nex == 0) {
9ee7055c 280 dbprintf(_("directory block is unmapped\n"));
2bd0ea18
NS
281 free(bmp);
282 return;
283 }
284 dfsbno = bmp->startblock + (bno - bmp->startoff);
285 ASSERT(typtab[next].typnm == next);
286 if (nex > 1)
287 make_bbmap(&bbmap, nex, bmp);
14f8b681 288 set_cur(&typtab[next], (int64_t)XFS_FSB_TO_DADDR(mp, dfsbno),
ff105f75 289 XFS_FSB_TO_BB(mp, mp->m_dir_geo->fsbcount), DB_RING_ADD,
2bd0ea18
NS
290 nex > 1 ? &bbmap : NULL);
291 free(bmp);
292}
293
294void
295fa_drfsbno(
296 void *obj,
297 int bit,
298 typnm_t next)
299{
5a35bf2c 300 xfs_rfsblock_t bno;
2bd0ea18 301
5a35bf2c
DC
302 bno = (xfs_rfsblock_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
303 if (bno == NULLRFSBLOCK) {
9ee7055c 304 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
305 return;
306 }
307 ASSERT(typtab[next].typnm == next);
14f8b681 308 set_cur(&typtab[next], (int64_t)XFS_FSB_TO_BB(mp, bno), blkbb,
2bd0ea18
NS
309 DB_RING_ADD, NULL);
310}
311
312/*ARGSUSED*/
313void
314fa_drtbno(
315 void *obj,
316 int bit,
317 typnm_t next)
318{
5a35bf2c 319 xfs_rtblock_t bno;
2bd0ea18 320
5a35bf2c
DC
321 bno = (xfs_rtblock_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
322 if (bno == NULLRTBLOCK) {
9ee7055c 323 dbprintf(_("null block number, cannot set new addr\n"));
2bd0ea18
NS
324 return;
325 }
326 /* need set_cur to understand rt subvolume */
327}
328
329/*ARGSUSED*/
330void
331fa_ino(
332 void *obj,
333 int bit,
334 typnm_t next)
335{
336 xfs_ino_t ino;
337
338 ASSERT(next == TYP_INODE);
339 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino), BVUNSIGNED);
340 if (ino == NULLFSINO) {
9ee7055c 341 dbprintf(_("null inode number, cannot set new addr\n"));
2bd0ea18
NS
342 return;
343 }
344 set_cur_inode(ino);
345}
346
347void
348fa_ino4(
349 void *obj,
350 int bit,
351 typnm_t next)
352{
353 xfs_ino_t ino;
2bd0ea18
NS
354
355 ASSERT(next == TYP_INODE);
d8bf9c63 356 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(XFS_INO32_SIZE), BVUNSIGNED);
2bd0ea18 357 if (ino == NULLFSINO) {
9ee7055c 358 dbprintf(_("null inode number, cannot set new addr\n"));
2bd0ea18
NS
359 return;
360 }
361 set_cur_inode(ino);
362}
363
364void
365fa_ino8(
366 void *obj,
367 int bit,
368 typnm_t next)
369{
370 xfs_ino_t ino;
2bd0ea18
NS
371
372 ASSERT(next == TYP_INODE);
d8bf9c63 373 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(XFS_INO64_SIZE), BVUNSIGNED);
2bd0ea18 374 if (ino == NULLFSINO) {
9ee7055c 375 dbprintf(_("null inode number, cannot set new addr\n"));
2bd0ea18
NS
376 return;
377 }
378 set_cur_inode(ino);
379}