speed-ups using the new constants
[unix-history] / usr / src / sys / kern / kern_descrip.c
index e986225..44e389c 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_descrip.c  5.11    82/10/10        */
+/*     kern_descrip.c  5.21    82/12/28        */
 
 #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,10 @@ close()
        fp = getf(uap->i);
        if (fp == 0)
                return;
        fp = getf(uap->i);
        if (fp == 0)
                return;
+#ifdef SUNMMAP
+       if (u.u_pofile[uap->i] & UF_MAPPED)
+               munmapfd(uap->i);
+#endif
        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 +159,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 */
 }
 
@@ -178,21 +182,19 @@ select()
        } *uap = (struct uap *)u.u_ap;
        int ibits[3], obits[3];
        struct timeval atv;
        } *uap = (struct uap *)u.u_ap;
        int ibits[3], obits[3];
        struct timeval atv;
-       int s, tsel, ncoll, rem;
+       int s, ncoll;
        label_t lqsave;
 
        label_t lqsave;
 
-       if (uap->nd >= NOFILE) {
-               u.u_error = EINVAL;
-               return;
-       }
+       obits[0] = obits[1] = obits[2] = 0;
+       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; \
-                       return; \
-               } \
+               u.u_error = copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \
+                   sizeof (ibits[x])); \
+               if (u.u_error) \
+                       goto done; \
        } else \
                ibits[x] = 0;
        getbits(in, 0);
        } else \
                ibits[x] = 0;
        getbits(in, 0);
@@ -201,13 +203,13 @@ 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;
-                       return;
-               }
+               u.u_error = copyin((caddr_t)uap->tv, (caddr_t)&atv,
+                       sizeof (atv));
+               if (u.u_error)
+                       goto done;
                if (itimerfix(&atv)) {
                        u.u_error = EINVAL;
                if (itimerfix(&atv)) {
                        u.u_error = EINVAL;
-                       return;
+                       goto done;
                }
                s = spl7(); timevaladd(&atv, &time); splx(s);
        }
                }
                s = spl7(); timevaladd(&atv, &time); splx(s);
        }
@@ -215,9 +217,7 @@ retry:
        ncoll = nselcoll;
        u.u_procp->p_flag |= SSEL;
        u.u_r.r_val1 = selscan(ibits, obits);
        ncoll = nselcoll;
        u.u_procp->p_flag |= SSEL;
        u.u_r.r_val1 = selscan(ibits, obits);
-       if (u.u_error)
-               return;
-       if (u.u_r.r_val1)
+       if (u.u_error || u.u_r.r_val1)
                goto done;
        s = spl6();
        if (uap->tv && timercmp(&time, &atv, >=)) {
                goto done;
        s = spl6();
        if (uap->tv && timercmp(&time, &atv, >=)) {
@@ -233,28 +233,27 @@ retry:
        if (uap->tv) {
                lqsave = u.u_qsave;
                if (setjmp(&u.u_qsave)) {
        if (uap->tv) {
                lqsave = u.u_qsave;
                if (setjmp(&u.u_qsave)) {
-                       untimeout(unselect, u.u_procp);
+                       untimeout(unselect, (caddr_t)u.u_procp);
                        u.u_error = EINTR;
                        splx(s);
                        u.u_error = EINTR;
                        splx(s);
-                       return;
+                       goto done;
                }
                }
-               timeout(unselect, u.u_procp, hzto(&atv));
+               timeout(unselect, (caddr_t)u.u_procp, hzto(&atv));
        }
        sleep((caddr_t)&selwait, PZERO+1);
        if (uap->tv) {
                u.u_qsave = lqsave;
        }
        sleep((caddr_t)&selwait, PZERO+1);
        if (uap->tv) {
                u.u_qsave = lqsave;
-               untimeout(unselect, u.u_procp);
+               untimeout(unselect, (caddr_t)u.u_procp);
        }
        splx(s);
        goto retry;
 done:
 #define        putbits(name, x) \
        if (uap->name) { \
        }
        splx(s);
        goto retry;
 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; \
-                       return; \
-               } \
+               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);
@@ -479,8 +478,7 @@ closef(fp, nouser, flags)
                return;
        }
        if (fp->f_type == DTYPE_SOCKET) {
                return;
        }
        if (fp->f_type == DTYPE_SOCKET) {
-               u.u_error = 0;                  /* XXX */
-               soclose(fp->f_socket, nouser);
+               u.u_error = soclose(fp->f_socket, nouser);
                if (nouser == 0 && u.u_error)
                        return;
                fp->f_socket = 0;
                if (nouser == 0 && u.u_error)
                        return;
                fp->f_socket = 0;
@@ -491,7 +489,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);