spl5 not splimp
[unix-history] / usr / src / sys / kern / vfs_syscalls.c
index b8a0b8a..c8ad364 100644 (file)
@@ -1,4 +1,4 @@
-/*     vfs_syscalls.c  4.3     %G%     */
+/*     vfs_syscalls.c  4.17    82/01/19        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -14,6 +14,8 @@
 #include "../h/conf.h"
 #include "../h/stat.h"
 #include "../h/inline.h"
 #include "../h/conf.h"
 #include "../h/stat.h"
 #include "../h/inline.h"
+#include "../h/socket.h"
+#include "../h/socketvar.h"
 
 /*
  * the fstat system call.
 
 /*
  * the fstat system call.
@@ -28,13 +30,16 @@ fstat()
 
        uap = (struct a *)u.u_ap;
        fp = getf(uap->fdes);
 
        uap = (struct a *)u.u_ap;
        fp = getf(uap->fdes);
-       if(fp == NULL)
+       if (fp == NULL)
                return;
                return;
-       stat1(fp->f_inode, uap->sb, fp->f_flag&FPIPE? fp->f_un.f_offset: 0);
+       if (fp->f_flag & FSOCKET)
+               u.u_error = sostat(fp->f_socket, uap->sb);
+       else
+               stat1(fp->f_inode, uap->sb);
 }
 
 /*
 }
 
 /*
- * the stat system call.
+ * Stat system call.
  */
 stat()
 {
  */
 stat()
 {
@@ -46,9 +51,9 @@ stat()
 
        uap = (struct a *)u.u_ap;
        ip = namei(uchar, 0);
 
        uap = (struct a *)u.u_ap;
        ip = namei(uchar, 0);
-       if(ip == NULL)
+       if (ip == NULL)
                return;
                return;
-       stat1(ip, uap->sb, (off_t)0);
+       stat1(ip, uap->sb);
        iput(ip);
 }
 
        iput(ip);
 }
 
@@ -56,10 +61,9 @@ stat()
  * The basic routine for fstat and stat:
  * get the inode and pass appropriate parts back.
  */
  * The basic routine for fstat and stat:
  * get the inode and pass appropriate parts back.
  */
-stat1(ip, ub, pipeadj)
-register struct inode *ip;
-struct stat *ub;
-off_t pipeadj;
+stat1(ip, ub)
+       register struct inode *ip;
+       struct stat *ub;
 {
        register struct dinode *dp;
        register struct buf *bp;
 {
        register struct dinode *dp;
        register struct buf *bp;
@@ -67,7 +71,7 @@ off_t pipeadj;
 
        IUPDAT(ip, &time, &time, 0);
        /*
 
        IUPDAT(ip, &time, &time, 0);
        /*
-        * first copy from inode table
+        * First 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;
@@ -76,9 +80,9 @@ off_t pipeadj;
        ds.st_uid = ip->i_uid;
        ds.st_gid = ip->i_gid;
        ds.st_rdev = (dev_t)ip->i_un.i_rdev;
        ds.st_uid = ip->i_uid;
        ds.st_gid = ip->i_gid;
        ds.st_rdev = (dev_t)ip->i_un.i_rdev;
-       ds.st_size = ip->i_size - pipeadj;
+       ds.st_size = ip->i_size;
        /*
        /*
-        * next the dates in the disk
+        * Next the dates in the disk
         */
        bp = bread(ip->i_dev, itod(ip->i_number));
        dp = bp->b_un.b_dino;
         */
        bp = bread(ip->i_dev, itod(ip->i_number));
        dp = bp->b_un.b_dino;
@@ -92,7 +96,7 @@ off_t pipeadj;
 }
 
 /*
 }
 
 /*
- * the dup system call.
+ * Dup system call.
  */
 dup()
 {
  */
 dup()
 {
@@ -107,7 +111,7 @@ dup()
        m = uap->fdes & ~077;
        uap->fdes &= 077;
        fp = getf(uap->fdes);
        m = uap->fdes & ~077;
        uap->fdes &= 077;
        fp = getf(uap->fdes);
-       if(fp == NULL)
+       if (fp == NULL)
                return;
        if ((m&0100) == 0) {
                if ((i = ufalloc()) < 0)
                return;
        if ((m&0100) == 0) {
                if ((i = ufalloc()) < 0)
@@ -118,22 +122,20 @@ dup()
                        u.u_error = EBADF;
                        return;
                }
                        u.u_error = EBADF;
                        return;
                }
-               if (u.u_vrpages[i]) {
-                       u.u_error = ETXTBSY;
-                       return;
-               }
                u.u_r.r_val1 = i;
        }
                u.u_r.r_val1 = i;
        }
-       if (i!=uap->fdes) {
+       if (i != uap->fdes) {
                if (u.u_ofile[i]!=NULL)
                if (u.u_ofile[i]!=NULL)
-                       closef(u.u_ofile[i]);
+                       closef(u.u_ofile[i], 0);
+               if (u.u_error)
+                       return;
                u.u_ofile[i] = fp;
                fp->f_count++;
        }
 }
 
 /*
                u.u_ofile[i] = fp;
                fp->f_count++;
        }
 }
 
 /*
- * the mount system call.
+ * Mount system call.
  */
 smount()
 {
  */
 smount()
 {
@@ -148,50 +150,56 @@ smount()
                char    *freg;
                int     ronly;
        } *uap;
                char    *freg;
                int     ronly;
        } *uap;
+       register char *cp;
 
        uap = (struct a *)u.u_ap;
        dev = getmdev();
 
        uap = (struct a *)u.u_ap;
        dev = getmdev();
-       if(u.u_error)
+       if (u.u_error)
                return;
        u.u_dirp = (caddr_t)uap->freg;
        ip = namei(uchar, 0);
                return;
        u.u_dirp = (caddr_t)uap->freg;
        ip = namei(uchar, 0);
-       if(ip == NULL)
+       if (ip == NULL)
                return;
                return;
-       if(ip->i_count!=1 || (ip->i_mode&(IFBLK&IFCHR))!=0)
+       if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR)
                goto out;
        smp = NULL;
                goto out;
        smp = NULL;
-       for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
-               if(mp->m_bufp != NULL) {
-                       if(dev == mp->m_dev)
+       for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
+               if (mp->m_bufp != NULL) {
+                       if (dev == mp->m_dev)
                                goto out;
                } else
                                goto out;
                } else
-               if(smp == NULL)
+               if (smp == NULL)
                        smp = mp;
        }
        mp = smp;
                        smp = mp;
        }
        mp = smp;
-       if(mp == NULL)
+       if (mp == NULL)
                goto out;
        (*bdevsw[major(dev)].d_open)(dev, !uap->ronly);
                goto out;
        (*bdevsw[major(dev)].d_open)(dev, !uap->ronly);
-       if(u.u_error)
+       if (u.u_error)
                goto out;
        bp = bread(dev, SUPERB);
                goto out;
        bp = bread(dev, SUPERB);
-       if(u.u_error) {
+       if (u.u_error) {
                brelse(bp);
                goto out1;
        }
        mp->m_inodp = ip;
        mp->m_dev = dev;
                brelse(bp);
                goto out1;
        }
        mp->m_inodp = ip;
        mp->m_dev = dev;
-       mp->m_bufp = geteblk();
-       bcopy((caddr_t)bp->b_un.b_addr, mp->m_bufp->b_un.b_addr, BSIZE);
-       fp = mp->m_bufp->b_un.b_filsys;
+       bp->b_flags |= B_LOCKED;
+       mp->m_bufp = bp;
+       fp = bp->b_un.b_filsys;
        fp->s_ilock = 0;
        fp->s_flock = 0;
        fp->s_ronly = uap->ronly & 1;
        fp->s_nbehind = 0;
        fp->s_lasti = 1;
        fp->s_ilock = 0;
        fp->s_flock = 0;
        fp->s_ronly = uap->ronly & 1;
        fp->s_nbehind = 0;
        fp->s_lasti = 1;
+       u.u_dirp = uap->freg;
+       for (cp = fp->s_fsmnt; cp < &fp->s_fsmnt[sizeof (fp->s_fsmnt) - 1]; )
+               if ((*cp++ = uchar()) == 0)
+                       u.u_dirp--;             /* get 0 again */
+       *cp = 0;
        brelse(bp);
        ip->i_flag |= IMOUNT;
        brelse(bp);
        ip->i_flag |= IMOUNT;
-       prele(ip);
+       irele(ip);
        return;
 
 out:
        return;
 
 out:
@@ -209,41 +217,43 @@ sumount()
        register struct inode *ip;
        register struct mount *mp;
        struct buf *bp;
        register struct inode *ip;
        register struct mount *mp;
        struct buf *bp;
-       int flag;
-       int stillopen = 0;
+       int stillopen, flag;
        register struct a {
                char    *fspec;
        };
 
        dev = getmdev();
        register struct a {
                char    *fspec;
        };
 
        dev = getmdev();
-       if(u.u_error)
+       if (u.u_error)
                return;
        xumount(dev);   /* remove unused sticky files from text table */
                return;
        xumount(dev);   /* remove unused sticky files from text table */
-       update();
-       for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
-               if(mp->m_bufp != NULL && dev == mp->m_dev)
+       update(0);
+       for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
+               if (mp->m_bufp != NULL && dev == mp->m_dev)
                        goto found;
        u.u_error = EINVAL;
        return;
 
 found:
                        goto found;
        u.u_error = EINVAL;
        return;
 
 found:
-       for(ip = &inode[0]; ip < &inode[NINODE]; ip++)
-               if(ip->i_number != 0 && dev == ip->i_dev) {
+       stillopen = 0;
+       for (ip = inode; ip < inodeNINODE; ip++)
+               if (ip->i_number != 0 && dev == ip->i_dev) {
                        u.u_error = EBUSY;
                        return;
                        u.u_error = EBUSY;
                        return;
-               } else if (ip->i_number != 0 && (ip->i_mode&IFMT) == IFBLK
-                       && ip->i_un.i_rdev == dev)
-                               stillopen++;
+               } else if (ip->i_number != 0 && (ip->i_mode&IFMT) == IFBLK &&
+                   ip->i_un.i_rdev == dev)
+                       stillopen++;
        ip = mp->m_inodp;
        ip->i_flag &= ~IMOUNT;
        ip = mp->m_inodp;
        ip->i_flag &= ~IMOUNT;
-       plock(ip);
+       ilock(ip);
        iput(ip);
        iput(ip);
-       bp = mp->m_bufp;
+       if ((bp = getblk(dev, SUPERB)) != mp->m_bufp)
+               panic("umount");
+       bp->b_flags &= ~B_LOCKED;
        flag = !bp->b_un.b_filsys->s_ronly;
        mp->m_bufp = NULL;
        brelse(bp);
        flag = !bp->b_un.b_filsys->s_ronly;
        mp->m_bufp = NULL;
        brelse(bp);
+       mpurge(mp - &mount[0]);
        if (!stillopen) {
        if (!stillopen) {
-               mpurge(mp - &mount[0]);
                (*bdevsw[major(dev)].d_close)(dev, flag);
                binval(dev);
        }
                (*bdevsw[major(dev)].d_close)(dev, flag);
                binval(dev);
        }
@@ -263,12 +273,12 @@ getmdev()
        if (!suser())
                return(NODEV);
        ip = namei(uchar, 0);
        if (!suser())
                return(NODEV);
        ip = namei(uchar, 0);
-       if(ip == NULL)
+       if (ip == NULL)
                return(NODEV);
                return(NODEV);
-       if((ip->i_mode&IFMT) != IFBLK)
+       if ((ip->i_mode&IFMT) != IFBLK)
                u.u_error = ENOTBLK;
        dev = (dev_t)ip->i_un.i_rdev;
                u.u_error = ENOTBLK;
        dev = (dev_t)ip->i_un.i_rdev;
-       if(major(dev) >= nblkdev)
+       if (major(dev) >= nblkdev)
                u.u_error = ENXIO;
        iput(ip);
        return(dev);
                u.u_error = ENXIO;
        iput(ip);
        return(dev);