]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/ioctl_tty.2
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man2 / ioctl_tty.2
CommitLineData
fea681da
MK
1.\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
2.\" and Andries Brouwer <aeb@cwi.nl>.
2297bf0e 3.\"
95fb8859 4.\" SPDX-License-Identifier: GPL-1.0-or-later
fea681da 5.\"
45186a5d 6.TH IOCTL_TTY 2 2021-08-27 "Linux man-pages (unreleased)"
fea681da 7.SH NAME
a78f6752 8ioctl_tty \- ioctls for terminals and serial lines
f0999011
AC
9.SH LIBRARY
10Standard C library
8fc3b2cf 11.RI ( libc ", " \-lc )
fea681da 12.SH SYNOPSIS
c7db92b9 13.nf
70f9a4ed 14.B #include <sys/ioctl.h>
c0236145
PR
15.BR "#include <asm/termbits.h>" " /* Definition of " "struct termios" ,
16.BR " struct termios2" ", and"
17.BR " Bnnn" ", " BOTHER ", " CBAUD ", " CLOCAL ,
18.BR " TC*" { FLUSH , ON , OFF "} and other constants */"
68e4db0a 19.PP
c13182ef 20.BI "int ioctl(int " fd ", int " cmd ", ...);"
c7db92b9 21.fi
fea681da
MK
22.SH DESCRIPTION
23The
0b80cf56 24.BR ioctl (2)
fea681da 25call for terminals and serial ports accepts many possible command arguments.
c6fa0841
MK
26Most require a third argument, of varying type, here called
27.I argp
28or
29.IR arg .
dd3568a1 30.PP
fea681da 31Use of
025a34a6 32.BR ioctl ()
d603cc27 33makes for nonportable programs.
c13182ef 34Use the POSIX interface described in
fea681da
MK
35.BR termios (3)
36whenever possible.
c0236145
PR
37.PP
38Please note that
39.B struct termios
40from
41.I <asm/termbits.h>
42is different and incompatible with
43.B struct termios
44from
45.IR <termios.h> .
46These ioctl calls require
47.B struct termios
48from
49.IR <asm/termbits.h> .
73d8cece 50.SS Get and set terminal attributes
fea681da 51.TP
2858b5b5
MK
52.B TCGETS
53Argument:
3d58eb6d 54.BI "struct termios\~*" argp
2858b5b5 55.IP
fea681da
MK
56Equivalent to
57.IR "tcgetattr(fd, argp)" .
322522ea 58.IP
fea681da
MK
59Get the current serial port settings.
60.TP
2858b5b5
MK
61.B TCSETS
62Argument:
3d58eb6d 63.BI "const struct termios\~*" argp
2858b5b5 64.IP
fea681da
MK
65Equivalent to
66.IR "tcsetattr(fd, TCSANOW, argp)" .
322522ea 67.IP
fea681da
MK
68Set the current serial port settings.
69.TP
2858b5b5
MK
70.B TCSETSW
71Argument:
3d58eb6d 72.BI "const struct termios\~*" argp
2858b5b5 73.IP
fea681da
MK
74Equivalent to
75.IR "tcsetattr(fd, TCSADRAIN, argp)" .
322522ea 76.IP
fea681da
MK
77Allow the output buffer to drain, and
78set the current serial port settings.
79.TP
2858b5b5
MK
80.B TCSETSF
81Argument:
3d58eb6d 82.BI "const struct termios\~*" argp
2858b5b5 83.IP
fea681da
MK
84Equivalent to
85.IR "tcsetattr(fd, TCSAFLUSH, argp)" .
322522ea 86.IP
fea681da
MK
87Allow the output buffer to drain, discard pending input, and
88set the current serial port settings.
dd3568a1 89.PP
c8219af7
MK
90The following four ioctls, added in Linux 2.6.20,
91.\" commit 64bb6c5e1ddcd47c951740485026ef08975ee2e6
92.\" commit 592ee3a5e5e2a981ef2829a0380093006d045661
93are just like
097585ed
MK
94.BR TCGETS ,
95.BR TCSETS ,
96.BR TCSETSW ,
97.BR TCSETSF ,
fea681da 98except that they take a
3d58eb6d 99.I "struct termios2\~*"
aad1f0e8 100instead of a
3d58eb6d 101.IR "struct termios\~*" .
5d9f0bc6 102If the structure member
aad1f0e8 103.B c_cflag
5d9f0bc6
MK
104contains the flag
105.BR BOTHER ,
106then the baud rate is stored in the structure members
aad1f0e8
PR
107.B c_ispeed
108and
109.B c_ospeed
110as integer values.
111These ioctls are not supported on all architectures.
112.RS
113.TS
114lb l.
115TCGETS2 \fBstruct termios2 *\fPargp
116TCSETS2 \fBconst struct termios2 *\fPargp
117TCSETSW2 \fBconst struct termios2 *\fPargp
118TCSETSF2 \fBconst struct termios2 *\fPargp
119.TE
120.RE
121.PP
122The following four ioctls are just like
123.BR TCGETS ,
124.BR TCSETS ,
125.BR TCSETSW ,
126.BR TCSETSF ,
127except that they take a
3d58eb6d 128.I "struct termio\~*"
fea681da 129instead of a
3d58eb6d 130.IR "struct termios\~*" .
aceee9e8
MK
131.RS
132.TS
133lb l.
134TCGETA \fBstruct termio *\fPargp
135TCSETA \fBconst struct termio *\fPargp
136TCSETAW \fBconst struct termio *\fPargp
137TCSETAF \fBconst struct termio *\fPargp
138.TE
139.RE
73d8cece 140.SS Locking the termios structure
4961e71d
MK
141The
142.I termios
132249c4 143structure of a terminal can be locked.
4961e71d
MK
144The lock is itself a
145.I termios
c7094399 146structure, with nonzero bits or fields indicating a
fea681da
MK
147locked value.
148.TP
2858b5b5
MK
149.B TIOCGLCKTRMIOS
150Argument:
3d58eb6d 151.BI "struct termios\~*" argp
2858b5b5 152.IP
4961e71d
MK
153Gets the locking status of the
154.I termios
155structure of the terminal.
fea681da 156.TP
2858b5b5
MK
157.B TIOCSLCKTRMIOS
158Argument:
3d58eb6d 159.BI "const struct termios\~*" argp
2858b5b5 160.IP
4961e71d
MK
161Sets the locking status of the
162.I termios
163structure of the terminal.
cb476d88 164Only a process with the
3d58eb6d 165.B CAP_SYS_ADMIN
cb476d88 166capability can do this.
73d8cece 167.SS Get and set window size
fea681da
MK
168Window sizes are kept in the kernel, but not used by the kernel
169(except in the case of virtual consoles, where the kernel will
170update the window size when the size of the virtual console changes,
75b94dc3 171for example, by loading a new font).
fea681da 172.TP
2858b5b5
MK
173.B TIOCGWINSZ
174Argument:
3d58eb6d 175.BI "struct winsize\~*" argp
2858b5b5 176.IP
fea681da
MK
177Get window size.
178.TP
2858b5b5
MK
179.B TIOCSWINSZ
180Argument:
3d58eb6d 181.BI "const struct winsize\~*" argp
2858b5b5 182.IP
fea681da 183Set window size.
dd3568a1 184.PP
fea681da 185The struct used by these ioctls is defined as
efeece04 186.PP
3f89ebc0 187.in +4n
b76974c1 188.EX
fea681da 189struct winsize {
cf0a9ace
MK
190 unsigned short ws_row;
191 unsigned short ws_col;
192 unsigned short ws_xpixel; /* unused */
193 unsigned short ws_ypixel; /* unused */
fea681da 194};
b76974c1 195.EE
3f89ebc0 196.in
efeece04 197.PP
8bd58774
MK
198When the window size changes, a
199.B SIGWINCH
200signal is sent to the
fea681da 201foreground process group.
73d8cece 202.SS Sending a break
fea681da 203.TP
2858b5b5
MK
204.B TCSBRK
205Argument:
206.BI "int " arg
207.IP
fea681da
MK
208Equivalent to
209.IR "tcsendbreak(fd, arg)" .
322522ea 210.IP
fea681da
MK
211If the terminal is using asynchronous serial data transmission, and
212.I arg
213is zero, then send a break (a stream of zero bits) for between
c13182ef
MK
2140.25 and 0.5 seconds.
215If the terminal is not using asynchronous
fea681da
MK
216serial data transmission, then either a break is sent, or the function
217returns without doing anything.
218When
219.I arg
c7094399 220is nonzero, nobody knows what will happen.
efeece04 221.IP
1d9a03e9 222(SVr4, UnixWare, Solaris, and Linux treat
fea681da 223.I "tcsendbreak(fd,arg)"
c7094399 224with nonzero
fea681da
MK
225.I arg
226like
227.IR "tcdrain(fd)" .
228SunOS treats
229.I arg
230as a multiplier, and sends a stream of bits
231.I arg
232times as long as done for zero
233.IR arg .
72cedc06 234DG/UX and AIX treat
fea681da 235.I arg
c7094399 236(when nonzero) as a time interval measured in milliseconds.
fea681da
MK
237HP-UX ignores
238.IR arg .)
239.TP
2858b5b5
MK
240.B TCSBRKP
241Argument:
242.BI "int " arg
243.IP
097585ed
MK
244So-called "POSIX version" of
245.BR TCSBRK .
c7094399 246It treats nonzero
fea681da 247.I arg
8842f534 248as a time interval measured in deciseconds, and does nothing
fea681da
MK
249when the driver does not support breaks.
250.TP
2aec4ef8 251.B TIOCSBRK
2858b5b5 252Argument:
1ae6b2c7 253.B void
2858b5b5 254.IP
fea681da
MK
255Turn break on, that is, start sending zero bits.
256.TP
2aec4ef8 257.B TIOCCBRK
2858b5b5 258Argument:
1ae6b2c7 259.B void
2858b5b5 260.IP
fea681da 261Turn break off, that is, stop sending zero bits.
73d8cece 262.SS Software flow control
fea681da 263.TP
2858b5b5
MK
264.B TCXONC
265Argument:
266.BI "int " arg
267.IP
fea681da
MK
268Equivalent to
269.IR "tcflow(fd, arg)" .
322522ea 270.IP
fea681da
MK
271See
272.BR tcflow (3)
097585ed
MK
273for the argument values
274.BR TCOOFF ,
275.BR TCOON ,
276.BR TCIOFF ,
277.BR TCION .
73d8cece 278.SS Buffer count and flushing
fea681da 279.TP
1ae6b2c7 280.B FIONREAD
2858b5b5 281Argument:
3d58eb6d 282.BI "int\~*" argp
2858b5b5 283.IP
fea681da
MK
284Get the number of bytes in the input buffer.
285.TP
2858b5b5
MK
286.B TIOCINQ
287Argument:
3d58eb6d 288.BI "int\~*" argp
2858b5b5 289.IP
097585ed
MK
290Same as
291.BR FIONREAD .
fea681da 292.TP
2858b5b5
MK
293.B TIOCOUTQ
294Argument:
3d58eb6d 295.BI "int\~*" argp
2858b5b5 296.IP
fea681da
MK
297Get the number of bytes in the output buffer.
298.TP
2858b5b5
MK
299.B TCFLSH
300Argument:
301.BI "int " arg
302.IP
fea681da
MK
303Equivalent to
304.IR "tcflush(fd, arg)" .
322522ea 305.IP
fea681da
MK
306See
307.BR tcflush (3)
097585ed
MK
308for the argument values
309.BR TCIFLUSH ,
310.BR TCOFLUSH ,
311.BR TCIOFLUSH .
73d8cece 312.SS Faking input
fea681da 313.TP
2858b5b5
MK
314.B TIOCSTI
315Argument:
3d58eb6d 316.BI "const char\~*" argp
2858b5b5 317.IP
fea681da 318Insert the given byte in the input queue.
73d8cece 319.SS Redirecting console output
fea681da 320.TP
2aec4ef8 321.B TIOCCONS
2858b5b5 322Argument:
1ae6b2c7 323.B void
2858b5b5 324.IP
fea681da
MK
325Redirect output that would have gone to
326.I /dev/console
327or
328.I /dev/tty0
132249c4 329to the given terminal.
b218b023 330If that was a pseudoterminal master, send it to the slave.
b5fa38a3
MK
331In Linux before version 2.6.10,
332anybody can do this as long as the output was not redirected yet;
cb476d88 333since version 2.6.10, only a process with the
1ae6b2c7 334.B CAP_SYS_ADMIN
cb476d88 335capability may do this.
c4316bb5 336If output was redirected already, then
097585ed
MK
337.B EBUSY
338is returned,
b5fa38a3 339but redirection can be stopped by using this ioctl with
fea681da
MK
340.I fd
341pointing at
342.I /dev/console
343or
344.IR /dev/tty0 .
73d8cece 345.SS Controlling terminal
fea681da 346.TP
2858b5b5
MK
347.B TIOCSCTTY
348Argument:
349.BI "int " arg
350.IP
132249c4 351Make the given terminal the controlling terminal of the calling process.
a1ffe9f5 352The calling process must be a session leader and not have a
132249c4 353controlling terminal already.
9ab0de3c
MK
354For this case,
355.I arg
356should be specified as zero.
efeece04 357.IP
132249c4 358If this terminal is already the controlling terminal
5cc100b9 359of a different session group, then the ioctl fails with
097585ed 360.BR EPERM ,
cb476d88 361unless the caller has the
1ae6b2c7 362.B CAP_SYS_ADMIN
cb476d88 363capability and
fea681da 364.I arg
132249c4
MK
365equals 1, in which case the terminal is stolen, and all processes that had
366it as controlling terminal lose it.
fea681da 367.TP
2aec4ef8 368.B TIOCNOTTY
2858b5b5 369Argument:
1ae6b2c7 370.B void
2858b5b5 371.IP
132249c4
MK
372If the given terminal was the controlling terminal of the calling process,
373give up this controlling terminal.
c13182ef 374If the process was session leader,
8bd58774
MK
375then send
376.B SIGHUP
377and
378.B SIGCONT
379to the foreground process group
132249c4 380and all processes in the current session lose their controlling terminal.
73d8cece 381.SS Process group and session ID
fea681da 382.TP
2858b5b5
MK
383.B TIOCGPGRP
384Argument:
3d58eb6d 385.BI "pid_t\~*" argp
2858b5b5 386.IP
fea681da
MK
387When successful, equivalent to
388.IR "*argp = tcgetpgrp(fd)" .
322522ea 389.IP
132249c4 390Get the process group ID of the foreground process group on this terminal.
fea681da 391.TP
2858b5b5
MK
392.B TIOCSPGRP
393Argument:
3d58eb6d 394.BI "const pid_t\~*" argp
2858b5b5 395.IP
fea681da
MK
396Equivalent to
397.IR "tcsetpgrp(fd, *argp)" .
322522ea 398.IP
132249c4 399Set the foreground process group ID of this terminal.
fea681da 400.TP
2858b5b5
MK
401.B TIOCGSID
402Argument:
3d58eb6d 403.BI "pid_t\~*" argp
2858b5b5 404.IP
44803dd0
PR
405When successful, equivalent to
406.IR "*argp = tcgetsid(fd)" .
407.IP
132249c4 408Get the session ID of the given terminal.
ad94e27c 409This fails with the error
097585ed 410.B ENOTTY
a23d8efa 411if the terminal is not a master pseudoterminal
132249c4 412and not our controlling terminal.
c13182ef 413Strange.
73d8cece 414.SS Exclusive mode
fea681da 415.TP
2aec4ef8 416.B TIOCEXCL
2858b5b5 417Argument:
1ae6b2c7 418.B void
2858b5b5 419.IP
132249c4 420Put the terminal into exclusive mode.
fea681da
MK
421No further
422.BR open (2)
423operations on the terminal are permitted.
ad94e27c 424(They fail with
097585ed 425.BR EBUSY ,
cb476d88 426except for a process with the
1ae6b2c7 427.B CAP_SYS_ADMIN
c0b75059 428capability.)
fea681da 429.TP
2858b5b5
MK
430.B TIOCGEXCL
431Argument:
3d58eb6d 432.BI "int\~*" argp
2858b5b5 433.IP
164b4016 434(since Linux 3.8)
8b17edbe
MK
435If the terminal is currently in exclusive mode,
436place a nonzero value in the location pointed to by
437.IR argp ;
438otherwise, place zero in
164b4016 439.IR *argp .
8b17edbe 440.TP
2aec4ef8 441.B TIOCNXCL
2858b5b5 442Argument:
1ae6b2c7 443.B void
2858b5b5 444.IP
fea681da 445Disable exclusive mode.
73d8cece 446.SS Line discipline
fea681da 447.TP
2858b5b5
MK
448.B TIOCGETD
449Argument:
3d58eb6d 450.BI "int\~*" argp
2858b5b5 451.IP
132249c4 452Get the line discipline of the terminal.
fea681da 453.TP
2858b5b5
MK
454.B TIOCSETD
455Argument:
3d58eb6d 456.BI "const int\~*" argp
2858b5b5 457.IP
132249c4 458Set the line discipline of the terminal.
73d8cece 459.SS Pseudoterminal ioctls
fea681da 460.TP
2858b5b5
MK
461.B TIOCPKT
462Argument:
3d58eb6d 463.BI "const int\~*" argp
2858b5b5 464.IP
fea681da
MK
465Enable (when
466.RI * argp
c7094399 467is nonzero) or disable packet mode.
b218b023 468Can be applied to the master side of a pseudoterminal only (and will return
097585ed
MK
469.B ENOTTY
470otherwise).
c13182ef 471In packet mode, each subsequent
fea681da 472.BR read (2)
c7094399 473will return a packet that either contains a single nonzero control byte,
cc1a0b7e 474or has a single byte containing zero (\(aq\e0\(aq) followed by data
b218b023 475written on the slave side of the pseudoterminal.
097585ed
MK
476If the first byte is not
477.B TIOCPKT_DATA
478(0), it is an OR of one
fea681da 479or more of the following bits:
efeece04 480.IP
0b174fe0 481.ad l
d6780634
MK
482.TS
483lb l.
0b174fe0
MK
484TIOCPKT_FLUSHREAD T{
485The read queue for the terminal is flushed.
486T}
487TIOCPKT_FLUSHWRITE T{
488The write queue for the terminal is flushed.
489T}
490TIOCPKT_STOP T{
491Output to the terminal is stopped.
492T}
493TIOCPKT_START T{
494Output to the terminal is restarted.
495T}
496TIOCPKT_DOSTOP T{
497The start and stop characters are \fB\(haS\fP/\fB\(haQ\fP.
498T}
499TIOCPKT_NOSTOP T{
500The start and stop characters are not \fB\(haS\fP/\fB\(haQ\fP.
501T}
d6780634 502.TE
0b174fe0 503.ad
efeece04 504.IP
c4316bb5 505While packet mode is in use, the presence
fea681da
MK
506of control status information to be read
507from the master side may be detected by a
508.BR select (2)
3352f579
MK
509for exceptional conditions or a
510.BR poll (2)
511for the
c4316bb5 512.B POLLPRI
3352f579 513event.
efeece04 514.IP
fea681da
MK
515This mode is used by
516.BR rlogin (1)
517and
518.BR rlogind (8)
f81fb444 519to implement a remote-echoed,
9ca13180 520locally \fB\(haS\fP/\fB\(haQ\fP flow-controlled remote login.
a3bee85c 521.TP
2858b5b5
MK
522.B TIOCGPKT
523Argument:
3d58eb6d 524.BI "const int\~*" argp
2858b5b5 525.IP
164b4016 526(since Linux 3.8)
a3bee85c 527Return the current packet mode setting in the integer pointed to by
164b4016 528.IR argp .
bd020450 529.TP
2858b5b5
MK
530.B TIOCSPTLCK
531Argument:
3d58eb6d 532.BI "int\~*" argp
2858b5b5 533.IP
bd020450 534Set (if
1ae6b2c7 535.I *argp
bd020450 536is nonzero) or remove (if
1ae6b2c7 537.I *argp
7b672080 538is zero) the lock on the pseudoterminal slave device.
bd020450
MK
539(See also
540.BR unlockpt (3).)
e757b911 541.TP
2858b5b5
MK
542.B TIOCGPTLCK
543Argument:
3d58eb6d 544.BI "int\~*" argp
2858b5b5 545.IP
164b4016 546(since Linux 3.8)
e757b911
MK
547Place the current lock state of the pseudoterminal slave device
548in the location pointed to by
164b4016 549.IR argp .
0ec74af9 550.TP
2858b5b5
MK
551.B TIOCGPTPEER
552Argument:
553.BI "int " flags
554.IP
91e34595
MK
555.\" commit 54ebbfb1603415d9953c150535850d30609ef077
556(since Linux 4.13)
557Given a file descriptor in
558.I fd
559that refers to a pseudoterminal master,
560open (with the given
0ec74af9 561.BR open (2)-style
91e34595
MK
562.IR flags )
563and return a new file descriptor that refers to the peer
564pseudoterminal slave device.
565This operation can be performed
566regardless of whether the pathname of the slave device
5115e06c 567is accessible through the calling process's mount namespace.
efeece04 568.IP
0ec74af9 569Security-conscious programs interacting with namespaces may wish to use this
91e34595 570operation rather than
0ec74af9 571.BR open (2)
91e34595 572with the pathname returned by
0ec74af9 573.BR ptsname (3),
91e34595 574and similar library functions that have insecure APIs.
d754b76d
MK
575(For example, confusion can occur in some cases using
576.BR ptsname (3)
577with a pathname where a devpts filesystem
578has been mounted in a different mount namespace.)
e1215bb9 579.PP
097585ed
MK
580The BSD ioctls
581.BR TIOCSTOP ,
582.BR TIOCSTART ,
583.BR TIOCUCNTL ,
fbe71b1b 584and
0daa9e92 585.B TIOCREMOTE
fea681da 586have not been implemented under Linux.
73d8cece 587.SS Modem control
fea681da 588.TP
2858b5b5
MK
589.B TIOCMGET
590Argument:
3d58eb6d 591.BI "int\~*" argp
2858b5b5 592.IP
2096c4f3 593Get the status of modem bits.
fea681da 594.TP
2858b5b5
MK
595.B TIOCMSET
596Argument:
3d58eb6d 597.BI "const int\~*" argp
2858b5b5 598.IP
2096c4f3 599Set the status of modem bits.
fea681da 600.TP
2858b5b5
MK
601.B TIOCMBIC
602Argument:
3d58eb6d 603.BI "const int\~*" argp
2858b5b5 604.IP
2096c4f3 605Clear the indicated modem bits.
fea681da 606.TP
2858b5b5
MK
607.B TIOCMBIS
608Argument:
3d58eb6d 609.BI "const int\~*" argp
2858b5b5 610.IP
2096c4f3 611Set the indicated modem bits.
dd3568a1 612.PP
d398da7b 613The following bits are used by the above ioctls:
efeece04 614.PP
d6780634
MK
615.TS
616lb l.
617TIOCM_LE DSR (data set ready/line enable)
618TIOCM_DTR DTR (data terminal ready)
619TIOCM_RTS RTS (request to send)
620TIOCM_ST Secondary TXD (transmit)
621TIOCM_SR Secondary RXD (receive)
622TIOCM_CTS CTS (clear to send)
623TIOCM_CAR DCD (data carrier detect)
624TIOCM_CD see TIOCM_CAR
625TIOCM_RNG RNG (ring)
626TIOCM_RI see TIOCM_RNG
627TIOCM_DSR DSR (data set ready)
628.TE
1dcf15dd 629.TP
2858b5b5
MK
630.B TIOCMIWAIT
631Argument:
632.BI "int " arg
633.IP
41556382
MK
634Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change.
635The bits of interest are specified as a bit mask in
636.IR arg ,
637by ORing together any of the bit values,
638.BR TIOCM_RNG ,
639.BR TIOCM_DSR ,
640.BR TIOCM_CD ,
641and
642.BR TIOCM_CTS .
643The caller should use
644.B TIOCGICOUNT
645to see which bit has changed.
646.TP
2858b5b5
MK
647.B TIOCGICOUNT
648Argument:
3d58eb6d 649.BI "struct serial_icounter_struct\~*" argp
2858b5b5 650.IP
452f300b 651Get counts of input serial line interrupts (DCD, RI, DSR, CTS).
5ffdc2fd 652The counts are written to the
452f300b
MK
653.I serial_icounter_struct
654structure pointed to by
655.IR argp .
efeece04 656.IP
452f300b
MK
657Note: both 1->0 and 0->1 transitions are counted, except for
658RI, where only 0->1 transitions are counted.
73d8cece 659.SS Marking a line as local
fea681da 660.TP
2858b5b5
MK
661.B TIOCGSOFTCAR
662Argument:
3d58eb6d 663.BI "int\~*" argp
2858b5b5 664.IP
fea681da
MK
665("Get software carrier flag")
666Get the status of the CLOCAL flag in the c_cflag field of the
4961e71d
MK
667.I termios
668structure.
fea681da 669.TP
2858b5b5
MK
670.B TIOCSSOFTCAR
671Argument:
3d58eb6d 672.BI "const int\~*" argp
2858b5b5 673.IP
fea681da 674("Set software carrier flag")
4961e71d
MK
675Set the CLOCAL flag in the
676.I termios
677structure when
fea681da 678.RI * argp
c7094399 679is nonzero, and clear it otherwise.
dd3568a1 680.PP
097585ed
MK
681If the
682.B CLOCAL
683flag for a line is off, the hardware carrier detect (DCD)
fea681da
MK
684signal is significant, and an
685.BR open (2)
132249c4 686of the corresponding terminal will block until DCD is asserted,
097585ed
MK
687unless the
688.B O_NONBLOCK
689flag is given.
690If
691.B CLOCAL
692is set, the line behaves as if DCD is always asserted.
fea681da
MK
693The software carrier flag is usually turned on for local devices,
694and is off for lines with modems.
73d8cece 695.SS Linux-specific
097585ed
MK
696For the
697.B TIOCLINUX
698ioctl, see
d49a2220 699.BR ioctl_console (2).
73d8cece 700.SS Kernel debugging
0daa9e92 701.B "#include <linux/tty.h>"
fea681da 702.TP
2858b5b5
MK
703.B TIOCTTYGSTRUCT
704Argument:
3d58eb6d 705.BI "struct tty_struct\~*" argp
2858b5b5 706.IP
f88233dd
MK
707Get the
708.I tty_struct
709corresponding to
fea681da 710.IR fd .
0e61ffa7
MK
711This command was removed in Linux 2.5.67.
712.\" commit b3506a09d15dc5aee6d4bb88d759b157016e1864
713.\" Author: Andries E. Brouwer <andries.brouwer@cwi.nl>
714.\" Date: Tue Apr 1 04:42:46 2003 -0800
715.\"
716.\" [PATCH] kill TIOCTTYGSTRUCT
717.\"
718.\" Only used for (dubious) debugging purposes, and exposes
719.\" internal kernel state.
c13182ef 720.\"
d282bb24 721.\" .SS Serial info
fea681da 722.\" .BR "#include <linux/serial.h>"
ba39b288 723.\" .PP
fea681da
MK
724.\" .TP
725.\" .BI "TIOCGSERIAL struct serial_struct *" argp
726.\" Get serial info.
727.\" .TP
728.\" .BI "TIOCSSERIAL const struct serial_struct *" argp
729.\" Set serial info.
47297adb 730.SH RETURN VALUE
fea681da 731The
0b80cf56 732.BR ioctl (2)
c13182ef 733system call returns 0 on success.
dec985f9 734On error, it returns \-1 and sets
fea681da 735.I errno
c112329f 736to indicate the error.
fea681da
MK
737.SH ERRORS
738.TP
fea681da
MK
739.B EINVAL
740Invalid command parameter.
741.TP
eab64696
MK
742.B ENOIOCTLCMD
743Unknown command.
fea681da
MK
744.TP
745.B ENOTTY
746Inappropriate
747.IR fd .
eab64696
MK
748.TP
749.B EPERM
750Insufficient permission.
a14af333 751.SH EXAMPLES
fea681da 752Check the condition of DTR on the serial port.
efeece04 753.PP
33857069 754.\" SRC BEGIN (tiocmget.c)
b76974c1 755.EX
fea681da 756#include <fcntl.h>
4ae706b0 757#include <stdio.h>
fea681da 758#include <sys/ioctl.h>
4ae706b0 759#include <unistd.h>
fea681da 760
cf0a9ace 761int
c13182ef 762main(void)
cf0a9ace 763{
fea681da
MK
764 int fd, serial;
765
766 fd = open("/dev/ttyS0", O_RDONLY);
767 ioctl(fd, TIOCMGET, &serial);
768 if (serial & TIOCM_DTR)
fea681da 769 puts("TIOCM_DTR is set");
e3f16cf7
MK
770 else
771 puts("TIOCM_DTR is not set");
fea681da
MK
772 close(fd);
773}
b76974c1 774.EE
33857069 775.\" SRC END
f528e587
PR
776.PP
777Get or set arbitrary baudrate on the serial port.
778.PP
33857069 779.\" SRC BEGIN (tcgets.c)
f528e587
PR
780.EX
781/* SPDX-License-Identifier: GPL-2.0-or-later */
782
783#include <asm/termbits.h>
784#include <fcntl.h>
785#include <stdio.h>
786#include <stdlib.h>
787#include <sys/ioctl.h>
f528e587
PR
788#include <unistd.h>
789
790int
791main(int argc, char *argv[])
792{
f0a0bcc6 793#if !defined BOTHER
f528e587
PR
794 fprintf(stderr, "BOTHER is unsupported\en");
795 /* Program may fallback to TCGETS/TCSETS with Bnnn constants */
796 exit(EXIT_FAILURE);
797#else
798 /* Declare tio structure, its type depends on supported ioctl */
f0a0bcc6 799# if defined TCGETS2
f528e587 800 struct termios2 tio;
f0a0bcc6 801# else
f528e587 802 struct termios tio;
f0a0bcc6 803# endif
f528e587
PR
804 int fd, rc;
805
806 if (argc != 2 && argc != 3 && argc != 4) {
807 fprintf(stderr, "Usage: %s device [output [input] ]\en", argv[0]);
808 exit(EXIT_FAILURE);
809 }
810
811 fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
812 if (fd < 0) {
813 perror("open");
814 exit(EXIT_FAILURE);
815 }
816
817 /* Get the current serial port settings via supported ioctl */
f0a0bcc6 818# if defined TCGETS2
f528e587 819 rc = ioctl(fd, TCGETS2, &tio);
f0a0bcc6 820# else
f528e587 821 rc = ioctl(fd, TCGETS, &tio);
f0a0bcc6 822# endif
f528e587
PR
823 if (rc) {
824 perror("TCGETS");
825 close(fd);
826 exit(EXIT_FAILURE);
827 }
828
829 /* Change baud rate when more arguments were provided */
830 if (argc == 3 || argc == 4) {
831 /* Clear the current output baud rate and fill a new value */
529027f0 832 tio.c_cflag &= \(tiCBAUD;
f528e587
PR
833 tio.c_cflag |= BOTHER;
834 tio.c_ospeed = atoi(argv[2]);
835
836 /* Clear the current input baud rate and fill a new value */
529027f0 837 tio.c_cflag &= \(ti(CBAUD << IBSHIFT);
f528e587
PR
838 tio.c_cflag |= BOTHER << IBSHIFT;
839 /* When 4th argument is not provided reuse output baud rate */
840 tio.c_ispeed = (argc == 4) ? atoi(argv[3]) : atoi(argv[2]);
841
842 /* Set new serial port settings via supported ioctl */
f0a0bcc6 843# if defined TCSETS2
f528e587 844 rc = ioctl(fd, TCSETS2, &tio);
f0a0bcc6 845# else
f528e587 846 rc = ioctl(fd, TCSETS, &tio);
f0a0bcc6 847# endif
f528e587
PR
848 if (rc) {
849 perror("TCSETS");
850 close(fd);
851 exit(EXIT_FAILURE);
852 }
853
854 /* And get new values which were really configured */
f0a0bcc6 855# if defined TCGETS2
f528e587 856 rc = ioctl(fd, TCGETS2, &tio);
f0a0bcc6 857# else
f528e587 858 rc = ioctl(fd, TCGETS, &tio);
f0a0bcc6 859# endif
f528e587
PR
860 if (rc) {
861 perror("TCGETS");
862 close(fd);
863 exit(EXIT_FAILURE);
864 }
865 }
866
867 close(fd);
868
869 printf("output baud rate: %u\en", tio.c_ospeed);
870 printf("input baud rate: %u\en", tio.c_ispeed);
871
872 exit(EXIT_SUCCESS);
873#endif
874}
875.EE
33857069 876.\" SRC END
47297adb 877.SH SEE ALSO
21a9b4fa 878.BR ldattach (8),
fea681da 879.BR ioctl (2),
d49a2220 880.BR ioctl_console (2),
fea681da 881.BR termios (3),
88ab292b 882.BR pty (7)
25a46448 883.\"
fea681da
MK
884.\" FIONBIO const int *
885.\" FIONCLEX void
886.\" FIOCLEX void
887.\" FIOASYNC const int *
888.\" from serial.c:
889.\" TIOCSERCONFIG void
890.\" TIOCSERGWILD int *
891.\" TIOCSERSWILD const int *
892.\" TIOCSERGSTRUCT struct async_struct *
893.\" TIOCSERGETLSR int *
894.\" TIOCSERGETMULTI struct serial_multiport_struct *
895.\" TIOCSERSETMULTI const struct serial_multiport_struct *
896.\" TIOCGSERIAL, TIOCSSERIAL (see above)