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