handle short reads on quota files by using default values
[unix-history] / usr / src / sys / ufs / ffs / ufs_lookup.c
index d7befb6..ad2edd0 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ufs_lookup.c        7.18 (Berkeley) %G%
+ *     @(#)ufs_lookup.c        7.21 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -22,6 +22,7 @@
 #include "buf.h"
 #include "file.h"
 #include "vnode.h"
 #include "buf.h"
 #include "file.h"
 #include "vnode.h"
+#include "../ufs/quota.h"
 #include "../ufs/inode.h"
 #include "../ufs/fs.h"
 
 #include "../ufs/inode.h"
 #include "../ufs/fs.h"
 
@@ -63,11 +64,10 @@ int dirchk = 1;
  *
  * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode unlocked.
  */
  *
  * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode unlocked.
  */
-ufs_lookup(vp, ndp)
-       struct vnode *vp;
+ufs_lookup(vdp, ndp)
+       register struct vnode *vdp;
        register struct nameidata *ndp;
 {
        register struct nameidata *ndp;
 {
-       register struct vnode *vdp;     /* vnode copy of dp */
        register struct inode *dp;      /* the directory we are searching */
        register struct fs *fs;         /* file system that directory is in */
        struct buf *bp = 0;             /* a buffer of directory entries */
        register struct inode *dp;      /* the directory we are searching */
        register struct fs *fs;         /* file system that directory is in */
        struct buf *bp = 0;             /* a buffer of directory entries */
@@ -89,9 +89,9 @@ ufs_lookup(vp, ndp)
        int wantparent;                 /* 1 => wantparent or lockparent flag */
        int error;
 
        int wantparent;                 /* 1 => wantparent or lockparent flag */
        int error;
 
-       ndp->ni_dvp = vp;
+       ndp->ni_dvp = vdp;
        ndp->ni_vp = NULL;
        ndp->ni_vp = NULL;
-       dp = VTOI(vp);
+       dp = VTOI(vdp);
        fs = dp->i_fs;
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        flag = ndp->ni_nameiop & OPFLAG;
        fs = dp->i_fs;
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        flag = ndp->ni_nameiop & OPFLAG;
@@ -102,7 +102,7 @@ ufs_lookup(vp, ndp)
         */
        if ((dp->i_mode&IFMT) != IFDIR)
                return (ENOTDIR);
         */
        if ((dp->i_mode&IFMT) != IFDIR)
                return (ENOTDIR);
-       if (error = iaccess(dp, IEXEC, ndp->ni_cred))
+       if (error = ufs_access(vdp, VEXEC, ndp->ni_cred))
                return (error);
 
        /*
                return (error);
 
        /*
@@ -117,7 +117,7 @@ ufs_lookup(vp, ndp)
 
                if (error == ENOENT)
                        return (error);
 
                if (error == ENOENT)
                        return (error);
-               if (vp == ndp->ni_rdir && ndp->ni_isdotdot)
+               if (vdp == ndp->ni_rdir && ndp->ni_isdotdot)
                        panic("ufs_lookup: .. through root");
                /*
                 * Get the next vnode in the path.
                        panic("ufs_lookup: .. through root");
                /*
                 * Get the next vnode in the path.
@@ -150,6 +150,7 @@ ufs_lookup(vp, ndp)
                }
                ILOCK(pdp);
                dp = pdp;
                }
                ILOCK(pdp);
                dp = pdp;
+               vdp = ITOV(dp);
                ndp->ni_vp = NULL;
        }
 
                ndp->ni_vp = NULL;
        }
 
@@ -314,7 +315,7 @@ searchloop:
                 * Access for write is interpreted as allowing
                 * creation of files in the directory.
                 */
                 * Access for write is interpreted as allowing
                 * creation of files in the directory.
                 */
-               if (error = iaccess(dp, IWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred))
                        return (error);
                /*
                 * Return an indication of where the new directory
                        return (error);
                /*
                 * Return an indication of where the new directory
@@ -389,7 +390,7 @@ found:
                /*
                 * Write access to directory required to delete files.
                 */
                /*
                 * Write access to directory required to delete files.
                 */
-               if (error = iaccess(dp, IWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred))
                        return (error);
                /*
                 * Return pointer to current entry in ndp->ni_offset,
                        return (error);
                /*
                 * Return pointer to current entry in ndp->ni_offset,
@@ -401,30 +402,29 @@ found:
                        ndp->ni_count = 0;
                else
                        ndp->ni_count = ndp->ni_offset - prevoff;
                        ndp->ni_count = 0;
                else
                        ndp->ni_count = ndp->ni_offset - prevoff;
-               vdp = ITOV(dp);
                if (dp->i_number == ndp->ni_dent.d_ino) {
                        VREF(vdp);
                if (dp->i_number == ndp->ni_dent.d_ino) {
                        VREF(vdp);
-               } else {
-                       if (error = iget(dp, ndp->ni_dent.d_ino, &tdp))
-                               return (error);
-                       vdp = ITOV(tdp);
-                       /*
-                        * If directory is "sticky", then user must own
-                        * the directory, or the file in it, else he
-                        * may not delete it (unless he's root). This
-                        * implements append-only directories.
-                        */
-                       if ((dp->i_mode & ISVTX) &&
-                           ndp->ni_cred->cr_uid != 0 &&
-                           ndp->ni_cred->cr_uid != dp->i_uid &&
-                           tdp->i_uid != ndp->ni_cred->cr_uid) {
-                               iput(tdp);
-                               return (EPERM);
-                       }
-                       if (!lockparent)
-                               IUNLOCK(dp);
+                       ndp->ni_vp = vdp;
+                       return (0);
                }
                }
-               ndp->ni_vp = vdp;
+               if (error = iget(dp, ndp->ni_dent.d_ino, &tdp))
+                       return (error);
+               /*
+                * If directory is "sticky", then user must own
+                * the directory, or the file in it, else she
+                * may not delete it (unless she's root). This
+                * implements append-only directories.
+                */
+               if ((dp->i_mode & ISVTX) &&
+                   ndp->ni_cred->cr_uid != 0 &&
+                   ndp->ni_cred->cr_uid != dp->i_uid &&
+                   tdp->i_uid != ndp->ni_cred->cr_uid) {
+                       iput(tdp);
+                       return (EPERM);
+               }
+               ndp->ni_vp = ITOV(tdp);
+               if (!lockparent)
+                       IUNLOCK(dp);
                return (0);
        }
 
                return (0);
        }
 
@@ -435,7 +435,7 @@ found:
         * regular file, or empty directory.
         */
        if (flag == RENAME && wantparent && *ndp->ni_next == 0) {
         * regular file, or empty directory.
         */
        if (flag == RENAME && wantparent && *ndp->ni_next == 0) {
-               if (error = iaccess(dp, IWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred))
                        return (error);
                /*
                 * Careful about locking second inode.
                        return (error);
                /*
                 * Careful about locking second inode.
@@ -481,7 +481,6 @@ found:
                        ILOCK(pdp);
                ndp->ni_vp = ITOV(tdp);
        } else if (dp->i_number == ndp->ni_dent.d_ino) {
                        ILOCK(pdp);
                ndp->ni_vp = ITOV(tdp);
        } else if (dp->i_number == ndp->ni_dent.d_ino) {
-               vdp = ITOV(dp);
                VREF(vdp);      /* we want ourself, ie "." */
                ndp->ni_vp = vdp;
        } else {
                VREF(vdp);      /* we want ourself, ie "." */
                ndp->ni_vp = vdp;
        } else {
@@ -571,6 +570,7 @@ direnter(ip, ndp)
                ndp->ni_count = newentrysize;
                ndp->ni_resid = newentrysize;
                ndp->ni_base = (caddr_t)&ndp->ni_dent;
                ndp->ni_count = newentrysize;
                ndp->ni_resid = newentrysize;
                ndp->ni_base = (caddr_t)&ndp->ni_dent;
+               ndp->ni_uioseg = UIO_SYSSPACE;
                error =
                    ufs_write(ndp->ni_dvp, &ndp->ni_uio, IO_SYNC, ndp->ni_cred);
                if (DIRBLKSIZ > dp->i_fs->fs_fsize)
                error =
                    ufs_write(ndp->ni_dvp, &ndp->ni_uio, IO_SYNC, ndp->ni_cred);
                if (DIRBLKSIZ > dp->i_fs->fs_fsize)
@@ -648,8 +648,8 @@ direnter(ip, ndp)
        bcopy((caddr_t)&ndp->ni_dent, (caddr_t)ep, (u_int)newentrysize);
        error = bwrite(bp);
        dp->i_flag |= IUPD|ICHG;
        bcopy((caddr_t)&ndp->ni_dent, (caddr_t)ep, (u_int)newentrysize);
        error = bwrite(bp);
        dp->i_flag |= IUPD|ICHG;
-       if (ndp->ni_endoff && ndp->ni_endoff < dp->i_size)
-               error = itrunc(dp, (u_long)ndp->ni_endoff);
+       if (!error && ndp->ni_endoff && ndp->ni_endoff < dp->i_size)
+               error = itrunc(dp, (u_long)ndp->ni_endoff, IO_SYNC);
        iput(dp);
        return (error);
 }
        iput(dp);
        return (error);
 }
@@ -681,6 +681,7 @@ dirremove(ndp)
                ndp->ni_dent.d_ino = 0;
                ndp->ni_count = ndp->ni_resid = DIRSIZ(&ndp->ni_dent);
                ndp->ni_base = (caddr_t)&ndp->ni_dent;
                ndp->ni_dent.d_ino = 0;
                ndp->ni_count = ndp->ni_resid = DIRSIZ(&ndp->ni_dent);
                ndp->ni_base = (caddr_t)&ndp->ni_dent;
+               ndp->ni_uioseg = UIO_SYSSPACE;
                error =
                    ufs_write(ndp->ni_dvp, &ndp->ni_uio, IO_SYNC, ndp->ni_cred);
        } else {
                error =
                    ufs_write(ndp->ni_dvp, &ndp->ni_uio, IO_SYNC, ndp->ni_cred);
        } else {
@@ -711,6 +712,7 @@ dirrewrite(dp, ip, ndp)
        ndp->ni_dent.d_ino = ip->i_number;
        ndp->ni_count = ndp->ni_resid = DIRSIZ(&ndp->ni_dent);
        ndp->ni_base = (caddr_t)&ndp->ni_dent;
        ndp->ni_dent.d_ino = ip->i_number;
        ndp->ni_count = ndp->ni_resid = DIRSIZ(&ndp->ni_dent);
        ndp->ni_base = (caddr_t)&ndp->ni_dent;
+       ndp->ni_uioseg = UIO_SYSSPACE;
        return (ufs_write(ITOV(dp), &ndp->ni_uio, IO_SYNC, ndp->ni_cred));
 }
 
        return (ufs_write(ITOV(dp), &ndp->ni_uio, IO_SYNC, ndp->ni_cred));
 }
 
@@ -734,17 +736,7 @@ blkatoff(ip, offset, res, bpp)
        int error;
 
        *bpp = 0;
        int error;
 
        *bpp = 0;
-       if (error = bmap(ip, lbn, &bn, (daddr_t *)0, (int *)0))
-               return (error);
-       if (bn == (daddr_t)-1) {
-               dirbad(ip, offset, "hole in dir");
-               return (EIO);
-       }
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, bn), bsize, fs->fs_dbsize);
-#else SECSIZE
-       error = bread(ip->i_devvp, bn, bsize, NOCRED, &bp);
-       if (error) {
+       if (error = bread(ITOV(ip), lbn, bsize, NOCRED, &bp)) {
                brelse(bp);
                return (error);
        }
                brelse(bp);
                return (error);
        }