BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / ufs / ufs_lookup.c
index 9ca6549..1efc997 100644 (file)
@@ -2,35 +2,54 @@
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  Neither the name of the University nor the names of
- * its contributors may 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
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ufs_lookup.c        7.23 (Berkeley) 6/28/90
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ufs_lookup.c        7.33 (Berkeley) 5/19/91
  */
 
 #include "param.h"
  */
 
 #include "param.h"
-#include "user.h"
+#include "namei.h"
 #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 "quota.h"
+#include "inode.h"
+#include "dir.h"
+#include "fs.h"
 
 struct nchstats nchstats;
 
 struct nchstats nchstats;
+#ifdef DIAGNOSTIC
 int    dirchk = 1;
 int    dirchk = 1;
+#else
+int    dirchk = 0;
+#endif
 
 /*
  * Convert a component of a pathname into a pointer to a locked inode.
 
 /*
  * Convert a component of a pathname into a pointer to a locked inode.
@@ -67,9 +86,10 @@ int  dirchk = 1;
  *
  * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode unlocked.
  */
  *
  * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode unlocked.
  */
-ufs_lookup(vdp, ndp)
+ufs_lookup(vdp, ndp, p)
        register struct vnode *vdp;
        register struct nameidata *ndp;
        register struct vnode *vdp;
        register struct nameidata *ndp;
+       struct proc *p;
 {
        register struct inode *dp;      /* the directory we are searching */
        register struct fs *fs;         /* file system that directory is in */
 {
        register struct inode *dp;      /* the directory we are searching */
        register struct fs *fs;         /* file system that directory is in */
@@ -83,7 +103,7 @@ ufs_lookup(vdp, ndp)
        int slotneeded;                 /* size of the entry we're seeking */
        int numdirpasses;               /* strategy for directory search */
        int endsearch;                  /* offset to end directory search */
        int slotneeded;                 /* size of the entry we're seeking */
        int numdirpasses;               /* strategy for directory search */
        int endsearch;                  /* offset to end directory search */
-       int prevoff;                    /* ndp->ni_offset of previous entry */
+       int prevoff;                    /* ndp->ni_ufs.ufs_offset of previous entry */
        struct inode *pdp;              /* saved dp during symlink work */
        struct inode *tdp;              /* returned by iget */
        off_t enduseful;                /* pointer past last used dir slot */
        struct inode *pdp;              /* saved dp during symlink work */
        struct inode *tdp;              /* returned by iget */
        off_t enduseful;                /* pointer past last used dir slot */
@@ -97,7 +117,7 @@ ufs_lookup(vdp, ndp)
        dp = VTOI(vdp);
        fs = dp->i_fs;
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        dp = VTOI(vdp);
        fs = dp->i_fs;
        lockparent = ndp->ni_nameiop & LOCKPARENT;
-       flag = ndp->ni_nameiop & OPFLAG;
+       flag = ndp->ni_nameiop & OPMASK;
        wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT);
 
        /*
        wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT);
 
        /*
@@ -105,7 +125,7 @@ ufs_lookup(vdp, ndp)
         */
        if ((dp->i_mode&IFMT) != IFDIR)
                return (ENOTDIR);
         */
        if ((dp->i_mode&IFMT) != IFDIR)
                return (ENOTDIR);
-       if (error = ufs_access(vdp, VEXEC, ndp->ni_cred))
+       if (error = ufs_access(vdp, VEXEC, ndp->ni_cred, p))
                return (error);
 
        /*
                return (error);
 
        /*
@@ -120,8 +140,10 @@ ufs_lookup(vdp, ndp)
 
                if (error == ENOENT)
                        return (error);
 
                if (error == ENOENT)
                        return (error);
+#ifdef PARANOID
                if (vdp == ndp->ni_rdir && ndp->ni_isdotdot)
                        panic("ufs_lookup: .. through root");
                if (vdp == ndp->ni_rdir && ndp->ni_isdotdot)
                        panic("ufs_lookup: .. through root");
+#endif
                /*
                 * Get the next vnode in the path.
                 * See comment below starting `Step through' for
                /*
                 * Get the next vnode in the path.
                 * See comment below starting `Step through' for
@@ -137,9 +159,12 @@ ufs_lookup(vdp, ndp)
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
+                       if (!error && lockparent && *ndp->ni_next == '\0')
+                               ILOCK(pdp);
                } else {
                        error = vget(vdp);
                } else {
                        error = vget(vdp);
-                       IUNLOCK(pdp);
+                       if (!lockparent || error || *ndp->ni_next != '\0')
+                               IUNLOCK(pdp);
                }
                /*
                 * Check that the capability number did not change
                }
                /*
                 * Check that the capability number did not change
@@ -148,8 +173,9 @@ ufs_lookup(vdp, ndp)
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
-                       else
-                               iput(dp);
+                       iput(dp);
+                       if (lockparent && pdp != dp && *ndp->ni_next == '\0')
+                               IUNLOCK(pdp);
                }
                ILOCK(pdp);
                dp = pdp;
                }
                ILOCK(pdp);
                dp = pdp;
@@ -167,7 +193,8 @@ ufs_lookup(vdp, ndp)
        if ((flag == CREATE || flag == RENAME) && *ndp->ni_next == 0) {
                slotstatus = NONE;
                slotfreespace = 0;
        if ((flag == CREATE || flag == RENAME) && *ndp->ni_next == 0) {
                slotstatus = NONE;
                slotfreespace = 0;
-               slotneeded = DIRSIZ(&ndp->ni_dent);
+               slotneeded = ((sizeof (struct direct) - (MAXNAMLEN + 1)) +
+                       ((ndp->ni_namelen + 1 + 3) &~ 3));
        }
 
        /*
        }
 
        /*
@@ -182,14 +209,14 @@ ufs_lookup(vdp, ndp)
         * of simplicity.
         */
        if (flag != LOOKUP || dp->i_diroff == 0 || dp->i_diroff > dp->i_size) {
         * of simplicity.
         */
        if (flag != LOOKUP || dp->i_diroff == 0 || dp->i_diroff > dp->i_size) {
-               ndp->ni_offset = 0;
+               ndp->ni_ufs.ufs_offset = 0;
                numdirpasses = 1;
        } else {
                numdirpasses = 1;
        } else {
-               ndp->ni_offset = dp->i_diroff;
-               entryoffsetinblock = blkoff(fs, ndp->ni_offset);
+               ndp->ni_ufs.ufs_offset = dp->i_diroff;
+               entryoffsetinblock = blkoff(fs, ndp->ni_ufs.ufs_offset);
                if (entryoffsetinblock != 0) {
                if (entryoffsetinblock != 0) {
-                       error = blkatoff(dp, ndp->ni_offset, (char **)0, &bp);
-                       if (error)
+                       if (error = blkatoff(dp, ndp->ni_ufs.ufs_offset,
+                           (char **)0, &bp))
                                return (error);
                }
                numdirpasses = 2;
                                return (error);
                }
                numdirpasses = 2;
@@ -199,17 +226,17 @@ ufs_lookup(vdp, ndp)
        enduseful = 0;
 
 searchloop:
        enduseful = 0;
 
 searchloop:
-       while (ndp->ni_offset < endsearch) {
+       while (ndp->ni_ufs.ufs_offset < endsearch) {
                /*
                 * If offset is on a block boundary,
                 * read the next directory block.
                 * Release previous if it exists.
                 */
                /*
                 * If offset is on a block boundary,
                 * read the next directory block.
                 * Release previous if it exists.
                 */
-               if (blkoff(fs, ndp->ni_offset) == 0) {
+               if (blkoff(fs, ndp->ni_ufs.ufs_offset) == 0) {
                        if (bp != NULL)
                                brelse(bp);
                        if (bp != NULL)
                                brelse(bp);
-                       error = blkatoff(dp, ndp->ni_offset, (char **)0, &bp);
-                       if (error)
+                       if (error = blkatoff(dp, ndp->ni_ufs.ufs_offset,
+                           (char **)0, &bp))
                                return (error);
                        entryoffsetinblock = 0;
                }
                                return (error);
                        entryoffsetinblock = 0;
                }
@@ -234,9 +261,9 @@ searchloop:
                    dirchk && dirbadentry(ep, entryoffsetinblock)) {
                        int i;
 
                    dirchk && dirbadentry(ep, entryoffsetinblock)) {
                        int i;
 
-                       dirbad(dp, ndp->ni_offset, "mangled entry");
+                       dirbad(dp, ndp->ni_ufs.ufs_offset, "mangled entry");
                        i = DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1));
                        i = DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1));
-                       ndp->ni_offset += i;
+                       ndp->ni_ufs.ufs_offset += i;
                        entryoffsetinblock += i;
                        continue;
                }
                        entryoffsetinblock += i;
                        continue;
                }
@@ -255,15 +282,17 @@ searchloop:
                        if (size > 0) {
                                if (size >= slotneeded) {
                                        slotstatus = FOUND;
                        if (size > 0) {
                                if (size >= slotneeded) {
                                        slotstatus = FOUND;
-                                       slotoffset = ndp->ni_offset;
+                                       slotoffset = ndp->ni_ufs.ufs_offset;
                                        slotsize = ep->d_reclen;
                                } else if (slotstatus == NONE) {
                                        slotfreespace += size;
                                        if (slotoffset == -1)
                                        slotsize = ep->d_reclen;
                                } else if (slotstatus == NONE) {
                                        slotfreespace += size;
                                        if (slotoffset == -1)
-                                               slotoffset = ndp->ni_offset;
+                                               slotoffset =
+                                                     ndp->ni_ufs.ufs_offset;
                                        if (slotfreespace >= slotneeded) {
                                                slotstatus = COMPACT;
                                        if (slotfreespace >= slotneeded) {
                                                slotstatus = COMPACT;
-                                               slotsize = ndp->ni_offset +
+                                               slotsize =
+                                                     ndp->ni_ufs.ufs_offset +
                                                      ep->d_reclen - slotoffset;
                                        }
                                }
                                                      ep->d_reclen - slotoffset;
                                        }
                                }
@@ -274,25 +303,25 @@ searchloop:
                 * Check for a name match.
                 */
                if (ep->d_ino) {
                 * Check for a name match.
                 */
                if (ep->d_ino) {
-                       if (ep->d_namlen == ndp->ni_dent.d_namlen &&
+                       if (ep->d_namlen == ndp->ni_namelen &&
                            !bcmp(ndp->ni_ptr, ep->d_name,
                                (unsigned)ep->d_namlen)) {
                                /*
                                 * Save directory entry's inode number and
                            !bcmp(ndp->ni_ptr, ep->d_name,
                                (unsigned)ep->d_namlen)) {
                                /*
                                 * Save directory entry's inode number and
-                                * reclen in ndp->ni_dent, and release
+                                * reclen in ndp->ni_ufs area, and release
                                 * directory buffer.
                                 */
                                 * directory buffer.
                                 */
-                               ndp->ni_dent.d_ino = ep->d_ino;
-                               ndp->ni_dent.d_reclen = ep->d_reclen;
+                               ndp->ni_ufs.ufs_ino = ep->d_ino;
+                               ndp->ni_ufs.ufs_reclen = ep->d_reclen;
                                brelse(bp);
                                goto found;
                        }
                }
                                brelse(bp);
                                goto found;
                        }
                }
-               prevoff = ndp->ni_offset;
-               ndp->ni_offset += ep->d_reclen;
+               prevoff = ndp->ni_ufs.ufs_offset;
+               ndp->ni_ufs.ufs_offset += ep->d_reclen;
                entryoffsetinblock += ep->d_reclen;
                if (ep->d_ino)
                entryoffsetinblock += ep->d_reclen;
                if (ep->d_ino)
-                       enduseful = ndp->ni_offset;
+                       enduseful = ndp->ni_ufs.ufs_offset;
        }
 /* notfound: */
        /*
        }
 /* notfound: */
        /*
@@ -301,7 +330,7 @@ searchloop:
         */
        if (numdirpasses == 2) {
                numdirpasses--;
         */
        if (numdirpasses == 2) {
                numdirpasses--;
-               ndp->ni_offset = 0;
+               ndp->ni_ufs.ufs_offset = 0;
                endsearch = dp->i_diroff;
                goto searchloop;
        }
                endsearch = dp->i_diroff;
                goto searchloop;
        }
@@ -318,27 +347,28 @@ 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 = ufs_access(vdp, VWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred, p))
                        return (error);
                /*
                 * Return an indication of where the new directory
                 * entry should be put.  If we didn't find a slot,
                        return (error);
                /*
                 * Return an indication of where the new directory
                 * entry should be put.  If we didn't find a slot,
-                * then set ndp->ni_count to 0 indicating that the new
-                * slot belongs at the end of the directory. If we found
-                * a slot, then the new entry can be put in the range
-                * [ndp->ni_offset .. ndp->ni_offset + ndp->ni_count)
+                * then set ndp->ni_ufs.ufs_count to 0 indicating
+                * that the new slot belongs at the end of the
+                * directory. If we found a slot, then the new entry
+                * can be put in the range from ndp->ni_ufs.ufs_offset
+                * to ndp->ni_ufs.ufs_offset + ndp->ni_ufs.ufs_count.
                 */
                if (slotstatus == NONE) {
                 */
                if (slotstatus == NONE) {
-                       ndp->ni_offset = roundup(dp->i_size, DIRBLKSIZ);
-                       ndp->ni_count = 0;
-                       enduseful = ndp->ni_offset;
+                       ndp->ni_ufs.ufs_offset = roundup(dp->i_size, DIRBLKSIZ);
+                       ndp->ni_ufs.ufs_count = 0;
+                       enduseful = ndp->ni_ufs.ufs_offset;
                } else {
                } else {
-                       ndp->ni_offset = slotoffset;
-                       ndp->ni_count = slotsize;
+                       ndp->ni_ufs.ufs_offset = slotoffset;
+                       ndp->ni_ufs.ufs_count = slotsize;
                        if (enduseful < slotoffset + slotsize)
                                enduseful = slotoffset + slotsize;
                }
                        if (enduseful < slotoffset + slotsize)
                                enduseful = slotoffset + slotsize;
                }
-               ndp->ni_endoff = roundup(enduseful, DIRBLKSIZ);
+               ndp->ni_ufs.ufs_endoff = roundup(enduseful, DIRBLKSIZ);
                dp->i_flag |= IUPD|ICHG;
                /*
                 * We return with the directory locked, so that
                dp->i_flag |= IUPD|ICHG;
                /*
                 * We return with the directory locked, so that
@@ -347,17 +377,20 @@ searchloop:
                 * We return ni_vp == NULL to indicate that the entry
                 * does not currently exist; we leave a pointer to
                 * the (locked) directory inode in ndp->ni_dvp.
                 * We return ni_vp == NULL to indicate that the entry
                 * does not currently exist; we leave a pointer to
                 * the (locked) directory inode in ndp->ni_dvp.
+                * The pathname buffer is saved so that the name
+                * can be obtained later.
                 *
                 * NB - if the directory is unlocked, then this
                 * information cannot be used.
                 */
                 *
                 * NB - if the directory is unlocked, then this
                 * information cannot be used.
                 */
+               ndp->ni_nameiop |= SAVENAME;
                if (!lockparent)
                        IUNLOCK(dp);
        }
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
                if (!lockparent)
                        IUNLOCK(dp);
        }
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
-       if (ndp->ni_makeentry)
+       if (ndp->ni_makeentry && flag != CREATE)
                cache_enter(ndp);
        return (ENOENT);
 
                cache_enter(ndp);
        return (ENOENT);
 
@@ -369,7 +402,7 @@ found:
         * of this entry.
         */
        if (entryoffsetinblock + DIRSIZ(ep) > dp->i_size) {
         * of this entry.
         */
        if (entryoffsetinblock + DIRSIZ(ep) > dp->i_size) {
-               dirbad(dp, ndp->ni_offset, "i_size too small");
+               dirbad(dp, ndp->ni_ufs.ufs_offset, "i_size too small");
                dp->i_size = entryoffsetinblock + DIRSIZ(ep);
                dp->i_flag |= IUPD|ICHG;
        }
                dp->i_size = entryoffsetinblock + DIRSIZ(ep);
                dp->i_flag |= IUPD|ICHG;
        }
@@ -380,7 +413,7 @@ found:
         * in the cache as to where the entry was found.
         */
        if (*ndp->ni_next == '\0' && flag == LOOKUP)
         * in the cache as to where the entry was found.
         */
        if (*ndp->ni_next == '\0' && flag == LOOKUP)
-               dp->i_diroff = ndp->ni_offset &~ (DIRBLKSIZ - 1);
+               dp->i_diroff = ndp->ni_ufs.ufs_offset &~ (DIRBLKSIZ - 1);
 
        /*
         * If deleting, and at end of pathname, return
 
        /*
         * If deleting, and at end of pathname, return
@@ -393,24 +426,24 @@ found:
                /*
                 * Write access to directory required to delete files.
                 */
                /*
                 * Write access to directory required to delete files.
                 */
-               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred, p))
                        return (error);
                /*
                        return (error);
                /*
-                * Return pointer to current entry in ndp->ni_offset,
+                * Return pointer to current entry in ndp->ni_ufs.ufs_offset,
                 * and distance past previous entry (if there
                 * and distance past previous entry (if there
-                * is a previous entry in this block) in ndp->ni_count.
+                * is a previous entry in this block) in ndp->ni_ufs.ufs_count.
                 * Save directory inode pointer in ndp->ni_dvp for dirremove().
                 */
                 * Save directory inode pointer in ndp->ni_dvp for dirremove().
                 */
-               if ((ndp->ni_offset&(DIRBLKSIZ-1)) == 0)
-                       ndp->ni_count = 0;
+               if ((ndp->ni_ufs.ufs_offset&(DIRBLKSIZ-1)) == 0)
+                       ndp->ni_ufs.ufs_count = 0;
                else
                else
-                       ndp->ni_count = ndp->ni_offset - prevoff;
-               if (dp->i_number == ndp->ni_dent.d_ino) {
+                       ndp->ni_ufs.ufs_count = ndp->ni_ufs.ufs_offset - prevoff;
+               if (dp->i_number == ndp->ni_ufs.ufs_ino) {
                        VREF(vdp);
                        ndp->ni_vp = vdp;
                        return (0);
                }
                        VREF(vdp);
                        ndp->ni_vp = vdp;
                        return (0);
                }
-               if (error = iget(dp, ndp->ni_dent.d_ino, &tdp))
+               if (error = iget(dp, ndp->ni_ufs.ufs_ino, &tdp))
                        return (error);
                /*
                 * If directory is "sticky", then user must own
                        return (error);
                /*
                 * If directory is "sticky", then user must own
@@ -438,17 +471,18 @@ 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 = ufs_access(vdp, VWRITE, ndp->ni_cred))
+               if (error = ufs_access(vdp, VWRITE, ndp->ni_cred, p))
                        return (error);
                /*
                 * Careful about locking second inode.
                 * This can only occur if the target is ".".
                 */
                        return (error);
                /*
                 * Careful about locking second inode.
                 * This can only occur if the target is ".".
                 */
-               if (dp->i_number == ndp->ni_dent.d_ino)
+               if (dp->i_number == ndp->ni_ufs.ufs_ino)
                        return (EISDIR);
                        return (EISDIR);
-               if (error = iget(dp, ndp->ni_dent.d_ino, &tdp))
+               if (error = iget(dp, ndp->ni_ufs.ufs_ino, &tdp))
                        return (error);
                ndp->ni_vp = ITOV(tdp);
                        return (error);
                ndp->ni_vp = ITOV(tdp);
+               ndp->ni_nameiop |= SAVENAME;
                if (!lockparent)
                        IUNLOCK(dp);
                return (0);
                if (!lockparent)
                        IUNLOCK(dp);
                return (0);
@@ -476,18 +510,18 @@ found:
        pdp = dp;
        if (ndp->ni_isdotdot) {
                IUNLOCK(pdp);   /* race to get the inode */
        pdp = dp;
        if (ndp->ni_isdotdot) {
                IUNLOCK(pdp);   /* race to get the inode */
-               if (error = iget(dp, ndp->ni_dent.d_ino, &tdp)) {
+               if (error = iget(dp, ndp->ni_ufs.ufs_ino, &tdp)) {
                        ILOCK(pdp);
                        return (error);
                }
                if (lockparent && *ndp->ni_next == '\0')
                        ILOCK(pdp);
                ndp->ni_vp = ITOV(tdp);
                        ILOCK(pdp);
                        return (error);
                }
                if (lockparent && *ndp->ni_next == '\0')
                        ILOCK(pdp);
                ndp->ni_vp = ITOV(tdp);
-       } else if (dp->i_number == ndp->ni_dent.d_ino) {
+       } else if (dp->i_number == ndp->ni_ufs.ufs_ino) {
                VREF(vdp);      /* we want ourself, ie "." */
                ndp->ni_vp = vdp;
        } else {
                VREF(vdp);      /* we want ourself, ie "." */
                ndp->ni_vp = vdp;
        } else {
-               if (error = iget(dp, ndp->ni_dent.d_ino, &tdp))
+               if (error = iget(dp, ndp->ni_ufs.ufs_ino, &tdp))
                        return (error);
                if (!lockparent || *ndp->ni_next != '\0')
                        IUNLOCK(pdp);
                        return (error);
                if (!lockparent || *ndp->ni_next != '\0')
                        IUNLOCK(pdp);
@@ -511,7 +545,8 @@ dirbad(ip, offset, how)
 
        printf("%s: bad dir ino %d at offset %d: %s\n",
            ip->i_fs->fs_fsmnt, ip->i_number, offset, how);
 
        printf("%s: bad dir ino %d at offset %d: %s\n",
            ip->i_fs->fs_fsmnt, ip->i_number, offset, how);
-       panic("bad dir");
+       if (ip->i_fs->fs_ronly == 0)
+               panic("bad dir");
 }
 
 /*
 }
 
 /*
@@ -540,11 +575,11 @@ dirbadentry(ep, entryoffsetinblock)
 
 /*
  * Write a directory entry after a call to namei, using the parameters
 
 /*
  * Write a directory entry after a call to namei, using the parameters
- * which it left in nameidata.  The argument ip is the inode which the
- * new directory entry will refer to.  The nameidata field ndp->ni_dvp
- * is a pointer to the directory to be written, which was left locked by
- * namei.  Remaining parameters (ndp->ni_offset, ndp->ni_count) indicate
- * how the space for the new entry is to be gotten.
+ * that it left in nameidata.  The argument ip is the inode which the new
+ * directory entry will refer to.  The nameidata field ndp->ni_dvp is a
+ * pointer to the directory to be written, which was left locked by namei.
+ * Remaining parameters (ndp->ni_ufs.ufs_offset, ndp->ni_ufs.ufs_count)
+ * indicate how the space for the new entry is to be obtained.
  */
 direnter(ip, ndp)
        struct inode *ip;
  */
 direnter(ip, ndp)
        struct inode *ip;
@@ -557,42 +592,54 @@ direnter(ip, ndp)
        u_int dsize;
        int newentrysize;
        char *dirbuf;
        u_int dsize;
        int newentrysize;
        char *dirbuf;
-
-       ndp->ni_dent.d_ino = ip->i_number;
-       newentrysize = DIRSIZ(&ndp->ni_dent);
-       if (ndp->ni_count == 0) {
+       struct uio auio;
+       struct iovec aiov;
+       struct direct newdir;
+
+#ifdef DIAGNOSTIC
+       if ((ndp->ni_nameiop & SAVENAME) == 0)
+               panic("direnter: missing name");
+#endif
+       newdir.d_ino = ip->i_number;
+       newdir.d_namlen = ndp->ni_namelen;
+       bcopy(ndp->ni_ptr, newdir.d_name, (unsigned)ndp->ni_namelen + 1);
+       newentrysize = DIRSIZ(&newdir);
+       if (ndp->ni_ufs.ufs_count == 0) {
                /*
                /*
-                * If ndp->ni_count is 0, then namei could find no space in the
-                * directory. In this case ndp->ni_offset will be on a directory
-                * block boundary and we will write the new entry into a fresh
-                * block.
+                * If ndp->ni_ufs.ufs_count is 0, then namei could find no
+                * space in the directory. Here, ndp->ni_ufs.ufs_offset will
+                * be on a directory block boundary and we will write the
+                * new entry into a fresh block.
                 */
                 */
-               if (ndp->ni_offset&(DIRBLKSIZ-1))
+               if (ndp->ni_ufs.ufs_offset & (DIRBLKSIZ - 1))
                        panic("wdir: newblk");
                        panic("wdir: newblk");
-               ndp->ni_dent.d_reclen = DIRBLKSIZ;
-               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);
+               auio.uio_offset = ndp->ni_ufs.ufs_offset;
+               newdir.d_reclen = DIRBLKSIZ;
+               auio.uio_resid = newentrysize;
+               aiov.iov_len = newentrysize;
+               aiov.iov_base = (caddr_t)&newdir;
+               auio.uio_iov = &aiov;
+               auio.uio_iovcnt = 1;
+               auio.uio_rw = UIO_WRITE;
+               auio.uio_segflg = UIO_SYSSPACE;
+               auio.uio_procp = (struct proc *)0;
+               error = ufs_write(ndp->ni_dvp, &auio, IO_SYNC, ndp->ni_cred);
                if (DIRBLKSIZ > dp->i_fs->fs_fsize) {
                        panic("wdir: blksize"); /* XXX - should grow w/balloc */
                if (DIRBLKSIZ > dp->i_fs->fs_fsize) {
                        panic("wdir: blksize"); /* XXX - should grow w/balloc */
-               } else {
+               } else if (!error) {
                        dp->i_size = roundup(dp->i_size, DIRBLKSIZ);
                        dp->i_flag |= ICHG;
                }
                        dp->i_size = roundup(dp->i_size, DIRBLKSIZ);
                        dp->i_flag |= ICHG;
                }
-               iput(dp);
                return (error);
        }
 
        /*
                return (error);
        }
 
        /*
-        * If ndp->ni_count is non-zero, then namei found space for the new
-        * entry in the range ndp->ni_offset to ndp->ni_offset + ndp->ni_count.
-        * in the directory.  To use this space, we may have to compact
-        * the entries located there, by copying them together towards
-        * the beginning of the block, leaving the free space in
-        * one usable chunk at the end.
+        * If ndp->ni_ufs.ufs_count is non-zero, then namei found space
+        * for the new entry in the range ndp->ni_ufs.ufs_offset to
+        * ndp->ni_ufs.ufs_offset + ndp->ni_ufs.ufs_count in the directory.
+        * To use this space, we may have to compact the entries located
+        * there, by copying them together towards the beginning of the
+        * block, leaving the free space in one usable chunk at the end.
         */
 
        /*
         */
 
        /*
@@ -602,25 +649,24 @@ direnter(ip, ndp)
         *
         * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN.
         */
         *
         * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN.
         */
-       if (ndp->ni_offset + ndp->ni_count > dp->i_size)
-               dp->i_size = ndp->ni_offset + ndp->ni_count;
+       if (ndp->ni_ufs.ufs_offset + ndp->ni_ufs.ufs_count > dp->i_size)
+               dp->i_size = ndp->ni_ufs.ufs_offset + ndp->ni_ufs.ufs_count;
        /*
         * Get the block containing the space for the new directory entry.
         */
        /*
         * Get the block containing the space for the new directory entry.
         */
-       if (error = blkatoff(dp, ndp->ni_offset, (char **)&dirbuf, &bp)) {
-               iput(dp);
+       if (error = blkatoff(dp, ndp->ni_ufs.ufs_offset, (char **)&dirbuf, &bp))
                return (error);
                return (error);
-       }
        /*
        /*
-        * Find space for the new entry.  In the simple case, the
-        * entry at offset base will have the space.  If it does
-        * not, then namei arranged that compacting the region
-        * ndp->ni_offset to ndp->ni_offset+ndp->ni_count would yield the space.
+        * Find space for the new entry. In the simple case, the entry at
+        * offset base will have the space. If it does not, then namei
+        * arranged that compacting the region ndp->ni_ufs.ufs_offset to
+        * ndp->ni_ufs.ufs_offset + ndp->ni_ufs.ufs_count would yield the
+        * space.
         */
        ep = (struct direct *)dirbuf;
        dsize = DIRSIZ(ep);
        spacefree = ep->d_reclen - dsize;
         */
        ep = (struct direct *)dirbuf;
        dsize = DIRSIZ(ep);
        spacefree = ep->d_reclen - dsize;
-       for (loc = ep->d_reclen; loc < ndp->ni_count; ) {
+       for (loc = ep->d_reclen; loc < ndp->ni_ufs.ufs_count; ) {
                nep = (struct direct *)(dirbuf + loc);
                if (ep->d_ino) {
                        /* trim the existing slot */
                nep = (struct direct *)(dirbuf + loc);
                if (ep->d_ino) {
                        /* trim the existing slot */
@@ -642,32 +688,32 @@ direnter(ip, ndp)
        if (ep->d_ino == 0) {
                if (spacefree + dsize < newentrysize)
                        panic("wdir: compact1");
        if (ep->d_ino == 0) {
                if (spacefree + dsize < newentrysize)
                        panic("wdir: compact1");
-               ndp->ni_dent.d_reclen = spacefree + dsize;
+               newdir.d_reclen = spacefree + dsize;
        } else {
                if (spacefree < newentrysize)
                        panic("wdir: compact2");
        } else {
                if (spacefree < newentrysize)
                        panic("wdir: compact2");
-               ndp->ni_dent.d_reclen = spacefree;
+               newdir.d_reclen = spacefree;
                ep->d_reclen = dsize;
                ep = (struct direct *)((char *)ep + dsize);
        }
                ep->d_reclen = dsize;
                ep = (struct direct *)((char *)ep + dsize);
        }
-       bcopy((caddr_t)&ndp->ni_dent, (caddr_t)ep, (u_int)newentrysize);
+       bcopy((caddr_t)&newdir, (caddr_t)ep, (u_int)newentrysize);
        error = bwrite(bp);
        dp->i_flag |= IUPD|ICHG;
        error = bwrite(bp);
        dp->i_flag |= IUPD|ICHG;
-       if (!error && ndp->ni_endoff && ndp->ni_endoff < dp->i_size)
-               error = itrunc(dp, (u_long)ndp->ni_endoff, IO_SYNC);
-       iput(dp);
+       if (!error && ndp->ni_ufs.ufs_endoff &&
+           ndp->ni_ufs.ufs_endoff < dp->i_size)
+               error = itrunc(dp, (u_long)ndp->ni_ufs.ufs_endoff, IO_SYNC);
        return (error);
 }
 
 /*
  * Remove a directory entry after a call to namei, using
  * the parameters which it left in nameidata. The entry
        return (error);
 }
 
 /*
  * Remove a directory entry after a call to namei, using
  * the parameters which it left in nameidata. The entry
- * ni_offset contains the offset into the directory of the
- * entry to be eliminated.  The ni_count field contains the
+ * ni_ufs.ufs_offset contains the offset into the directory of the
+ * entry to be eliminated.  The ni_ufs.ufs_count field contains the
  * size of the previous record in the directory.  If this
  * is 0, the first entry is being deleted, so we need only
  * zero the inode number to mark the entry as free.  If the
  * size of the previous record in the directory.  If this
  * is 0, the first entry is being deleted, so we need only
  * zero the inode number to mark the entry as free.  If the
- * entry isn't the first in the directory, we must reclaim
+ * entry is not the first in the directory, we must reclaim
  * the space of the now empty record by adding the record size
  * to the size of the previous entry.
  */
  * the space of the now empty record by adding the record size
  * to the size of the previous entry.
  */
@@ -679,28 +725,28 @@ dirremove(ndp)
        struct buf *bp;
        int error;
 
        struct buf *bp;
        int error;
 
-       if (ndp->ni_count == 0) {
+       if (ndp->ni_ufs.ufs_count == 0) {
                /*
                 * First entry in block: set d_ino to zero.
                 */
                /*
                 * First entry in block: set d_ino to zero.
                 */
-               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 {
-               /*
-                * Collapse new free space into previous entry.
-                */
-               if (error = blkatoff(dp, ndp->ni_offset - ndp->ni_count,
-                   (char **)&ep, &bp)) {
+               error = blkatoff(dp, ndp->ni_ufs.ufs_offset, (char **)&ep, &bp);
+               if (error)
                        return (error);
                        return (error);
-               }
-               ep->d_reclen += ndp->ni_dent.d_reclen;
+               ep->d_ino = 0;
                error = bwrite(bp);
                dp->i_flag |= IUPD|ICHG;
                error = bwrite(bp);
                dp->i_flag |= IUPD|ICHG;
+               return (error);
        }
        }
+       /*
+        * Collapse new free space into previous entry.
+        */
+       if (error = blkatoff(dp, ndp->ni_ufs.ufs_offset - ndp->ni_ufs.ufs_count,
+           (char **)&ep, &bp)) {
+               return (error);
+       }
+       ep->d_reclen += ndp->ni_ufs.ufs_reclen;
+       error = bwrite(bp);
+       dp->i_flag |= IUPD|ICHG;
        return (error);
 }
 
        return (error);
 }
 
@@ -713,12 +759,16 @@ dirrewrite(dp, ip, ndp)
        struct inode *dp, *ip;
        struct nameidata *ndp;
 {
        struct inode *dp, *ip;
        struct nameidata *ndp;
 {
+       struct direct *ep;
+       struct buf *bp;
+       int error;
 
 
-       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));
+       if (error = blkatoff(dp, ndp->ni_ufs.ufs_offset, (char **)&ep, &bp))
+               return (error);
+       ep->d_ino = ip->i_number;
+       error = bwrite(bp);
+       dp->i_flag |= IUPD|ICHG;
+       return (error);
 }
 
 /*
 }
 
 /*
@@ -772,8 +822,8 @@ dirempty(ip, parentino, cred)
 #define        MINDIRSIZ (sizeof (struct dirtemplate) / 2)
 
        for (off = 0; off < ip->i_size; off += dp->d_reclen) {
 #define        MINDIRSIZ (sizeof (struct dirtemplate) / 2)
 
        for (off = 0; off < ip->i_size; off += dp->d_reclen) {
-               error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ,
-                   off, UIO_SYSSPACE, IO_NODELOCKED, cred, &count);
+               error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off,
+                  UIO_SYSSPACE, IO_NODELOCKED, cred, &count, (struct proc *)0);
                /*
                 * Since we read MINDIRSIZ, residual must
                 * be 0 unless we're at end of file.
                /*
                 * Since we read MINDIRSIZ, residual must
                 * be 0 unless we're at end of file.
@@ -833,7 +883,7 @@ checkpath(source, target, cred)
                }
                error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)&dirbuf,
                        sizeof (struct dirtemplate), (off_t)0, UIO_SYSSPACE,
                }
                error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)&dirbuf,
                        sizeof (struct dirtemplate), (off_t)0, UIO_SYSSPACE,
-                       IO_NODELOCKED, cred, (int *)0);
+                       IO_NODELOCKED, cred, (int *)0, (struct proc *)0);
                if (error != 0)
                        break;
                if (dirbuf.dotdot_namlen != 2 ||
                if (error != 0)
                        break;
                if (dirbuf.dotdot_namlen != 2 ||