Deleted Added
full compact
ext2_bmap.c (96572) ext2_bmap.c (96596)
1/*
2 * Copyright (c) 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)ufs_bmap.c 8.7 (Berkeley) 3/21/95
1/*
2 * Copyright (c) 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)ufs_bmap.c 8.7 (Berkeley) 3/21/95
39 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_bmap.c 96572 2002-05-14 11:09:43Z phk $
39 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_bmap.c 96596 2002-05-14 17:14:01Z iedowse $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bio.h>
45#include <sys/buf.h>
46#include <sys/proc.h>
47#include <sys/vnode.h>
48#include <sys/mount.h>
49#include <sys/resourcevar.h>
50#include <sys/stat.h>
51
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bio.h>
45#include <sys/buf.h>
46#include <sys/proc.h>
47#include <sys/vnode.h>
48#include <sys/mount.h>
49#include <sys/resourcevar.h>
50#include <sys/stat.h>
51
52#include <ufs/ufs/extattr.h>
53#include <ufs/ufs/quota.h>
54#include <ufs/ufs/inode.h>
55#include <ufs/ufs/ufsmount.h>
56#include <ufs/ufs/ufs_extern.h>
52#include <gnu/ext2fs/inode.h>
53#include <gnu/ext2fs/ext2_mount.h>
54#include <gnu/ext2fs/ext2_extern.h>
57
58/*
59 * Bmap converts a the logical block number of a file to its physical block
60 * number on the disk. The conversion is done by using the logical block
61 * number to index into the array of block pointers described by the dinode.
62 */
63int
55
56/*
57 * Bmap converts a the logical block number of a file to its physical block
58 * number on the disk. The conversion is done by using the logical block
59 * number to index into the array of block pointers described by the dinode.
60 */
61int
64ufs_bmap(ap)
62ext2_bmap(ap)
65 struct vop_bmap_args /* {
66 struct vnode *a_vp;
67 daddr_t a_bn;
68 struct vnode **a_vpp;
69 daddr_t *a_bnp;
70 int *a_runp;
71 int *a_runb;
72 } */ *ap;
73{
74 daddr_t blkno;
75 int error;
76
77 /*
78 * Check for underlying vnode requests and ensure that logical
79 * to physical mapping is requested.
80 */
81 if (ap->a_vpp != NULL)
82 *ap->a_vpp = VTOI(ap->a_vp)->i_devvp;
83 if (ap->a_bnp == NULL)
84 return (0);
85
63 struct vop_bmap_args /* {
64 struct vnode *a_vp;
65 daddr_t a_bn;
66 struct vnode **a_vpp;
67 daddr_t *a_bnp;
68 int *a_runp;
69 int *a_runb;
70 } */ *ap;
71{
72 daddr_t blkno;
73 int error;
74
75 /*
76 * Check for underlying vnode requests and ensure that logical
77 * to physical mapping is requested.
78 */
79 if (ap->a_vpp != NULL)
80 *ap->a_vpp = VTOI(ap->a_vp)->i_devvp;
81 if (ap->a_bnp == NULL)
82 return (0);
83
86 error = ufs_bmaparray(ap->a_vp, ap->a_bn, &blkno,
84 error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno,
87 ap->a_runp, ap->a_runb);
88 *ap->a_bnp = blkno;
89 return (error);
90}
91
92/*
93 * Indirect blocks are now on the vnode for the file. They are given negative
94 * logical block numbers. Indirect blocks are addressed by the negative
95 * address of the first data block to which they point. Double indirect blocks
96 * are addressed by one less than the address of the first indirect block to
97 * which they point. Triple indirect blocks are addressed by one less than
98 * the address of the first double indirect block to which they point.
99 *
100 * ufs_bmaparray does the bmap conversion, and if requested returns the
101 * array of logical blocks which must be traversed to get to a block.
102 * Each entry contains the offset into that block that gets you to the
103 * next block and the disk address of the block (if it is assigned).
104 */
105
106int
85 ap->a_runp, ap->a_runb);
86 *ap->a_bnp = blkno;
87 return (error);
88}
89
90/*
91 * Indirect blocks are now on the vnode for the file. They are given negative
92 * logical block numbers. Indirect blocks are addressed by the negative
93 * address of the first data block to which they point. Double indirect blocks
94 * are addressed by one less than the address of the first indirect block to
95 * which they point. Triple indirect blocks are addressed by one less than
96 * the address of the first double indirect block to which they point.
97 *
98 * ufs_bmaparray does the bmap conversion, and if requested returns the
99 * array of logical blocks which must be traversed to get to a block.
100 * Each entry contains the offset into that block that gets you to the
101 * next block and the disk address of the block (if it is assigned).
102 */
103
104int
107ufs_bmaparray(vp, bn, bnp, runp, runb)
105ext2_bmaparray(vp, bn, bnp, runp, runb)
108 struct vnode *vp;
106 struct vnode *vp;
109 ufs_daddr_t bn;
110 ufs_daddr_t *bnp;
107 daddr_t bn;
108 daddr_t *bnp;
111 int *runp;
112 int *runb;
113{
114 struct inode *ip;
115 struct buf *bp;
109 int *runp;
110 int *runb;
111{
112 struct inode *ip;
113 struct buf *bp;
116 struct ufsmount *ump;
114 struct ext2mount *ump;
117 struct mount *mp;
118 struct vnode *devvp;
119 struct indir a[NIADDR+1], *ap;
115 struct mount *mp;
116 struct vnode *devvp;
117 struct indir a[NIADDR+1], *ap;
120 ufs_daddr_t daddr;
118 daddr_t daddr;
121 long metalbn;
122 int error, num, maxrun = 0;
123 int *nump;
124
125 ap = NULL;
126 ip = VTOI(vp);
127 mp = vp->v_mount;
119 long metalbn;
120 int error, num, maxrun = 0;
121 int *nump;
122
123 ap = NULL;
124 ip = VTOI(vp);
125 mp = vp->v_mount;
128 ump = VFSTOUFS(mp);
126 ump = VFSTOEXT2(mp);
129 devvp = ump->um_devvp;
130
131 if (runp) {
132 maxrun = mp->mnt_iosize_max / mp->mnt_stat.f_iosize - 1;
133 *runp = 0;
134 }
135
136 if (runb) {
137 *runb = 0;
138 }
139
140
141 ap = a;
142 nump = &num;
127 devvp = ump->um_devvp;
128
129 if (runp) {
130 maxrun = mp->mnt_iosize_max / mp->mnt_stat.f_iosize - 1;
131 *runp = 0;
132 }
133
134 if (runb) {
135 *runb = 0;
136 }
137
138
139 ap = a;
140 nump = &num;
143 error = ufs_getlbns(vp, bn, ap, nump);
141 error = ext2_getlbns(vp, bn, ap, nump);
144 if (error)
145 return (error);
146
147 num = *nump;
148 if (num == 0) {
149 *bnp = blkptrtodb(ump, ip->i_db[bn]);
142 if (error)
143 return (error);
144
145 num = *nump;
146 if (num == 0) {
147 *bnp = blkptrtodb(ump, ip->i_db[bn]);
150 /*
151 * Since this is FFS independent code, we are out of
152 * scope for the definitions of BLK_NOCOPY and
153 * BLK_SNAP, but we do know that they will fall in
154 * the range 1..um_seqinc, so we use that test and
155 * return a request for a zeroed out buffer if attempts
156 * are made to read a BLK_NOCOPY or BLK_SNAP block.
157 */
158 if ((ip->i_flags & SF_SNAPSHOT) &&
159 ip->i_db[bn] > 0 && ip->i_db[bn] < ump->um_seqinc) {
148 if (*bnp == 0) {
160 *bnp = -1;
149 *bnp = -1;
161 } else if (*bnp == 0) {
162 if (ip->i_flags & SF_SNAPSHOT)
163 *bnp = blkptrtodb(ump, bn * ump->um_seqinc);
164 else
165 *bnp = -1;
166 } else if (runp) {
167 daddr_t bnb = bn;
168 for (++bn; bn < NDADDR && *runp < maxrun &&
169 is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]);
170 ++bn, ++*runp);
171 bn = bnb;
172 if (runb && (bn > 0)) {
173 for (--bn; (bn >= 0) && (*runb < maxrun) &&
174 is_sequential(ump, ip->i_db[bn],
175 ip->i_db[bn+1]);
176 --bn, ++*runb);
177 }
178 }
179 return (0);
180 }
181
182
183 /* Get disk address out of indirect block array */
184 daddr = ip->i_ib[ap->in_off];
185
186 for (bp = NULL, ++ap; --num; ++ap) {
187 /*
188 * Exit the loop if there is no disk address assigned yet and
189 * the indirect block isn't in the cache, or if we were
190 * looking for an indirect block and we've found it.
191 */
192
193 metalbn = ap->in_lbn;
194 if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn)
195 break;
196 /*
197 * If we get here, we've either got the block in the cache
198 * or we have a disk address for it, go fetch it.
199 */
200 if (bp)
201 bqrelse(bp);
202
203 ap->in_exists = 1;
204 bp = getblk(vp, metalbn, mp->mnt_stat.f_iosize, 0, 0);
205 if ((bp->b_flags & B_CACHE) == 0) {
206#ifdef DIAGNOSTIC
207 if (!daddr)
208 panic("ufs_bmaparray: indirect block not in cache");
209#endif
210 bp->b_blkno = blkptrtodb(ump, daddr);
211 bp->b_iocmd = BIO_READ;
212 bp->b_flags &= ~B_INVAL;
213 bp->b_ioflags &= ~BIO_ERROR;
214 vfs_busy_pages(bp, 0);
215 BUF_STRATEGY(bp);
216 curproc->p_stats->p_ru.ru_inblock++; /* XXX */
217 error = bufwait(bp);
218 if (error) {
219 brelse(bp);
220 return (error);
221 }
222 }
223
150 } else if (runp) {
151 daddr_t bnb = bn;
152 for (++bn; bn < NDADDR && *runp < maxrun &&
153 is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]);
154 ++bn, ++*runp);
155 bn = bnb;
156 if (runb && (bn > 0)) {
157 for (--bn; (bn >= 0) && (*runb < maxrun) &&
158 is_sequential(ump, ip->i_db[bn],
159 ip->i_db[bn+1]);
160 --bn, ++*runb);
161 }
162 }
163 return (0);
164 }
165
166
167 /* Get disk address out of indirect block array */
168 daddr = ip->i_ib[ap->in_off];
169
170 for (bp = NULL, ++ap; --num; ++ap) {
171 /*
172 * Exit the loop if there is no disk address assigned yet and
173 * the indirect block isn't in the cache, or if we were
174 * looking for an indirect block and we've found it.
175 */
176
177 metalbn = ap->in_lbn;
178 if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn)
179 break;
180 /*
181 * If we get here, we've either got the block in the cache
182 * or we have a disk address for it, go fetch it.
183 */
184 if (bp)
185 bqrelse(bp);
186
187 ap->in_exists = 1;
188 bp = getblk(vp, metalbn, mp->mnt_stat.f_iosize, 0, 0);
189 if ((bp->b_flags & B_CACHE) == 0) {
190#ifdef DIAGNOSTIC
191 if (!daddr)
192 panic("ufs_bmaparray: indirect block not in cache");
193#endif
194 bp->b_blkno = blkptrtodb(ump, daddr);
195 bp->b_iocmd = BIO_READ;
196 bp->b_flags &= ~B_INVAL;
197 bp->b_ioflags &= ~BIO_ERROR;
198 vfs_busy_pages(bp, 0);
199 BUF_STRATEGY(bp);
200 curproc->p_stats->p_ru.ru_inblock++; /* XXX */
201 error = bufwait(bp);
202 if (error) {
203 brelse(bp);
204 return (error);
205 }
206 }
207
224 daddr = ((ufs_daddr_t *)bp->b_data)[ap->in_off];
208 daddr = ((daddr_t *)bp->b_data)[ap->in_off];
225 if (num == 1 && daddr && runp) {
226 for (bn = ap->in_off + 1;
227 bn < MNINDIR(ump) && *runp < maxrun &&
228 is_sequential(ump,
209 if (num == 1 && daddr && runp) {
210 for (bn = ap->in_off + 1;
211 bn < MNINDIR(ump) && *runp < maxrun &&
212 is_sequential(ump,
229 ((ufs_daddr_t *)bp->b_data)[bn - 1],
230 ((ufs_daddr_t *)bp->b_data)[bn]);
213 ((daddr_t *)bp->b_data)[bn - 1],
214 ((daddr_t *)bp->b_data)[bn]);
231 ++bn, ++*runp);
232 bn = ap->in_off;
233 if (runb && bn) {
234 for(--bn; bn >= 0 && *runb < maxrun &&
235 is_sequential(ump, ((daddr_t *)bp->b_data)[bn],
236 ((daddr_t *)bp->b_data)[bn+1]);
237 --bn, ++*runb);
238 }
239 }
240 }
241 if (bp)
242 bqrelse(bp);
243
244 /*
245 * Since this is FFS independent code, we are out of scope for the
246 * definitions of BLK_NOCOPY and BLK_SNAP, but we do know that they
247 * will fall in the range 1..um_seqinc, so we use that test and
248 * return a request for a zeroed out buffer if attempts are made
249 * to read a BLK_NOCOPY or BLK_SNAP block.
250 */
251 if ((ip->i_flags & SF_SNAPSHOT) && daddr > 0 && daddr < ump->um_seqinc){
252 *bnp = -1;
253 return (0);
254 }
255 *bnp = blkptrtodb(ump, daddr);
256 if (*bnp == 0) {
215 ++bn, ++*runp);
216 bn = ap->in_off;
217 if (runb && bn) {
218 for(--bn; bn >= 0 && *runb < maxrun &&
219 is_sequential(ump, ((daddr_t *)bp->b_data)[bn],
220 ((daddr_t *)bp->b_data)[bn+1]);
221 --bn, ++*runb);
222 }
223 }
224 }
225 if (bp)
226 bqrelse(bp);
227
228 /*
229 * Since this is FFS independent code, we are out of scope for the
230 * definitions of BLK_NOCOPY and BLK_SNAP, but we do know that they
231 * will fall in the range 1..um_seqinc, so we use that test and
232 * return a request for a zeroed out buffer if attempts are made
233 * to read a BLK_NOCOPY or BLK_SNAP block.
234 */
235 if ((ip->i_flags & SF_SNAPSHOT) && daddr > 0 && daddr < ump->um_seqinc){
236 *bnp = -1;
237 return (0);
238 }
239 *bnp = blkptrtodb(ump, daddr);
240 if (*bnp == 0) {
257 if (ip->i_flags & SF_SNAPSHOT)
258 *bnp = blkptrtodb(ump, bn * ump->um_seqinc);
259 else
260 *bnp = -1;
241 *bnp = -1;
261 }
262 return (0);
263}
264
265/*
266 * Create an array of logical block number/offset pairs which represent the
267 * path of indirect blocks required to access a data block. The first "pair"
268 * contains the logical block number of the appropriate single, double or
269 * triple indirect block and the offset into the inode indirect block array.
270 * Note, the logical block number of the inode single/double/triple indirect
271 * block appears twice in the array, once with the offset into the i_ib and
272 * once with the offset into the page itself.
273 */
274int
242 }
243 return (0);
244}
245
246/*
247 * Create an array of logical block number/offset pairs which represent the
248 * path of indirect blocks required to access a data block. The first "pair"
249 * contains the logical block number of the appropriate single, double or
250 * triple indirect block and the offset into the inode indirect block array.
251 * Note, the logical block number of the inode single/double/triple indirect
252 * block appears twice in the array, once with the offset into the i_ib and
253 * once with the offset into the page itself.
254 */
255int
275ufs_getlbns(vp, bn, ap, nump)
256ext2_getlbns(vp, bn, ap, nump)
276 struct vnode *vp;
257 struct vnode *vp;
277 ufs_daddr_t bn;
258 daddr_t bn;
278 struct indir *ap;
279 int *nump;
280{
281 long blockcnt, metalbn, realbn;
259 struct indir *ap;
260 int *nump;
261{
262 long blockcnt, metalbn, realbn;
282 struct ufsmount *ump;
263 struct ext2mount *ump;
283 int i, numlevels, off;
284 int64_t qblockcnt;
285
264 int i, numlevels, off;
265 int64_t qblockcnt;
266
286 ump = VFSTOUFS(vp->v_mount);
267 ump = VFSTOEXT2(vp->v_mount);
287 if (nump)
288 *nump = 0;
289 numlevels = 0;
290 realbn = bn;
291 if ((long)bn < 0)
292 bn = -(long)bn;
293
294 /* The first NDADDR blocks are direct blocks. */
295 if (bn < NDADDR)
296 return (0);
297
298 /*
299 * Determine the number of levels of indirection. After this loop
300 * is done, blockcnt indicates the number of data blocks possible
301 * at the previous level of indirection, and NIADDR - i is the number
302 * of levels of indirection needed to locate the requested block.
303 */
304 for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) {
305 if (i == 0)
306 return (EFBIG);
307 /*
308 * Use int64_t's here to avoid overflow for triple indirect
309 * blocks when longs have 32 bits and the block size is more
310 * than 4K.
311 */
312 qblockcnt = (int64_t)blockcnt * MNINDIR(ump);
313 if (bn < qblockcnt)
314 break;
315 blockcnt = qblockcnt;
316 }
317
318 /* Calculate the address of the first meta-block. */
319 if (realbn >= 0)
320 metalbn = -(realbn - bn + NIADDR - i);
321 else
322 metalbn = -(-realbn - bn + NIADDR - i);
323
324 /*
325 * At each iteration, off is the offset into the bap array which is
326 * an array of disk addresses at the current level of indirection.
327 * The logical block number and the offset in that block are stored
328 * into the argument array.
329 */
330 ap->in_lbn = metalbn;
331 ap->in_off = off = NIADDR - i;
332 ap->in_exists = 0;
333 ap++;
334 for (++numlevels; i <= NIADDR; i++) {
335 /* If searching for a meta-data block, quit when found. */
336 if (metalbn == realbn)
337 break;
338
339 off = (bn / blockcnt) % MNINDIR(ump);
340
341 ++numlevels;
342 ap->in_lbn = metalbn;
343 ap->in_off = off;
344 ap->in_exists = 0;
345 ++ap;
346
347 metalbn -= -1 + off * blockcnt;
348 blockcnt /= MNINDIR(ump);
349 }
350 if (nump)
351 *nump = numlevels;
352 return (0);
353}
268 if (nump)
269 *nump = 0;
270 numlevels = 0;
271 realbn = bn;
272 if ((long)bn < 0)
273 bn = -(long)bn;
274
275 /* The first NDADDR blocks are direct blocks. */
276 if (bn < NDADDR)
277 return (0);
278
279 /*
280 * Determine the number of levels of indirection. After this loop
281 * is done, blockcnt indicates the number of data blocks possible
282 * at the previous level of indirection, and NIADDR - i is the number
283 * of levels of indirection needed to locate the requested block.
284 */
285 for (blockcnt = 1, i = NIADDR, bn -= NDADDR;; i--, bn -= blockcnt) {
286 if (i == 0)
287 return (EFBIG);
288 /*
289 * Use int64_t's here to avoid overflow for triple indirect
290 * blocks when longs have 32 bits and the block size is more
291 * than 4K.
292 */
293 qblockcnt = (int64_t)blockcnt * MNINDIR(ump);
294 if (bn < qblockcnt)
295 break;
296 blockcnt = qblockcnt;
297 }
298
299 /* Calculate the address of the first meta-block. */
300 if (realbn >= 0)
301 metalbn = -(realbn - bn + NIADDR - i);
302 else
303 metalbn = -(-realbn - bn + NIADDR - i);
304
305 /*
306 * At each iteration, off is the offset into the bap array which is
307 * an array of disk addresses at the current level of indirection.
308 * The logical block number and the offset in that block are stored
309 * into the argument array.
310 */
311 ap->in_lbn = metalbn;
312 ap->in_off = off = NIADDR - i;
313 ap->in_exists = 0;
314 ap++;
315 for (++numlevels; i <= NIADDR; i++) {
316 /* If searching for a meta-data block, quit when found. */
317 if (metalbn == realbn)
318 break;
319
320 off = (bn / blockcnt) % MNINDIR(ump);
321
322 ++numlevels;
323 ap->in_lbn = metalbn;
324 ap->in_off = off;
325 ap->in_exists = 0;
326 ++ap;
327
328 metalbn -= -1 + off * blockcnt;
329 blockcnt /= MNINDIR(ump);
330 }
331 if (nump)
332 *nump = numlevels;
333 return (0);
334}