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