ufs_vinit prototype changed for new vn_if
[unix-history] / usr / src / sys / ufs / ffs / ffs_alloc.c
index 2e5327c..4ff1455 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ffs_alloc.c 7.28 (Berkeley) %G%
+ *     @(#)ffs_alloc.c 7.34 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -15,6 +15,8 @@
 #include <sys/kernel.h>
 #include <sys/syslog.h>
 
 #include <sys/kernel.h>
 #include <sys/syslog.h>
 
+#include <vm/vm.h>
+
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 
@@ -52,25 +54,29 @@ static daddr_t      ffs_mapsearch __P((struct fs *, struct cg *, daddr_t, int));
  *   2) quadradically rehash into other cylinder groups, until an
  *      available block is located.
  */
  *   2) quadradically rehash into other cylinder groups, until an
  *      available block is located.
  */
-ffs_alloc(ip, lbn, bpref, size, bnp)
+ffs_alloc(ip, lbn, bpref, size, cred, bnp)
        register struct inode *ip;
        daddr_t lbn, bpref;
        int size;
        register struct inode *ip;
        daddr_t lbn, bpref;
        int size;
+       struct ucred *cred;
        daddr_t *bnp;
 {
        daddr_t bno;
        register struct fs *fs;
        register struct buf *bp;
        int cg, error;
        daddr_t *bnp;
 {
        daddr_t bno;
        register struct fs *fs;
        register struct buf *bp;
        int cg, error;
-       struct ucred *cred = curproc->p_ucred;          /* XXX */
        
        *bnp = 0;
        fs = ip->i_fs;
        
        *bnp = 0;
        fs = ip->i_fs;
+#ifdef DIAGNOSTIC
        if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) {
                printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
                    ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
                panic("ffs_alloc: bad size");
        }
        if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) {
                printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n",
                    ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt);
                panic("ffs_alloc: bad size");
        }
+       if (cred == NOCRED)
+               panic("ffs_alloc: missing credential\n");
+#endif /* DIAGNOSTIC */
        if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
        if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
        if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
        if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
@@ -113,21 +119,22 @@ nospace:
  * the original block. Failing that, the regular block allocator is
  * invoked to get an appropriate block.
  */
  * the original block. Failing that, the regular block allocator is
  * invoked to get an appropriate block.
  */
-ffs_realloccg(ip, lbprev, bpref, osize, nsize, bpp)
+ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp)
        register struct inode *ip;
        register struct inode *ip;
-       off_t lbprev;
+       daddr_t lbprev;
        daddr_t bpref;
        int osize, nsize;
        daddr_t bpref;
        int osize, nsize;
+       struct ucred *cred;
        struct buf **bpp;
 {
        register struct fs *fs;
        struct buf *bp, *obp;
        int cg, request, error;
        daddr_t bprev, bno;
        struct buf **bpp;
 {
        register struct fs *fs;
        struct buf *bp, *obp;
        int cg, request, error;
        daddr_t bprev, bno;
-       struct ucred *cred = curproc->p_ucred;          /* XXX */
        
        *bpp = 0;
        fs = ip->i_fs;
        
        *bpp = 0;
        fs = ip->i_fs;
+#ifdef DIAGNOSTIC
        if ((unsigned)osize > fs->fs_bsize || fragoff(fs, osize) != 0 ||
            (unsigned)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) {
                printf(
        if ((unsigned)osize > fs->fs_bsize || fragoff(fs, osize) != 0 ||
            (unsigned)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) {
                printf(
@@ -135,6 +142,9 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, bpp)
                    ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
                panic("ffs_realloccg: bad size");
        }
                    ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
                panic("ffs_realloccg: bad size");
        }
+       if (cred == NOCRED)
+               panic("ffs_realloccg: missing credential\n");
+#endif /* DIAGNOSTIC */
        if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
                goto nospace;
        if ((bprev = ip->i_db[lbprev]) == 0) {
        if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
                goto nospace;
        if ((bprev = ip->i_db[lbprev]) == 0) {
@@ -232,10 +242,10 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, bpp)
 #else SECSIZE
                        munhash(ip->i_dev, bn + i * CLBYTES / DEV_BSIZE);
 #endif SECSIZE
 #else SECSIZE
                        munhash(ip->i_dev, bn + i * CLBYTES / DEV_BSIZE);
 #endif SECSIZE
-               ffs_blkfree(ip, bprev, (off_t)osize);
+               ffs_blkfree(ip, bprev, (long)osize);
                if (nsize < request)
                        ffs_blkfree(ip, bno + numfrags(fs, nsize),
                if (nsize < request)
                        ffs_blkfree(ip, bno + numfrags(fs, nsize),
-                           (off_t)(request - nsize));
+                           (long)(request - nsize));
                ip->i_blocks += btodb(nsize - osize);
                ip->i_flag |= IUPD|ICHG;
                allocbuf(bp, nsize);
                ip->i_blocks += btodb(nsize - osize);
                ip->i_flag |= IUPD|ICHG;
                allocbuf(bp, nsize);
@@ -275,24 +285,26 @@ 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_ialloc(pip, mode, cred, ipp)
-       register struct inode *pip;
+ffs_valloc(pvp, mode, cred, vpp)
+       register struct vnode *pvp;
        int mode;
        struct ucred *cred;
        int mode;
        struct ucred *cred;
-       struct inode **ipp;
+       struct vnode **vpp;
 {
 {
+       register struct inode *pip;
        register struct fs *fs;
        register struct inode *ip;
        ino_t ino, ipref;
        int cg, error;
        
        register struct fs *fs;
        register struct inode *ip;
        ino_t ino, ipref;
        int cg, error;
        
-       *ipp = NULL;
+       *vpp = NULL;
+       pip = VTOI(pvp);
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
                goto noinodes;
 
        if ((mode & IFMT) == IFDIR)
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
                goto noinodes;
 
        if ((mode & IFMT) == IFDIR)
-               ipref = ffs_dirpref(pip->i_fs);
+               ipref = ffs_dirpref(fs);
        else
                ipref = pip->i_number;
        if (ipref >= fs->fs_ncg * fs->fs_ipg)
        else
                ipref = pip->i_number;
        if (ipref >= fs->fs_ncg * fs->fs_ipg)
@@ -301,16 +313,16 @@ ffs_ialloc(pip, mode, cred, ipp)
        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_iget(pip, ino, ipp);
+       error = ffs_vget(pvp->v_mount, ino, vpp);
        if (error) {
        if (error) {
-               ffs_ifree(pip, ino, mode);      /* XXX already freed? */
+               ffs_vfree(pvp, ino, mode);
                return (error);
        }
                return (error);
        }
-       ip = *ipp;
+       ip = VTOI(*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);
-               panic("ffs_ialloc: dup alloc");
+               panic("ffs_valloc: dup alloc");
        }
        if (ip->i_blocks) {                             /* XXX */
                printf("free inode %s/%d had %d blocks\n",
        }
        if (ip->i_blocks) {                             /* XXX */
                printf("free inode %s/%d had %d blocks\n",
@@ -582,7 +594,7 @@ ffs_fragextend(ip, cg, bprev, osize, nsize)
  * Check to see if a block of the apprpriate size is available,
  * and if it is, allocate it.
  */
  * Check to see if a block of the apprpriate size is available,
  * and if it is, allocate it.
  */
-daddr_t
+static daddr_t
 ffs_alloccg(ip, cg, bpref, size)
        struct inode *ip;
        int cg;
 ffs_alloccg(ip, cg, bpref, size)
        struct inode *ip;
        int cg;
@@ -877,14 +889,13 @@ gotit:
 ffs_blkfree(ip, bno, size)
        register struct inode *ip;
        daddr_t bno;
 ffs_blkfree(ip, bno, size)
        register struct inode *ip;
        daddr_t bno;
-       off_t size;
+       long size;
 {
        register struct fs *fs;
        register struct cg *cgp;
        struct buf *bp;
        int error, cg, blk, frags, bbase;
        register int i;
 {
        register struct fs *fs;
        register struct cg *cgp;
        struct buf *bp;
        int error, cg, blk, frags, bbase;
        register int i;
-       struct ucred *cred = curproc->p_ucred;  /* XXX */
 
        fs = ip->i_fs;
        if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) {
 
        fs = ip->i_fs;
        if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) {
@@ -895,7 +906,7 @@ ffs_blkfree(ip, bno, size)
        cg = dtog(fs, bno);
        if ((unsigned)bno >= fs->fs_size) {
                printf("bad block %d, ino %d\n", bno, ip->i_number);
        cg = dtog(fs, bno);
        if ((unsigned)bno >= fs->fs_size) {
                printf("bad block %d, ino %d\n", bno, ip->i_number);
-               ffs_fserr(fs, cred->cr_uid, "bad block");
+               ffs_fserr(fs, ip->i_uid, "bad block");
                return;
        }
 #ifdef SECSIZE
                return;
        }
 #ifdef SECSIZE
@@ -982,16 +993,18 @@ ffs_blkfree(ip, bno, size)
  * The specified inode is placed back in the free map.
  */
 void
  * The specified inode is placed back in the free map.
  */
 void
-ffs_ifree(pip, ino, mode)
-       struct inode *pip;
+ffs_vfree(pvp, ino, mode)
+       struct vnode *pvp;
        ino_t ino;
        int mode;
 {
        register struct fs *fs;
        register struct cg *cgp;
        ino_t ino;
        int mode;
 {
        register struct fs *fs;
        register struct cg *cgp;
+       register struct inode *pip;
        struct buf *bp;
        int error, cg;
 
        struct buf *bp;
        int error, cg;
 
+       pip = VTOI(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",