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