]>
Commit | Line | Data |
---|---|---|
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 | |
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) { | |
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*/ | |
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) { | |
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*/ | |
63 | void | |
64 | fa_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; |
3a2414fa | 72 | xfs_extnum_t nex; |
2bd0ea18 | 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 | ||
91 | void | |
92 | fa_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; | |
3a2414fa | 100 | xfs_extnum_t nex; |
2bd0ea18 | 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 | ||
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; | |
5a35bf2c DC |
128 | xfs_fileoff_t bno; |
129 | xfs_fsblock_t dfsbno; | |
3a2414fa CB |
130 | xfs_extnum_t nb; |
131 | xfs_extnum_t nex; | |
2bd0ea18 | 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 | ||
156 | void | |
157 | fa_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 | ||
177 | void | |
178 | fa_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; | |
3a2414fa | 186 | xfs_extnum_t nex; |
2bd0ea18 | 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 | ||
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; | |
5a35bf2c DC |
213 | xfs_fileoff_t bno; |
214 | xfs_fsblock_t dfsbno; | |
3a2414fa CB |
215 | xfs_extnum_t nb; |
216 | xfs_extnum_t nex; | |
2bd0ea18 | 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 | ||
240 | void | |
241 | fa_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*/ | |
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; | |
14f8b681 | 267 | uint32_t bno; |
5a35bf2c | 268 | xfs_fsblock_t dfsbno; |
3a2414fa | 269 | xfs_extnum_t nex; |
2bd0ea18 | 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 | ||
294 | void | |
295 | fa_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*/ | |
313 | void | |
314 | fa_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*/ | |
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) { | |
9ee7055c | 341 | dbprintf(_("null inode number, cannot set new addr\n")); |
2bd0ea18 NS |
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; | |
2bd0ea18 NS |
354 | |
355 | ASSERT(next == TYP_INODE); | |
e9ff33f6 DW |
356 | ino = (xfs_ino_t)getbitval(obj, bit, bitize(XFS_INO32_SIZE), |
357 | BVUNSIGNED); | |
2bd0ea18 | 358 | if (ino == NULLFSINO) { |
9ee7055c | 359 | dbprintf(_("null inode number, cannot set new addr\n")); |
2bd0ea18 NS |
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; | |
2bd0ea18 NS |
372 | |
373 | ASSERT(next == TYP_INODE); | |
e9ff33f6 DW |
374 | ino = (xfs_ino_t)getbitval(obj, bit, bitize(XFS_INO64_SIZE), |
375 | BVUNSIGNED); | |
2bd0ea18 | 376 | if (ino == NULLFSINO) { |
9ee7055c | 377 | dbprintf(_("null inode number, cannot set new addr\n")); |
2bd0ea18 NS |
378 | return; |
379 | } | |
380 | set_cur_inode(ino); | |
381 | } |