Deleted Added
full compact
ffs_alloc.c (2922) ffs_alloc.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_alloc.c 8.8 (Berkeley) 2/21/94
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.3 1994/08/02 07:54:17 davidg Exp $
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) {
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%x, bsize = %d, size = %d, fs = %s\n",
105 ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
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
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 if (error = chkdq(ip, (long)btodb(size), cred, 0))
116 error = chkdq(ip, (long)btodb(size), cred, 0);
117 if (error)
117 return (error);
118#endif
119 if (bpref >= fs->fs_size)
120 bpref = 0;
121 if (bpref == 0)
122 cg = ino_to_cg(fs, ip->i_number);
123 else
124 cg = dtog(fs, bpref);

--- 40 unchanged lines hidden (view full) ---

165 daddr_t bprev, bno;
166
167 *bpp = 0;
168 fs = ip->i_fs;
169#ifdef DIAGNOSTIC
170 if ((u_int)osize > fs->fs_bsize || fragoff(fs, osize) != 0 ||
171 (u_int)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) {
172 printf(
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(
173 "dev = 0x%x, bsize = %d, osize = %d, nsize = %d, fs = %s\n",
174 ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
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);
175 panic("ffs_realloccg: bad size");
176 }
177 if (cred == NOCRED)
178 panic("ffs_realloccg: missing credential\n");
179#endif /* DIAGNOSTIC */
180 if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
181 goto nospace;
182 if ((bprev = ip->i_db[lbprev]) == 0) {
183 printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n",
184 ip->i_dev, fs->fs_bsize, bprev, fs->fs_fsmnt);
185 panic("ffs_realloccg: bad bprev");
186 }
187 /*
188 * Allocate the extra space in the buffer.
189 */
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 */
190 if (error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp)) {
191 error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp);
192 if (error) {
191 brelse(bp);
192 return (error);
193 }
194#ifdef QUOTA
193 brelse(bp);
194 return (error);
195 }
196#ifdef QUOTA
195 if (error = chkdq(ip, (long)btodb(nsize - osize), cred, 0)) {
197 error = chkdq(ip, (long)btodb(nsize - osize), cred, 0);
198 if (error) {
196 brelse(bp);
197 return (error);
198 }
199#endif
200 /*
201 * Check for extension in the existing location.
202 */
203 cg = dtog(fs, bprev);
199 brelse(bp);
200 return (error);
201 }
202#endif
203 /*
204 * Check for extension in the existing location.
205 */
206 cg = dtog(fs, bprev);
204 if (bno = ffs_fragextend(ip, cg, (long)bprev, osize, nsize)) {
207 bno = ffs_fragextend(ip, cg, (long)bprev, osize, nsize);
208 if (bno) {
205 if (bp->b_blkno != fsbtodb(fs, bno))
206 panic("bad blockno");
207 ip->i_blocks += btodb(nsize - osize);
208 ip->i_flag |= IN_CHANGE | IN_UPDATE;
209 allocbuf(bp, nsize);
210 bp->b_flags |= B_DONE;
211 bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
212 *bpp = bp;

--- 37 unchanged lines hidden (view full) ---

250 if (fs->fs_cstotal.cs_nffree <
251 fs->fs_dsize * (fs->fs_minfree - 2) / 100)
252 break;
253 log(LOG_NOTICE, "%s: optimization changed from TIME to SPACE\n",
254 fs->fs_fsmnt);
255 fs->fs_optim = FS_OPTSPACE;
256 break;
257 default:
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:
258 printf("dev = 0x%x, optim = %d, fs = %s\n",
259 ip->i_dev, fs->fs_optim, fs->fs_fsmnt);
262 printf("dev = 0x%lx, optim = %ld, fs = %s\n",
263 (u_long)ip->i_dev, fs->fs_optim, fs->fs_fsmnt);
260 panic("ffs_realloccg: bad optim");
261 /* NOTREACHED */
262 }
263 bno = (daddr_t)ffs_hashalloc(ip, cg, (long)bpref, request,
264 (u_long (*)())ffs_alloccg);
265 if (bno > 0) {
266 bp->b_blkno = fsbtodb(fs, bno);
267 (void) vnode_pager_uncache(ITOV(ip));

--- 52 unchanged lines hidden (view full) ---

320 } */ *ap;
321{
322 struct fs *fs;
323 struct inode *ip;
324 struct vnode *vp;
325 struct buf *sbp, *ebp;
326 daddr_t *bap, *sbap, *ebap = 0;
327 struct cluster_save *buflist;
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;
328 daddr_t start_lbn, end_lbn, soff, eoff, newblk, blkno;
332 daddr_t start_lbn, end_lbn, soff, newblk, blkno;
329 struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp;
330 int i, len, start_lvl, end_lvl, pref, ssize;
331
332 vp = ap->a_vp;
333 ip = VTOI(vp);
334 fs = ip->i_fs;
335 if (fs->fs_contigsumsize <= 0)
336 return (ENOSPC);

--- 171 unchanged lines hidden (view full) ---

508 goto noinodes;
509 error = VFS_VGET(pvp->v_mount, ino, ap->a_vpp);
510 if (error) {
511 VOP_VFREE(pvp, ino, mode);
512 return (error);
513 }
514 ip = VTOI(*ap->a_vpp);
515 if (ip->i_mode) {
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) {
516 printf("mode = 0%o, inum = %d, fs = %s\n",
520 printf("mode = 0%o, inum = %ld, fs = %s\n",
517 ip->i_mode, ip->i_number, fs->fs_fsmnt);
518 panic("ffs_valloc: dup alloc");
519 }
520 if (ip->i_blocks) { /* XXX */
521 ip->i_mode, ip->i_number, fs->fs_fsmnt);
522 panic("ffs_valloc: dup alloc");
523 }
524 if (ip->i_blocks) { /* XXX */
521 printf("free inode %s/%d had %d blocks\n",
525 printf("free inode %s/%ld had %ld blocks\n",
522 fs->fs_fsmnt, ino, ip->i_blocks);
523 ip->i_blocks = 0;
524 }
525 ip->i_flags = 0;
526 /*
527 * Set up a new generation number for this inode.
528 */
529 if (++nextgennumber < (u_long)time.tv_sec)

--- 637 unchanged lines hidden (view full) ---

1167 register struct fs *fs;
1168 register struct cg *cgp;
1169 struct buf *bp;
1170 daddr_t blkno;
1171 int i, error, cg, blk, frags, bbase;
1172
1173 fs = ip->i_fs;
1174 if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
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) {
1175 printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
1176 ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
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);
1177 panic("blkfree: bad size");
1178 }
1179 cg = dtog(fs, bno);
1180 if ((u_int)bno >= fs->fs_size) {
1181 printf("bad block %d, ino %d\n", bno, ip->i_number);
1182 ffs_fserr(fs, ip->i_uid, "bad block");
1183 return;
1184 }

--- 108 unchanged lines hidden (view full) ---

1293 cgp = (struct cg *)bp->b_data;
1294 if (!cg_chkmagic(cgp)) {
1295 brelse(bp);
1296 return (0);
1297 }
1298 cgp->cg_time = time.tv_sec;
1299 ino %= fs->fs_ipg;
1300 if (isclr(cg_inosused(cgp), ino)) {
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)) {
1301 printf("dev = 0x%x, ino = %d, fs = %s\n",
1302 pip->i_dev, ino, fs->fs_fsmnt);
1305 printf("dev = 0x%lx, ino = %d, fs = %s\n",
1306 (u_long)pip->i_dev, ino, fs->fs_fsmnt);
1303 if (fs->fs_ronly == 0)
1304 panic("ifree: freeing free inode");
1305 }
1306 clrbit(cg_inosused(cgp), ino);
1307 if (ino < cgp->cg_irotor)
1308 cgp->cg_irotor = ino;
1309 cgp->cg_cs.cs_nifree++;
1310 fs->fs_cstotal.cs_nifree++;

--- 63 unchanged lines hidden (view full) ---

1374 subfield = inside[allocsiz];
1375 for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
1376 if ((blk & field) == subfield)
1377 return (bno + pos);
1378 field <<= 1;
1379 subfield <<= 1;
1380 }
1381 }
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 }
1382 printf("bno = %d, fs = %s\n", bno, fs->fs_fsmnt);
1386 printf("bno = %lu, fs = %s\n", (u_long)bno, fs->fs_fsmnt);
1383 panic("ffs_alloccg: block not in map");
1384 return (-1);
1385}
1386
1387/*
1388 * Update the cluster map because of an allocation or free.
1389 *
1390 * Cnt == 1 means free; cnt == -1 means allocating.

--- 94 unchanged lines hidden ---
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 ---