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. --- 22 unchanged lines hidden (view full) --- 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 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 |
52#include <gnu/ext2fs/inode.h> 53#include <gnu/ext2fs/ext2_mount.h> 54#include <gnu/ext2fs/ext2_extern.h> |
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 |
62ext2_bmap(ap) |
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; --- 5 unchanged lines hidden (view full) --- 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 |
84 error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno, |
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 --- 4 unchanged lines hidden (view full) --- 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 |
105ext2_bmaparray(vp, bn, bnp, runp, runb) |
106 struct vnode *vp; |
107 daddr_t bn; 108 daddr_t *bnp; |
109 int *runp; 110 int *runb; 111{ 112 struct inode *ip; 113 struct buf *bp; |
114 struct ext2mount *ump; |
115 struct mount *mp; 116 struct vnode *devvp; 117 struct indir a[NIADDR+1], *ap; |
118 daddr_t daddr; |
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; |
126 ump = VFSTOEXT2(mp); |
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 = # |
141 error = ext2_getlbns(vp, bn, ap, nump); |
142 if (error) 143 return (error); 144 145 num = *nump; 146 if (num == 0) { 147 *bnp = blkptrtodb(ump, ip->i_db[bn]); |
148 if (*bnp == 0) { |
149 *bnp = -1; |
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) && --- 42 unchanged lines hidden (view full) --- 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 |
208 daddr = ((daddr_t *)bp->b_data)[ap->in_off]; |
209 if (num == 1 && daddr && runp) { 210 for (bn = ap->in_off + 1; 211 bn < MNINDIR(ump) && *runp < maxrun && 212 is_sequential(ump, |
213 ((daddr_t *)bp->b_data)[bn - 1], 214 ((daddr_t *)bp->b_data)[bn]); |
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 } --- 10 unchanged lines hidden (view full) --- 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) { |
241 *bnp = -1; |
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 |
256ext2_getlbns(vp, bn, ap, nump) |
257 struct vnode *vp; |
258 daddr_t bn; |
259 struct indir *ap; 260 int *nump; 261{ 262 long blockcnt, metalbn, realbn; |
263 struct ext2mount *ump; |
264 int i, numlevels, off; 265 int64_t qblockcnt; 266 |
267 ump = VFSTOEXT2(vp->v_mount); |
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. */ --- 59 unchanged lines hidden --- |