]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/faddr.c
Update copyright dates (again)
[thirdparty/xfsprogs-dev.git] / db / faddr.c
1 /*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "data.h"
35 #include "type.h"
36 #include "faddr.h"
37 #include "inode.h"
38 #include "io.h"
39 #include "bit.h"
40 #include "bmap.h"
41 #include "output.h"
42 #include "mount.h"
43
44 void
45 fa_agblock(
46 void *obj,
47 int bit,
48 typnm_t next)
49 {
50 xfs_agblock_t bno;
51
52 if (cur_agno == NULLAGNUMBER) {
53 dbprintf("no current allocation group, cannot set new addr\n");
54 return;
55 }
56 bno = (xfs_agblock_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
57 if (bno == NULLAGBLOCK) {
58 dbprintf("null block number, cannot set new addr\n");
59 return;
60 }
61 ASSERT(typtab[next].typnm == next);
62 set_cur(&typtab[next], XFS_AGB_TO_DADDR(mp, cur_agno, bno), blkbb,
63 DB_RING_ADD, NULL);
64 }
65
66 /*ARGSUSED*/
67 void
68 fa_agino(
69 void *obj,
70 int bit,
71 typnm_t next)
72 {
73 xfs_agino_t agino;
74
75 if (cur_agno == NULLAGNUMBER) {
76 dbprintf("no current allocation group, cannot set new addr\n");
77 return;
78 }
79 agino = (xfs_agino_t)getbitval(obj, bit, bitsz(agino), BVUNSIGNED);
80 if (agino == NULLAGINO) {
81 dbprintf("null inode number, cannot set new addr\n");
82 return;
83 }
84 set_cur_inode(XFS_AGINO_TO_INO(mp, cur_agno, agino));
85 }
86
87 /*ARGSUSED*/
88 void
89 fa_attrblock(
90 void *obj,
91 int bit,
92 typnm_t next)
93 {
94 bmap_ext_t bm;
95 __uint32_t bno;
96 xfs_dfsbno_t dfsbno;
97 int nex;
98
99 bno = (__uint32_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
100 if (bno == 0) {
101 dbprintf("null attribute block number, cannot set new addr\n");
102 return;
103 }
104 nex = 1;
105 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
106 if (nex == 0) {
107 dbprintf("attribute block is unmapped\n");
108 return;
109 }
110 dfsbno = bm.startblock + (bno - bm.startoff);
111 ASSERT(typtab[next].typnm == next);
112 set_cur(&typtab[next], (__int64_t)XFS_FSB_TO_DADDR(mp, dfsbno), blkbb,
113 DB_RING_ADD, NULL);
114 }
115
116 void
117 fa_cfileoffa(
118 void *obj,
119 int bit,
120 typnm_t next)
121 {
122 bmap_ext_t bm;
123 xfs_dfiloff_t bno;
124 xfs_dfsbno_t dfsbno;
125 int nex;
126
127 bno = (xfs_dfiloff_t)getbitval(obj, bit, BMBT_STARTOFF_BITLEN,
128 BVUNSIGNED);
129 if (bno == NULLDFILOFF) {
130 dbprintf("null block number, cannot set new addr\n");
131 return;
132 }
133 nex = 1;
134 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
135 if (nex == 0) {
136 dbprintf("file block is unmapped\n");
137 return;
138 }
139 dfsbno = bm.startblock + (bno - bm.startoff);
140 ASSERT(typtab[next].typnm == next);
141 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), blkbb, DB_RING_ADD,
142 NULL);
143 }
144
145 void
146 fa_cfileoffd(
147 void *obj,
148 int bit,
149 typnm_t next)
150 {
151 bbmap_t bbmap;
152 bmap_ext_t *bmp;
153 xfs_dfiloff_t bno;
154 xfs_dfsbno_t dfsbno;
155 int nb;
156 int nex;
157
158 bno = (xfs_dfiloff_t)getbitval(obj, bit, BMBT_STARTOFF_BITLEN,
159 BVUNSIGNED);
160 if (bno == NULLDFILOFF) {
161 dbprintf("null block number, cannot set new addr\n");
162 return;
163 }
164 nex = nb = next == TYP_DIR2 ? mp->m_dirblkfsbs : 1;
165 bmp = malloc(nb * sizeof(*bmp));
166 bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
167 if (nex == 0) {
168 dbprintf("file block is unmapped\n");
169 free(bmp);
170 return;
171 }
172 dfsbno = bmp->startblock + (bno - bmp->startoff);
173 ASSERT(typtab[next].typnm == next);
174 if (nex > 1)
175 make_bbmap(&bbmap, nex, bmp);
176 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), nb * blkbb,
177 DB_RING_ADD, nex > 1 ? &bbmap: NULL);
178 free(bmp);
179 }
180
181 void
182 fa_cfsblock(
183 void *obj,
184 int bit,
185 typnm_t next)
186 {
187 xfs_dfsbno_t bno;
188
189 bno = (xfs_dfsbno_t)getbitval(obj, bit, BMBT_STARTBLOCK_BITLEN,
190 BVUNSIGNED);
191 if (bno == NULLDFSBNO) {
192 dbprintf("null block number, cannot set new addr\n");
193 return;
194 }
195 ASSERT(typtab[next].typnm == next);
196 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, bno), blkbb, DB_RING_ADD,
197 NULL);
198 }
199
200 void
201 fa_dfiloffa(
202 void *obj,
203 int bit,
204 typnm_t next)
205 {
206 bmap_ext_t bm;
207 xfs_dfiloff_t bno;
208 xfs_dfsbno_t dfsbno;
209 int nex;
210
211 bno = (xfs_dfiloff_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
212 if (bno == NULLDFILOFF) {
213 dbprintf("null block number, cannot set new addr\n");
214 return;
215 }
216 nex = 1;
217 bmap(bno, 1, XFS_ATTR_FORK, &nex, &bm);
218 if (nex == 0) {
219 dbprintf("file block is unmapped\n");
220 return;
221 }
222 dfsbno = bm.startblock + (bno - bm.startoff);
223 ASSERT(typtab[next].typnm == next);
224 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), blkbb, DB_RING_ADD,
225 NULL);
226 }
227
228 void
229 fa_dfiloffd(
230 void *obj,
231 int bit,
232 typnm_t next)
233 {
234 bbmap_t bbmap;
235 bmap_ext_t *bmp;
236 xfs_dfiloff_t bno;
237 xfs_dfsbno_t dfsbno;
238 int nb;
239 int nex;
240
241 bno = (xfs_dfiloff_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
242 if (bno == NULLDFILOFF) {
243 dbprintf("null block number, cannot set new addr\n");
244 return;
245 }
246 nex = nb = next == TYP_DIR2 ? mp->m_dirblkfsbs : 1;
247 bmp = malloc(nb * sizeof(*bmp));
248 bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
249 if (nex == 0) {
250 dbprintf("file block is unmapped\n");
251 free(bmp);
252 return;
253 }
254 dfsbno = bmp->startblock + (bno - bmp->startoff);
255 ASSERT(typtab[next].typnm == next);
256 if (nex > 1)
257 make_bbmap(&bbmap, nex, bmp);
258 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, dfsbno), nb * blkbb,
259 DB_RING_ADD, nex > 1 ? &bbmap : NULL);
260 free(bmp);
261 }
262
263 void
264 fa_dfsbno(
265 void *obj,
266 int bit,
267 typnm_t next)
268 {
269 xfs_dfsbno_t bno;
270
271 bno = (xfs_dfsbno_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
272 if (bno == NULLDFSBNO) {
273 dbprintf("null block number, cannot set new addr\n");
274 return;
275 }
276 ASSERT(typtab[next].typnm == next);
277 set_cur(&typtab[next], XFS_FSB_TO_DADDR(mp, bno), blkbb, DB_RING_ADD,
278 NULL);
279 }
280
281 /*ARGSUSED*/
282 void
283 fa_dirblock(
284 void *obj,
285 int bit,
286 typnm_t next)
287 {
288 bbmap_t bbmap;
289 bmap_ext_t *bmp;
290 __uint32_t bno;
291 xfs_dfsbno_t dfsbno;
292 int nex;
293
294 bno = (__uint32_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
295 if (bno == 0) {
296 dbprintf("null directory block number, cannot set new addr\n");
297 return;
298 }
299 nex = mp->m_dirblkfsbs;
300 bmp = malloc(nex * sizeof(*bmp));
301 bmap(bno, mp->m_dirblkfsbs, XFS_DATA_FORK, &nex, bmp);
302 if (nex == 0) {
303 dbprintf("directory block is unmapped\n");
304 free(bmp);
305 return;
306 }
307 dfsbno = bmp->startblock + (bno - bmp->startoff);
308 ASSERT(typtab[next].typnm == next);
309 if (nex > 1)
310 make_bbmap(&bbmap, nex, bmp);
311 set_cur(&typtab[next], (__int64_t)XFS_FSB_TO_DADDR(mp, dfsbno),
312 (int)XFS_FSB_TO_DADDR(mp, mp->m_dirblkfsbs), DB_RING_ADD,
313 nex > 1 ? &bbmap : NULL);
314 free(bmp);
315 }
316
317 void
318 fa_drfsbno(
319 void *obj,
320 int bit,
321 typnm_t next)
322 {
323 xfs_drfsbno_t bno;
324
325 bno = (xfs_drfsbno_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
326 if (bno == NULLDRFSBNO) {
327 dbprintf("null block number, cannot set new addr\n");
328 return;
329 }
330 ASSERT(typtab[next].typnm == next);
331 set_cur(&typtab[next], (__int64_t)XFS_FSB_TO_BB(mp, bno), blkbb,
332 DB_RING_ADD, NULL);
333 }
334
335 /*ARGSUSED*/
336 void
337 fa_drtbno(
338 void *obj,
339 int bit,
340 typnm_t next)
341 {
342 xfs_drtbno_t bno;
343
344 bno = (xfs_drtbno_t)getbitval(obj, bit, bitsz(bno), BVUNSIGNED);
345 if (bno == NULLDRTBNO) {
346 dbprintf("null block number, cannot set new addr\n");
347 return;
348 }
349 /* need set_cur to understand rt subvolume */
350 }
351
352 /*ARGSUSED*/
353 void
354 fa_ino(
355 void *obj,
356 int bit,
357 typnm_t next)
358 {
359 xfs_ino_t ino;
360
361 ASSERT(next == TYP_INODE);
362 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino), BVUNSIGNED);
363 if (ino == NULLFSINO) {
364 dbprintf("null inode number, cannot set new addr\n");
365 return;
366 }
367 set_cur_inode(ino);
368 }
369
370 void
371 fa_ino4(
372 void *obj,
373 int bit,
374 typnm_t next)
375 {
376 xfs_ino_t ino;
377 xfs_dir2_ino4_t ino4;
378
379 ASSERT(next == TYP_INODE);
380 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino4), BVUNSIGNED);
381 if (ino == NULLFSINO) {
382 dbprintf("null inode number, cannot set new addr\n");
383 return;
384 }
385 set_cur_inode(ino);
386 }
387
388 void
389 fa_ino8(
390 void *obj,
391 int bit,
392 typnm_t next)
393 {
394 xfs_ino_t ino;
395 xfs_dir2_ino8_t ino8;
396
397 ASSERT(next == TYP_INODE);
398 ino = (xfs_ino_t)getbitval(obj, bit, bitsz(ino8), BVUNSIGNED);
399 if (ino == NULLFSINO) {
400 dbprintf("null inode number, cannot set new addr\n");
401 return;
402 }
403 set_cur_inode(ino);
404 }