1 .\" Copyright 2002 Walter Harms <walter.harms@informatik.uni-oldenburg.de>
2 .\" and Andries Brouwer <aeb@cwi.nl>.
3 .\" Distributed under GPL.
5 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
6 .\" all rights reserved.
7 .\" Translated Sat Oct 16 06:08:24 JST 2004
8 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
10 .TH TTY_IOCTL 4 2008-10-29 "Linux" "Linux Programmer's Manual"
13 .\"O tty_ioctl \- ioctls for terminals and serial lines
14 tty_ioctl \- 端末とシリアルラインの ioctl (入出力制御)
17 .B "#include <termios.h>"
19 .BI "int ioctl(int " fd ", int " cmd ", ...);"
24 .\"O call for terminals and serial ports accepts many possible command arguments.
27 コールは、多くのコマンド引き数を受け付ける。
28 .\"O Most require a third argument, of varying type, here called \fIargp\fP
30 多くがいろいろな型の 3 番目の引き数を必要とする。
31 ここでは \fIargp\fP または \fIarg\fP と呼ぶ。
35 .\"O makes for nonportable programs.
36 .\"O Use the POSIX interface described in
38 .\"O whenever possible.
43 に記述されている POSIX インタフェースを使うこと。
44 .\"O .SS "Get and Set Terminal Attributes"
47 .BI "TCGETS struct termios *" argp
49 .\"O .IR "tcgetattr(fd, argp)" .
50 .I "tcgetattr(fd, argp)"
53 .\"O Get the current serial port settings.
56 .BI "TCSETS const struct termios *" argp
58 .\"O .IR "tcsetattr(fd, TCSANOW, argp)" .
59 .I "tcsetattr(fd, TCSANOW, argp)"
62 .\"O Set the current serial port settings.
65 .BI "TCSETSW const struct termios *" argp
67 .\"O .IR "tcsetattr(fd, TCSADRAIN, argp)" .
68 .I "tcsetattr(fd, TCSADRAIN, argp)"
71 .\"O Allow the output buffer to drain, and
72 .\"O set the current serial port settings.
73 排出 (drain) を行うための出力バッファの使用を許可し、
76 .BI "TCSETSF const struct termios *" argp
78 .\"O .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
79 .I "tcsetattr(fd, TCSAFLUSH, argp)"
82 .\"O Allow the output buffer to drain, discard pending input, and
83 .\"O set the current serial port settings.
84 排出 (drain) を行うための出力バッファの使用を許可し、
88 .\"O The following four ioctls are just like
93 .\"O except that they take a
94 .\"O .I "struct termio *"
96 .\"O .IR "struct termios *" .
104 .I "struct termios *"
109 .BI "TCGETA struct termio *" argp
111 .BI "TCSETA const struct termio *" argp
113 .BI "TCSETAW const struct termio *" argp
115 .BI "TCSETAF const struct termio *" argp
116 .\"O .SS "Locking the termios structure"
117 .SS "termios 構造体のロック"
120 .\"O structure of a terminal can be locked.
121 .\"O The lock is itself a
123 .\"O structure, with nonzero bits or fields indicating a
131 0 でないビットまたはフィールドはロックされた値を示す。
133 .BI "TIOCGLCKTRMIOS struct termios *" argp
134 .\"O Gets the locking status of the
136 .\"O structure of the terminal.
141 .BI "TIOCSLCKTRMIOS const struct termios *" argp
142 .\"O Sets the locking status of the
144 .\"O structure of the terminal.
145 .\"O Only root (more precisely: a process with the
146 .\"O .BR CAP_SYS_ADMIN
147 .\"O capability) can do this.
153 ケーパビリティを持つプロセス) がこれを実行できる。
154 .\"O .SS "Get and Set Window Size"
156 .\"O Window sizes are kept in the kernel, but not used by the kernel
157 .\"O (except in the case of virtual consoles, where the kernel will
158 .\"O update the window size when the size of the virtual console changes,
159 .\"O for example, by loading a new font).
160 ウィンドウサイズはカーネル内に保持されるが、
162 (仮想コンソールの場合は例外であり、新しいフォントを読み込んだ場合など、
163 仮想端末のサイズが変更された場合、カーネルはウィンドウサイズを更新する)。
165 .\"O The following constants and structure are defined in
166 .\"O .IR <sys/ioctl.h> .
171 .BI "TIOCGWINSZ struct winsize *" argp
172 .\"O Get window size.
175 .BI "TIOCSWINSZ const struct winsize *" argp
176 .\"O Set window size.
179 .\"O The struct used by these ioctls is defined as
180 これらの ioctl で使用される構造体は、以下のように定義される。
185 unsigned short ws_row;
186 unsigned short ws_col;
187 .\"O unsigned short ws_xpixel; /* unused */
188 .\"O unsigned short ws_ypixel; /* unused */
189 unsigned short ws_xpixel; /* 未使用 */
190 unsigned short ws_ypixel; /* 未使用 */
195 .\"O When the window size changes, a
197 .\"O signal is sent to the
198 .\"O foreground process group.
203 .\"O .SS "Sending a Break"
206 .BI "TCSBRK int " arg
208 .\"O .IR "tcsendbreak(fd, arg)" .
209 .I "tcsendbreak(fd, arg)"
212 .\"O If the terminal is using asynchronous serial data transmission, and
214 .\"O is zero, then send a break (a stream of zero bits) for between
215 .\"O 0.25 and 0.5 seconds.
216 .\"O If the terminal is not using asynchronous
217 .\"O serial data transmission, then either a break is sent, or the function
218 .\"O returns without doing anything.
219 端末が非同期シリアルデータ転送を使用しており、
221 が 0 の場合、0.25 から 0.5 秒の間に
222 break (0 のビット列のストリーム) が送信される。
223 端末が非同期シリアルデータ転送を使用している場合、
224 break が送信されるか、この関数は何もせずに返る。
227 .\"O is nonzero, nobody knows what will happen.
229 が 0 以外の場合、何が起こるか分からない。
231 .\"O (SVr4, UnixWare, Solaris, Linux treat
232 .\"O .I "tcsendbreak(fd,arg)"
236 .\"O .IR "tcdrain(fd)" .
237 (SVr4, UnixWare, Solaris, Linux は、
238 .I "tcsendbreak(fd,arg)"
246 .\"O as a multiplier, and sends a stream of bits
248 .\"O times as long as done for zero
257 .\"O DG/UX and AIX treat
259 .\"O (when nonzero) as a time interval measured in milliseconds.
260 DG/UX と AIX は、(0 以外の場合)
269 .BI "TCSBRKP int " arg
270 .\"O So-called "POSIX version" of
272 .\"O It treats nonzero
274 .\"O as a timeinterval measured in deciseconds, and does nothing
275 .\"O when the driver does not support breaks.
281 を 1/10 秒単位の時間間隔として扱う。
282 またドライバが break をサポートしていない場合は、何もしない。
285 .\"O Turn break on, that is, start sending zero bits.
290 .\"O Turn break off, that is, stop sending zero bits.
293 .\"O .SS "Software flow control"
296 .BI "TCXONC int " arg
298 .\"O .IR "tcflow(fd, arg)" .
304 .\"O for the argument values
316 .\"O .SS "Buffer count and flushing"
317 .SS "バッファのカウントと書き出し (flush)"
319 .BI "FIONREAD int *" argp
320 .\"O Get the number of bytes in the input buffer.
323 .BI "TIOCINQ int *" argp
329 .BI "TIOCOUTQ int *" argp
330 .\"O Get the number of bytes in the output buffer.
333 .BI "TCFLSH int " arg
335 .\"O .IR "tcflush(fd, arg)" .
336 .I "tcflush(fd, arg)"
341 .\"O for the argument values
351 .\"O .SS "Faking input"
354 .BI "TIOCSTI const char *" argp
355 .\"O Insert the given byte in the input queue.
357 .\"O .SS "Redirecting console output"
361 .\"O Redirect output that would have gone to
365 .\"O to the given terminal.
366 .\"O If that was a pseudoterminal master, send it to the slave.
370 に送られる出力を、指定された端末リダイレクトする。
371 指定された端末が疑似端末 (pseudoterminal) のマスタの場合、
373 .\"O In Linux before version 2.6.10,
374 .\"O anybody can do this as long as the output was not redirected yet;
375 .\"O since version 2.6.10, only root (a process with the
376 .\"O .BR CAP_SYS_ADMIN
377 .\"O capability) may do this.
378 バージョン 2.6.10 より前の Linux では、出力がまだリダイレクトされて
379 いなければ、誰でもリダイレクトを行うことができる。
380 バージョン 2.6.10 以降では、root
382 ケーパビリティを持つプロセス) だけがリダイレクトを行うことができる。
383 .\"O If output was redirected already
386 .\"O but redirection can be stopped by using this ioctl with
400 に対してこの ioctl を使用することで、リダイレクトを止めることができる。
401 .\"O .SS "Controlling terminal"
404 .BI "TIOCSCTTY int " arg
405 .\"O Make the given terminal the controlling terminal of the calling process.
406 指定された端末を呼び出し元のプロセスの制御端末にする。
407 .\"O The calling process must be a session leader and not have a
408 .\"O controlling terminal already.
409 .\"O If this terminal is already the controlling terminal
410 .\"O of a different session group then the ioctl fails with
412 .\"O unless the caller is root (more precisely: has the
413 .\"O .BR CAP_SYS_ADMIN
416 .\"O equals 1, in which case the terminal is stolen, and all processes that had
417 .\"O it as controlling terminal lose it.
418 呼び出し元のプロセスはセッションリーダでなければならず、
420 この端末が既に他のセッショングループの制御端末である場合、
423 で失敗する。ただし呼び出したユーザが root で
429 この場合、端末は盗まれ (stolen)、
430 この端末を制御端末としていた全てのプロセスは端末を失う。
433 .\"O If the given terminal was the controlling terminal of the calling process,
434 .\"O give up this controlling terminal.
435 .\"O If the process was session leader,
440 .\"O to the foreground process group
441 .\"O and all processes in the current session lose their controlling terminal.
442 指定された端末が呼び出し元のプロセスの制御端末である場合、
449 を送り、カレントセッションの全てのプロセスは制御端末を失う。
450 .\"O .SS "Process group and session ID"
451 .SS "グループ ID とセッション ID の処理"
453 .BI "TIOCGPGRP pid_t *" argp
454 .\"O When successful, equivalent to
455 .\"O .IR "*argp = tcgetpgrp(fd)" .
457 .I "*argp = tcgetpgrp(fd)"
460 .\"O Get the process group ID of the foreground process group on this terminal.
461 この端末上のフォアグラウンドプロセスのプロセスグループ ID を取得する。
463 .BI "TIOCSPGRP const pid_t *" argp
465 .\"O .IR "tcsetpgrp(fd, *argp)" .
466 .I "tcsetpgrp(fd, *argp)"
469 .\"O Set the foreground process group ID of this terminal.
470 この端末のフォアグラウンドプロセスのグループ ID を設定する。
472 .BI "TIOCGSID pid_t *" argp
473 .\"O Get the session ID of the given terminal.
474 .\"O This will fail with
476 .\"O in case the terminal is not a master pseudoterminal
477 .\"O and not our controlling terminal.
479 指定された端末のセッション ID を取得する。
480 端末がマスタ疑似端末または制御端末でない場合は、
484 .\"O .SS "Exclusive mode"
488 .\"O Put the terminal into exclusive mode.
491 .\"O operations on the terminal are permitted.
492 .\"O (They will fail with
494 .\"O except for root, that is, a process with the
495 .\"O .BR CAP_SYS_ADMIN
503 ケーパビリティを持たないプロセスの場合、これ以降の
510 .\"O Disable exclusive mode.
512 .\"O .SS "Line discipline"
513 .SS "ライン制御 (line discipline)"
515 .BI "TIOCGETD int *" argp
516 .\"O Get the line discipline of the terminal.
519 .BI "TIOCSETD const int *" argp
520 .\"O Set the line discipline of the terminal.
522 .\"O .SS "Pseudoterminal ioctls"
525 .BI "TIOCPKT const int *" argp
528 .\"O is nonzero) or disable packet mode.
532 .\"O Can be applied to the master side of a pseudoterminal only (and will return
535 .\"O In packet mode, each subsequent
537 .\"O will return a packet that either contains a single nonzero control byte,
538 .\"O or has a single byte containing zero (\(aq\0\(aq) followed by data
539 .\"O written on the slave side of the pseudoterminal.
540 .\"O If the first byte is not
542 .\"O (0), it is an OR of one
543 .\"O or more of the following bits:
544 疑似端末のマスタ側にのみ適用できる (それ以外の場合は
549 は、値が 0 以外の 1 つの制御バイトを含むパケットか、
550 値が 0 の 1 バイト (\(aq\\0\(aq) に疑似端末のスレーブ側で書き込まれた
554 (0) でない場合、以下のビットの 1 つ以上を OR したものである:
557 .\"O TIOCPKT_FLUSHREAD The read queue for the terminal is flushed.
558 TIOCPKT_FLUSHREAD 端末の読み込みキューがフラッシュ (flush) される。
559 .\"O TIOCPKT_FLUSHWRITE The write queue for the terminal is flushed.
560 TIOCPKT_FLUSHWRITE 端末の書き出しキューがフラッシュされる。
561 .\"O TIOCPKT_STOP Output to the terminal is stopped.
562 TIOCPKT_STOP 端末への出力が停止される。
563 .\"O TIOCPKT_START Output to the terminal is restarted.
564 TIOCPKT_START 端末への出力が再開される。
565 .\"O TIOCPKT_DOSTOP The start and stop characters are \fB^S\fP/\fB^Q\fP.
566 .\"O TIOCPKT_NOSTOP The start and stop characters are not \fB^S\fP/\fB^Q\fP.
567 TIOCPKT_DOSTOP 開始文字と終了文字が \fB^S\fP/\fB^Q\fP である。
568 TIOCPKT_NOSTOP 開始文字と終了文字が \fB^S\fP/\fB^Q\fP でない。
571 .\"O While this mode is in use, the presence
572 .\"O of control status information to be read
573 .\"O from the master side may be detected by a
575 .\"O for exceptional conditions.
577 制御状態情報の存在がマスタ側から読み込めるかは、
582 .\"O This mode is used by
586 .\"O to implement a remote-echoed,
587 .\"O locally \fB^S\fP/\fB^Q\fP flow-controlled remote login.
592 で使われ、リモートエコーのリモートログインと
593 ローカルでの \fB^S\fP/\fB^Q\fP フロー制御のリモートログインを実装している。
600 .\"O have not been implemented under Linux.
607 .\"O .SS "Modem control"
610 .BI "TIOCMGET int *" argp
611 .\"O get the status of modem bits.
614 .BI "TIOCMSET const int *" argp
615 .\"O set the status of modem bits.
618 .BI "TIOCMBIC const int *" argp
619 .\"O clear the indicated modem bits.
622 .BI "TIOCMBIS const int *" argp
623 .\"O set the indicated modem bits.
626 .\"O Bits used by these four ioctls:
627 これらの 4 つの ioctl で使われるビットは以下の通り:
630 TIOCM_LE DSR (data set ready/line enable)
631 TIOCM_DTR DTR (data terminal ready)
632 TIOCM_RTS RTS (request to send)
633 TIOCM_ST Secondary TXD (transmit)
634 TIOCM_SR Secondary RXD (receive)
635 TIOCM_CTS CTS (clear to send)
636 TIOCM_CAR DCD (data carrier detect)
637 .\"O TIOCM_CD see TIOCM_CAR
638 TIOCM_CD TIOCM_CAR を参照。
640 .\"O TIOCM_RI see TIOCM_RNG
641 TIOCM_RI TIOCM_RNG を参照。
642 TIOCM_DSR DSR (data set ready)
644 .\"O .SS "Marking a line as local"
645 .SS "回線をローカルとしてマークする"
647 .BI "TIOCGSOFTCAR int *" argp
648 .\"O ("Get software carrier flag")
649 .\"O Get the status of the CLOCAL flag in the c_cflag field of the
658 .BI "TIOCSSOFTCAR const int *" argp
659 .\"O ("Set software carrier flag")
660 .\"O Set the CLOCAL flag in the
664 .\"O is nonzero, and clear it otherwise.
676 .\"O flag for a line is off, the hardware carrier detect (DCD)
677 .\"O signal is significant, and an
679 .\"O of the corresponding terminal will block until DCD is asserted,
686 ハードウェアキャリア検出 (hardware carrier detect, DCD) シグナルが重要であり、
690 は DCD が示されるまでブロックされる。
693 .\"O is set, the line behaves as if DCD is always asserted.
696 ラインは常に DCD が示されているかのように動作する。
697 .\"O The software carrier flag is usually turned on for local devices,
698 .\"O and is off for lines with modems.
699 ソフトウェアキャリアフラグは、ローカルデバイスでは通常はオンになっており、
701 .\"O .SS "Linux-specific"
702 .SS "Linux 固有の ioctl"
706 .\"O .BR console_ioctl (4).
709 .BR console_ioctl (4)
711 .\"O .SS "Kernel debugging"
713 .B "#include <linux/tty.h>"
715 .BI "TIOCTTYGSTRUCT struct tty_struct *" argp
718 .\"O corresponding to
724 .\"O .\" .SS "Serial info"
726 .\" .BR "#include <linux/serial.h>"
729 .\" .BI "TIOCGSERIAL struct serial_struct *" argp
730 .\"O .\" Get serial info.
733 .\" .BI "TIOCSSERIAL const struct serial_struct *" argp
734 .\"O .\" Set serial info.
736 .\"O .SH "RETURN VALUE"
740 .\"O system call returns 0 on success.
741 .\"O On error it returns \-1 and sets
745 システムコールは、成功した場合は 0 を返す。
753 .\"O Invalid command parameter.
757 .\"O Unknown command.
767 .\"O Insufficient permission.
771 .\"O Check the condition of DTR on the serial port.
772 シリアルポートの DTR の状態をチェックする。
777 #include <sys/ioctl.h>
784 fd = open("/dev/ttyS0", O_RDONLY);
785 ioctl(fd, TIOCMGET, &serial);
786 if (serial & TIOCM_DTR)
787 .\"O puts("TIOCM_DTR is not set");
788 puts("TIOCM_DTR が設定されていない。");
790 .\"O puts("TIOCM_DTR is set");
791 puts("TIOCM_DTR が設定されている。");
799 .BR console_ioctl (4),
802 .\" FIONBIO const int *
805 .\" FIOASYNC const int *
806 .\"O .\" from serial.c:
808 .\" TIOCSERCONFIG void
809 .\" TIOCSERGWILD int *
810 .\" TIOCSERSWILD const int *
811 .\" TIOCSERGSTRUCT struct async_struct *
812 .\" TIOCSERGETLSR int *
813 .\" TIOCSERGETMULTI struct serial_multiport_struct *
814 .\" TIOCSERSETMULTI const struct serial_multiport_struct *
815 .\"O .\" TIOCGSERIAL, TIOCSSERIAL (see above)
816 .\" TIOCGSERIAL, TIOCSSERIAL (上記を参照)