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