vrevoke/single-user - fix more revoke issues.
[dragonfly.git] / sys / sys / tty.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)tty.h 8.6 (Berkeley) 1/21/94
39 * $FreeBSD: src/sys/sys/tty.h,v 1.53.2.1 2001/02/26 04:23:21 jlemon Exp $
b13267a5 40 * $DragonFly: src/sys/sys/tty.h,v 1.12 2006/09/10 01:26:40 dillon Exp $
984263bc
MD
41 */
42
43#ifndef _SYS_TTY_H_
44#define _SYS_TTY_H_
45
03d6a592 46#ifndef _SYS_TERMIOS_H_
984263bc 47#include <sys/termios.h>
03d6a592 48#endif
9183fa5b
MD
49#ifndef _SYS_SELINFO_H_
50#include <sys/selinfo.h>
03d6a592 51#endif
fef8985e
MD
52#ifdef _KERNEL
53#include <sys/device.h>
54#endif
984263bc
MD
55
56/*
57 * Clists are character lists, which is a variable length linked list
58 * of cblocks, with a count of the number of characters in the list.
59 */
60struct clist {
61 int c_cc; /* Number of characters in the clist. */
62 int c_cbcount; /* Number of cblocks. */
63 int c_cbmax; /* Max # cblocks allowed for this clist. */
64 int c_cbreserved; /* # cblocks reserved for this clist. */
65 char *c_cf; /* Pointer to the first cblock. */
66 char *c_cl; /* Pointer to the last cblock. */
67};
68
03d6a592
MD
69#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
70
71#ifndef _SYS_QUEUE_H_
72#include <sys/queue.h>
73#endif
74
984263bc
MD
75/*
76 * Per-tty structure.
77 *
78 * Should be split in two, into device and tty drivers.
79 * Glue could be masks of what to echo and circular buffer
80 * (low, high, timeout).
81 */
82struct tty {
83 struct clist t_rawq; /* Device raw input queue. */
84 long t_rawcc; /* Raw input queue statistics. */
85 struct clist t_canq; /* Device canonical queue. */
86 long t_cancc; /* Canonical queue statistics. */
87 struct clist t_outq; /* Device output queue. */
88 long t_outcc; /* Output queue statistics. */
89 int t_line; /* Interface to device drivers. */
b13267a5 90 struct cdev *t_dev; /* Device. */
984263bc
MD
91 int t_state; /* Device and driver (TS*) state. */
92 int t_flags; /* Tty flags. */
93 int t_timeout; /* Timeout for ttywait() */
94 struct pgrp *t_pgrp; /* Foreground process group. */
95 struct session *t_session; /* Enclosing session. */
96 struct sigio *t_sigio; /* Information for async I/O. */
97 struct selinfo t_rsel; /* Tty read/oob select. */
98 struct selinfo t_wsel; /* Tty write select. */
99 struct termios t_termios; /* Termios state. */
100 struct winsize t_winsize; /* Window size. */
101 /* Start output. */
b153f746 102 void (*t_oproc) (struct tty *);
984263bc 103 /* Stop output. */
b153f746 104 void (*t_stop) (struct tty *, int);
984263bc 105 /* Set hardware state. */
b153f746 106 int (*t_param) (struct tty *, struct termios *);
984263bc
MD
107 void *t_sc; /* XXX: net/if_sl.c:sl_softc. */
108 int t_column; /* Tty output column. */
109 int t_rocount, t_rocol; /* Tty. */
110 int t_ififosize; /* Total size of upstream fifos. */
111 int t_ihiwat; /* High water mark for input. */
112 int t_ilowat; /* Low water mark for input. */
113 speed_t t_ispeedwat; /* t_ispeed override for watermarks. */
114 int t_ohiwat; /* High water mark for output. */
115 int t_olowat; /* Low water mark for output. */
116 speed_t t_ospeedwat; /* t_ospeed override for watermarks. */
117 int t_gen; /* Generation number. */
118 SLIST_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */
119};
120
121#define t_cc t_termios.c_cc
122#define t_cflag t_termios.c_cflag
123#define t_iflag t_termios.c_iflag
124#define t_ispeed t_termios.c_ispeed
125#define t_lflag t_termios.c_lflag
126#define t_min t_termios.c_min
127#define t_oflag t_termios.c_oflag
128#define t_ospeed t_termios.c_ospeed
129#define t_time t_termios.c_time
130
03d6a592
MD
131#endif
132
984263bc
MD
133/*
134 * User data unfortunately has to be copied through buffers on the way to
135 * and from clists. The buffers are on the stack so their sizes must be
136 * fairly small.
137 */
138#define IBUFSIZ 384 /* Should be >= max value of MIN. */
139#define OBUFSIZ 100
140
141#ifndef TTYHOG
142#define TTYHOG 1024
143#endif
144
145#ifdef _KERNEL
146#define TTMAXHIWAT roundup(2048, CBSIZE)
147#define TTMINHIWAT roundup(100, CBSIZE)
148#define TTMAXLOWAT 256
149#define TTMINLOWAT 32
150#endif
151
152/* These flags are kept in t_state. */
153#define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */
154#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
155#define TS_BUSY 0x00004 /* Draining output. */
156#define TS_CARR_ON 0x00008 /* Carrier is present. */
157#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
158#define TS_ISOPEN 0x00020 /* Open has completed. */
159#define TS_TBLOCK 0x00040 /* Further input blocked. */
160#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
161#define TS_TTSTOP 0x00100 /* Output paused. */
162#ifdef notyet
163#define TS_WOPEN 0x00200 /* Open in progress. */
164#endif
165#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
166
167/* State for intra-line fancy editing work. */
168#define TS_BKSL 0x00800 /* State for lowercase \ work. */
169#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
170#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
171#define TS_LNCH 0x04000 /* Next character is literal. */
172#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
173#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
174
175/* Extras. */
176#define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */
177#define TS_CONNECTED 0x020000 /* Connection open. */
178#define TS_SNOOP 0x040000 /* Device is being snooped on. */
179#define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */
180#define TS_ZOMBIE 0x100000 /* Connection lost. */
181
182/* Hardware flow-control-invoked bits. */
183#define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */
184#ifdef notyet
185#define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */
186#define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */
187#endif
188
189/* Character type information. */
190#define ORDINARY 0
191#define CONTROL 1
192#define BACKSPACE 2
193#define NEWLINE 3
194#define TAB 4
195#define VTAB 5
196#define RETURN 6
197
198struct speedtab {
199 int sp_speed; /* Speed. */
200 int sp_code; /* Code. */
201};
202
203/* Modem control commands (driver). */
204#define DMSET 0
205#define DMBIS 1
206#define DMBIC 2
207#define DMGET 3
208
209/* Flags on a character passed to ttyinput. */
210#define TTY_CHARMASK 0x000000ff /* Character mask */
211#define TTY_QUOTE 0x00000100 /* Character quoted */
212#define TTY_ERRORMASK 0xff000000 /* Error mask */
213#define TTY_FE 0x01000000 /* Framing error */
214#define TTY_PE 0x02000000 /* Parity error */
215#define TTY_OE 0x04000000 /* Overrun error */
216#define TTY_BI 0x08000000 /* Break condition */
217
218/* Is tp controlling terminal for p? */
219#define isctty(p, tp) \
220 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
221
222/* Is p in background of tp? */
223#define isbackground(p, tp) \
224 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
225
226/* Unique sleep addresses. */
227#define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
228#define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf)
229#define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl)
230#define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
231#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf)
232#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl)
233#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
234
235#ifdef _KERNEL
03d6a592
MD
236
237#ifndef _SYS_MALLOC_H_
238#include <sys/malloc.h>
984263bc 239#endif
03d6a592
MD
240
241MALLOC_DECLARE(M_TTYS);
242
984263bc
MD
243extern struct tty *constty; /* Temporary virtual console. */
244
b153f746
RG
245int b_to_q (char *cp, int cc, struct clist *q);
246void catq (struct clist *from, struct clist *to);
247void clist_alloc_cblocks (struct clist *q, int ccmax, int ccres);
248void clist_free_cblocks (struct clist *q);
0ced1954
MD
249int clist_getc (struct clist *q);
250int clist_unputc (struct clist *q);
b153f746
RG
251void ndflush (struct clist *q, int cc);
252char *nextc (struct clist *q, char *cp, int *c);
253void nottystop (struct tty *tp, int rw);
0ced1954 254int clist_putc (int c, struct clist *q);
b153f746
RG
255int q_to_b (struct clist *q, char *cp, int cc);
256void termioschars (struct termios *t);
257int tputchar (int c, struct tty *tp);
258int ttcompat (struct tty *tp, u_long com, caddr_t data, int flag);
259int ttioctl (struct tty *tp, u_long com, void *data, int flag);
260int ttread (struct tty *tp, struct uio *uio, int flag);
261void ttrstrt (void *tp);
262int ttsetcompat (struct tty *tp, u_long *com, caddr_t data,
263 struct termios *term);
264void ttsetwater (struct tty *tp);
265int ttspeedtab (int speed, struct speedtab *table);
266int ttstart (struct tty *tp);
267void ttwakeup (struct tty *tp);
268int ttwrite (struct tty *tp, struct uio *uio, int flag);
269void ttwwakeup (struct tty *tp);
270void ttyblock (struct tty *tp);
271void ttychars (struct tty *tp);
272int ttycheckoutq (struct tty *tp, int wait);
273int ttyclose (struct tty *tp);
8b90699b 274void ttyclearsession (struct tty *tp);
5fd012e0 275void ttyclosesession (struct session *, int);
b153f746
RG
276void ttyflush (struct tty *tp, int rw);
277void ttyfree (struct tty *tp);
278void ttyinfo (struct tty *tp);
279int ttyinput (int c, struct tty *tp);
280int ttylclose (struct tty *tp, int flag);
281struct tty *ttymalloc (struct tty *tp);
282int ttymodem (struct tty *tp, int flag);
b13267a5 283int ttyopen (cdev_t device, struct tty *tp);
fef8985e
MD
284int ttypoll (struct dev_poll_args *);
285int ttykqfilter (struct dev_kqfilter_args *);
286int ttyread (struct dev_read_args *);
b153f746
RG
287void ttyregister (struct tty *tp);
288int ttysleep (struct tty *tp, void *chan, int slpflags, char *wmesg,
289 int timeout);
a32446b7 290int ttyrevoke (struct dev_revoke_args *);
b153f746 291int ttywait (struct tty *tp);
fef8985e 292int ttywrite (struct dev_write_args *);
984263bc
MD
293
294#endif /* _KERNEL */
295
296#endif /* !_SYS_TTY_H_ */