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