p_devtmp => p_dupfd; eliminate u.u_error from RETURN macro
[unix-history] / usr / src / sys / kern / tty_tty.c
index 71151bf..7fb68d7 100644 (file)
@@ -3,33 +3,42 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)tty_tty.c   7.3 (Berkeley) %G%
+ *     @(#)tty_tty.c   7.9 (Berkeley) %G%
  */
 
 /*
  * Indirect driver for controlling tty.
  */
 
 /*
  * Indirect driver for controlling tty.
- *
- * THIS IS GARBAGE: MUST SOON BE DONE WITH struct inode * IN PROC TABLE.
  */
 #include "param.h"
 #include "systm.h"
 #include "conf.h"
  */
 #include "param.h"
 #include "systm.h"
 #include "conf.h"
-#include "dir.h"
 #include "user.h"
 #include "ioctl.h"
 #include "tty.h"
 #include "proc.h"
 #include "user.h"
 #include "ioctl.h"
 #include "tty.h"
 #include "proc.h"
+#include "vnode.h"
+#include "file.h"
 #include "uio.h"
 
 #include "uio.h"
 
+#define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
+
 /*ARGSUSED*/
 syopen(dev, flag)
        dev_t dev;
        int flag;
 {
 /*ARGSUSED*/
 syopen(dev, flag)
        dev_t dev;
        int flag;
 {
+       struct vnode *ttyvp = cttyvp(u.u_procp);
+       int error;
 
 
-       if (u.u_ttyp == NULL)
+       if (ttyvp == NULL)
                return (ENXIO);
                return (ENXIO);
-       return ((*cdevsw[major(u.u_ttyd)].d_open)(u.u_ttyd, flag));
+       VOP_LOCK(ttyvp);
+       error = VOP_ACCESS(ttyvp,
+          (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred);
+       VOP_UNLOCK(ttyvp);
+       if (error)
+               return (error);
+       return (VOP_OPEN(ttyvp, flag, NOCRED));
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -37,10 +46,15 @@ syread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 {
        dev_t dev;
        struct uio *uio;
 {
+       register struct vnode *ttyvp = cttyvp(u.u_procp);
+       int error;
 
 
-       if (u.u_ttyp == NULL)
+       if (ttyvp == NULL)
                return (ENXIO);
                return (ENXIO);
-       return ((*cdevsw[major(u.u_ttyd)].d_read)(u.u_ttyd, uio, flag));
+       VOP_LOCK(ttyvp);
+       error = VOP_READ(ttyvp, uio, flag, NOCRED);
+       VOP_UNLOCK(ttyvp);
+       return (error);
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -48,10 +62,15 @@ sywrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 {
        dev_t dev;
        struct uio *uio;
 {
+       register struct vnode *ttyvp = cttyvp(u.u_procp);
+       int error;
 
 
-       if (u.u_ttyp == NULL)
+       if (ttyvp == NULL)
                return (ENXIO);
                return (ENXIO);
-       return ((*cdevsw[major(u.u_ttyd)].d_write)(u.u_ttyd, uio, flag));
+       VOP_LOCK(ttyvp);
+       error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
+       VOP_UNLOCK(ttyvp);
+       return (error);
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -61,22 +80,18 @@ syioctl(dev, cmd, addr, flag)
        caddr_t addr;
        int flag;
 {
        caddr_t addr;
        int flag;
 {
+       struct vnode *ttyvp = cttyvp(u.u_procp);
 
 
+       if (ttyvp == NULL)
+               return (ENXIO);
        if (cmd == TIOCNOTTY) {
        if (cmd == TIOCNOTTY) {
-               if (SESS_LEADER(u.u_procp)) {
-                       /* 
-                        * XXX - check posix draft
-                        */
-                       u.u_ttyp->t_session = 0;
-                       u.u_ttyp->t_pgid = 0;
-               }
-               u.u_ttyp = 0;
-               u.u_ttyd = 0;
-               return (0);
+               if (!SESS_LEADER(u.u_procp)) {
+                       u.u_procp->p_flag &= ~SCTTY;
+                       return (0);
+               } else
+                       return (EINVAL);
        }
        }
-       if (u.u_ttyp == NULL)
-               return (ENXIO);
-       return ((*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag));
+       return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED));
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -84,10 +99,9 @@ syselect(dev, flag)
        dev_t dev;
        int flag;
 {
        dev_t dev;
        int flag;
 {
+       struct vnode *ttyvp = cttyvp(u.u_procp);
 
 
-       if (u.u_ttyp == NULL) {
-               u.u_error = ENXIO;
-               return (0);
-       }
-       return ((*cdevsw[major(u.u_ttyd)].d_select)(u.u_ttyd, flag));
+       if (ttyvp == NULL)
+               return (1);     /* try operation to get EOF/failure */
+       return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED));
 }
 }