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