ulfs_bmap.c revision 1.4.2.2 1 1.4.2.2 tls /* $NetBSD: ulfs_bmap.c,v 1.4.2.2 2013/06/23 06:18:39 tls Exp $ */
2 1.4.2.2 tls /* from NetBSD: ufs_bmap.c,v 1.50 2013/01/22 09:39:18 dholland Exp */
3 1.4.2.2 tls
4 1.4.2.2 tls /*
5 1.4.2.2 tls * Copyright (c) 1989, 1991, 1993
6 1.4.2.2 tls * The Regents of the University of California. All rights reserved.
7 1.4.2.2 tls * (c) UNIX System Laboratories, Inc.
8 1.4.2.2 tls * All or some portions of this file are derived from material licensed
9 1.4.2.2 tls * to the University of California by American Telephone and Telegraph
10 1.4.2.2 tls * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 1.4.2.2 tls * the permission of UNIX System Laboratories, Inc.
12 1.4.2.2 tls *
13 1.4.2.2 tls * Redistribution and use in source and binary forms, with or without
14 1.4.2.2 tls * modification, are permitted provided that the following conditions
15 1.4.2.2 tls * are met:
16 1.4.2.2 tls * 1. Redistributions of source code must retain the above copyright
17 1.4.2.2 tls * notice, this list of conditions and the following disclaimer.
18 1.4.2.2 tls * 2. Redistributions in binary form must reproduce the above copyright
19 1.4.2.2 tls * notice, this list of conditions and the following disclaimer in the
20 1.4.2.2 tls * documentation and/or other materials provided with the distribution.
21 1.4.2.2 tls * 3. Neither the name of the University nor the names of its contributors
22 1.4.2.2 tls * may be used to endorse or promote products derived from this software
23 1.4.2.2 tls * without specific prior written permission.
24 1.4.2.2 tls *
25 1.4.2.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.4.2.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.4.2.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.4.2.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.4.2.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.4.2.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.4.2.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.4.2.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.4.2.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.4.2.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.4.2.2 tls * SUCH DAMAGE.
36 1.4.2.2 tls *
37 1.4.2.2 tls * @(#)ufs_bmap.c 8.8 (Berkeley) 8/11/95
38 1.4.2.2 tls */
39 1.4.2.2 tls
40 1.4.2.2 tls #include <sys/cdefs.h>
41 1.4.2.2 tls __KERNEL_RCSID(0, "$NetBSD: ulfs_bmap.c,v 1.4.2.2 2013/06/23 06:18:39 tls Exp $");
42 1.4.2.2 tls
43 1.4.2.2 tls #include <sys/param.h>
44 1.4.2.2 tls #include <sys/systm.h>
45 1.4.2.2 tls #include <sys/stat.h>
46 1.4.2.2 tls #include <sys/buf.h>
47 1.4.2.2 tls #include <sys/proc.h>
48 1.4.2.2 tls #include <sys/vnode.h>
49 1.4.2.2 tls #include <sys/mount.h>
50 1.4.2.2 tls #include <sys/resourcevar.h>
51 1.4.2.2 tls #include <sys/trace.h>
52 1.4.2.2 tls #include <sys/fstrans.h>
53 1.4.2.2 tls
54 1.4.2.2 tls #include <miscfs/specfs/specdev.h>
55 1.4.2.2 tls
56 1.4.2.2 tls #include <ufs/lfs/ulfs_inode.h>
57 1.4.2.2 tls #include <ufs/lfs/ulfsmount.h>
58 1.4.2.2 tls #include <ufs/lfs/ulfs_extern.h>
59 1.4.2.2 tls #include <ufs/lfs/ulfs_bswap.h>
60 1.4.2.2 tls
61 1.4.2.2 tls static bool
62 1.4.2.2 tls ulfs_issequential(const struct ulfsmount *ump, daddr_t daddr0, daddr_t daddr1)
63 1.4.2.2 tls {
64 1.4.2.2 tls
65 1.4.2.2 tls /* for ulfs, blocks in a hole is not 'contiguous'. */
66 1.4.2.2 tls if (daddr0 == 0)
67 1.4.2.2 tls return false;
68 1.4.2.2 tls
69 1.4.2.2 tls return (daddr0 + ump->um_seqinc == daddr1);
70 1.4.2.2 tls }
71 1.4.2.2 tls
72 1.4.2.2 tls /*
73 1.4.2.2 tls * Bmap converts the logical block number of a file to its physical block
74 1.4.2.2 tls * number on the disk. The conversion is done by using the logical block
75 1.4.2.2 tls * number to index into the array of block pointers described by the dinode.
76 1.4.2.2 tls */
77 1.4.2.2 tls int
78 1.4.2.2 tls ulfs_bmap(void *v)
79 1.4.2.2 tls {
80 1.4.2.2 tls struct vop_bmap_args /* {
81 1.4.2.2 tls struct vnode *a_vp;
82 1.4.2.2 tls daddr_t a_bn;
83 1.4.2.2 tls struct vnode **a_vpp;
84 1.4.2.2 tls daddr_t *a_bnp;
85 1.4.2.2 tls int *a_runp;
86 1.4.2.2 tls } */ *ap = v;
87 1.4.2.2 tls int error;
88 1.4.2.2 tls
89 1.4.2.2 tls /*
90 1.4.2.2 tls * Check for underlying vnode requests and ensure that logical
91 1.4.2.2 tls * to physical mapping is requested.
92 1.4.2.2 tls */
93 1.4.2.2 tls if (ap->a_vpp != NULL)
94 1.4.2.2 tls *ap->a_vpp = VTOI(ap->a_vp)->i_devvp;
95 1.4.2.2 tls if (ap->a_bnp == NULL)
96 1.4.2.2 tls return (0);
97 1.4.2.2 tls
98 1.4.2.2 tls fstrans_start(ap->a_vp->v_mount, FSTRANS_SHARED);
99 1.4.2.2 tls error = ulfs_bmaparray(ap->a_vp, ap->a_bn, ap->a_bnp, NULL, NULL,
100 1.4.2.2 tls ap->a_runp, ulfs_issequential);
101 1.4.2.2 tls fstrans_done(ap->a_vp->v_mount);
102 1.4.2.2 tls return error;
103 1.4.2.2 tls }
104 1.4.2.2 tls
105 1.4.2.2 tls /*
106 1.4.2.2 tls * Indirect blocks are now on the vnode for the file. They are given negative
107 1.4.2.2 tls * logical block numbers. Indirect blocks are addressed by the negative
108 1.4.2.2 tls * address of the first data block to which they point. Double indirect blocks
109 1.4.2.2 tls * are addressed by one less than the address of the first indirect block to
110 1.4.2.2 tls * which they point. Triple indirect blocks are addressed by one less than
111 1.4.2.2 tls * the address of the first double indirect block to which they point.
112 1.4.2.2 tls *
113 1.4.2.2 tls * ulfs_bmaparray does the bmap conversion, and if requested returns the
114 1.4.2.2 tls * array of logical blocks which must be traversed to get to a block.
115 1.4.2.2 tls * Each entry contains the offset into that block that gets you to the
116 1.4.2.2 tls * next block and the disk address of the block (if it is assigned).
117 1.4.2.2 tls */
118 1.4.2.2 tls
119 1.4.2.2 tls int
120 1.4.2.2 tls ulfs_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, struct indir *ap,
121 1.4.2.2 tls int *nump, int *runp, ulfs_issequential_callback_t is_sequential)
122 1.4.2.2 tls {
123 1.4.2.2 tls struct inode *ip;
124 1.4.2.2 tls struct buf *bp, *cbp;
125 1.4.2.2 tls struct ulfsmount *ump;
126 1.4.2.2 tls struct mount *mp;
127 1.4.2.2 tls struct indir a[ULFS_NIADDR + 1], *xap;
128 1.4.2.2 tls daddr_t daddr;
129 1.4.2.2 tls daddr_t metalbn;
130 1.4.2.2 tls int error, maxrun = 0, num;
131 1.4.2.2 tls
132 1.4.2.2 tls ip = VTOI(vp);
133 1.4.2.2 tls mp = vp->v_mount;
134 1.4.2.2 tls ump = ip->i_ump;
135 1.4.2.2 tls #ifdef DIAGNOSTIC
136 1.4.2.2 tls if ((ap != NULL && nump == NULL) || (ap == NULL && nump != NULL))
137 1.4.2.2 tls panic("ulfs_bmaparray: invalid arguments");
138 1.4.2.2 tls #endif
139 1.4.2.2 tls
140 1.4.2.2 tls if (runp) {
141 1.4.2.2 tls /*
142 1.4.2.2 tls * XXX
143 1.4.2.2 tls * If MAXBSIZE is the largest transfer the disks can handle,
144 1.4.2.2 tls * we probably want maxrun to be 1 block less so that we
145 1.4.2.2 tls * don't create a block larger than the device can handle.
146 1.4.2.2 tls */
147 1.4.2.2 tls *runp = 0;
148 1.4.2.2 tls maxrun = MAXPHYS / mp->mnt_stat.f_iosize - 1;
149 1.4.2.2 tls }
150 1.4.2.2 tls
151 1.4.2.2 tls if (bn >= 0 && bn < ULFS_NDADDR) {
152 1.4.2.2 tls if (nump != NULL)
153 1.4.2.2 tls *nump = 0;
154 1.4.2.2 tls if (ump->um_fstype == ULFS1)
155 1.4.2.2 tls daddr = ulfs_rw32(ip->i_ffs1_db[bn],
156 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
157 1.4.2.2 tls else
158 1.4.2.2 tls daddr = ulfs_rw64(ip->i_ffs2_db[bn],
159 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
160 1.4.2.2 tls *bnp = blkptrtodb(ump, daddr);
161 1.4.2.2 tls /*
162 1.4.2.2 tls * Since this is FFS independent code, we are out of
163 1.4.2.2 tls * scope for the definitions of BLK_NOCOPY and
164 1.4.2.2 tls * BLK_SNAP, but we do know that they will fall in
165 1.4.2.2 tls * the range 1..um_seqinc, so we use that test and
166 1.4.2.2 tls * return a request for a zeroed out buffer if attempts
167 1.4.2.2 tls * are made to read a BLK_NOCOPY or BLK_SNAP block.
168 1.4.2.2 tls */
169 1.4.2.2 tls if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL)) == SF_SNAPSHOT
170 1.4.2.2 tls && daddr > 0 &&
171 1.4.2.2 tls daddr < ump->um_seqinc) {
172 1.4.2.2 tls *bnp = -1;
173 1.4.2.2 tls } else if (*bnp == 0) {
174 1.4.2.2 tls if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL))
175 1.4.2.2 tls == SF_SNAPSHOT) {
176 1.4.2.2 tls *bnp = blkptrtodb(ump, bn * ump->um_seqinc);
177 1.4.2.2 tls } else {
178 1.4.2.2 tls *bnp = -1;
179 1.4.2.2 tls }
180 1.4.2.2 tls } else if (runp) {
181 1.4.2.2 tls if (ump->um_fstype == ULFS1) {
182 1.4.2.2 tls for (++bn; bn < ULFS_NDADDR && *runp < maxrun &&
183 1.4.2.2 tls is_sequential(ump,
184 1.4.2.2 tls ulfs_rw32(ip->i_ffs1_db[bn - 1],
185 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)),
186 1.4.2.2 tls ulfs_rw32(ip->i_ffs1_db[bn],
187 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)));
188 1.4.2.2 tls ++bn, ++*runp);
189 1.4.2.2 tls } else {
190 1.4.2.2 tls for (++bn; bn < ULFS_NDADDR && *runp < maxrun &&
191 1.4.2.2 tls is_sequential(ump,
192 1.4.2.2 tls ulfs_rw64(ip->i_ffs2_db[bn - 1],
193 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)),
194 1.4.2.2 tls ulfs_rw64(ip->i_ffs2_db[bn],
195 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)));
196 1.4.2.2 tls ++bn, ++*runp);
197 1.4.2.2 tls }
198 1.4.2.2 tls }
199 1.4.2.2 tls return (0);
200 1.4.2.2 tls }
201 1.4.2.2 tls
202 1.4.2.2 tls xap = ap == NULL ? a : ap;
203 1.4.2.2 tls if (!nump)
204 1.4.2.2 tls nump = #
205 1.4.2.2 tls if ((error = ulfs_getlbns(vp, bn, xap, nump)) != 0)
206 1.4.2.2 tls return (error);
207 1.4.2.2 tls
208 1.4.2.2 tls num = *nump;
209 1.4.2.2 tls
210 1.4.2.2 tls /* Get disk address out of indirect block array */
211 1.4.2.2 tls if (ump->um_fstype == ULFS1)
212 1.4.2.2 tls daddr = ulfs_rw32(ip->i_ffs1_ib[xap->in_off],
213 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
214 1.4.2.2 tls else
215 1.4.2.2 tls daddr = ulfs_rw64(ip->i_ffs2_ib[xap->in_off],
216 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
217 1.4.2.2 tls
218 1.4.2.2 tls for (bp = NULL, ++xap; --num; ++xap) {
219 1.4.2.2 tls /*
220 1.4.2.2 tls * Exit the loop if there is no disk address assigned yet and
221 1.4.2.2 tls * the indirect block isn't in the cache, or if we were
222 1.4.2.2 tls * looking for an indirect block and we've found it.
223 1.4.2.2 tls */
224 1.4.2.2 tls
225 1.4.2.2 tls metalbn = xap->in_lbn;
226 1.4.2.2 tls if (metalbn == bn)
227 1.4.2.2 tls break;
228 1.4.2.2 tls if (daddr == 0) {
229 1.4.2.2 tls mutex_enter(&bufcache_lock);
230 1.4.2.2 tls cbp = incore(vp, metalbn);
231 1.4.2.2 tls mutex_exit(&bufcache_lock);
232 1.4.2.2 tls if (cbp == NULL)
233 1.4.2.2 tls break;
234 1.4.2.2 tls }
235 1.4.2.2 tls
236 1.4.2.2 tls /*
237 1.4.2.2 tls * If we get here, we've either got the block in the cache
238 1.4.2.2 tls * or we have a disk address for it, go fetch it.
239 1.4.2.2 tls */
240 1.4.2.2 tls if (bp)
241 1.4.2.2 tls brelse(bp, 0);
242 1.4.2.2 tls
243 1.4.2.2 tls xap->in_exists = 1;
244 1.4.2.2 tls bp = getblk(vp, metalbn, mp->mnt_stat.f_iosize, 0, 0);
245 1.4.2.2 tls if (bp == NULL) {
246 1.4.2.2 tls
247 1.4.2.2 tls /*
248 1.4.2.2 tls * getblk() above returns NULL only iff we are
249 1.4.2.2 tls * pagedaemon. See the implementation of getblk
250 1.4.2.2 tls * for detail.
251 1.4.2.2 tls */
252 1.4.2.2 tls
253 1.4.2.2 tls return (ENOMEM);
254 1.4.2.2 tls }
255 1.4.2.2 tls if (bp->b_oflags & (BO_DONE | BO_DELWRI)) {
256 1.4.2.2 tls trace(TR_BREADHIT, pack(vp, size), metalbn);
257 1.4.2.2 tls }
258 1.4.2.2 tls #ifdef DIAGNOSTIC
259 1.4.2.2 tls else if (!daddr)
260 1.4.2.2 tls panic("ulfs_bmaparray: indirect block not in cache");
261 1.4.2.2 tls #endif
262 1.4.2.2 tls else {
263 1.4.2.2 tls trace(TR_BREADMISS, pack(vp, size), metalbn);
264 1.4.2.2 tls bp->b_blkno = blkptrtodb(ump, daddr);
265 1.4.2.2 tls bp->b_flags |= B_READ;
266 1.4.2.2 tls BIO_SETPRIO(bp, BPRIO_TIMECRITICAL);
267 1.4.2.2 tls VOP_STRATEGY(vp, bp);
268 1.4.2.2 tls curlwp->l_ru.ru_inblock++; /* XXX */
269 1.4.2.2 tls if ((error = biowait(bp)) != 0) {
270 1.4.2.2 tls brelse(bp, 0);
271 1.4.2.2 tls return (error);
272 1.4.2.2 tls }
273 1.4.2.2 tls }
274 1.4.2.2 tls if (ump->um_fstype == ULFS1) {
275 1.4.2.2 tls daddr = ulfs_rw32(((u_int32_t *)bp->b_data)[xap->in_off],
276 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
277 1.4.2.2 tls if (num == 1 && daddr && runp) {
278 1.4.2.2 tls for (bn = xap->in_off + 1;
279 1.4.2.2 tls bn < MNINDIR(ump) && *runp < maxrun &&
280 1.4.2.2 tls is_sequential(ump,
281 1.4.2.2 tls ulfs_rw32(((int32_t *)bp->b_data)[bn-1],
282 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)),
283 1.4.2.2 tls ulfs_rw32(((int32_t *)bp->b_data)[bn],
284 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)));
285 1.4.2.2 tls ++bn, ++*runp);
286 1.4.2.2 tls }
287 1.4.2.2 tls } else {
288 1.4.2.2 tls daddr = ulfs_rw64(((u_int64_t *)bp->b_data)[xap->in_off],
289 1.4.2.2 tls ULFS_MPNEEDSWAP(ump));
290 1.4.2.2 tls if (num == 1 && daddr && runp) {
291 1.4.2.2 tls for (bn = xap->in_off + 1;
292 1.4.2.2 tls bn < MNINDIR(ump) && *runp < maxrun &&
293 1.4.2.2 tls is_sequential(ump,
294 1.4.2.2 tls ulfs_rw64(((int64_t *)bp->b_data)[bn-1],
295 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)),
296 1.4.2.2 tls ulfs_rw64(((int64_t *)bp->b_data)[bn],
297 1.4.2.2 tls ULFS_MPNEEDSWAP(ump)));
298 1.4.2.2 tls ++bn, ++*runp);
299 1.4.2.2 tls }
300 1.4.2.2 tls }
301 1.4.2.2 tls }
302 1.4.2.2 tls if (bp)
303 1.4.2.2 tls brelse(bp, 0);
304 1.4.2.2 tls
305 1.4.2.2 tls /*
306 1.4.2.2 tls * Since this is FFS independent code, we are out of scope for the
307 1.4.2.2 tls * definitions of BLK_NOCOPY and BLK_SNAP, but we do know that they
308 1.4.2.2 tls * will fall in the range 1..um_seqinc, so we use that test and
309 1.4.2.2 tls * return a request for a zeroed out buffer if attempts are made
310 1.4.2.2 tls * to read a BLK_NOCOPY or BLK_SNAP block.
311 1.4.2.2 tls */
312 1.4.2.2 tls if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL)) == SF_SNAPSHOT
313 1.4.2.2 tls && daddr > 0 && daddr < ump->um_seqinc) {
314 1.4.2.2 tls *bnp = -1;
315 1.4.2.2 tls return (0);
316 1.4.2.2 tls }
317 1.4.2.2 tls *bnp = blkptrtodb(ump, daddr);
318 1.4.2.2 tls if (*bnp == 0) {
319 1.4.2.2 tls if ((ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL))
320 1.4.2.2 tls == SF_SNAPSHOT) {
321 1.4.2.2 tls *bnp = blkptrtodb(ump, bn * ump->um_seqinc);
322 1.4.2.2 tls } else {
323 1.4.2.2 tls *bnp = -1;
324 1.4.2.2 tls }
325 1.4.2.2 tls }
326 1.4.2.2 tls return (0);
327 1.4.2.2 tls }
328 1.4.2.2 tls
329 1.4.2.2 tls /*
330 1.4.2.2 tls * Create an array of logical block number/offset pairs which represent the
331 1.4.2.2 tls * path of indirect blocks required to access a data block. The first "pair"
332 1.4.2.2 tls * contains the logical block number of the appropriate single, double or
333 1.4.2.2 tls * triple indirect block and the offset into the inode indirect block array.
334 1.4.2.2 tls * Note, the logical block number of the inode single/double/triple indirect
335 1.4.2.2 tls * block appears twice in the array, once with the offset into the i_ffs1_ib and
336 1.4.2.2 tls * once with the offset into the page itself.
337 1.4.2.2 tls */
338 1.4.2.2 tls int
339 1.4.2.2 tls ulfs_getlbns(struct vnode *vp, daddr_t bn, struct indir *ap, int *nump)
340 1.4.2.2 tls {
341 1.4.2.2 tls daddr_t metalbn, realbn;
342 1.4.2.2 tls struct ulfsmount *ump;
343 1.4.2.2 tls int64_t blockcnt;
344 1.4.2.2 tls int lbc;
345 1.4.2.2 tls int i, numlevels, off;
346 1.4.2.2 tls
347 1.4.2.2 tls ump = VFSTOULFS(vp->v_mount);
348 1.4.2.2 tls if (nump)
349 1.4.2.2 tls *nump = 0;
350 1.4.2.2 tls numlevels = 0;
351 1.4.2.2 tls realbn = bn;
352 1.4.2.2 tls if (bn < 0)
353 1.4.2.2 tls bn = -bn;
354 1.4.2.2 tls KASSERT(bn >= ULFS_NDADDR);
355 1.4.2.2 tls
356 1.4.2.2 tls /*
357 1.4.2.2 tls * Determine the number of levels of indirection. After this loop
358 1.4.2.2 tls * is done, blockcnt indicates the number of data blocks possible
359 1.4.2.2 tls * at the given level of indirection, and ULFS_NIADDR - i is the number
360 1.4.2.2 tls * of levels of indirection needed to locate the requested block.
361 1.4.2.2 tls */
362 1.4.2.2 tls
363 1.4.2.2 tls bn -= ULFS_NDADDR;
364 1.4.2.2 tls for (lbc = 0, i = ULFS_NIADDR;; i--, bn -= blockcnt) {
365 1.4.2.2 tls if (i == 0)
366 1.4.2.2 tls return (EFBIG);
367 1.4.2.2 tls
368 1.4.2.2 tls lbc += ump->um_lognindir;
369 1.4.2.2 tls blockcnt = (int64_t)1 << lbc;
370 1.4.2.2 tls
371 1.4.2.2 tls if (bn < blockcnt)
372 1.4.2.2 tls break;
373 1.4.2.2 tls }
374 1.4.2.2 tls
375 1.4.2.2 tls /* Calculate the address of the first meta-block. */
376 1.4.2.2 tls metalbn = -((realbn >= 0 ? realbn : -realbn) - bn + ULFS_NIADDR - i);
377 1.4.2.2 tls
378 1.4.2.2 tls /*
379 1.4.2.2 tls * At each iteration, off is the offset into the bap array which is
380 1.4.2.2 tls * an array of disk addresses at the current level of indirection.
381 1.4.2.2 tls * The logical block number and the offset in that block are stored
382 1.4.2.2 tls * into the argument array.
383 1.4.2.2 tls */
384 1.4.2.2 tls ap->in_lbn = metalbn;
385 1.4.2.2 tls ap->in_off = off = ULFS_NIADDR - i;
386 1.4.2.2 tls ap->in_exists = 0;
387 1.4.2.2 tls ap++;
388 1.4.2.2 tls for (++numlevels; i <= ULFS_NIADDR; i++) {
389 1.4.2.2 tls /* If searching for a meta-data block, quit when found. */
390 1.4.2.2 tls if (metalbn == realbn)
391 1.4.2.2 tls break;
392 1.4.2.2 tls
393 1.4.2.2 tls lbc -= ump->um_lognindir;
394 1.4.2.2 tls off = (bn >> lbc) & (MNINDIR(ump) - 1);
395 1.4.2.2 tls
396 1.4.2.2 tls ++numlevels;
397 1.4.2.2 tls ap->in_lbn = metalbn;
398 1.4.2.2 tls ap->in_off = off;
399 1.4.2.2 tls ap->in_exists = 0;
400 1.4.2.2 tls ++ap;
401 1.4.2.2 tls
402 1.4.2.2 tls metalbn -= -1 + ((int64_t)off << lbc);
403 1.4.2.2 tls }
404 1.4.2.2 tls if (nump)
405 1.4.2.2 tls *nump = numlevels;
406 1.4.2.2 tls return (0);
407 1.4.2.2 tls }
408