drop #ifdef SIMFS for /etc/config's sake
[unix-history] / usr / src / sys / ufs / ffs / ufs_vnops.c
index ece9c45..580ac39 100644 (file)
@@ -1,23 +1,16 @@
-/*     ufs_vnops.c     4.21    82/03/18        */
+/*     ufs_vnops.c     4.27    82/06/25        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/dir.h"
 #include "../h/user.h"
-#include "../h/reg.h"
 #include "../h/file.h"
 #include "../h/file.h"
+#include "../h/stat.h"
 #include "../h/inode.h"
 #include "../h/inode.h"
-#include "../h/ino.h"
-#include "../h/pte.h"
-#include "../h/vm.h"
+#include "../h/fs.h"
 #include "../h/buf.h"
 #include "../h/buf.h"
-#include "../h/mtpr.h"
 #include "../h/proc.h"
 #include "../h/inline.h"
 #include "../h/proc.h"
 #include "../h/inline.h"
-#include "../h/conf.h"
-#include "../h/socket.h"
-#include "../h/socketvar.h"
-#include "../h/stat.h"
 
 chdir()
 {
 
 chdir()
 {
@@ -49,11 +42,9 @@ register struct inode **ipp;
        }
        if(access(ip, IEXEC))
                goto bad;
        }
        if(access(ip, IEXEC))
                goto bad;
-       irele(ip);
-       if (*ipp) {
-               ilock(*ipp);
-               iput(*ipp);
-       }
+       iunlock(ip);
+       if (*ipp)
+               irele(*ipp);
        *ipp = ip;
        return;
 
        *ipp = ip;
        return;
 
@@ -124,11 +115,13 @@ open1(ip, mode, trf)
                                u.u_error = EISDIR;
                }
        }
                                u.u_error = EISDIR;
                }
        }
-       if (u.u_error)
-               goto out;
+       if (u.u_error) {
+               iput(ip);
+               return;
+       }
        if (trf == 1)
                itrunc(ip);
        if (trf == 1)
                itrunc(ip);
-       irele(ip);
+       iunlock(ip);
        if ((fp = falloc()) == NULL)
                goto out;
        fp->f_flag = mode&(FREAD|FWRITE);
        if ((fp = falloc()) == NULL)
                goto out;
        fp->f_flag = mode&(FREAD|FWRITE);
@@ -140,8 +133,7 @@ open1(ip, mode, trf)
        u.u_ofile[i] = NULL;
        fp->f_count--;
 out:
        u.u_ofile[i] = NULL;
        fp->f_count--;
 out:
-       if (ip != NULL)
-               iput(ip);
+       irele(ip);
 }
 
 /*
 }
 
 /*
@@ -174,7 +166,7 @@ mknod()
                 * Want to be able to use this to make badblock
                 * inodes, so don't truncate the dev number.
                 */
                 * Want to be able to use this to make badblock
                 * inodes, so don't truncate the dev number.
                 */
-               ip->i_un.i_rdev = uap->dev;
+               ip->i_rdev = uap->dev;
                ip->i_flag |= IACC|IUPD|ICHG;
        }
 
                ip->i_flag |= IACC|IUPD|ICHG;
        }
 
@@ -202,7 +194,7 @@ link()
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        iupdat(ip, &time, &time, 1);
        ip->i_nlink++;
        ip->i_flag |= ICHG;
        iupdat(ip, &time, &time, 1);
-       irele(ip);
+       iunlock(ip);
        u.u_dirp = (caddr_t)uap->linkname;
        xp = namei(uchar, 1, 0);
        if (xp != NULL) {
        u.u_dirp = (caddr_t)uap->linkname;
        xp = namei(uchar, 1, 0);
        if (xp != NULL) {
@@ -224,7 +216,7 @@ out:
                ip->i_flag |= ICHG;
        }
 out1:
                ip->i_flag |= ICHG;
        }
 out1:
-       iput(ip);
+       irele(ip);
 }
 
 /*
 }
 
 /*
@@ -282,6 +274,10 @@ unlink()
        struct a {
                char    *fname;
        };
        struct a {
                char    *fname;
        };
+       struct fs *fs;
+       struct buf *bp;
+       int lbn, bn, base;
+       int unlinkingdot = 0;
 
        pp = namei(uchar, 2, 0);
        if(pp == NULL)
 
        pp = namei(uchar, 2, 0);
        if(pp == NULL)
@@ -293,8 +289,9 @@ unlink()
        if (pp->i_number == u.u_dent.d_ino) {
                ip = pp;
                ip->i_count++;
        if (pp->i_number == u.u_dent.d_ino) {
                ip = pp;
                ip->i_count++;
+               unlinkingdot++;
        } else
        } else
-               ip = iget(pp->i_dev, u.u_dent.d_ino);
+               ip = iget(pp->i_dev, pp->i_fs, u.u_dent.d_ino);
        if(ip == NULL)
                goto out1;
        if((ip->i_mode&IFMT)==IFDIR && !suser())
        if(ip == NULL)
                goto out1;
        if((ip->i_mode&IFMT)==IFDIR && !suser())
@@ -314,16 +311,40 @@ unlink()
                goto out;
        }
 */
                goto out;
        }
 */
-       u.u_offset -= sizeof(struct direct);
-       u.u_base = (caddr_t)&u.u_dent;
-       u.u_count = sizeof(struct direct);
-       u.u_dent.d_ino = 0;
-       writei(pp);
+       if (u.u_count == 0) {
+               /*
+                * first entry in block, so set d_ino to zero.
+                */
+               u.u_base = (caddr_t)&u.u_dent;
+               u.u_count = DIRSIZ(&u.u_dent);
+               u.u_dent.d_ino = 0;
+               writei(pp);
+       } else {
+               /*
+                * updating preceeding entry to skip over current entry.
+                */
+               fs = pp->i_fs;
+               lbn = lblkno(fs, u.u_offset);
+               base = blkoff(fs, u.u_offset);
+               bn = fsbtodb(fs, bmap(pp, lbn, B_WRITE, base + u.u_count));
+               bp = bread(pp->i_dev, bn, blksize(fs, pp, lbn));
+               if (bp->b_flags & B_ERROR) {
+                       brelse(bp);
+                       goto out;
+               }
+               ((struct direct *)(bp->b_un.b_addr + base))->d_reclen +=
+                   u.u_dent.d_reclen;
+               bwrite(bp);
+               pp->i_flag |= IUPD|ICHG;
+       }
        ip->i_nlink--;
        ip->i_flag |= ICHG;
 
 out:
        ip->i_nlink--;
        ip->i_flag |= ICHG;
 
 out:
-       iput(ip);
+       if (unlinkingdot)
+               irele(ip);
+       else
+               iput(ip);
 out1:
        iput(pp);
 }
 out1:
        iput(pp);
 }
@@ -409,7 +430,7 @@ fstat()
 }
 
 /*
 }
 
 /*
- * Stat system call.  This version does not follow links.
+ * Stat system call.  This version follows links.
  */
 stat()
 {
  */
 stat()
 {
@@ -420,7 +441,7 @@ stat()
        } *uap;
 
        uap = (struct a *)u.u_ap;
        } *uap;
 
        uap = (struct a *)u.u_ap;
-       ip = namei(uchar, 0, 0);
+       ip = namei(uchar, 0, 1);
        if (ip == NULL)
                return;
        stat1(ip, uap->sb);
        if (ip == NULL)
                return;
        stat1(ip, uap->sb);
@@ -428,7 +449,7 @@ stat()
 }
 
 /*
 }
 
 /*
- * Lstat system call.  This version does follow links.
+ * Lstat system call.  This version does not follow links.
  */
 lstat()
 {
  */
 lstat()
 {
@@ -439,7 +460,7 @@ lstat()
        } *uap;
 
        uap = (struct a *)u.u_ap;
        } *uap;
 
        uap = (struct a *)u.u_ap;
-       ip = namei(uchar, 0, 1);
+       ip = namei(uchar, 0, 0);
        if (ip == NULL)
                return;
        stat1(ip, uap->sb);
        if (ip == NULL)
                return;
        stat1(ip, uap->sb);
@@ -454,13 +475,11 @@ stat1(ip, ub)
        register struct inode *ip;
        struct stat *ub;
 {
        register struct inode *ip;
        struct stat *ub;
 {
-       register struct dinode *dp;
-       register struct buf *bp;
        struct stat ds;
 
        IUPDAT(ip, &time, &time, 0);
        /*
        struct stat ds;
 
        IUPDAT(ip, &time, &time, 0);
        /*
-        * First copy from inode table
+        * Copy from inode table
         */
        ds.st_dev = ip->i_dev;
        ds.st_ino = ip->i_number;
         */
        ds.st_dev = ip->i_dev;
        ds.st_ino = ip->i_number;
@@ -468,18 +487,12 @@ stat1(ip, ub)
        ds.st_nlink = ip->i_nlink;
        ds.st_uid = ip->i_uid;
        ds.st_gid = ip->i_gid;
        ds.st_nlink = ip->i_nlink;
        ds.st_uid = ip->i_uid;
        ds.st_gid = ip->i_gid;
-       ds.st_rdev = (dev_t)ip->i_un.i_rdev;
+       ds.st_rdev = (dev_t)ip->i_rdev;
        ds.st_size = ip->i_size;
        ds.st_size = ip->i_size;
-       /*
-        * next the dates in the disk
-        */
-       bp = bread(ip->i_dev, itod(ip->i_number));
-       dp = bp->b_un.b_dino;
-       dp += itoo(ip->i_number);
-       ds.st_atime = dp->di_atime;
-       ds.st_mtime = dp->di_mtime;
-       ds.st_ctime = dp->di_ctime;
-       brelse(bp);
+       ds.st_atime = ip->i_atime;
+       ds.st_mtime = ip->i_mtime;
+       ds.st_ctime = ip->i_ctime;
+       ds.st_blksize = ip->i_fs->fs_bsize;
        if (copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds)) < 0)
                u.u_error = EFAULT;
 }
        if (copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds)) < 0)
                u.u_error = EFAULT;
 }