]>
Commit | Line | Data |
---|---|---|
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 | 8 | ioctl_tty \- ioctls for terminals and serial lines |
f0999011 AC |
9 | .SH LIBRARY |
10 | Standard 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 |
23 | The | |
0b80cf56 | 24 | .BR ioctl (2) |
fea681da | 25 | call for terminals and serial ports accepts many possible command arguments. |
c6fa0841 MK |
26 | Most require a third argument, of varying type, here called |
27 | .I argp | |
28 | or | |
29 | .IR arg . | |
dd3568a1 | 30 | .PP |
fea681da | 31 | Use of |
025a34a6 | 32 | .BR ioctl () |
d603cc27 | 33 | makes for nonportable programs. |
c13182ef | 34 | Use the POSIX interface described in |
fea681da MK |
35 | .BR termios (3) |
36 | whenever possible. | |
c0236145 PR |
37 | .PP |
38 | Please note that | |
39 | .B struct termios | |
40 | from | |
41 | .I <asm/termbits.h> | |
42 | is different and incompatible with | |
43 | .B struct termios | |
44 | from | |
45 | .IR <termios.h> . | |
46 | These ioctl calls require | |
47 | .B struct termios | |
48 | from | |
49 | .IR <asm/termbits.h> . | |
73d8cece | 50 | .SS Get and set terminal attributes |
fea681da | 51 | .TP |
2858b5b5 MK |
52 | .B TCGETS |
53 | Argument: | |
3d58eb6d | 54 | .BI "struct termios\~*" argp |
2858b5b5 | 55 | .IP |
fea681da MK |
56 | Equivalent to |
57 | .IR "tcgetattr(fd, argp)" . | |
322522ea | 58 | .IP |
fea681da MK |
59 | Get the current serial port settings. |
60 | .TP | |
2858b5b5 MK |
61 | .B TCSETS |
62 | Argument: | |
3d58eb6d | 63 | .BI "const struct termios\~*" argp |
2858b5b5 | 64 | .IP |
fea681da MK |
65 | Equivalent to |
66 | .IR "tcsetattr(fd, TCSANOW, argp)" . | |
322522ea | 67 | .IP |
fea681da MK |
68 | Set the current serial port settings. |
69 | .TP | |
2858b5b5 MK |
70 | .B TCSETSW |
71 | Argument: | |
3d58eb6d | 72 | .BI "const struct termios\~*" argp |
2858b5b5 | 73 | .IP |
fea681da MK |
74 | Equivalent to |
75 | .IR "tcsetattr(fd, TCSADRAIN, argp)" . | |
322522ea | 76 | .IP |
fea681da MK |
77 | Allow the output buffer to drain, and |
78 | set the current serial port settings. | |
79 | .TP | |
2858b5b5 MK |
80 | .B TCSETSF |
81 | Argument: | |
3d58eb6d | 82 | .BI "const struct termios\~*" argp |
2858b5b5 | 83 | .IP |
fea681da MK |
84 | Equivalent to |
85 | .IR "tcsetattr(fd, TCSAFLUSH, argp)" . | |
322522ea | 86 | .IP |
fea681da MK |
87 | Allow the output buffer to drain, discard pending input, and |
88 | set the current serial port settings. | |
dd3568a1 | 89 | .PP |
c8219af7 MK |
90 | The following four ioctls, added in Linux 2.6.20, |
91 | .\" commit 64bb6c5e1ddcd47c951740485026ef08975ee2e6 | |
92 | .\" commit 592ee3a5e5e2a981ef2829a0380093006d045661 | |
93 | are just like | |
097585ed MK |
94 | .BR TCGETS , |
95 | .BR TCSETS , | |
96 | .BR TCSETSW , | |
97 | .BR TCSETSF , | |
fea681da | 98 | except that they take a |
3d58eb6d | 99 | .I "struct termios2\~*" |
aad1f0e8 | 100 | instead of a |
3d58eb6d | 101 | .IR "struct termios\~*" . |
5d9f0bc6 | 102 | If the structure member |
aad1f0e8 | 103 | .B c_cflag |
5d9f0bc6 MK |
104 | contains the flag |
105 | .BR BOTHER , | |
106 | then the baud rate is stored in the structure members | |
aad1f0e8 PR |
107 | .B c_ispeed |
108 | and | |
109 | .B c_ospeed | |
110 | as integer values. | |
111 | These ioctls are not supported on all architectures. | |
112 | .RS | |
113 | .TS | |
114 | lb l. | |
115 | TCGETS2 \fBstruct termios2 *\fPargp | |
116 | TCSETS2 \fBconst struct termios2 *\fPargp | |
117 | TCSETSW2 \fBconst struct termios2 *\fPargp | |
118 | TCSETSF2 \fBconst struct termios2 *\fPargp | |
119 | .TE | |
120 | .RE | |
121 | .PP | |
122 | The following four ioctls are just like | |
123 | .BR TCGETS , | |
124 | .BR TCSETS , | |
125 | .BR TCSETSW , | |
126 | .BR TCSETSF , | |
127 | except that they take a | |
3d58eb6d | 128 | .I "struct termio\~*" |
fea681da | 129 | instead of a |
3d58eb6d | 130 | .IR "struct termios\~*" . |
aceee9e8 MK |
131 | .RS |
132 | .TS | |
133 | lb l. | |
134 | TCGETA \fBstruct termio *\fPargp | |
135 | TCSETA \fBconst struct termio *\fPargp | |
136 | TCSETAW \fBconst struct termio *\fPargp | |
137 | TCSETAF \fBconst struct termio *\fPargp | |
138 | .TE | |
139 | .RE | |
73d8cece | 140 | .SS Locking the termios structure |
4961e71d MK |
141 | The |
142 | .I termios | |
132249c4 | 143 | structure of a terminal can be locked. |
4961e71d MK |
144 | The lock is itself a |
145 | .I termios | |
c7094399 | 146 | structure, with nonzero bits or fields indicating a |
fea681da MK |
147 | locked value. |
148 | .TP | |
2858b5b5 MK |
149 | .B TIOCGLCKTRMIOS |
150 | Argument: | |
3d58eb6d | 151 | .BI "struct termios\~*" argp |
2858b5b5 | 152 | .IP |
4961e71d MK |
153 | Gets the locking status of the |
154 | .I termios | |
155 | structure of the terminal. | |
fea681da | 156 | .TP |
2858b5b5 MK |
157 | .B TIOCSLCKTRMIOS |
158 | Argument: | |
3d58eb6d | 159 | .BI "const struct termios\~*" argp |
2858b5b5 | 160 | .IP |
4961e71d MK |
161 | Sets the locking status of the |
162 | .I termios | |
163 | structure of the terminal. | |
cb476d88 | 164 | Only a process with the |
3d58eb6d | 165 | .B CAP_SYS_ADMIN |
cb476d88 | 166 | capability can do this. |
73d8cece | 167 | .SS Get and set window size |
fea681da MK |
168 | Window sizes are kept in the kernel, but not used by the kernel |
169 | (except in the case of virtual consoles, where the kernel will | |
170 | update the window size when the size of the virtual console changes, | |
75b94dc3 | 171 | for example, by loading a new font). |
fea681da | 172 | .TP |
2858b5b5 MK |
173 | .B TIOCGWINSZ |
174 | Argument: | |
3d58eb6d | 175 | .BI "struct winsize\~*" argp |
2858b5b5 | 176 | .IP |
fea681da MK |
177 | Get window size. |
178 | .TP | |
2858b5b5 MK |
179 | .B TIOCSWINSZ |
180 | Argument: | |
3d58eb6d | 181 | .BI "const struct winsize\~*" argp |
2858b5b5 | 182 | .IP |
fea681da | 183 | Set window size. |
dd3568a1 | 184 | .PP |
fea681da | 185 | The struct used by these ioctls is defined as |
efeece04 | 186 | .PP |
3f89ebc0 | 187 | .in +4n |
b76974c1 | 188 | .EX |
fea681da | 189 | struct 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 |
198 | When the window size changes, a |
199 | .B SIGWINCH | |
200 | signal is sent to the | |
fea681da | 201 | foreground process group. |
73d8cece | 202 | .SS Sending a break |
fea681da | 203 | .TP |
2858b5b5 MK |
204 | .B TCSBRK |
205 | Argument: | |
206 | .BI "int " arg | |
207 | .IP | |
fea681da MK |
208 | Equivalent to |
209 | .IR "tcsendbreak(fd, arg)" . | |
322522ea | 210 | .IP |
fea681da MK |
211 | If the terminal is using asynchronous serial data transmission, and |
212 | .I arg | |
213 | is zero, then send a break (a stream of zero bits) for between | |
c13182ef MK |
214 | 0.25 and 0.5 seconds. |
215 | If the terminal is not using asynchronous | |
fea681da MK |
216 | serial data transmission, then either a break is sent, or the function |
217 | returns without doing anything. | |
218 | When | |
219 | .I arg | |
c7094399 | 220 | is nonzero, nobody knows what will happen. |
efeece04 | 221 | .IP |
1d9a03e9 | 222 | (SVr4, UnixWare, Solaris, and Linux treat |
fea681da | 223 | .I "tcsendbreak(fd,arg)" |
c7094399 | 224 | with nonzero |
fea681da MK |
225 | .I arg |
226 | like | |
227 | .IR "tcdrain(fd)" . | |
228 | SunOS treats | |
229 | .I arg | |
230 | as a multiplier, and sends a stream of bits | |
231 | .I arg | |
232 | times as long as done for zero | |
233 | .IR arg . | |
72cedc06 | 234 | DG/UX and AIX treat |
fea681da | 235 | .I arg |
c7094399 | 236 | (when nonzero) as a time interval measured in milliseconds. |
fea681da MK |
237 | HP-UX ignores |
238 | .IR arg .) | |
239 | .TP | |
2858b5b5 MK |
240 | .B TCSBRKP |
241 | Argument: | |
242 | .BI "int " arg | |
243 | .IP | |
097585ed MK |
244 | So-called "POSIX version" of |
245 | .BR TCSBRK . | |
c7094399 | 246 | It treats nonzero |
fea681da | 247 | .I arg |
8842f534 | 248 | as a time interval measured in deciseconds, and does nothing |
fea681da MK |
249 | when the driver does not support breaks. |
250 | .TP | |
2aec4ef8 | 251 | .B TIOCSBRK |
2858b5b5 | 252 | Argument: |
1ae6b2c7 | 253 | .B void |
2858b5b5 | 254 | .IP |
fea681da MK |
255 | Turn break on, that is, start sending zero bits. |
256 | .TP | |
2aec4ef8 | 257 | .B TIOCCBRK |
2858b5b5 | 258 | Argument: |
1ae6b2c7 | 259 | .B void |
2858b5b5 | 260 | .IP |
fea681da | 261 | Turn break off, that is, stop sending zero bits. |
73d8cece | 262 | .SS Software flow control |
fea681da | 263 | .TP |
2858b5b5 MK |
264 | .B TCXONC |
265 | Argument: | |
266 | .BI "int " arg | |
267 | .IP | |
fea681da MK |
268 | Equivalent to |
269 | .IR "tcflow(fd, arg)" . | |
322522ea | 270 | .IP |
fea681da MK |
271 | See |
272 | .BR tcflow (3) | |
097585ed MK |
273 | for 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 | 281 | Argument: |
3d58eb6d | 282 | .BI "int\~*" argp |
2858b5b5 | 283 | .IP |
fea681da MK |
284 | Get the number of bytes in the input buffer. |
285 | .TP | |
2858b5b5 MK |
286 | .B TIOCINQ |
287 | Argument: | |
3d58eb6d | 288 | .BI "int\~*" argp |
2858b5b5 | 289 | .IP |
097585ed MK |
290 | Same as |
291 | .BR FIONREAD . | |
fea681da | 292 | .TP |
2858b5b5 MK |
293 | .B TIOCOUTQ |
294 | Argument: | |
3d58eb6d | 295 | .BI "int\~*" argp |
2858b5b5 | 296 | .IP |
fea681da MK |
297 | Get the number of bytes in the output buffer. |
298 | .TP | |
2858b5b5 MK |
299 | .B TCFLSH |
300 | Argument: | |
301 | .BI "int " arg | |
302 | .IP | |
fea681da MK |
303 | Equivalent to |
304 | .IR "tcflush(fd, arg)" . | |
322522ea | 305 | .IP |
fea681da MK |
306 | See |
307 | .BR tcflush (3) | |
097585ed MK |
308 | for 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 |
315 | Argument: | |
3d58eb6d | 316 | .BI "const char\~*" argp |
2858b5b5 | 317 | .IP |
fea681da | 318 | Insert the given byte in the input queue. |
73d8cece | 319 | .SS Redirecting console output |
fea681da | 320 | .TP |
2aec4ef8 | 321 | .B TIOCCONS |
2858b5b5 | 322 | Argument: |
1ae6b2c7 | 323 | .B void |
2858b5b5 | 324 | .IP |
fea681da MK |
325 | Redirect output that would have gone to |
326 | .I /dev/console | |
327 | or | |
328 | .I /dev/tty0 | |
132249c4 | 329 | to the given terminal. |
b218b023 | 330 | If that was a pseudoterminal master, send it to the slave. |
b5fa38a3 MK |
331 | In Linux before version 2.6.10, |
332 | anybody can do this as long as the output was not redirected yet; | |
cb476d88 | 333 | since version 2.6.10, only a process with the |
1ae6b2c7 | 334 | .B CAP_SYS_ADMIN |
cb476d88 | 335 | capability may do this. |
c4316bb5 | 336 | If output was redirected already, then |
097585ed MK |
337 | .B EBUSY |
338 | is returned, | |
b5fa38a3 | 339 | but redirection can be stopped by using this ioctl with |
fea681da MK |
340 | .I fd |
341 | pointing at | |
342 | .I /dev/console | |
343 | or | |
344 | .IR /dev/tty0 . | |
73d8cece | 345 | .SS Controlling terminal |
fea681da | 346 | .TP |
2858b5b5 MK |
347 | .B TIOCSCTTY |
348 | Argument: | |
349 | .BI "int " arg | |
350 | .IP | |
132249c4 | 351 | Make the given terminal the controlling terminal of the calling process. |
a1ffe9f5 | 352 | The calling process must be a session leader and not have a |
132249c4 | 353 | controlling terminal already. |
9ab0de3c MK |
354 | For this case, |
355 | .I arg | |
356 | should be specified as zero. | |
efeece04 | 357 | .IP |
132249c4 | 358 | If this terminal is already the controlling terminal |
5cc100b9 | 359 | of a different session group, then the ioctl fails with |
097585ed | 360 | .BR EPERM , |
cb476d88 | 361 | unless the caller has the |
1ae6b2c7 | 362 | .B CAP_SYS_ADMIN |
cb476d88 | 363 | capability and |
fea681da | 364 | .I arg |
132249c4 MK |
365 | equals 1, in which case the terminal is stolen, and all processes that had |
366 | it as controlling terminal lose it. | |
fea681da | 367 | .TP |
2aec4ef8 | 368 | .B TIOCNOTTY |
2858b5b5 | 369 | Argument: |
1ae6b2c7 | 370 | .B void |
2858b5b5 | 371 | .IP |
132249c4 MK |
372 | If the given terminal was the controlling terminal of the calling process, |
373 | give up this controlling terminal. | |
c13182ef | 374 | If the process was session leader, |
8bd58774 MK |
375 | then send |
376 | .B SIGHUP | |
377 | and | |
378 | .B SIGCONT | |
379 | to the foreground process group | |
132249c4 | 380 | and 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 |
384 | Argument: | |
3d58eb6d | 385 | .BI "pid_t\~*" argp |
2858b5b5 | 386 | .IP |
fea681da MK |
387 | When successful, equivalent to |
388 | .IR "*argp = tcgetpgrp(fd)" . | |
322522ea | 389 | .IP |
132249c4 | 390 | Get the process group ID of the foreground process group on this terminal. |
fea681da | 391 | .TP |
2858b5b5 MK |
392 | .B TIOCSPGRP |
393 | Argument: | |
3d58eb6d | 394 | .BI "const pid_t\~*" argp |
2858b5b5 | 395 | .IP |
fea681da MK |
396 | Equivalent to |
397 | .IR "tcsetpgrp(fd, *argp)" . | |
322522ea | 398 | .IP |
132249c4 | 399 | Set the foreground process group ID of this terminal. |
fea681da | 400 | .TP |
2858b5b5 MK |
401 | .B TIOCGSID |
402 | Argument: | |
3d58eb6d | 403 | .BI "pid_t\~*" argp |
2858b5b5 | 404 | .IP |
44803dd0 PR |
405 | When successful, equivalent to |
406 | .IR "*argp = tcgetsid(fd)" . | |
407 | .IP | |
132249c4 | 408 | Get the session ID of the given terminal. |
ad94e27c | 409 | This fails with the error |
097585ed | 410 | .B ENOTTY |
a23d8efa | 411 | if the terminal is not a master pseudoterminal |
132249c4 | 412 | and not our controlling terminal. |
c13182ef | 413 | Strange. |
73d8cece | 414 | .SS Exclusive mode |
fea681da | 415 | .TP |
2aec4ef8 | 416 | .B TIOCEXCL |
2858b5b5 | 417 | Argument: |
1ae6b2c7 | 418 | .B void |
2858b5b5 | 419 | .IP |
132249c4 | 420 | Put the terminal into exclusive mode. |
fea681da MK |
421 | No further |
422 | .BR open (2) | |
423 | operations on the terminal are permitted. | |
ad94e27c | 424 | (They fail with |
097585ed | 425 | .BR EBUSY , |
cb476d88 | 426 | except for a process with the |
1ae6b2c7 | 427 | .B CAP_SYS_ADMIN |
c0b75059 | 428 | capability.) |
fea681da | 429 | .TP |
2858b5b5 MK |
430 | .B TIOCGEXCL |
431 | Argument: | |
3d58eb6d | 432 | .BI "int\~*" argp |
2858b5b5 | 433 | .IP |
164b4016 | 434 | (since Linux 3.8) |
8b17edbe MK |
435 | If the terminal is currently in exclusive mode, |
436 | place a nonzero value in the location pointed to by | |
437 | .IR argp ; | |
438 | otherwise, place zero in | |
164b4016 | 439 | .IR *argp . |
8b17edbe | 440 | .TP |
2aec4ef8 | 441 | .B TIOCNXCL |
2858b5b5 | 442 | Argument: |
1ae6b2c7 | 443 | .B void |
2858b5b5 | 444 | .IP |
fea681da | 445 | Disable exclusive mode. |
73d8cece | 446 | .SS Line discipline |
fea681da | 447 | .TP |
2858b5b5 MK |
448 | .B TIOCGETD |
449 | Argument: | |
3d58eb6d | 450 | .BI "int\~*" argp |
2858b5b5 | 451 | .IP |
132249c4 | 452 | Get the line discipline of the terminal. |
fea681da | 453 | .TP |
2858b5b5 MK |
454 | .B TIOCSETD |
455 | Argument: | |
3d58eb6d | 456 | .BI "const int\~*" argp |
2858b5b5 | 457 | .IP |
132249c4 | 458 | Set the line discipline of the terminal. |
73d8cece | 459 | .SS Pseudoterminal ioctls |
fea681da | 460 | .TP |
2858b5b5 MK |
461 | .B TIOCPKT |
462 | Argument: | |
3d58eb6d | 463 | .BI "const int\~*" argp |
2858b5b5 | 464 | .IP |
fea681da MK |
465 | Enable (when |
466 | .RI * argp | |
c7094399 | 467 | is nonzero) or disable packet mode. |
b218b023 | 468 | Can be applied to the master side of a pseudoterminal only (and will return |
097585ed MK |
469 | .B ENOTTY |
470 | otherwise). | |
c13182ef | 471 | In packet mode, each subsequent |
fea681da | 472 | .BR read (2) |
c7094399 | 473 | will return a packet that either contains a single nonzero control byte, |
cc1a0b7e | 474 | or has a single byte containing zero (\(aq\e0\(aq) followed by data |
b218b023 | 475 | written on the slave side of the pseudoterminal. |
097585ed MK |
476 | If the first byte is not |
477 | .B TIOCPKT_DATA | |
478 | (0), it is an OR of one | |
fea681da | 479 | or more of the following bits: |
efeece04 | 480 | .IP |
0b174fe0 | 481 | .ad l |
d6780634 MK |
482 | .TS |
483 | lb l. | |
0b174fe0 MK |
484 | TIOCPKT_FLUSHREAD T{ |
485 | The read queue for the terminal is flushed. | |
486 | T} | |
487 | TIOCPKT_FLUSHWRITE T{ | |
488 | The write queue for the terminal is flushed. | |
489 | T} | |
490 | TIOCPKT_STOP T{ | |
491 | Output to the terminal is stopped. | |
492 | T} | |
493 | TIOCPKT_START T{ | |
494 | Output to the terminal is restarted. | |
495 | T} | |
496 | TIOCPKT_DOSTOP T{ | |
497 | The start and stop characters are \fB\(haS\fP/\fB\(haQ\fP. | |
498 | T} | |
499 | TIOCPKT_NOSTOP T{ | |
500 | The start and stop characters are not \fB\(haS\fP/\fB\(haQ\fP. | |
501 | T} | |
d6780634 | 502 | .TE |
0b174fe0 | 503 | .ad |
efeece04 | 504 | .IP |
c4316bb5 | 505 | While packet mode is in use, the presence |
fea681da MK |
506 | of control status information to be read |
507 | from the master side may be detected by a | |
508 | .BR select (2) | |
3352f579 MK |
509 | for exceptional conditions or a |
510 | .BR poll (2) | |
511 | for the | |
c4316bb5 | 512 | .B POLLPRI |
3352f579 | 513 | event. |
efeece04 | 514 | .IP |
fea681da MK |
515 | This mode is used by |
516 | .BR rlogin (1) | |
517 | and | |
518 | .BR rlogind (8) | |
f81fb444 | 519 | to implement a remote-echoed, |
9ca13180 | 520 | locally \fB\(haS\fP/\fB\(haQ\fP flow-controlled remote login. |
a3bee85c | 521 | .TP |
2858b5b5 MK |
522 | .B TIOCGPKT |
523 | Argument: | |
3d58eb6d | 524 | .BI "const int\~*" argp |
2858b5b5 | 525 | .IP |
164b4016 | 526 | (since Linux 3.8) |
a3bee85c | 527 | Return the current packet mode setting in the integer pointed to by |
164b4016 | 528 | .IR argp . |
bd020450 | 529 | .TP |
2858b5b5 MK |
530 | .B TIOCSPTLCK |
531 | Argument: | |
3d58eb6d | 532 | .BI "int\~*" argp |
2858b5b5 | 533 | .IP |
bd020450 | 534 | Set (if |
1ae6b2c7 | 535 | .I *argp |
bd020450 | 536 | is nonzero) or remove (if |
1ae6b2c7 | 537 | .I *argp |
7b672080 | 538 | is 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 |
543 | Argument: | |
3d58eb6d | 544 | .BI "int\~*" argp |
2858b5b5 | 545 | .IP |
164b4016 | 546 | (since Linux 3.8) |
e757b911 MK |
547 | Place the current lock state of the pseudoterminal slave device |
548 | in the location pointed to by | |
164b4016 | 549 | .IR argp . |
0ec74af9 | 550 | .TP |
2858b5b5 MK |
551 | .B TIOCGPTPEER |
552 | Argument: | |
553 | .BI "int " flags | |
554 | .IP | |
91e34595 MK |
555 | .\" commit 54ebbfb1603415d9953c150535850d30609ef077 |
556 | (since Linux 4.13) | |
557 | Given a file descriptor in | |
558 | .I fd | |
559 | that refers to a pseudoterminal master, | |
560 | open (with the given | |
0ec74af9 | 561 | .BR open (2)-style |
91e34595 MK |
562 | .IR flags ) |
563 | and return a new file descriptor that refers to the peer | |
564 | pseudoterminal slave device. | |
565 | This operation can be performed | |
566 | regardless of whether the pathname of the slave device | |
5115e06c | 567 | is accessible through the calling process's mount namespace. |
efeece04 | 568 | .IP |
0ec74af9 | 569 | Security-conscious programs interacting with namespaces may wish to use this |
91e34595 | 570 | operation rather than |
0ec74af9 | 571 | .BR open (2) |
91e34595 | 572 | with the pathname returned by |
0ec74af9 | 573 | .BR ptsname (3), |
91e34595 | 574 | and similar library functions that have insecure APIs. |
d754b76d MK |
575 | (For example, confusion can occur in some cases using |
576 | .BR ptsname (3) | |
577 | with a pathname where a devpts filesystem | |
578 | has been mounted in a different mount namespace.) | |
e1215bb9 | 579 | .PP |
097585ed MK |
580 | The BSD ioctls |
581 | .BR TIOCSTOP , | |
582 | .BR TIOCSTART , | |
583 | .BR TIOCUCNTL , | |
fbe71b1b | 584 | and |
0daa9e92 | 585 | .B TIOCREMOTE |
fea681da | 586 | have not been implemented under Linux. |
73d8cece | 587 | .SS Modem control |
fea681da | 588 | .TP |
2858b5b5 MK |
589 | .B TIOCMGET |
590 | Argument: | |
3d58eb6d | 591 | .BI "int\~*" argp |
2858b5b5 | 592 | .IP |
2096c4f3 | 593 | Get the status of modem bits. |
fea681da | 594 | .TP |
2858b5b5 MK |
595 | .B TIOCMSET |
596 | Argument: | |
3d58eb6d | 597 | .BI "const int\~*" argp |
2858b5b5 | 598 | .IP |
2096c4f3 | 599 | Set the status of modem bits. |
fea681da | 600 | .TP |
2858b5b5 MK |
601 | .B TIOCMBIC |
602 | Argument: | |
3d58eb6d | 603 | .BI "const int\~*" argp |
2858b5b5 | 604 | .IP |
2096c4f3 | 605 | Clear the indicated modem bits. |
fea681da | 606 | .TP |
2858b5b5 MK |
607 | .B TIOCMBIS |
608 | Argument: | |
3d58eb6d | 609 | .BI "const int\~*" argp |
2858b5b5 | 610 | .IP |
2096c4f3 | 611 | Set the indicated modem bits. |
dd3568a1 | 612 | .PP |
d398da7b | 613 | The following bits are used by the above ioctls: |
efeece04 | 614 | .PP |
d6780634 MK |
615 | .TS |
616 | lb l. | |
617 | TIOCM_LE DSR (data set ready/line enable) | |
618 | TIOCM_DTR DTR (data terminal ready) | |
619 | TIOCM_RTS RTS (request to send) | |
620 | TIOCM_ST Secondary TXD (transmit) | |
621 | TIOCM_SR Secondary RXD (receive) | |
622 | TIOCM_CTS CTS (clear to send) | |
623 | TIOCM_CAR DCD (data carrier detect) | |
624 | TIOCM_CD see TIOCM_CAR | |
625 | TIOCM_RNG RNG (ring) | |
626 | TIOCM_RI see TIOCM_RNG | |
627 | TIOCM_DSR DSR (data set ready) | |
628 | .TE | |
1dcf15dd | 629 | .TP |
2858b5b5 MK |
630 | .B TIOCMIWAIT |
631 | Argument: | |
632 | .BI "int " arg | |
633 | .IP | |
41556382 MK |
634 | Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change. |
635 | The bits of interest are specified as a bit mask in | |
636 | .IR arg , | |
637 | by ORing together any of the bit values, | |
638 | .BR TIOCM_RNG , | |
639 | .BR TIOCM_DSR , | |
640 | .BR TIOCM_CD , | |
641 | and | |
642 | .BR TIOCM_CTS . | |
643 | The caller should use | |
644 | .B TIOCGICOUNT | |
645 | to see which bit has changed. | |
646 | .TP | |
2858b5b5 MK |
647 | .B TIOCGICOUNT |
648 | Argument: | |
3d58eb6d | 649 | .BI "struct serial_icounter_struct\~*" argp |
2858b5b5 | 650 | .IP |
452f300b | 651 | Get counts of input serial line interrupts (DCD, RI, DSR, CTS). |
5ffdc2fd | 652 | The counts are written to the |
452f300b MK |
653 | .I serial_icounter_struct |
654 | structure pointed to by | |
655 | .IR argp . | |
efeece04 | 656 | .IP |
452f300b MK |
657 | Note: both 1->0 and 0->1 transitions are counted, except for |
658 | RI, where only 0->1 transitions are counted. | |
73d8cece | 659 | .SS Marking a line as local |
fea681da | 660 | .TP |
2858b5b5 MK |
661 | .B TIOCGSOFTCAR |
662 | Argument: | |
3d58eb6d | 663 | .BI "int\~*" argp |
2858b5b5 | 664 | .IP |
fea681da MK |
665 | ("Get software carrier flag") |
666 | Get the status of the CLOCAL flag in the c_cflag field of the | |
4961e71d MK |
667 | .I termios |
668 | structure. | |
fea681da | 669 | .TP |
2858b5b5 MK |
670 | .B TIOCSSOFTCAR |
671 | Argument: | |
3d58eb6d | 672 | .BI "const int\~*" argp |
2858b5b5 | 673 | .IP |
fea681da | 674 | ("Set software carrier flag") |
4961e71d MK |
675 | Set the CLOCAL flag in the |
676 | .I termios | |
677 | structure when | |
fea681da | 678 | .RI * argp |
c7094399 | 679 | is nonzero, and clear it otherwise. |
dd3568a1 | 680 | .PP |
097585ed MK |
681 | If the |
682 | .B CLOCAL | |
683 | flag for a line is off, the hardware carrier detect (DCD) | |
fea681da MK |
684 | signal is significant, and an |
685 | .BR open (2) | |
132249c4 | 686 | of the corresponding terminal will block until DCD is asserted, |
097585ed MK |
687 | unless the |
688 | .B O_NONBLOCK | |
689 | flag is given. | |
690 | If | |
691 | .B CLOCAL | |
692 | is set, the line behaves as if DCD is always asserted. | |
fea681da MK |
693 | The software carrier flag is usually turned on for local devices, |
694 | and is off for lines with modems. | |
73d8cece | 695 | .SS Linux-specific |
097585ed MK |
696 | For the |
697 | .B TIOCLINUX | |
698 | ioctl, 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 |
704 | Argument: | |
3d58eb6d | 705 | .BI "struct tty_struct\~*" argp |
2858b5b5 | 706 | .IP |
f88233dd MK |
707 | Get the |
708 | .I tty_struct | |
709 | corresponding to | |
fea681da | 710 | .IR fd . |
0e61ffa7 MK |
711 | This 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 | 731 | The |
0b80cf56 | 732 | .BR ioctl (2) |
c13182ef | 733 | system call returns 0 on success. |
dec985f9 | 734 | On error, it returns \-1 and sets |
fea681da | 735 | .I errno |
c112329f | 736 | to indicate the error. |
fea681da MK |
737 | .SH ERRORS |
738 | .TP | |
fea681da MK |
739 | .B EINVAL |
740 | Invalid command parameter. | |
741 | .TP | |
eab64696 MK |
742 | .B ENOIOCTLCMD |
743 | Unknown command. | |
fea681da MK |
744 | .TP |
745 | .B ENOTTY | |
746 | Inappropriate | |
747 | .IR fd . | |
eab64696 MK |
748 | .TP |
749 | .B EPERM | |
750 | Insufficient permission. | |
a14af333 | 751 | .SH EXAMPLES |
fea681da | 752 | Check 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 | 761 | int |
c13182ef | 762 | main(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 |
777 | Get 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 | ||
790 | int | |
791 | main(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) |