1: #include "param.h"
   2: #include <sys/systm.h>
   3: #include <sys/dir.h>
   4: #include <sys/user.h>
   5: #include <sys/tty.h>
   6: #include <sys/proc.h>
   7: #ifdef  MPX_FILS
   8: #include <sys/mx.h>
   9: #endif
  10: #include <sys/inode.h>
  11: #include <sys/file.h>
  12: #include <sys/conf.h>
  13: #include <sys/buf.h>
  14: 
  15: /*
  16:  *	SCCS id	@(#)bk.c	2.1 (Berkeley)	8/5/83
  17:  */
  18: 
  19: #ifdef UCB_NTTY
  20: 
  21: /*
  22:  * When running dz's using only SAE (silo alarm) on input
  23:  * it is necessary to call dzrint() at clock interrupt time.
  24:  * This is unsafe unless spl5()s in tty code are changed to
  25:  * spl6()s to block clock interrupts.  Note that the dh driver
  26:  * currently in use works the same way as the dz, even though
  27:  * we could try to more intelligently manage its silo.
  28:  * Thus don't take this out if you have no dz's unless you
  29:  * change clock.c and dhtimer().
  30:  */
  31: #define spl5    spl6
  32: 
  33: /*
  34:  * Line discipline for Berkeley network.
  35:  *
  36:  * This supplies single lines to a user level program
  37:  * with a minimum of fuss.  Lines are newline terminated.
  38:  * A later version will implement full 8-bit paths by providing
  39:  * an escape sequence to include a newline in a record.
  40:  *
  41:  * This discipline requires that tty device drivers call
  42:  * the line specific l_ioctl routine from their ioctl routines,
  43:  * assigning the result to cmd so that we can refuse most tty specific
  44:  * ioctls which are unsafe because we have ambushed the
  45:  * teletype input queues, overlaying them with other information.
  46:  */
  47: 
  48: /*
  49:  * Open as networked discipline.  Called when discipline changed
  50:  * with ioctl, this assigns a buffer to the line for input, and
  51:  * changing the interpretation of the information in the tty structure.
  52:  */
  53: bkopen(tp)
  54: register struct tty *tp;
  55: {
  56:     register struct buf *bp;
  57: 
  58:     if (u.u_error)
  59:         return;     /* paranoia */
  60:     /*
  61: 	 * The suser check was added since once it gets set you can't turn
  62: 	 * it off, even as root.  Theoretically a setuid root program could
  63: 	 * be run over the net which opened /dev/tty but this seems farfetched.
  64: 	 */
  65:     if (tp->t_line == NETLDISC && !suser()) {
  66:         u.u_error = EBUSY;      /* sometimes the network */
  67:         return;             /* ... opens /dev/tty */
  68:     }
  69:     bp = geteblk();
  70:     flushtty(tp,FREAD|FWRITE);
  71:     tp->t_bufp = bp;
  72:     tp->t_cp = (char *)bp->b_un.b_addr;
  73:     tp->t_inbuf = 0;
  74:     tp->t_rec = 0;
  75: }
  76: 
  77: /*
  78:  * Break down... called when discipline changed or from device
  79:  * close routine.
  80:  */
  81: bkclose(tp)
  82: register struct tty *tp;
  83: {
  84:     register s;
  85:     register struct buf *bp;
  86: 
  87:     s = spl5();
  88:     wakeup((caddr_t)&tp->t_rawq);
  89:     if (tp->t_bufp) {
  90:         abrelse(tp->t_bufp);
  91:         tp->t_bufp = 0;
  92:     } else
  93:         printf("bkclose: no buf\n");
  94:     tp->t_cp = 0;
  95:     tp->t_inbuf = 0;
  96:     tp->t_rec = 0;
  97:     tp->t_line = DFLT_LDISC;        /* paranoid: avoid races */
  98:     splx(s);
  99: }
 100: 
 101: /*
 102:  * Read from a network line.
 103:  * Characters have been buffered in a system buffer and are
 104:  * now dumped back to the user in one fell swoop, and with a
 105:  * minimum of fuss.  Note that no input is accepted when a record
 106:  * is waiting.  Our clearing tp->t_rec here allows further input
 107:  * to accumulate.
 108:  */
 109: bkread(tp)
 110: register struct tty *tp;
 111: {
 112:     register int i;
 113:     register s;
 114: 
 115:     if ((tp->t_state&CARR_ON)==0)
 116:         return (-1);
 117:     s = spl5();
 118:     while (tp->t_rec == 0 && tp->t_line == NETLDISC)
 119:         sleep((caddr_t)&tp->t_rawq, TTIPRI);
 120:     splx(s);
 121:     if (tp->t_line != NETLDISC)
 122:         return (-1);
 123:     i = MIN(tp->t_inbuf, (int)u.u_count);
 124:     if (copyout(tp->t_bufp->b_un.b_addr, u.u_base, (unsigned)i)) {
 125:         u.u_error = EFAULT;
 126:         return (-1);
 127:     }
 128:     u.u_count -= i;
 129:     u.u_base += i;
 130:     u.u_offset += i;
 131:     tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
 132:     tp->t_inbuf = 0;
 133:     tp->t_rec = 0;
 134:     return (0);
 135: }
 136: 
 137: /*
 138:  * Low level character input routine.
 139:  * Stuff the character in the buffer, and wake up the top
 140:  * half after setting t_rec if this completes the record
 141:  * or if the buffer is (ick!) full.
 142:  *
 143:  * This is where the formatting should get done to allow
 144:  * 8 character data paths through escapes.
 145:  *
 146:  * This routine should be expanded in-line in the receiver
 147:  * interrupt routine of the dh-11 to make it run as fast as possible.
 148:  */
 149: bkinput(c, tp)
 150: register c;
 151: register struct tty *tp;
 152: {
 153: 
 154:     if (tp->t_rec)
 155:         return;
 156:     *tp->t_cp++ = c;
 157:     if (++tp->t_inbuf == BSIZE || c == '\n') {
 158:         tp->t_rec = 1;
 159:         wakeup((caddr_t)&tp->t_rawq);
 160:     }
 161: }
 162: 
 163: /*
 164:  * This routine is called whenever a ioctl is about to be performed
 165:  * and gets a chance to reject the ioctl.  We reject all teletype
 166:  * oriented ioctl's except those which set the discipline, and
 167:  * those which get parameters (gtty and get special characters).
 168:  */
 169: /*ARGSUSED*/
 170: bkioctl(tp, cmd, addr)
 171: struct tty *tp;
 172: caddr_t addr;
 173: {
 174: 
 175:     if ((cmd>>8) != 't')
 176:         return (cmd);
 177:     switch (cmd) {
 178: 
 179:     case TIOCSETD:
 180:     case TIOCGETD:
 181:     case TIOCGETP:
 182:     case TIOCGETC:
 183:         return (cmd);
 184:     }
 185:     u.u_error = ENOTTY;
 186:     return (0);
 187: }
 188: #endif UCB_NTTY

Defined functions

bkclose defined in line 81; never used
bkinput defined in line 149; never used
bkioctl defined in line 170; never used
bkopen defined in line 53; never used
bkread defined in line 109; never used

Defined macros

spl5 defined in line 31; used 2 times
Last modified: 1983-08-06
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 865
Valid CSS Valid XHTML 1.0 Strict