formatting
[unix-history] / usr / src / sys / kern / kern_descrip.c
index 9d8ec10..5bd7a0a 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_descrip.c  5.15    82/10/22        */
+/*     kern_descrip.c  5.23    83/01/17        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -48,11 +48,10 @@ getdprop()
                return;
        adtype.dt_type = 0;             /* XXX */
        adtype.dt_protocol = 0;         /* XXX */
                return;
        adtype.dt_type = 0;             /* XXX */
        adtype.dt_protocol = 0;         /* XXX */
-       if (copyout((caddr_t)&adtype, (caddr_t)uap->dtypeb,
-           sizeof (struct dtype)) < 0) {
-               u.u_error = EFAULT;
+       u.u_error = copyout((caddr_t)&adtype, (caddr_t)uap->dtypeb,
+           sizeof (struct dtype))
+       if (u.u_error)
                return;
                return;
-       }
 }
 
 getdopt()
 }
 
 getdopt()
@@ -81,7 +80,7 @@ dup()
        j = ufalloc();
        if (j < 0)
                return;
        j = ufalloc();
        if (j < 0)
                return;
-       dupit(j, fp, u.u_pofile[uap->i] & (RDLOCK|WRLOCK));
+       dupit(j, fp, u.u_pofile[uap->i] & (UF_SHLOCK|UF_EXLOCK));
 }
 
 dup2()
 }
 
 dup2()
@@ -102,13 +101,15 @@ dup2()
        if (uap->i == uap->j)
                return;
        if (u.u_ofile[uap->j]) {
        if (uap->i == uap->j)
                return;
        if (u.u_ofile[uap->j]) {
+               if (u.u_pofile[uap->j] & UF_MAPPED)
+                       munmapfd(uap->j);
                closef(u.u_ofile[uap->j], 0, u.u_pofile[uap->j]);
                if (u.u_error)
                        return;
                /* u.u_ofile[uap->j] = 0; */
                /* u.u_pofile[uap->j] = 0; */
        }
                closef(u.u_ofile[uap->j], 0, u.u_pofile[uap->j]);
                if (u.u_error)
                        return;
                /* u.u_ofile[uap->j] = 0; */
                /* u.u_pofile[uap->j] = 0; */
        }
-       dupit(uap->j, fp, u.u_pofile[uap->i] & (RDLOCK|WRLOCK));
+       dupit(uap->j, fp, u.u_pofile[uap->i] & (UF_SHLOCK|UF_EXLOCK));
 }
 
 dupit(fd, fp, lockflags)
 }
 
 dupit(fd, fp, lockflags)
@@ -120,10 +121,10 @@ dupit(fd, fp, lockflags)
        u.u_ofile[fd] = fp;
        u.u_pofile[fd] = lockflags;
        fp->f_count++;
        u.u_ofile[fd] = fp;
        u.u_pofile[fd] = lockflags;
        fp->f_count++;
-       if (lockflags&RDLOCK)
-               fp->f_inode->i_rdlockc++;
-       if (lockflags&WRLOCK)
-               fp->f_inode->i_wrlockc++;
+       if (lockflags&UF_SHLOCK)
+               fp->f_inode->i_shlockc++;
+       if (lockflags&UF_EXLOCK)
+               fp->f_inode->i_exlockc++;
 }
 
 close()
 }
 
 close()
@@ -136,6 +137,8 @@ close()
        fp = getf(uap->i);
        if (fp == 0)
                return;
        fp = getf(uap->i);
        if (fp == 0)
                return;
+       if (u.u_pofile[uap->i] & UF_MAPPED)
+               munmapfd(uap->i);
        closef(fp, 0, u.u_pofile[uap->i]);
        /* WHAT IF u.u_error ? */
        u.u_ofile[uap->i] = NULL;
        closef(fp, 0, u.u_pofile[uap->i]);
        /* WHAT IF u.u_error ? */
        u.u_ofile[uap->i] = NULL;
@@ -154,11 +157,10 @@ wrap()
        fp = getf(uap->d);
        if (fp == 0)
                return;
        fp = getf(uap->d);
        if (fp == 0)
                return;
-       if (copyin((caddr_t)uap->dtypeb, (caddr_t)&adtype,
-           sizeof (struct dtype)) < 0) {
-               u.u_error = EFAULT;
+       u.u_error = copyin((caddr_t)uap->dtypeb, (caddr_t)&adtype,
+           sizeof (struct dtype));
+       if (u.u_error)
                return;
                return;
-       }
        /* DO WRAP */
 }
 
        /* DO WRAP */
 }
 
@@ -182,18 +184,15 @@ select()
        label_t lqsave;
 
        obits[0] = obits[1] = obits[2] = 0;
        label_t lqsave;
 
        obits[0] = obits[1] = obits[2] = 0;
-       if (uap->nd >= NOFILE) {
-               u.u_error = EINVAL;
-               goto done;
-       }
+       if (uap->nd > NOFILE)
+               uap->nd = NOFILE;       /* forgiving, if slightly wrong */
 
 #define        getbits(name, x) \
        if (uap->name) { \
 
 #define        getbits(name, x) \
        if (uap->name) { \
-               if (copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \
-                   sizeof (ibits[x]))) { \
-                       u.u_error = EFAULT; \
+               u.u_error = copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \
+                   sizeof (ibits[x])); \
+               if (u.u_error) \
                        goto done; \
                        goto done; \
-               } \
        } else \
                ibits[x] = 0;
        getbits(in, 0);
        } else \
                ibits[x] = 0;
        getbits(in, 0);
@@ -202,10 +201,10 @@ select()
 #undef getbits
 
        if (uap->tv) {
 #undef getbits
 
        if (uap->tv) {
-               if (copyin((caddr_t)uap->tv, (caddr_t)&atv, sizeof (atv))) {
-                       u.u_error = EFAULT;
+               u.u_error = copyin((caddr_t)uap->tv, (caddr_t)&atv,
+                       sizeof (atv));
+               if (u.u_error)
                        goto done;
                        goto done;
-               }
                if (itimerfix(&atv)) {
                        u.u_error = EINVAL;
                        goto done;
                if (itimerfix(&atv)) {
                        u.u_error = EINVAL;
                        goto done;
@@ -249,9 +248,10 @@ retry:
 done:
 #define        putbits(name, x) \
        if (uap->name) { \
 done:
 #define        putbits(name, x) \
        if (uap->name) { \
-               if (copyout((caddr_t)obits[x], (caddr_t)uap->name, \
-                   sizeof (obits[x]))) \
-                       u.u_error = EFAULT; \
+               int error = copyout((caddr_t)&obits[x], (caddr_t)uap->name, \
+                   sizeof (obits[x])); \
+               if (error) \
+                       u.u_error = error; \
        }
        putbits(in, 0);
        putbits(ou, 1);
        }
        putbits(in, 0);
        putbits(ou, 1);
@@ -350,21 +350,18 @@ selwakeup(p, coll)
        register struct proc *p;
        int coll;
 {
        register struct proc *p;
        int coll;
 {
-       int s;
 
        if (coll) {
                nselcoll++;
                wakeup((caddr_t)&selwait);
        }
        if (p) {
 
        if (coll) {
                nselcoll++;
                wakeup((caddr_t)&selwait);
        }
        if (p) {
+               int s = spl6();
                if (p->p_wchan == (caddr_t)&selwait)
                        setrun(p);
                if (p->p_wchan == (caddr_t)&selwait)
                        setrun(p);
-               else {
-                       s = spl6();
-                       if (p->p_flag & SSEL)
-                               p->p_flag &= ~SSEL;
-                       splx(s);
-               }
+               else if (p->p_flag & SSEL)
+                       p->p_flag &= ~SSEL;
+               splx(s);
        }
 }
 
        }
 }
 
@@ -487,7 +484,7 @@ closef(fp, nouser, flags)
        ip = fp->f_inode;
        dev = (dev_t)ip->i_rdev;
        mode = ip->i_mode & IFMT;
        ip = fp->f_inode;
        dev = (dev_t)ip->i_rdev;
        mode = ip->i_mode & IFMT;
-       flags &= RDLOCK|WRLOCK;                 /* conservative */
+       flags &= UF_SHLOCK|UF_EXLOCK;                   /* conservative */
        if (flags)
                funlocki(ip, flags);
        ilock(ip);
        if (flags)
                funlocki(ip, flags);
        ilock(ip);