since it replaces cu, put it in usr/bin
[unix-history] / usr / src / sys / kern / tty_bk.c
CommitLineData
a8d3bf7f 1/* tty_bk.c 4.7 82/10/17 */
f2d9204a
BJ
2
3#include "bk.h"
4
5#if NBK > 0
6#include "../h/param.h"
7#include "../h/systm.h"
8#include "../h/dir.h"
9#include "../h/user.h"
10#include "../h/tty.h"
11#include "../h/proc.h"
12#include "../h/inode.h"
13#include "../h/file.h"
14#include "../h/conf.h"
15#include "../h/buf.h"
740e4029 16#include "../h/uio.h"
f2d9204a
BJ
17
18/*
19 * Line discipline for Berkeley network.
20 *
21 * This supplies single lines to a user level program
22 * with a minimum of fuss. Lines are newline terminated.
23 *
24 * This discipline requires that tty device drivers call
25 * the line specific l_ioctl routine from their ioctl routines,
26 * assigning the result to cmd so that we can refuse most tty specific
27 * ioctls which are unsafe because we have ambushed the
28 * teletype input queues, overlaying them with other information.
29 */
30
31/*
32 * Open as networked discipline. Called when discipline changed
33 * with ioctl, this assigns a buffer to the line for input, and
34 * changing the interpretation of the information in the tty structure.
35 */
36/*ARGSUSED*/
37bkopen(dev, tp)
942f05a9
SL
38 dev_t dev;
39 register struct tty *tp;
f2d9204a
BJ
40{
41 register struct buf *bp;
42
e5c9c00b
BJ
43 if (tp->t_line == NETLDISC)
44 return (EBUSY); /* sometimes the network opens /dev/tty */
f2d9204a
BJ
45 bp = geteblk(1024);
46 flushtty(tp, FREAD|FWRITE);
47 tp->t_bufp = bp;
48 tp->t_cp = (char *)bp->b_un.b_addr;
49 tp->t_inbuf = 0;
50 tp->t_rec = 0;
e5c9c00b 51 return (0);
f2d9204a
BJ
52}
53
54/*
55 * Break down... called when discipline changed or from device
56 * close routine.
57 */
58bkclose(tp)
e5c9c00b 59 register struct tty *tp;
f2d9204a 60{
e5c9c00b 61 register int s;
f2d9204a
BJ
62
63 s = spl5();
64 wakeup((caddr_t)&tp->t_rawq);
65 if (tp->t_bufp) {
66 brelse(tp->t_bufp);
67 tp->t_bufp = 0;
68 } else
69 printf("bkclose: no buf\n");
70 tp->t_cp = 0;
71 tp->t_inbuf = 0;
72 tp->t_rec = 0;
73 tp->t_line = 0; /* paranoid: avoid races */
74 splx(s);
75}
76
77/*
78 * Read from a network line.
79 * Characters have been buffered in a system buffer and are
80 * now dumped back to the user in one fell swoop, and with a
81 * minimum of fuss. Note that no input is accepted when a record
82 * is waiting. Our clearing tp->t_rec here allows further input
83 * to accumulate.
84 */
740e4029
BJ
85bkread(tp, uio)
86 register struct tty *tp;
87 struct uio *uio;
f2d9204a 88{
a8d3bf7f 89 register int s;
840510a3 90 int error;
f2d9204a
BJ
91
92 if ((tp->t_state&TS_CARR_ON)==0)
93 return (-1);
94 s = spl5();
95 while (tp->t_rec == 0 && tp->t_line == NETLDISC)
96 sleep((caddr_t)&tp->t_rawq, TTIPRI);
97 splx(s);
98 if (tp->t_line != NETLDISC)
99 return (-1);
840510a3 100 error = uiomove(tp->t_bufp->b_un.b_addr, tp->t_inbuf, UIO_READ, uio);
f2d9204a
BJ
101 tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
102 tp->t_inbuf = 0;
103 tp->t_rec = 0;
840510a3 104 return (error);
f2d9204a
BJ
105}
106
107/*
108 * Low level character input routine.
109 * Stuff the character in the buffer, and wake up the top
110 * half after setting t_rec if this completes the record
111 * or if the buffer is (ick!) full.
112 *
113 * Thisis where the formatting should get done to allow
114 * 8 character data paths through escapes.
115 *
116 * This rutine should be expanded in-line in the receiver
117 * interrupt routine of the dh-11 to make it run as fast as possible.
118 */
119bkinput(c, tp)
120register c;
121register struct tty *tp;
122{
123
124 if (tp->t_rec)
125 return;
126 *tp->t_cp++ = c;
127 if (++tp->t_inbuf == 1024 || c == '\n') {
128 tp->t_rec = 1;
129 wakeup((caddr_t)&tp->t_rawq);
130 }
131}
132
133/*
134 * This routine is called whenever a ioctl is about to be performed
135 * and gets a chance to reject the ioctl. We reject all teletype
136 * oriented ioctl's except those which set the discipline, and
137 * those which get parameters (gtty and get special characters).
138 */
139/*ARGSUSED*/
942f05a9
SL
140bkioctl(tp, cmd, data, flag)
141 struct tty *tp;
142 caddr_t data;
f2d9204a
BJ
143{
144
145 if ((cmd>>8) != 't')
e5c9c00b 146 return (-1);
f2d9204a
BJ
147 switch (cmd) {
148
149 case TIOCSETD:
150 case TIOCGETD:
151 case TIOCGETP:
152 case TIOCGETC:
e5c9c00b 153 return (-1);
f2d9204a 154 }
e5c9c00b 155 return (ENOTTY);
f2d9204a
BJ
156}
157#endif