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