ffs_balloc.c (1817) | ffs_balloc.c (3487) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_balloc.c 8.4 (Berkeley) 9/23/93 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_balloc.c 8.4 (Berkeley) 9/23/93 |
34 * $Id$ | 34 * $Id: ffs_balloc.c,v 1.3 1994/08/02 07:54:18 davidg Exp $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/buf.h> 40#include <sys/proc.h> 41#include <sys/file.h> 42#include <sys/vnode.h> --- 111 unchanged lines hidden (view full) --- 154 ip->i_flag |= IN_CHANGE | IN_UPDATE; 155 *bpp = bp; 156 return (0); 157 } 158 /* 159 * Determine the number of levels of indirection. 160 */ 161 pref = 0; | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/buf.h> 40#include <sys/proc.h> 41#include <sys/file.h> 42#include <sys/vnode.h> --- 111 unchanged lines hidden (view full) --- 154 ip->i_flag |= IN_CHANGE | IN_UPDATE; 155 *bpp = bp; 156 return (0); 157 } 158 /* 159 * Determine the number of levels of indirection. 160 */ 161 pref = 0; |
162 if (error = ufs_getlbns(vp, bn, indirs, &num)) | 162 error = ufs_getlbns(vp, bn, indirs, &num); 163 if (error) |
163 return(error); 164#ifdef DIAGNOSTIC 165 if (num < 1) 166 panic ("ffs_balloc: ufs_bmaparray returned indirect block\n"); 167#endif 168 /* 169 * Fetch the first indirect block allocating if necessary. 170 */ 171 --num; 172 nb = ip->i_ib[indirs[0].in_off]; 173 if (nb == 0) { 174 pref = ffs_blkpref(ip, lbn, 0, (daddr_t *)0); | 164 return(error); 165#ifdef DIAGNOSTIC 166 if (num < 1) 167 panic ("ffs_balloc: ufs_bmaparray returned indirect block\n"); 168#endif 169 /* 170 * Fetch the first indirect block allocating if necessary. 171 */ 172 --num; 173 nb = ip->i_ib[indirs[0].in_off]; 174 if (nb == 0) { 175 pref = ffs_blkpref(ip, lbn, 0, (daddr_t *)0); |
175 if (error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, 176 cred, &newb)) | 176 error = ffs_alloc(ip, lbn, pref, 177 (int)fs->fs_bsize, cred, &newb); 178 if (error) |
177 return (error); 178 nb = newb; 179 bp = getblk(vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0); 180 bp->b_blkno = fsbtodb(fs, newb); 181 clrbuf(bp); 182 /* 183 * Write synchronously so that indirect blocks 184 * never point at garbage. 185 */ | 179 return (error); 180 nb = newb; 181 bp = getblk(vp, indirs[1].in_lbn, fs->fs_bsize, 0, 0); 182 bp->b_blkno = fsbtodb(fs, newb); 183 clrbuf(bp); 184 /* 185 * Write synchronously so that indirect blocks 186 * never point at garbage. 187 */ |
186 if (error = bwrite(bp)) { | 188 error = bwrite(bp); 189 if (error) { |
187 ffs_blkfree(ip, nb, fs->fs_bsize); 188 return (error); 189 } 190 ip->i_ib[indirs[0].in_off] = newb; 191 ip->i_flag |= IN_CHANGE | IN_UPDATE; 192 } 193 /* 194 * Fetch through the indirect blocks, allocating as necessary. --- 11 unchanged lines hidden (view full) --- 206 break; 207 i += 1; 208 if (nb != 0) { 209 brelse(bp); 210 continue; 211 } 212 if (pref == 0) 213 pref = ffs_blkpref(ip, lbn, 0, (daddr_t *)0); | 190 ffs_blkfree(ip, nb, fs->fs_bsize); 191 return (error); 192 } 193 ip->i_ib[indirs[0].in_off] = newb; 194 ip->i_flag |= IN_CHANGE | IN_UPDATE; 195 } 196 /* 197 * Fetch through the indirect blocks, allocating as necessary. --- 11 unchanged lines hidden (view full) --- 209 break; 210 i += 1; 211 if (nb != 0) { 212 brelse(bp); 213 continue; 214 } 215 if (pref == 0) 216 pref = ffs_blkpref(ip, lbn, 0, (daddr_t *)0); |
214 if (error = 215 ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, cred, &newb)) { | 217 error = 218 ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, cred, &newb); 219 if (error) { |
216 brelse(bp); 217 return (error); 218 } 219 nb = newb; 220 nbp = getblk(vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0); 221 nbp->b_blkno = fsbtodb(fs, nb); 222 clrbuf(nbp); 223 /* 224 * Write synchronously so that indirect blocks 225 * never point at garbage. 226 */ | 220 brelse(bp); 221 return (error); 222 } 223 nb = newb; 224 nbp = getblk(vp, indirs[i].in_lbn, fs->fs_bsize, 0, 0); 225 nbp->b_blkno = fsbtodb(fs, nb); 226 clrbuf(nbp); 227 /* 228 * Write synchronously so that indirect blocks 229 * never point at garbage. 230 */ |
227 if (error = bwrite(nbp)) { | 231 error = bwrite(nbp); 232 if (error) { |
228 ffs_blkfree(ip, nb, fs->fs_bsize); 229 brelse(bp); 230 return (error); 231 } 232 bap[indirs[i - 1].in_off] = nb; 233 /* 234 * If required, write synchronously, otherwise use 235 * delayed write. --- 4 unchanged lines hidden (view full) --- 240 bdwrite(bp); 241 } 242 } 243 /* 244 * Get the data block, allocating if necessary. 245 */ 246 if (nb == 0) { 247 pref = ffs_blkpref(ip, lbn, indirs[i].in_off, &bap[0]); | 233 ffs_blkfree(ip, nb, fs->fs_bsize); 234 brelse(bp); 235 return (error); 236 } 237 bap[indirs[i - 1].in_off] = nb; 238 /* 239 * If required, write synchronously, otherwise use 240 * delayed write. --- 4 unchanged lines hidden (view full) --- 245 bdwrite(bp); 246 } 247 } 248 /* 249 * Get the data block, allocating if necessary. 250 */ 251 if (nb == 0) { 252 pref = ffs_blkpref(ip, lbn, indirs[i].in_off, &bap[0]); |
248 if (error = ffs_alloc(ip, 249 lbn, pref, (int)fs->fs_bsize, cred, &newb)) { | 253 error = ffs_alloc(ip, 254 lbn, pref, (int)fs->fs_bsize, cred, &newb); 255 if (error) { |
250 brelse(bp); 251 return (error); 252 } 253 nb = newb; 254 nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0); 255 nbp->b_blkno = fsbtodb(fs, nb); 256 if (flags & B_CLRBUF) 257 clrbuf(nbp); --- 27 unchanged lines hidden --- | 256 brelse(bp); 257 return (error); 258 } 259 nb = newb; 260 nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0); 261 nbp->b_blkno = fsbtodb(fs, nb); 262 if (flags & B_CLRBUF) 263 clrbuf(nbp); --- 27 unchanged lines hidden --- |