brealloc => allocbuf
[unix-history] / usr / src / sys / ufs / ffs / ffs_alloc.c
index f282721..416461f 100644 (file)
@@ -2,24 +2,13 @@
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)ffs_alloc.c 7.13 (Berkeley) %G%
+ *     @(#)ffs_alloc.c 7.21 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "mount.h"
 #include "buf.h"
 #include "user.h"
 #include "vnode.h"
 #include "buf.h"
 #include "user.h"
 #include "vnode.h"
@@ -69,6 +58,7 @@ alloc(ip, lbn, bpref, size, bnp)
        register struct fs *fs;
        register struct buf *bp;
        int cg, error;
        register struct fs *fs;
        register struct buf *bp;
        int cg, error;
+       struct ucred *cred = u.u_cred;          /* XXX */
        
        *bnp = 0;
        fs = ip->i_fs;
        
        *bnp = 0;
        fs = ip->i_fs;
@@ -79,10 +69,10 @@ alloc(ip, lbn, bpref, size, bnp)
        }
        if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
        }
        if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
-       if (u.u_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
+       if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
                goto nospace;
 #ifdef QUOTA
                goto nospace;
 #ifdef QUOTA
-       if (error = chkdq(ip, (long)btodb(size), 0))
+       if (error = chkdq(ip, (long)btodb(size), cred, 0))
                return (error);
 #endif
        if (bpref >= fs->fs_size)
                return (error);
 #endif
        if (bpref >= fs->fs_size)
@@ -100,7 +90,7 @@ alloc(ip, lbn, bpref, size, bnp)
                return (0);
        }
 nospace:
                return (0);
        }
 nospace:
-       fserr(fs, "file system full");
+       fserr(fs, cred->cr_uid, "file system full");
        uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
        uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
@@ -125,6 +115,7 @@ realloccg(ip, lbprev, bpref, osize, nsize, bpp)
        int cg, request;
        daddr_t bprev, bno, bn;
        int i, error, count;
        int cg, request;
        daddr_t bprev, bno, bn;
        int i, error, count;
+       struct ucred *cred = u.u_cred;          /* XXX */
        
        *bpp = 0;
        fs = ip->i_fs;
        
        *bpp = 0;
        fs = ip->i_fs;
@@ -134,7 +125,7 @@ realloccg(ip, lbprev, bpref, osize, nsize, bpp)
                    ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
                panic("realloccg: bad size");
        }
                    ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt);
                panic("realloccg: bad size");
        }
-       if (u.u_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
+       if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
                goto nospace;
        if ((bprev = ip->i_db[lbprev]) == 0) {
                printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n",
                goto nospace;
        if ((bprev = ip->i_db[lbprev]) == 0) {
                printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n",
@@ -142,7 +133,7 @@ realloccg(ip, lbprev, bpref, osize, nsize, bpp)
                panic("realloccg: bad bprev");
        }
 #ifdef QUOTA
                panic("realloccg: bad bprev");
        }
 #ifdef QUOTA
-       if (error = chkdq(ip, (long)btodb(nsize - osize), 0))
+       if (error = chkdq(ip, (long)btodb(nsize - osize), cred, 0))
                return (error);
 #endif
        /*
                return (error);
 #endif
        /*
@@ -152,18 +143,18 @@ realloccg(ip, lbprev, bpref, osize, nsize, bpp)
                brelse(bp);
                return (error);
        }
                brelse(bp);
                return (error);
        }
-       brealloc(bp, nsize);
+       allocbuf(bp, nsize);
        bp->b_flags |= B_DONE;
        bzero(bp->b_un.b_addr + osize, (unsigned)nsize - osize);
        bp->b_flags |= B_DONE;
        bzero(bp->b_un.b_addr + osize, (unsigned)nsize - osize);
-       ip->i_blocks += btodb(nsize - osize);
-       ip->i_flag |= IUPD|ICHG;
        /*
         * Check for extension in the existing location.
         */
        cg = dtog(fs, bprev);
        if (bno = fragextend(ip, cg, (long)bprev, osize, nsize)) {
        /*
         * Check for extension in the existing location.
         */
        cg = dtog(fs, bprev);
        if (bno = fragextend(ip, cg, (long)bprev, osize, nsize)) {
-               if (bp->b_blkno != bno)
+               if (bp->b_blkno != fsbtodb(fs, bno))
                        panic("bad blockno");
                        panic("bad blockno");
+               ip->i_blocks += btodb(nsize - osize);
+               ip->i_flag |= IUPD|ICHG;
                *bpp = bp;
                return (0);
        }
                *bpp = bp;
                return (0);
        }
@@ -244,7 +235,7 @@ nospace:
        /*
         * no space available
         */
        /*
         * no space available
         */
-       fserr(fs, "file system full");
+       fserr(fs, cred->cr_uid, "file system full");
        uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
        uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
        return (ENOSPC);
 }
@@ -264,10 +255,11 @@ 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.
  */
-ialloc(pip, ipref, mode, ipp)
+ialloc(pip, ipref, mode, cred, ipp)
        register struct inode *pip;
        ino_t ipref;
        int mode;
        register struct inode *pip;
        ino_t ipref;
        int mode;
+       struct ucred *cred;
        struct inode **ipp;
 {
        ino_t ino;
        struct inode **ipp;
 {
        ino_t ino;
@@ -279,10 +271,6 @@ ialloc(pip, ipref, mode, ipp)
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
                goto noinodes;
        fs = pip->i_fs;
        if (fs->fs_cstotal.cs_nifree == 0)
                goto noinodes;
-#ifdef QUOTA
-       if (error = chkiq(pip->i_dev, (struct inode *)NULL, u.u_uid, 0))
-               return (error);
-#endif
        if (ipref >= fs->fs_ncg * fs->fs_ipg)
                ipref = 0;
        cg = itog(fs, ipref);
        if (ipref >= fs->fs_ncg * fs->fs_ipg)
                ipref = 0;
        cg = itog(fs, ipref);
@@ -291,7 +279,7 @@ ialloc(pip, ipref, mode, ipp)
                goto noinodes;
        error = iget(pip, ino, ipp);
        if (error) {
                goto noinodes;
        error = iget(pip, ino, ipp);
        if (error) {
-               ifree(pip, ino, 0);
+               ifree(pip, ino, mode);
                return (error);
        }
        ip = *ipp;
                return (error);
        }
        ip = *ipp;
@@ -314,7 +302,7 @@ ialloc(pip, ipref, mode, ipp)
        ip->i_gen = nextgennumber;
        return (0);
 noinodes:
        ip->i_gen = nextgennumber;
        return (0);
 noinodes:
-       fserr(fs, "out of inodes");
+       fserr(fs, 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);
 }
@@ -872,6 +860,7 @@ blkfree(ip, bno, size)
        struct buf *bp;
        int error, cg, blk, frags, bbase;
        register int i;
        struct buf *bp;
        int error, cg, blk, frags, bbase;
        register int i;
+       struct ucred *cred = u.u_cred;  /* 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) {
@@ -880,8 +869,9 @@ blkfree(ip, bno, size)
                panic("blkfree: bad size");
        }
        cg = dtog(fs, bno);
                panic("blkfree: bad size");
        }
        cg = dtog(fs, bno);
-       if (badblock(fs, bno)) {
+       if ((unsigned)bno >= fs->fs_size) {
                printf("bad block %d, ino %d\n", bno, ip->i_number);
                printf("bad block %d, ino %d\n", bno, ip->i_number);
+               fserr(fs, cred->cr_uid, "bad block");
                return;
        }
 #ifdef SECSIZE
                return;
        }
 #ifdef SECSIZE
@@ -1093,10 +1083,11 @@ mapsearch(fs, cgp, bpref, allocsiz)
  * The form of the error message is:
  *     fs: error message
  */
  * The form of the error message is:
  *     fs: error message
  */
-fserr(fs, cp)
+fserr(fs, uid, cp)
        struct fs *fs;
        struct fs *fs;
+       uid_t uid;
        char *cp;
 {
 
        char *cp;
 {
 
-       log(LOG_ERR, "%s: %s\n", fs->fs_fsmnt, cp);
+       log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->fs_fsmnt, cp);
 }
 }