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_alloc.c 8.8 (Berkeley) 2/21/94 |
34 * $Id: ffs_alloc.c,v 1.4 1994/09/20 05:53:24 bde 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/vnode.h> 42#include <sys/mount.h> --- 53 unchanged lines hidden (view full) --- 96 register struct fs *fs; 97 daddr_t bno; 98 int cg, error; 99 100 *bnp = 0; 101 fs = ip->i_fs; 102#ifdef DIAGNOSTIC 103 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) { |
104 printf("dev = 0x%lx, bsize = %ld, size = %d, fs = %s\n", 105 (u_long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt); |
106 panic("ffs_alloc: bad size"); 107 } 108 if (cred == NOCRED) 109 panic("ffs_alloc: missing credential\n"); 110#endif /* DIAGNOSTIC */ 111 if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0) 112 goto nospace; 113 if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0) 114 goto nospace; 115#ifdef QUOTA |
116 error = chkdq(ip, (long)btodb(size), cred, 0); 117 if (error) |
118 return (error); 119#endif 120 if (bpref >= fs->fs_size) 121 bpref = 0; 122 if (bpref == 0) 123 cg = ino_to_cg(fs, ip->i_number); 124 else 125 cg = dtog(fs, bpref); --- 40 unchanged lines hidden (view full) --- 166 daddr_t bprev, bno; 167 168 *bpp = 0; 169 fs = ip->i_fs; 170#ifdef DIAGNOSTIC 171 if ((u_int)osize > fs->fs_bsize || fragoff(fs, osize) != 0 || 172 (u_int)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) { 173 printf( |
174 "dev = 0x%lx, bsize = %d, osize = %d, nsize = %d, fs = %s\n", 175 (u_long)ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt); |
176 panic("ffs_realloccg: bad size"); 177 } 178 if (cred == NOCRED) 179 panic("ffs_realloccg: missing credential\n"); 180#endif /* DIAGNOSTIC */ 181 if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0) 182 goto nospace; 183 if ((bprev = ip->i_db[lbprev]) == 0) { 184 printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n", 185 ip->i_dev, fs->fs_bsize, bprev, fs->fs_fsmnt); 186 panic("ffs_realloccg: bad bprev"); 187 } 188 /* 189 * Allocate the extra space in the buffer. 190 */ |
191 error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp); 192 if (error) { |
193 brelse(bp); 194 return (error); 195 } 196#ifdef QUOTA |
197 error = chkdq(ip, (long)btodb(nsize - osize), cred, 0); 198 if (error) { |
199 brelse(bp); 200 return (error); 201 } 202#endif 203 /* 204 * Check for extension in the existing location. 205 */ 206 cg = dtog(fs, bprev); |
207 bno = ffs_fragextend(ip, cg, (long)bprev, osize, nsize); 208 if (bno) { |
209 if (bp->b_blkno != fsbtodb(fs, bno)) 210 panic("bad blockno"); 211 ip->i_blocks += btodb(nsize - osize); 212 ip->i_flag |= IN_CHANGE | IN_UPDATE; 213 allocbuf(bp, nsize); 214 bp->b_flags |= B_DONE; 215 bzero((char *)bp->b_data + osize, (u_int)nsize - osize); 216 *bpp = bp; --- 37 unchanged lines hidden (view full) --- 254 if (fs->fs_cstotal.cs_nffree < 255 fs->fs_dsize * (fs->fs_minfree - 2) / 100) 256 break; 257 log(LOG_NOTICE, "%s: optimization changed from TIME to SPACE\n", 258 fs->fs_fsmnt); 259 fs->fs_optim = FS_OPTSPACE; 260 break; 261 default: |
262 printf("dev = 0x%lx, optim = %ld, fs = %s\n", 263 (u_long)ip->i_dev, fs->fs_optim, fs->fs_fsmnt); |
264 panic("ffs_realloccg: bad optim"); 265 /* NOTREACHED */ 266 } 267 bno = (daddr_t)ffs_hashalloc(ip, cg, (long)bpref, request, 268 (u_long (*)())ffs_alloccg); 269 if (bno > 0) { 270 bp->b_blkno = fsbtodb(fs, bno); 271 (void) vnode_pager_uncache(ITOV(ip)); --- 52 unchanged lines hidden (view full) --- 324 } */ *ap; 325{ 326 struct fs *fs; 327 struct inode *ip; 328 struct vnode *vp; 329 struct buf *sbp, *ebp; 330 daddr_t *bap, *sbap, *ebap = 0; 331 struct cluster_save *buflist; |
332 daddr_t start_lbn, end_lbn, soff, newblk, blkno; |
333 struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp; 334 int i, len, start_lvl, end_lvl, pref, ssize; 335 336 vp = ap->a_vp; 337 ip = VTOI(vp); 338 fs = ip->i_fs; 339 if (fs->fs_contigsumsize <= 0) 340 return (ENOSPC); --- 171 unchanged lines hidden (view full) --- 512 goto noinodes; 513 error = VFS_VGET(pvp->v_mount, ino, ap->a_vpp); 514 if (error) { 515 VOP_VFREE(pvp, ino, mode); 516 return (error); 517 } 518 ip = VTOI(*ap->a_vpp); 519 if (ip->i_mode) { |
520 printf("mode = 0%o, inum = %ld, fs = %s\n", |
521 ip->i_mode, ip->i_number, fs->fs_fsmnt); 522 panic("ffs_valloc: dup alloc"); 523 } 524 if (ip->i_blocks) { /* XXX */ |
525 printf("free inode %s/%ld had %ld blocks\n", |
526 fs->fs_fsmnt, ino, ip->i_blocks); 527 ip->i_blocks = 0; 528 } 529 ip->i_flags = 0; 530 /* 531 * Set up a new generation number for this inode. 532 */ 533 if (++nextgennumber < (u_long)time.tv_sec) --- 637 unchanged lines hidden (view full) --- 1171 register struct fs *fs; 1172 register struct cg *cgp; 1173 struct buf *bp; 1174 daddr_t blkno; 1175 int i, error, cg, blk, frags, bbase; 1176 1177 fs = ip->i_fs; 1178 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) { |
1179 printf("dev = 0x%lx, bsize = %ld, size = %ld, fs = %s\n", 1180 (u_long)ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt); |
1181 panic("blkfree: bad size"); 1182 } 1183 cg = dtog(fs, bno); 1184 if ((u_int)bno >= fs->fs_size) { 1185 printf("bad block %d, ino %d\n", bno, ip->i_number); 1186 ffs_fserr(fs, ip->i_uid, "bad block"); 1187 return; 1188 } --- 108 unchanged lines hidden (view full) --- 1297 cgp = (struct cg *)bp->b_data; 1298 if (!cg_chkmagic(cgp)) { 1299 brelse(bp); 1300 return (0); 1301 } 1302 cgp->cg_time = time.tv_sec; 1303 ino %= fs->fs_ipg; 1304 if (isclr(cg_inosused(cgp), ino)) { |
1305 printf("dev = 0x%lx, ino = %d, fs = %s\n", 1306 (u_long)pip->i_dev, ino, fs->fs_fsmnt); |
1307 if (fs->fs_ronly == 0) 1308 panic("ifree: freeing free inode"); 1309 } 1310 clrbit(cg_inosused(cgp), ino); 1311 if (ino < cgp->cg_irotor) 1312 cgp->cg_irotor = ino; 1313 cgp->cg_cs.cs_nifree++; 1314 fs->fs_cstotal.cs_nifree++; --- 63 unchanged lines hidden (view full) --- 1378 subfield = inside[allocsiz]; 1379 for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) { 1380 if ((blk & field) == subfield) 1381 return (bno + pos); 1382 field <<= 1; 1383 subfield <<= 1; 1384 } 1385 } |
1386 printf("bno = %lu, fs = %s\n", (u_long)bno, fs->fs_fsmnt); |
1387 panic("ffs_alloccg: block not in map"); 1388 return (-1); 1389} 1390 1391/* 1392 * Update the cluster map because of an allocation or free. 1393 * 1394 * Cnt == 1 means free; cnt == -1 means allocating. --- 94 unchanged lines hidden --- |