1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <sys/termios.h>
41 #include <sys/queue.h>
42 #include <sys/selinfo.h>
43 #include <sys/timeout.h>
44
45 #define KERN_TTY_TKNIN 1
46 #define KERN_TTY_TKNOUT 2
47 #define KERN_TTY_TKRAWCC 3
48 #define KERN_TTY_TKCANCC 4
49 #define KERN_TTY_INFO 5
50 #define KERN_TTY_MAXPTYS 6
51 #define KERN_TTY_NPTYS 7
52 #define KERN_TTY_MAXID 8
53
54 #define CTL_KERN_TTY_NAMES { \
55 { 0, 0 }, \
56 { "tk_nin", CTLTYPE_QUAD }, \
57 { "tk_nout", CTLTYPE_QUAD }, \
58 { "tk_rawcc", CTLTYPE_QUAD }, \
59 { "tk_cancc", CTLTYPE_QUAD }, \
60 { "ttyinfo", CTLTYPE_STRUCT }, \
61 { "maxptys", CTLTYPE_INT }, \
62 { "nptys", CTLTYPE_INT }, \
63 }
64
65
66
67 struct ptmget {
68 int cfd;
69 int sfd;
70 char cn[16];
71 char sn[16];
72 };
73 #define PTMGET _IOR('t', 1, struct ptmget)
74 #define PATH_PTMDEV "/dev/ptm"
75 #define TTY_GID 4
76
77
78
79
80
81
82
83
84
85 struct clist {
86 int c_cc;
87 int c_cn;
88 u_char *c_cf;
89 u_char *c_cl;
90 u_char *c_cs;
91 u_char *c_ce;
92 u_char *c_cq;
93 };
94
95
96
97
98
99
100
101
102 struct tty {
103 TAILQ_ENTRY(tty) tty_link;
104 struct clist t_rawq;
105 long t_rawcc;
106 struct clist t_canq;
107 long t_cancc;
108 struct clist t_outq;
109 long t_outcc;
110 u_char t_line;
111 dev_t t_dev;
112 int t_state;
113 int t_flags;
114 struct pgrp *t_pgrp;
115 struct session *t_session;
116 struct selinfo t_rsel;
117 struct selinfo t_wsel;
118 struct termios t_termios;
119 struct winsize t_winsize;
120
121 void (*t_oproc)(struct tty *);
122
123 int (*t_param)(struct tty *, struct termios *);
124
125 int (*t_hwiflow)(struct tty *tp, int flag);
126 void *t_sc;
127 short t_column;
128 short t_rocount, t_rocol;
129 short t_hiwat;
130 short t_lowat;
131 short t_gen;
132 struct timeout t_rstrt_to;
133 struct timeval t_tv;
134 };
135
136
137
138
139 struct itty {
140 dev_t t_dev;
141 int t_rawq_c_cc;
142 int t_canq_c_cc;
143 int t_outq_c_cc;
144 short t_hiwat;
145 short t_lowat;
146 short t_column;
147 int t_state;
148 struct session *t_session;
149 pid_t t_pgrp_pg_id;
150 u_char t_line;
151 };
152
153 #define t_cc t_termios.c_cc
154 #define t_cflag t_termios.c_cflag
155 #define t_iflag t_termios.c_iflag
156 #define t_ispeed t_termios.c_ispeed
157 #define t_lflag t_termios.c_lflag
158 #define t_min t_termios.c_min
159 #define t_oflag t_termios.c_oflag
160 #define t_ospeed t_termios.c_ospeed
161 #define t_time t_termios.c_time
162
163 #define TTIPRI 25
164 #define TTOPRI 26
165
166 #define TTMASK 15
167 #define OBUFSIZ 512
168 #define TTYHOG 1024
169
170 #ifdef _KERNEL
171 #define TTMAXHIWAT roundup(2048, CBSIZE)
172 #define TTMINHIWAT roundup(100, CBSIZE)
173 #define TTMAXLOWAT 256
174 #define TTMINLOWAT 32
175 #endif
176
177
178 #define TS_ASLEEP 0x00001
179 #define TS_ASYNC 0x00002
180 #define TS_BUSY 0x00004
181 #define TS_CARR_ON 0x00008
182 #define TS_FLUSH 0x00010
183 #define TS_ISOPEN 0x00020
184 #define TS_TBLOCK 0x00040
185 #define TS_TIMEOUT 0x00080
186 #define TS_TTSTOP 0x00100
187 #define TS_WOPEN 0x00200
188 #define TS_XCLUDE 0x00400
189
190
191 #define TS_BKSL 0x00800
192 #define TS_CNTTB 0x01000
193 #define TS_ERASE 0x02000
194 #define TS_LNCH 0x04000
195 #define TS_TYPEN 0x08000
196 #define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
197
198 #define TS_TSTAMPDCDSET 0x10000
199 #define TS_TSTAMPDCDCLR 0x20000
200 #define TS_TSTAMPCTSSET 0x40000
201 #define TS_TSTAMPCTSCLR 0x80000
202
203
204 #define ORDINARY 0
205 #define CONTROL 1
206 #define BACKSPACE 2
207 #define NEWLINE 3
208 #define TAB 4
209 #define VTAB 5
210 #define RETURN 6
211
212 struct speedtab {
213 int sp_speed;
214 int sp_code;
215 };
216
217
218 #define DMSET 0
219 #define DMBIS 1
220 #define DMBIC 2
221 #define DMGET 3
222
223
224 #define TTY_CHARMASK 0x000000ff
225 #define TTY_QUOTE 0x00000100
226 #define TTY_ERRORMASK 0xff000000
227 #define TTY_FE 0x01000000
228 #define TTY_PE 0x02000000
229
230
231 #define isctty(p, tp) \
232 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
233
234
235 #define isbackground(p, tp) \
236 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
237
238
239
240
241 TAILQ_HEAD(ttylist_head, tty);
242
243 #ifdef _KERNEL
244
245 extern int tty_count;
246 extern struct ttychars ttydefaults;
247
248
249 extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
250
251 int sysctl_tty(int *, u_int, void *, size_t *, void *, size_t);
252 int sysctl_pty(int *, u_int, void *, size_t *, void *, size_t);
253
254 int b_to_q(u_char *cp, int cc, struct clist *q);
255 void catq(struct clist *from, struct clist *to);
256 void clist_init(void);
257 int getc(struct clist *q);
258 void ndflush(struct clist *q, int cc);
259 int ndqb(struct clist *q, int flag);
260 u_char *nextc(struct clist *q, u_char *cp, int *c);
261 int putc(int c, struct clist *q);
262 int q_to_b(struct clist *q, u_char *cp, int cc);
263 int unputc(struct clist *q);
264
265 int nullmodem(struct tty *tp, int flag);
266 int tputchar(int c, struct tty *tp);
267 int ttioctl(struct tty *tp, u_long com, caddr_t data, int flag,
268 struct proc *p);
269 int ttread(struct tty *tp, struct uio *uio, int flag);
270 void ttrstrt(void *tp);
271 int ttpoll(dev_t device, int events, struct proc *p);
272 int ttkqfilter(dev_t dev, struct knote *kn);
273 void ttsetwater(struct tty *tp);
274 int ttspeedtab(int speed, const struct speedtab *table);
275 int ttstart(struct tty *tp);
276 void ttwakeup(struct tty *tp);
277 int ttwrite(struct tty *tp, struct uio *uio, int flag);
278 void ttychars(struct tty *tp);
279 int ttycheckoutq(struct tty *tp, int wait);
280 int ttyclose(struct tty *tp);
281 void ttyflush(struct tty *tp, int rw);
282 void ttyinfo(struct tty *tp);
283 int ttyinput(int c, struct tty *tp);
284 int ttylclose(struct tty *tp, int flag);
285 int ttymodem(struct tty *tp, int flag);
286 int ttyopen(dev_t device, struct tty *tp);
287 int ttyoutput(int c, struct tty *tp);
288 void ttypend(struct tty *tp);
289 void ttyretype(struct tty *tp);
290 void ttyrub(int c, struct tty *tp);
291 int ttysleep(struct tty *tp,
292 void *chan, int pri, char *wmesg, int timeout);
293 int ttywait(struct tty *tp);
294 int ttywflush(struct tty *tp);
295 void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd);
296
297 void tty_init(void);
298 struct tty *ttymalloc(void);
299 void ttyfree(struct tty *);
300 u_char *firstc(struct clist *clp, int *c);
301
302 int cttyopen(dev_t, int, int, struct proc *);
303 int cttyread(dev_t, struct uio *, int);
304 int cttywrite(dev_t, struct uio *, int);
305 int cttyioctl(dev_t, u_long, caddr_t, int, struct proc *);
306 int cttypoll(dev_t, int, struct proc *);
307
308 int clalloc(struct clist *, int, int);
309 void clfree(struct clist *);
310
311 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \
312 defined(COMPAT_FREEBSD) || defined(COMPAT_OSF1)
313 # define COMPAT_OLDTTY
314 int ttcompat(struct tty *, u_long, caddr_t, int, struct proc *);
315 #endif
316
317 #endif