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