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