ext2_bmap.c (8876) | ext2_bmap.c (10551) |
---|---|
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.6 (Berkeley) 1/21/94 | 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.6 (Berkeley) 1/21/94 |
39 * $Id: ufs_bmap.c,v 1.7 1995/03/28 07:58:16 bde Exp $ | 39 * $Id: ufs_bmap.c,v 1.8 1995/05/30 08:15:31 rgrimes Exp $ |
40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/buf.h> 45#include <sys/proc.h> 46#include <sys/vnode.h> 47#include <sys/mount.h> --- 14 unchanged lines hidden (view full) --- 62int 63ufs_bmap(ap) 64 struct vop_bmap_args /* { 65 struct vnode *a_vp; 66 daddr_t a_bn; 67 struct vnode **a_vpp; 68 daddr_t *a_bnp; 69 int *a_runp; | 40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/buf.h> 45#include <sys/proc.h> 46#include <sys/vnode.h> 47#include <sys/mount.h> --- 14 unchanged lines hidden (view full) --- 62int 63ufs_bmap(ap) 64 struct vop_bmap_args /* { 65 struct vnode *a_vp; 66 daddr_t a_bn; 67 struct vnode **a_vpp; 68 daddr_t *a_bnp; 69 int *a_runp; |
70 int *a_runb; |
|
70 } */ *ap; 71{ 72 /* 73 * Check for underlying vnode requests and ensure that logical 74 * to physical mapping is requested. 75 */ 76 if (ap->a_vpp != NULL) 77 *ap->a_vpp = VTOI(ap->a_vp)->i_devvp; 78 if (ap->a_bnp == NULL) 79 return (0); 80 81 return (ufs_bmaparray(ap->a_vp, ap->a_bn, ap->a_bnp, NULL, NULL, | 71 } */ *ap; 72{ 73 /* 74 * Check for underlying vnode requests and ensure that logical 75 * to physical mapping is requested. 76 */ 77 if (ap->a_vpp != NULL) 78 *ap->a_vpp = VTOI(ap->a_vp)->i_devvp; 79 if (ap->a_bnp == NULL) 80 return (0); 81 82 return (ufs_bmaparray(ap->a_vp, ap->a_bn, ap->a_bnp, NULL, NULL, |
82 ap->a_runp)); | 83 ap->a_runp, ap->a_runb)); |
83} 84 85/* 86 * Indirect blocks are now on the vnode for the file. They are given negative 87 * logical block numbers. Indirect blocks are addressed by the negative 88 * address of the first data block to which they point. Double indirect blocks 89 * are addressed by one less than the address of the first indirect block to 90 * which they point. Triple indirect blocks are addressed by one less than 91 * the address of the first double indirect block to which they point. 92 * 93 * ufs_bmaparray does the bmap conversion, and if requested returns the 94 * array of logical blocks which must be traversed to get to a block. 95 * Each entry contains the offset into that block that gets you to the 96 * next block and the disk address of the block (if it is assigned). 97 */ 98 99int | 84} 85 86/* 87 * Indirect blocks are now on the vnode for the file. They are given negative 88 * logical block numbers. Indirect blocks are addressed by the negative 89 * address of the first data block to which they point. Double indirect blocks 90 * are addressed by one less than the address of the first indirect block to 91 * which they point. Triple indirect blocks are addressed by one less than 92 * the address of the first double indirect block to which they point. 93 * 94 * ufs_bmaparray does the bmap conversion, and if requested returns the 95 * array of logical blocks which must be traversed to get to a block. 96 * Each entry contains the offset into that block that gets you to the 97 * next block and the disk address of the block (if it is assigned). 98 */ 99 100int |
100ufs_bmaparray(vp, bn, bnp, ap, nump, runp) | 101ufs_bmaparray(vp, bn, bnp, ap, nump, runp, runb) |
101 struct vnode *vp; 102 register daddr_t bn; 103 daddr_t *bnp; 104 struct indir *ap; 105 int *nump; 106 int *runp; | 102 struct vnode *vp; 103 register daddr_t bn; 104 daddr_t *bnp; 105 struct indir *ap; 106 int *nump; 107 int *runp; |
108 int *runb; |
|
107{ 108 register struct inode *ip; 109 struct buf *bp; 110 struct ufsmount *ump; 111 struct mount *mp; 112 struct vnode *devvp; 113 struct indir a[NIADDR], *xap; 114 daddr_t daddr; --- 14 unchanged lines hidden (view full) --- 129 * If MAXPHYS is the largest transfer the disks can handle, 130 * we probably want maxrun to be 1 block less so that we 131 * don't create a block larger than the device can handle. 132 */ 133 *runp = 0; 134 maxrun = MAXPHYS / mp->mnt_stat.f_iosize - 1; 135 } 136 | 109{ 110 register struct inode *ip; 111 struct buf *bp; 112 struct ufsmount *ump; 113 struct mount *mp; 114 struct vnode *devvp; 115 struct indir a[NIADDR], *xap; 116 daddr_t daddr; --- 14 unchanged lines hidden (view full) --- 131 * If MAXPHYS is the largest transfer the disks can handle, 132 * we probably want maxrun to be 1 block less so that we 133 * don't create a block larger than the device can handle. 134 */ 135 *runp = 0; 136 maxrun = MAXPHYS / mp->mnt_stat.f_iosize - 1; 137 } 138 |
139 if (runb) { 140 *runb = 0; 141 } 142 |
|
137 xap = ap == NULL ? a : ap; 138 if (!nump) 139 nump = # 140 error = ufs_getlbns(vp, bn, xap, nump); 141 if (error) 142 return (error); 143 144 num = *nump; 145 if (num == 0) { 146 *bnp = blkptrtodb(ump, ip->i_db[bn]); 147 if (*bnp == 0) 148 *bnp = -1; | 143 xap = ap == NULL ? a : ap; 144 if (!nump) 145 nump = # 146 error = ufs_getlbns(vp, bn, xap, nump); 147 if (error) 148 return (error); 149 150 num = *nump; 151 if (num == 0) { 152 *bnp = blkptrtodb(ump, ip->i_db[bn]); 153 if (*bnp == 0) 154 *bnp = -1; |
149 else if (runp) | 155 else if (runp) { 156 daddr_t bnb = bn; |
150 for (++bn; bn < NDADDR && *runp < maxrun && 151 is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]); 152 ++bn, ++*runp); | 157 for (++bn; bn < NDADDR && *runp < maxrun && 158 is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]); 159 ++bn, ++*runp); |
160 bn = bnb; 161 if (runb && (bn > 0)) { 162 for (--bn; (bn >= 0) && (*runb < maxrun) && 163 is_sequential(ump, ip->i_db[bn], 164 ip->i_db[bn+1]); 165 --bn, ++*runb); 166 } 167 } |
|
153 return (0); 154 } 155 156 157 /* Get disk address out of indirect block array */ 158 daddr = ip->i_ib[xap->in_off]; 159 160 devvp = VFSTOUFS(vp->v_mount)->um_devvp; --- 29 unchanged lines hidden (view full) --- 190 error = biowait(bp); 191 if (error) { 192 brelse(bp); 193 return (error); 194 } 195 } 196 197 daddr = ((daddr_t *)bp->b_data)[xap->in_off]; | 168 return (0); 169 } 170 171 172 /* Get disk address out of indirect block array */ 173 daddr = ip->i_ib[xap->in_off]; 174 175 devvp = VFSTOUFS(vp->v_mount)->um_devvp; --- 29 unchanged lines hidden (view full) --- 205 error = biowait(bp); 206 if (error) { 207 brelse(bp); 208 return (error); 209 } 210 } 211 212 daddr = ((daddr_t *)bp->b_data)[xap->in_off]; |
198 if (num == 1 && daddr && runp) | 213 if (num == 1 && daddr && runp) { |
199 for (bn = xap->in_off + 1; 200 bn < MNINDIR(ump) && *runp < maxrun && 201 is_sequential(ump, ((daddr_t *)bp->b_data)[bn - 1], 202 ((daddr_t *)bp->b_data)[bn]); 203 ++bn, ++*runp); | 214 for (bn = xap->in_off + 1; 215 bn < MNINDIR(ump) && *runp < maxrun && 216 is_sequential(ump, ((daddr_t *)bp->b_data)[bn - 1], 217 ((daddr_t *)bp->b_data)[bn]); 218 ++bn, ++*runp); |
219 bn = xap->in_off; 220 if (runb && bn) { 221 for(--bn; bn > 0 && *runb < maxrun && 222 is_sequential(ump, ((daddr_t *)bp->b_data)[bn], 223 ((daddr_t *)bp->b_data)[bn+1]); 224 --bn, ++*runb); 225 } 226 } |
|
204 } 205 if (bp) 206 brelse(bp); 207 208 daddr = blkptrtodb(ump, daddr); 209 *bnp = daddr == 0 ? -1 : daddr; 210 return (0); 211} --- 83 unchanged lines hidden --- | 227 } 228 if (bp) 229 brelse(bp); 230 231 daddr = blkptrtodb(ump, daddr); 232 *bnp = daddr == 0 ? -1 : daddr; 233 return (0); 234} --- 83 unchanged lines hidden --- |