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