4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / ufs / ffs / ffs_alloc.c
index db37041..a601d7d 100644 (file)
@@ -1,10 +1,10 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ffs_alloc.c 7.33 (Berkeley) %G%
+ *     @(#)ffs_alloc.c 8.1 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -12,6 +12,7 @@
 #include <sys/buf.h>
 #include <sys/proc.h>
 #include <sys/vnode.h>
 #include <sys/buf.h>
 #include <sys/proc.h>
 #include <sys/vnode.h>
+#include <sys/mount.h>
 #include <sys/kernel.h>
 #include <sys/syslog.h>
 
 #include <sys/kernel.h>
 #include <sys/syslog.h>
 
@@ -285,19 +286,23 @@ nospace:
  *   2) quadradically rehash into other cylinder groups, until an
  *      available inode is located.
  */
  *   2) quadradically rehash into other cylinder groups, until an
  *      available inode is located.
  */
-ffs_valloc(pvp, mode, cred, vpp)
-       register struct vnode *pvp;
-       int mode;
-       struct ucred *cred;
-       struct vnode **vpp;
+ffs_valloc(ap)
+       struct vop_valloc_args /* {
+               struct vnode *a_pvp;
+               int a_mode;
+               struct ucred *a_cred;
+               struct vnode **a_vpp;
+       } */ *ap;
 {
 {
+       register struct vnode *pvp = ap->a_pvp;
        register struct inode *pip;
        register struct fs *fs;
        register struct inode *ip;
        register struct inode *pip;
        register struct fs *fs;
        register struct inode *ip;
+       mode_t mode = ap->a_mode;
        ino_t ino, ipref;
        int cg, error;
        
        ino_t ino, ipref;
        int cg, error;
        
-       *vpp = NULL;
+       *ap->a_vpp = NULL;
        pip = VTOI(pvp);
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
        pip = VTOI(pvp);
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
@@ -313,12 +318,12 @@ ffs_valloc(pvp, mode, cred, vpp)
        ino = (ino_t)ffs_hashalloc(pip, cg, (long)ipref, mode, ffs_ialloccg);
        if (ino == 0)
                goto noinodes;
        ino = (ino_t)ffs_hashalloc(pip, cg, (long)ipref, mode, ffs_ialloccg);
        if (ino == 0)
                goto noinodes;
-       error = ffs_vget(pvp->v_mount, ino, vpp);
+       error = VFS_VGET(pvp->v_mount, ino, ap->a_vpp);
        if (error) {
        if (error) {
-               ffs_vfree(pvp, ino, mode);
+               VOP_VFREE(pvp, ino, mode);
                return (error);
        }
                return (error);
        }
-       ip = VTOI(*vpp);
+       ip = VTOI(*ap->a_vpp);
        if (ip->i_mode) {
                printf("mode = 0%o, inum = %d, fs = %s\n",
                    ip->i_mode, ip->i_number, fs->fs_fsmnt);
        if (ip->i_mode) {
                printf("mode = 0%o, inum = %d, fs = %s\n",
                    ip->i_mode, ip->i_number, fs->fs_fsmnt);
@@ -338,7 +343,7 @@ ffs_valloc(pvp, mode, cred, vpp)
        ip->i_gen = nextgennumber;
        return (0);
 noinodes:
        ip->i_gen = nextgennumber;
        return (0);
 noinodes:
-       ffs_fserr(fs, cred->cr_uid, "out of inodes");
+       ffs_fserr(fs, ap->a_cred->cr_uid, "out of inodes");
        uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
        uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
@@ -441,9 +446,8 @@ ffs_blkpref(ip, lbn, indx, bap)
         * requested rotationally delayed by fs_rotdelay milliseconds.
         */
        nextblk = bap[indx - 1] + fs->fs_frag;
         * requested rotationally delayed by fs_rotdelay milliseconds.
         */
        nextblk = bap[indx - 1] + fs->fs_frag;
-       if (indx > fs->fs_maxcontig &&
-           bap[indx - fs->fs_maxcontig] + blkstofrags(fs, fs->fs_maxcontig)
-           != nextblk)
+       if (indx < fs->fs_maxcontig || bap[indx - fs->fs_maxcontig] +
+           blkstofrags(fs, fs->fs_maxcontig) != nextblk)
                return (nextblk);
        if (fs->fs_rotdelay != 0)
                /*
                return (nextblk);
        if (fs->fs_rotdelay != 0)
                /*
@@ -725,10 +729,13 @@ ffs_alloccgblk(fs, cgp, bpref)
                goto norot;
        if (fs->fs_cpc == 0) {
                /*
                goto norot;
        if (fs->fs_cpc == 0) {
                /*
-                * block layout info is not available, so just have
-                * to take any block in this cylinder.
+                * Block layout information is not available.
+                * Leaving bpref unchanged means we take the
+                * next available free block following the one 
+                * we just allocated. Hopefully this will at
+                * least hit a track cache on drives of unknown
+                * geometry (e.g. SCSI).
                 */
                 */
-               bpref = howmany(fs->fs_spc * cylno, NSPF(fs));
                goto norot;
        }
        /*
                goto norot;
        }
        /*
@@ -992,19 +999,22 @@ ffs_blkfree(ip, bno, size)
  *
  * The specified inode is placed back in the free map.
  */
  *
  * The specified inode is placed back in the free map.
  */
-void
-ffs_vfree(pvp, ino, mode)
-       struct vnode *pvp;
-       ino_t ino;
-       int mode;
+int
+ffs_vfree(ap)
+       struct vop_vfree_args /* {
+               struct vnode *a_pvp;
+               ino_t a_ino;
+               int a_mode;
+       } */ *ap;
 {
        register struct fs *fs;
        register struct cg *cgp;
        register struct inode *pip;
 {
        register struct fs *fs;
        register struct cg *cgp;
        register struct inode *pip;
+       ino_t ino = ap->a_ino;
        struct buf *bp;
        int error, cg;
 
        struct buf *bp;
        int error, cg;
 
-       pip = VTOI(pvp);
+       pip = VTOI(ap->a_pvp);
        fs = pip->i_fs;
        if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg)
                panic("ifree: range: dev = 0x%x, ino = %d, fs = %s\n",
        fs = pip->i_fs;
        if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg)
                panic("ifree: range: dev = 0x%x, ino = %d, fs = %s\n",
@@ -1018,13 +1028,13 @@ ffs_vfree(pvp, ino, mode)
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
-               return;
+               return (0);
        }
 #endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
        }
 #endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
-               return;
+               return (0);
        }
        cgp->cg_time = time.tv_sec;
        ino %= fs->fs_ipg;
        }
        cgp->cg_time = time.tv_sec;
        ino %= fs->fs_ipg;
@@ -1040,13 +1050,14 @@ ffs_vfree(pvp, ino, mode)
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
        fs->fs_cs(fs, cg).cs_nifree++;
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
        fs->fs_cs(fs, cg).cs_nifree++;
-       if ((mode & IFMT) == IFDIR) {
+       if ((ap->a_mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
                fs->fs_cs(fs, cg).cs_ndir--;
        }
        fs->fs_fmod = 1;
        bdwrite(bp);
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
                fs->fs_cs(fs, cg).cs_ndir--;
        }
        fs->fs_fmod = 1;
        bdwrite(bp);
+       return (0);
 }
 
 /*
 }
 
 /*