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