rid of NFILE
[unix-history] / usr / src / sys / kern / tty_pty.c
index af2bc02..f069166 100644 (file)
@@ -1,4 +1,4 @@
-/*     tty_pty.c       4.4     %G%     */
+/*     tty_pty.c       4.5     %G%     */
 
 /*
  * Pseudo-teletype Driver
 
 /*
  * Pseudo-teletype Driver
 #include "../h/user.h"
 #include "../h/conf.h"
 #include "../h/buf.h"
 #include "../h/user.h"
 #include "../h/conf.h"
 #include "../h/buf.h"
+#include "../h/file.h"
 
 
-#define NPTY 16                 /* Number of pseudo-teletypes */
-#define BUFSIZ 100              /* Chunk size iomoved from user */
+#define NPTY 16                        /* Number of pseudo-teletypes */
+#define BUFSIZ 100             /* Chunk size iomoved from user */
 #define ALLDELAYS (NLDELAY|TBDELAY|XTABS|CRDELAY|VTDELAY)
 /*
  * A pseudo-teletype is a special device which is not unlike a pipe.
  * It is used to communicate between two processes.  However, it allows
  * one to simulate a teletype, including mode setting, interrupt, and
 #define ALLDELAYS (NLDELAY|TBDELAY|XTABS|CRDELAY|VTDELAY)
 /*
  * A pseudo-teletype is a special device which is not unlike a pipe.
  * It is used to communicate between two processes.  However, it allows
  * one to simulate a teletype, including mode setting, interrupt, and
- * multiple end of files (all not possible on a pipe).  There are
+ * multiple end of files (all not possible on a pipe). There are
  * really two drivers here.  One is the device which looks like a TTY
  * and can be thought of as the slave device, and hence its routines
  * really two drivers here.  One is the device which looks like a TTY
  * and can be thought of as the slave device, and hence its routines
- * are prefixed with 'pts' (PTY Slave).  The other driver can be
+ * are prefixed with 'pts' (PTY Slave).         The other driver can be
  * thought of as the controlling device, and its routines are prefixed
  * by 'ptc' (PTY Controller).  To type on the simulated keyboard of the
  * PTY, one does a 'write' to the controlling device.  To get the
  * thought of as the controlling device, and its routines are prefixed
  * by 'ptc' (PTY Controller).  To type on the simulated keyboard of the
  * PTY, one does a 'write' to the controlling device.  To get the
  * slave device is called 'ttyx' (to make programs like 'who' happy).
  */
 
  * slave device is called 'ttyx' (to make programs like 'who' happy).
  */
 
-struct tty pt_tty[NPTY];                /* TTY headers for PTYs */
+struct tty pt_tty[NPTY];               /* TTY headers for PTYs */
 
 /*ARGSUSED*/
 ptsopen(dev, flag)
 dev_t dev;
 
 /*ARGSUSED*/
 ptsopen(dev, flag)
 dev_t dev;
-{                                       /* Open for PTY Slave */
+{                                      /* Open for PTY Slave */
        register struct tty *tp;
 
        if(minor(dev) >= NPTY) {
        register struct tty *tp;
 
        if(minor(dev) >= NPTY) {
@@ -49,13 +50,13 @@ dev_t dev;
        }
        tp = &pt_tty[minor(dev)];
        if((tp->t_state & ISOPEN) == 0) {
        }
        tp = &pt_tty[minor(dev)];
        if((tp->t_state & ISOPEN) == 0) {
-               ttychars(tp);           /* Set up default chars */
-               tp->t_flags = 0;        /* No features (nor raw mode) */
+               ttychars(tp);           /* Set up default chars */
+               tp->t_flags = 0;        /* No features (nor raw mode) */
        } else if(tp->t_state&XCLUDE && u.u_uid != 0) {
                u.u_error = EBUSY;
                return;
        }
        } else if(tp->t_state&XCLUDE && u.u_uid != 0) {
                u.u_error = EBUSY;
                return;
        }
-       if(tp->t_oproc)                 /* Ctrlr still around. */
+       if(tp->t_oproc)                 /* Ctrlr still around. */
                tp->t_state |= CARR_ON;
        while((tp->t_state & CARR_ON) == 0) {
                tp->t_state |= WOPEN;
                tp->t_state |= CARR_ON;
        while((tp->t_state & CARR_ON) == 0) {
                tp->t_state |= WOPEN;
@@ -66,7 +67,7 @@ dev_t dev;
 
 ptsclose(dev)
 dev_t dev;
 
 ptsclose(dev)
 dev_t dev;
-{                                       /* Close slave part of PTY */
+{                                      /* Close slave part of PTY */
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
@@ -75,7 +76,7 @@ dev_t dev;
 
 ptsread(dev)
 dev_t dev;
 
 ptsread(dev)
 dev_t dev;
-{       /* Read from PTY, i.e. from data written by controlling device */
+{      /* Read from PTY, i.e. from data written by controlling device */
        register struct tty    *tp;
 
        tp = &pt_tty[minor(dev)];
        register struct tty    *tp;
 
        tp = &pt_tty[minor(dev)];
@@ -88,7 +89,7 @@ dev_t dev;
 
 ptswrite(dev)
 dev_t dev;
 
 ptswrite(dev)
 dev_t dev;
-{                       /* Write on PTY, i.e. to be read from
+{                      /* Write on PTY, i.e. to be read from
                           controlling device */
        register struct tty *tp;
 
                           controlling device */
        register struct tty *tp;
 
@@ -100,7 +101,7 @@ dev_t dev;
 
 ptsstart(tp)
 struct tty *tp;
 
 ptsstart(tp)
 struct tty *tp;
-{                       /* Called by 'ttstart' to output a character.
+{                      /* Called by 'ttstart' to output a character.
                           Merely wakes up controlling half, which
                           does actual work */
        if(tp->t_state & TTSTOP)
                           Merely wakes up controlling half, which
                           does actual work */
        if(tp->t_state & TTSTOP)
@@ -111,7 +112,7 @@ struct tty *tp;
 /*ARGSUSED*/
 ptcopen(dev, flag)
 dev_t dev;
 /*ARGSUSED*/
 ptcopen(dev, flag)
 dev_t dev;
-{                               /* Open for PTY Controller */
+{                              /* Open for PTY Controller */
        register struct tty *tp;
 
        if(minor(dev) >= NPTY) {
        register struct tty *tp;
 
        if(minor(dev) >= NPTY) {
@@ -123,7 +124,7 @@ dev_t dev;
                u.u_error = EIO;
                return;
        }
                u.u_error = EIO;
                return;
        }
-       tp->t_oproc = ptsstart;         /* Set address of start routine */
+       tp->t_oproc = ptsstart;         /* Set address of start routine */
        tp->t_iproc = 0;
        if(tp->t_state & WOPEN)
                wakeup((caddr_t)&tp->t_rawq);
        tp->t_iproc = 0;
        if(tp->t_state & WOPEN)
                wakeup((caddr_t)&tp->t_rawq);
@@ -132,27 +133,27 @@ dev_t dev;
 
 ptcclose(dev)
 dev_t dev;
 
 ptcclose(dev)
 dev_t dev;
-{                                       /* Close controlling part of PTY */
+{                                      /* Close controlling part of PTY */
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
        if(tp->t_state & ISOPEN)
                gsignal(tp->t_pgrp, SIGHUP);
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
        if(tp->t_state & ISOPEN)
                gsignal(tp->t_pgrp, SIGHUP);
-       tp->t_state &= ~CARR_ON;        /* Virtual carrier is gone */
-       flushtty(tp);                   /* Clean things up */
-       tp->t_oproc = 0;                /* Mark as closed */
+       tp->t_state &= ~CARR_ON;        /* Virtual carrier is gone */
+       flushtty(tp, FREAD|FWRITE);                  /* Clean things up */
+       tp->t_oproc = 0;                /* Mark as closed */
 }
 
 ptcread(dev)
 dev_t dev;
 }
 
 ptcread(dev)
 dev_t dev;
-{                                       /* Read from PTY's output buffer */
+{                                      /* Read from PTY's output buffer */
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
        if((tp->t_state&(CARR_ON|ISOPEN)) == 0)
                return;
        register struct tty *tp;
 
        tp = &pt_tty[minor(dev)];
        if((tp->t_state&(CARR_ON|ISOPEN)) == 0)
                return;
-       while(tp->t_outq.c_cc == 0 ||   /* Wait for something to arrive */
-             (tp->t_state&TTSTOP))     /* (Woken by ptsstart) */
+       while(tp->t_outq.c_cc == 0 ||   /* Wait for something to arrive */
+             (tp->t_state&TTSTOP))     /* (Woken by ptsstart) */
                sleep((caddr_t)&tp->t_outq.c_cf, TTIPRI);
        while(tp->t_outq.c_cc && passc(getc(&tp->t_outq)) >= 0);
        if(tp->t_outq.c_cc <= TTLOWAT(tp)  && (tp->t_state&ASLEEP)) {
                sleep((caddr_t)&tp->t_outq.c_cf, TTIPRI);
        while(tp->t_outq.c_cc && passc(getc(&tp->t_outq)) >= 0);
        if(tp->t_outq.c_cc <= TTLOWAT(tp)  && (tp->t_state&ASLEEP)) {
@@ -166,7 +167,7 @@ dev_t dev;
 
 ptcwrite(dev)
 dev_t dev;
 
 ptcwrite(dev)
 dev_t dev;
-{                       /* Stuff characters into PTY's input buffer */
+{                      /* Stuff characters into PTY's input buffer */
        register struct tty *tp;
        register char *cp, *ce;
        register int cc;
        register struct tty *tp;
        register char *cp, *ce;
        register int cc;
@@ -218,10 +219,10 @@ dev_t dev;
 #endif
                        tbd = tp->t_flags & TBDELAY;
                        tp->t_flags &= ~ALLDELAYS;
 #endif
                        tbd = tp->t_flags & TBDELAY;
                        tp->t_flags &= ~ALLDELAYS;
-                       if(tbd == TBDELAY)      /* Wants tab expansion */
+                       if(tbd == TBDELAY)      /* Wants tab expansion */
                                tp->t_flags |= tbd;
 #ifdef BLAND
                                tp->t_flags |= tbd;
 #ifdef BLAND
-                       if(nld == NLDELAY)      /* Allow ANN ARBOR mode. */
+                       if(nld == NLDELAY)      /* Allow ANN ARBOR mode. */
                                tp->t_flags |= nld;
 #endif
                }
                                tp->t_flags |= nld;
 #endif
                }