xref: /original-bsd/share/man/man4/tty.4 (revision 84651319)
1.\" Copyright (c) 1991, 1992 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)tty.4	6.11 (Berkeley) 08/15/92
7.\"
8.Dd August 14, 1992
9.Dt TTY 4
10.Os BSD 4
11.Sh NAME
12.Nm tty
13.Nd general terminal interface
14.Sh SYNOPSIS
15.Fd #include <sys/ioctl.h>
16.Sh DESCRIPTION
17This section describes the interface to the terminal drivers
18in the system.
19.Ss Terminal Special Files
20Each hardware terminal port on the system usually has a terminal special device
21file associated with it in the directory ``/dev/'' (for
22example, ``/dev/tty03'').
23When a user logs into
24the system on one of these hardware terminal ports, the system has already
25opened the associated device and prepared the line for normal interactive
26use (see
27.Xr getty 8 .)
28There is also a special case of a terminal file that connects not to
29a hardware terminal port, but to another program on the other side.
30These special terminal devices are called
31.Em ptys
32and provide the mechanism necessary to give users the same interface to the
33system when logging in over a network (using
34.Xr rlogin 1 ,
35or
36.Xr telnet 1
37for example.)  Even in these cases the details of how the terminal
38file was opened and set up is already handled by special software
39in the system.
40Thus, users do not normally need to worry about the details of
41how these lines are opened or used.  Also, these lines are often used
42for dialing out of a system (through an out-calling modem), but again
43the system provides programs that hide the details of accessing
44these terminal special files (see
45.Xr tip 2 .)
46.Pp
47When an interactive user logs in, the system prepares the line to
48behave in a certain way (called a
49.Em "line discipline" ),
50the particular details of which is described in
51.Xr stty 1
52at the command level, and in
53.Xr termios 4
54at the programming level.  A user may be concerned with changing
55settings associated with his particular login terminal and should refer
56to the preceding man pages for the common cases.  The remainder of
57this man page is concerned
58with describing details of using and controlling terminal devices
59at a low level, such as that possibly required by a program wishing
60to provide features similar to those provided by the system.
61.Ss Line disciplines
62A terminal file is used like any other file in the system in that
63it can be opened, read, and written to using standard system
64calls.  For each existing terminal file, a software processing module
65called a
66.Em "line discipline"
67is associated with it.  The
68.Em "line discipline"
69essentially glues the low level device driver code with the high
70level generic interface routines (such as
71.Xr read 2
72and
73.Xr write 2 ),
74and is responsible for implementing the semantics associated
75with the device.  When a terminal file is first opened by a program,
76the default
77.Em "line discipline"
78called the
79.Dv termios
80line discipline is associated with the file.  This is the primary
81line discipline that is used in most cases and provides the semantics
82that users normally associate with a terminal.  When the
83.Dv termios
84line discipline is in effect, the terminal file behaves and is
85operated according to the rules described in
86.Xr termios 4 .
87Please refer to that man page for a full description of the terminal
88semantics.
89The operations described here
90generally represent features common
91across all
92.Em "line disciplines"
93however, some of these calls may not
94make sense in conjunction with a line discipline other than
95.Dv termios ,
96and some may not be supported by the underlying
97hardware or (lack thereof, as in the case of ptys).
98.Ss Terminal File Operations
99All of the following operations are invoked using the
100.Xr ioctl 2
101system call.  Refer to that man page for a description of
102the
103.Em request
104and
105.Em argp
106parameter.
107In addition to the ioctl
108.Em requests
109defined here, the specific line discipline
110in effect will define other
111.Em requests
112specific to it (actually
113.Xr termios 4
114defines them as function calls, not ioctl
115.Em requests .)
116The following section lists the available ioctl requests.  The
117name of the request and the typed
118.Em argp
119parameter (if any)
120is listed along with a description of its
121purpose.  For example, the first entry says
122.Pp
123.D1 Em "TIOCSETD int *ldisc"
124.Pp
125and would be called on the terminal associated with
126file discriptor zero by the following code fragment:
127.Bd -literal
128	int ldisc;
129
130	ldisc = TTYDISC;
131	ioctl(0, TIOCSETD, &ldisc);
132.Ed
133.Ss Terminal File Request Descriptions
134.Bl -tag -width TIOCGWINSZ
135.It Dv TIOCSETD Fa int *ldisc
136Change to the new line discipline pointed to by
137.Fa ldisc .
138The available line disciplines are listed in
139.Pa Aq sys/termios.h
140and currently are:
141.Pp
142.Bl -tag -width TIOCGWINSZ -compact
143.It TTYDISC
144Termios interactive line discipline.
145.It TABLDISC
146Tablet line discipline.
147.It SLIPDISC
148Serial IP line discipline.
149.El
150.Pp
151.It Dv TIOCGETD Fa int *ldisc
152Return the current line discipline in the integer pointed to by
153.Fa ldisc .
154.It Dv TIOCSBRK Fa void
155Set the terminal hardware into BREAK condition.
156.It Dv TIOCCBRK Fa void
157Clear the terminal hardware BREAK condition.
158.It Dv TIOCSDTR Fa void
159Assert data terminal ready (DTR).
160.It Dv TIOCCDTR Fa void
161Clear data terminal ready (DTR).
162.It Dv TIOCGPGRP Fa int *tpgrp
163Return the current process group the terminal is associated
164with in the integer pointed to by
165.Fa tpgrp .
166This is the underlying call that implements the
167.Xr termios 4
168.Fn tcgetattr
169call.
170.It Dv TIOCSPGRP Fa int *tpgrp
171Associate the terminal with the process group (as an integer) pointed to by
172.Fa tpgrp .
173This is the underlying call that implements the
174.Xr termios 4
175.Fn tcsetattr
176call.
177.It Dv TIOCGETA Fa struct termios *term
178Place the current value of the termios state associated with the
179device in the termios structure pointed to by
180.Fa term .
181This is the underlying call that implements the
182.Xr termios 4
183.Fn tcgetattr
184call.
185.It Dv TIOCSETA Fa struct termios *term
186Set the termios state associated with the device immediatly.
187This is the underlying call that implements the
188.Xr termios 4
189.Fn tcsetattr
190call with the
191.Dv TCSANOW
192option.
193.It Dv TIOCSETAW Fa struct termios *term
194First wait for any output to complete, then set the termios state
195associated with the device.
196This is the underlying call that implements the
197.Xr termios 4
198.Fn tcsetattr
199call with the
200.Dv TCSADRAIN
201option.
202.It Dv TIOCSETAF Fa struct termios *term
203First wait for any output to complete, clear any pending input,
204then set the termios state associated with the device.
205This is the underlying call that implements the
206.Xr termios 4
207.Fn tcsetattr
208call with the
209.Dv TCSAFLUSH
210option.
211.It Dv TIOCOUTQ Fa int *num
212Place the current number of characters in the output queue in the
213integer pointed to by
214.Fa num .
215.It Dv TIOCSTI Fa char *cp
216Simulate typed input.  Pretend as if the terminal recieved the
217character pointed to by
218.Fa cp .
219.It Dv TIOCNOTTY Fa void
220This call is obsolete but left for compatability.  In the past, when
221a process that didn't have a controlling terminal (see
222.Em The Controlling Terminal
223in
224.Xr termios 4 )
225first opened a terminal device, it acquired that terminal as its
226controlling terminal.  For some programs this was a hazard as they
227didn't want a controlling terminal in the first place, and this
228provided a mechanism to disassociate the controlling terminal from
229the calling process.  It
230.Em must
231be called by opening the file
232.Pa /dev/tty
233and calling
234.Dv TIOCNOTTY
235on that file descriptor.
236.Pp
237The current system does not allocate a controlling terminal to
238a process on an
239.Fn open
240call: there is a specific ioctl called
241.Dv TIOSCTTY
242to make a terminal the controlling
243terminal.
244In addition, a program can
245.Fn fork
246and call the
247.Fn setsid
248system call which will place the process into its own session - which
249has the effect of disassociating it from the controlling terminal.  This
250is the new and prefered method for programs to lose their controlling
251terminal.
252.It Dv TIOCSTOP Fa void
253Stop output on the terminal (like typing ^S at the keyboard).
254.It Dv TIOCSTART Fa void
255Start output on the terminal (like typing ^Q at the kayboard).
256.It Dv TIOCSCTTY Fa void
257Make the terminal the controlling terminal for the process (the process
258must not currently have a controlling terminal).
259.It Dv TIOCDRAIN Fa void
260Wait until all output is drained.
261.It Dv TIOCEXCL Fa void
262Set exclusive use on the terminal.  No further opens are permitted
263except by root.  Of course, this means that programs that are run by
264root (or setuid) will not obey the exclusive setting - which limits
265the usefullness of this feature.
266.It Dv TIOCNXCL Fa void
267Clear exclusive use of the terminal.  Further opens are permitted.
268.It Dv TIOCFLUSH Fa int *what
269If the value of the int pointed to by
270.Fa what
271contains the
272.Dv FREAD
273bit as defined in
274.Pa Aq sys/file.h ,
275then all characters in the input queue are cleared.  If it contains
276the
277.Dv FWRITE
278bit, then all characters in the output queue are cleared.  If the
279value of the integer is zero, then it behaves as if both the
280.Dv FREAD
281and
282.Dv FWRITE
283bits were set (i.e. clears both queues).
284.It Dv TIOCGWINSZ Fa struct winsize *ws
285Put the window size information associated with the terminal in the
286.Va winsize
287structure pointed to by
288.Fa ws .
289The window size structure contains the number of rows and columns (and pixels
290if appropiate) of the devices attached to the terminal.  It is set by user software
291and is the means by which most full\&-screen oriented programs determine the
292screen size.  The
293.Va winsize
294structure is defined in
295.Pa Aq sys/ioctl.h .
296.It Dv TIOCSWINSZ Fa struct winsize *ws
297Set the window size associated with the terminal to be the value in
298the
299.Va winsize
300structure pointed to by
301.Fa ws
302(see above).
303.It Dv TIOCCONS Fa int *on
304If
305.Fa on
306points to a non-zero integer, redirect kernel console output (kernel printf's)
307to this terminal.
308If
309.Fa on
310points to a zero integer, redirect kernel console output back to the normal
311console.  This is usually used on workstations to redirect kernel messages
312to a particular window.
313.It Dv TIOCMSET Fa int *state
314The integer pointed to by
315.Fa state
316contains bits that correspond to modem state.  Following is a list
317of defined variables and the modem state they represent:
318.Pp
319.Bl -tag -width TIOCMXCTS -compact
320.It TIOCM_LE
321Line Enable.
322.It TIOCM_DTR
323Data Terminal Ready.
324.It TIOCM_RTS
325Request To Send.
326.It TIOCM_ST
327Secondary Transmit.
328.It TIOCM_SR
329Secondary Recieve.
330.It TIOCM_CTS
331Clear To Send.
332.It TIOCM_CAR
333Carrier Detect.
334.It TIOCM_CD
335Carier Detect (synonym).
336.It TIOCM_RNG
337Ring Indication.
338.It TIOCM_RI
339Ring Indication (synonym).
340.It TIOCM_DSR
341Data Set Ready.
342.El
343.Pp
344This call sets the terminal modem state to that represented by
345.Fa state .
346Not all terminals may support this.
347.It Dv TIOCMGET Fa int *state
348Return the current state of the terminal modem lines as represented
349above in the integer pointed to by
350.Fa state .
351.It Dv TIOCMBIS Fa int *state
352The bits in the integer pointed to by
353.Fa state
354represent modem state as described above, however the state is OR-ed
355in with the current state.
356.It Dv TIOCMBIC Fa int *state
357The bits in the integer pointed to by
358.Fa state
359represent modem state as described above, however each bit which is on
360in
361.Fa state
362is cleared in the terminal.
363.El
364.Sh SEE ALSO
365.Xr getty 8 ,
366.Xr ioctl 2 ,
367.Xr pty 4 ,
368.Xr stty 1 ,
369.Xr termios 4
370