]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man4/tty_ioctl.4
Formatted signal names
[thirdparty/man-pages.git] / man4 / tty_ioctl.4
CommitLineData
fea681da
MK
1.\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
2.\" and Andries Brouwer <aeb@cwi.nl>.
3.\" Distributed under GPL.
4.\"
5.TH TTY_IOCTL 4 2002-12-29 "Linux" "Linux Programmer's Manual"
6.SH NAME
7tty ioctl \- ioctls for terminals and serial lines
8.SH SYNOPSIS
9.sp
c13182ef 10.BR "#include <termios.h>"
fea681da 11.sp
c13182ef 12.BI "int ioctl(int " fd ", int " cmd ", ...);"
fea681da
MK
13.SH DESCRIPTION
14The
31e9a9ec 15.BR ioctl ()
fea681da
MK
16call for terminals and serial ports accepts many possible command arguments.
17Most require a third argument, of varying type, here called \fIargp\fP
18or \fIarg\fP.
19.LP
20Use of
21.I ioctl
c13182ef
MK
22makes for non-portable programs.
23Use the POSIX interface described in
fea681da
MK
24.BR termios (3)
25whenever possible.
fea681da
MK
26.SS "Get and Set Terminal Attributes"
27.TP
28.BI "TCGETS struct termios *" argp
29Equivalent to
30.IR "tcgetattr(fd, argp)" .
31.br
32Get the current serial port settings.
33.TP
34.BI "TCSETS const struct termios *" argp
35Equivalent to
36.IR "tcsetattr(fd, TCSANOW, argp)" .
37.br
38Set the current serial port settings.
39.TP
40.BI "TCSETSW const struct termios *" argp
41Equivalent to
42.IR "tcsetattr(fd, TCSADRAIN, argp)" .
43.br
44Allow the output buffer to drain, and
45set the current serial port settings.
46.TP
47.BI "TCSETSF const struct termios *" argp
48Equivalent to
49.IR "tcsetattr(fd, TCSAFLUSH, argp)" .
50.br
51Allow the output buffer to drain, discard pending input, and
52set the current serial port settings.
53.LP
54The following four ioctls are just like TCGETS, TCSETS, TCSETSW, TCSETSF,
55except that they take a
8478ee02 56.I "struct termio *"
fea681da 57instead of a
8478ee02 58.IR "struct termios *" .
fea681da
MK
59.TP
60.BI "TCGETA struct termio *" argp
61.TP
62.BI "TCSETA const struct termio *" argp
63.TP
64.BI "TCSETAW const struct termio *" argp
65.TP
66.BI "TCSETAF const struct termio *" argp
fea681da 67.SS "Locking the termios structure"
c13182ef
MK
68The termios structure of a tty can be locked.
69The lock is itself
f59a3f19 70a termios structure, with non-zero bits or fields indicating a
fea681da
MK
71locked value.
72.TP
73.BI "TIOCGLCKTRMIOS struct termios *" argp
c13182ef 74Gets the locking status of the termios structure of
fea681da
MK
75the terminal.
76.TP
77.BI "TIOCSLCKTRMIOS const struct termios *" argp
c13182ef
MK
78Sets the locking status of the termios structure of
79the terminal.
80Only root can do this.
fea681da
MK
81.SS "Get and Set Window Size"
82Window sizes are kept in the kernel, but not used by the kernel
83(except in the case of virtual consoles, where the kernel will
84update the window size when the size of the virtual console changes,
75b94dc3 85for example, by loading a new font).
fea681da
MK
86.TP
87.BI "TIOCGWINSZ struct winsize *" argp
88Get window size.
89.TP
90.BI "TIOCSWINSZ const struct winsize *" argp
91Set window size.
92.LP
93The struct used by these ioctls is defined as
94
95.nf
96struct winsize {
cf0a9ace
MK
97 unsigned short ws_row;
98 unsigned short ws_col;
99 unsigned short ws_xpixel; /* unused */
100 unsigned short ws_ypixel; /* unused */
fea681da
MK
101};
102.fi
103
8bd58774
MK
104When the window size changes, a
105.B SIGWINCH
106signal is sent to the
fea681da 107foreground process group.
fea681da
MK
108.SS "Sending a Break"
109.TP
110.BI "TCSBRK int " arg
111Equivalent to
112.IR "tcsendbreak(fd, arg)" .
113.br
114If the terminal is using asynchronous serial data transmission, and
115.I arg
116is zero, then send a break (a stream of zero bits) for between
c13182ef
MK
1170.25 and 0.5 seconds.
118If the terminal is not using asynchronous
fea681da
MK
119serial data transmission, then either a break is sent, or the function
120returns without doing anything.
121When
122.I arg
f59a3f19 123is non-zero, nobody knows what will happen.
fea681da 124
72cedc06 125(SVr4, UnixWare, Solaris, Linux treat
fea681da 126.I "tcsendbreak(fd,arg)"
f59a3f19 127with non-zero
fea681da
MK
128.I arg
129like
130.IR "tcdrain(fd)" .
131SunOS treats
132.I arg
133as a multiplier, and sends a stream of bits
134.I arg
135times as long as done for zero
136.IR arg .
72cedc06 137DG/UX and AIX treat
fea681da 138.I arg
f59a3f19 139(when non-zero) as a timeinterval measured in milliseconds.
fea681da
MK
140HP-UX ignores
141.IR arg .)
142.TP
143.BI "TCSBRKP int " arg
c13182ef
MK
144So-called "POSIX version" of TCSBRK.
145It treats non-zero
fea681da
MK
146.I arg
147as a timeinterval measured in deciseconds, and does nothing
148when the driver does not support breaks.
149.TP
150.BI "TIOCSBRK void"
151Turn break on, that is, start sending zero bits.
152.TP
153.BI "TIOCCBRK void"
154Turn break off, that is, stop sending zero bits.
fea681da
MK
155.SS "Software flow control"
156.TP
157.BI "TCXONC int " arg
158Equivalent to
159.IR "tcflow(fd, arg)" .
160.br
161See
162.BR tcflow (3)
163for the argument values TCOOFF, TCOON, TCIOFF, TCION.
fea681da
MK
164.SS "Buffer count and flushing"
165.TP
166.BI "FIONREAD int *" argp
167Get the number of bytes in the input buffer.
168.TP
169.BI "TIOCINQ int *" argp
170Same as FIONREAD.
171.TP
172.BI "TIOCOUTQ int *" argp
173Get the number of bytes in the output buffer.
174.TP
175.BI "TCFLSH int " arg
176Equivalent to
177.IR "tcflush(fd, arg)" .
178.br
179See
180.BR tcflush (3)
181for the argument values TCIFLUSH, TCOFLUSH, TCIOFLUSH.
fea681da
MK
182.SS "Faking input"
183.TP
184.BI "TIOCSTI const char *" argp
185Insert the given byte in the input queue.
fea681da
MK
186.SS "Redirecting console output"
187.TP
188.BI "TIOCCONS void"
189Redirect output that would have gone to
190.I /dev/console
191or
192.I /dev/tty0
c13182ef
MK
193to the given tty.
194If that was a pty master, send it to the slave.
fea681da
MK
195Anybody can do this as long as the output was not redirected yet.
196If it was redirected already EBUSY is returned,
197but root may stop redirection by using this ioctl with
198.I fd
199pointing at
200.I /dev/console
201or
202.IR /dev/tty0 .
fea681da
MK
203.SS "Controlling tty"
204.TP
205.BI "TIOCSCTTY int " arg
206Make the given tty the controlling tty of the current process.
207The current process must be a session leader and not have a
c13182ef
MK
208controlling tty already.
209If this tty is already the controlling tty
fea681da
MK
210of a different session group then the ioctl fails with EPERM,
211unless the caller is root and
212.I arg
213equals 1, in which case the tty is stolen, and all processes that had
214it as controlling tty lose it.
215.TP
216.BI TIOCNOTTY void
217If the given tty was the controlling tty of the current process,
c13182ef
MK
218give up this controlling tty.
219If the process was session leader,
8bd58774
MK
220then send
221.B SIGHUP
222and
223.B SIGCONT
224to the foreground process group
fea681da 225and all processes in the current session lose their controlling tty.
fea681da
MK
226.SS "Process group and session ID"
227.TP
228.BI "TIOCGPGRP pid_t *" argp
229When successful, equivalent to
230.IR "*argp = tcgetpgrp(fd)" .
231.br
9fdfa163 232Get the process group ID of the foreground process group on this tty.
fea681da
MK
233.TP
234.BI "TIOCSPGRP const pid_t *" argp
235Equivalent to
236.IR "tcsetpgrp(fd, *argp)" .
237.br
357cf3fe 238Set the foreground process group ID of this tty.
fea681da
MK
239.TP
240.BI "TIOCGSID pid_t *" argp
c13182ef
MK
241Get the session ID of the given tty.
242This will fail with ENOTTY
243in case the tty is not a master pty and not our controlling tty.
244Strange.
fea681da
MK
245.SS "Exclusive mode"
246.TP
247.BI "TIOCEXCL void"
248Put the tty into exclusive mode.
249No further
250.BR open (2)
251operations on the terminal are permitted.
252(They will fail with EBUSY, except for root.)
253.TP
254.BI "TIOCNXCL void"
255Disable exclusive mode.
fea681da
MK
256.SS "Line discipline"
257.TP
258.BI "TIOCGETD int *" argp
259Get the line discipline of the tty.
260.TP
261.BI "TIOCSETD const int *" argp
262Set the line discipline of the tty.
fea681da
MK
263.SS "Pseudo-tty ioctls"
264.TP
265.BI "TIOCPKT const int *" argp
266Enable (when
267.RI * argp
f59a3f19 268is non-zero) or disable packet mode.
5e8051e6 269Can be applied to the master side of a pseudo-terminal only (and will return
c13182ef
MK
270ENOTTY otherwise).
271In packet mode, each subsequent
fea681da 272.BR read (2)
f59a3f19 273will return a packet that either contains a single non-zero control byte,
c13182ef
MK
274or has a single byte containing zero (''\0') followed by data
275written on the slave side of the pty.
28d88c17 276If the first byte is not TIOCPKT_DATA (0), it is an OR of one
fea681da
MK
277or more of the following bits:
278
279.nf
280TIOCPKT_FLUSHREAD The read queue for the terminal is flushed.
281TIOCPKT_FLUSHWRITE The write queue for the terminal is flushed.
282TIOCPKT_STOP Output to the terminal is stopped.
283TIOCPKT_START Output to the terminal is restarted.
284TIOCPKT_DOSTOP t_stopc is `^S' and t_startc is `^Q'.
285TIOCPKT_NOSTOP the start and stop characters are not `^S/^Q'.
286.fi
287
288While this mode is in use, the presence
289of control status information to be read
290from the master side may be detected by a
291.BR select (2)
292for exceptional conditions.
293
294This mode is used by
295.BR rlogin (1)
296and
297.BR rlogind (8)
298to implement a remote-echoed, locally `^S/^Q' flow-controlled remote login.
299
300The BSD ioctls TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE
301have not been implemented under Linux.
fea681da
MK
302.SS "Modem control"
303.TP
304.BI "TIOCMGET int *" argp
305get the status of modem bits.
306.TP
307.BI "TIOCMSET const int *" argp
308set the status of modem bits.
309.TP
310.BI "TIOCMBIC const int *" argp
311clear the indicated modem bits.
312.TP
313.BI "TIOCMBIS const int *" argp
314set the indicated modem bits.
315.LP
316Bits used by these four ioctls:
317
318.nf
319TIOCM_LE DSR (data set ready/line enable)
320TIOCM_DTR DTR (data terminal ready)
321TIOCM_RTS RTS (request to send)
322TIOCM_ST Secondary TXD (transmit)
323TIOCM_SR Secondary RXD (receive)
324TIOCM_CTS CTS (clear to send)
325TIOCM_CAR DCD (data carrier detect)
326TIOCM_CD see TIOCM_CAR
327TIOCM_RNG RNG (ring)
328TIOCM_RI see TIOCM_RNG
329TIOCM_DSR DSR (data set ready)
330.fi
fea681da
MK
331.SS "Marking a line as local"
332.TP
333.BI "TIOCGSOFTCAR int *" argp
334("Get software carrier flag")
335Get the status of the CLOCAL flag in the c_cflag field of the
336termios structure.
337.TP
338.BI "TIOCSSOFTCAR const int *" argp
339("Set software carrier flag")
340Set the CLOCAL flag in the termios structure when
341.RI * argp
f59a3f19 342is non-zero, and clear it otherwise.
fea681da
MK
343.LP
344If the CLOCAL flag for a line is off, the hardware carrier detect (DCD)
345signal is significant, and an
346.BR open (2)
347of the corresponding tty will block until DCD is asserted,
348unless the O_NONBLOCK flag is given.
349If CLOCAL is set, the line behaves as if DCD is always asserted.
350The software carrier flag is usually turned on for local devices,
351and is off for lines with modems.
fea681da
MK
352.SS "Linux specific"
353For the TIOCLINUX ioctl, see
354.BR console_ioctl (4).
fea681da
MK
355.SS "Kernel debugging"
356.sp
357.BR "#include <linux/tty.h>"
fea681da
MK
358.TP
359.BI "TIOCTTYGSTRUCT struct tty_struct *" argp
360Get the tty_struct corresponding to
361.IR fd .
c13182ef 362.\"
fea681da
MK
363.\" .SS "Serial info"
364.\" .sp
365.\" .BR "#include <linux/serial.h>"
366.\" .sp
367.\" .TP
368.\" .BI "TIOCGSERIAL struct serial_struct *" argp
369.\" Get serial info.
370.\" .TP
371.\" .BI "TIOCSSERIAL const struct serial_struct *" argp
372.\" Set serial info.
fea681da
MK
373.SH "RETURN VALUE"
374The
31e9a9ec 375.BR ioctl ()
c13182ef
MK
376system call returns 0 on success.
377On error it returns \-1 and sets
fea681da
MK
378.I errno
379appropriately.
fea681da
MK
380.SH ERRORS
381.TP
382.B ENOIOCTLCMD
383Unknown command.
384.TP
385.B EINVAL
386Invalid command parameter.
387.TP
388.B EPERM
389Insufficient permission.
390.TP
391.B ENOTTY
392Inappropriate
393.IR fd .
394.SH EXAMPLE
395Check the condition of DTR on the serial port.
396
397.nf
398#include <termios.h>
399#include <fcntl.h>
400#include <sys/ioctl.h>
401
cf0a9ace 402int
c13182ef 403main(void)
cf0a9ace 404{
fea681da
MK
405 int fd, serial;
406
407 fd = open("/dev/ttyS0", O_RDONLY);
408 ioctl(fd, TIOCMGET, &serial);
409 if (serial & TIOCM_DTR)
410 puts("TIOCM_DTR is not set");
411 else
412 puts("TIOCM_DTR is set");
413 close(fd);
414}
415.fi
fea681da
MK
416.SH "SEE ALSO"
417.BR ioctl (2),
418.BR termios (3),
50c00f7e 419.BR console_ioctl (4),
88ab292b 420.BR pty (7)
fea681da
MK
421
422.\" FIONBIO const int *
423.\" FIONCLEX void
424.\" FIOCLEX void
425.\" FIOASYNC const int *
426.\" from serial.c:
427.\" TIOCSERCONFIG void
428.\" TIOCSERGWILD int *
429.\" TIOCSERSWILD const int *
430.\" TIOCSERGSTRUCT struct async_struct *
431.\" TIOCSERGETLSR int *
432.\" TIOCSERGETMULTI struct serial_multiport_struct *
433.\" TIOCSERSETMULTI const struct serial_multiport_struct *
434.\" TIOCGSERIAL, TIOCSSERIAL (see above)