date and time created 83/02/20 23:36:57 by sam
[unix-history] / usr / src / sys / kern / vfs_lookup.c
index 9cb4575..96e7e79 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_lookup.c    4.30    82/11/13        */
+/*     vfs_lookup.c    4.35    83/02/10        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -159,7 +159,7 @@ dirloop2:
         * e.g. like "/." or ".".
         */
        if (u.u_dent.d_name[0] == 0) {
         * e.g. like "/." or ".".
         */
        if (u.u_dent.d_name[0] == 0) {
-               if (flag) {
+               if (flag || lockparent) {
                        u.u_error = ENOENT;
                        goto bad;
                }
                        u.u_error = ENOENT;
                        goto bad;
                }
@@ -537,7 +537,7 @@ direnter(ip)
 {
        register struct direct *ep, *nep;
        struct buf *bp;
 {
        register struct direct *ep, *nep;
        struct buf *bp;
-       int loc, freespace;
+       int loc, freespace, error = 0;
        u_int dsize;
        int newentrysize;
        char *dirbuf;
        u_int dsize;
        int newentrysize;
        char *dirbuf;
@@ -555,10 +555,10 @@ direnter(ip)
                if (u.u_offset&(DIRBLKSIZ-1))
                        panic("wdir: newblk");
                u.u_dent.d_reclen = DIRBLKSIZ;
                if (u.u_offset&(DIRBLKSIZ-1))
                        panic("wdir: newblk");
                u.u_dent.d_reclen = DIRBLKSIZ;
-               (void) rdwri(UIO_WRITE, u.u_pdir, (caddr_t)&u.u_dent,
+               error = rdwri(UIO_WRITE, u.u_pdir, (caddr_t)&u.u_dent,
                    newentrysize, u.u_offset, 1, (int *)0);
                iput(u.u_pdir);
                    newentrysize, u.u_offset, 1, (int *)0);
                iput(u.u_pdir);
-               return;
+               return (error);
        }
 
        /*
        }
 
        /*
@@ -580,12 +580,12 @@ direnter(ip)
 
        /*
         * Get the block containing the space for the new directory
 
        /*
         * Get the block containing the space for the new directory
-        * entry.
+        * entry.  Should return error by result instead of u.u_error.
         */
        bp = blkatoff(u.u_pdir, u.u_offset, (char **)&dirbuf);
        if (bp == 0) {
                iput(u.u_pdir);
         */
        bp = blkatoff(u.u_pdir, u.u_offset, (char **)&dirbuf);
        if (bp == 0) {
                iput(u.u_pdir);
-               return;
+               return (u.u_error);
        }
 
        /*
        }
 
        /*
@@ -631,6 +631,7 @@ direnter(ip)
        bwrite(bp);
        u.u_pdir->i_flag |= IUPD|ICHG;
        iput(u.u_pdir);
        bwrite(bp);
        u.u_pdir->i_flag |= IUPD|ICHG;
        iput(u.u_pdir);
+       return (error);
 }
 
 /*
 }
 
 /*
@@ -651,13 +652,14 @@ dirremove()
        register struct buf *bp;
        struct direct *ep;
 
        register struct buf *bp;
        struct direct *ep;
 
-       if (u.u_count == 0)
+       if (u.u_count == 0) {
                /*
                 * First entry in block: set d_ino to zero.
                 */
                /*
                 * First entry in block: set d_ino to zero.
                 */
+               u.u_dent.d_ino = 0;
                (void) rdwri(UIO_WRITE, dp, (caddr_t)&u.u_dent,
                    (int)DIRSIZ(&u.u_dent), u.u_offset, 1, (int *)0);
                (void) rdwri(UIO_WRITE, dp, (caddr_t)&u.u_dent,
                    (int)DIRSIZ(&u.u_dent), u.u_offset, 1, (int *)0);
-       else {
+       else {
                /*
                 * Collapse new free space into previous entry.
                 */
                /*
                 * Collapse new free space into previous entry.
                 */
@@ -722,17 +724,19 @@ blkatoff(ip, offset, res)
  * Inode supplied must be locked.
  */
 dirempty(ip)
  * Inode supplied must be locked.
  */
 dirempty(ip)
-       struct inode *ip;
+       register struct inode *ip;
 {
        register off_t off;
        struct direct dbuf;
        register struct direct *dp = &dbuf;
 {
        register off_t off;
        struct direct dbuf;
        register struct direct *dp = &dbuf;
-       int error;
+       int error, count;
 
        for (off = 0; off < ip->i_size; off += dp->d_reclen) {
                error = rdwri(UIO_READ, ip, (caddr_t)dp,
 
        for (off = 0; off < ip->i_size; off += dp->d_reclen) {
                error = rdwri(UIO_READ, ip, (caddr_t)dp,
-                       sizeof (struct direct), off, 1, (int *)0);
-               if (error)
+                       sizeof (struct direct), off, 1, &count);
+               count = sizeof (struct direct) - count;
+#define        MINDIRSIZ (sizeof (struct direct) - (MAXNAMLEN + 1))
+               if (error || count < MINDIRSIZ || count < DIRSIZ(dp))
                        return (0);
                if (dp->d_ino == 0)
                        continue;
                        return (0);
                if (dp->d_ino == 0)
                        continue;