Scroll to navigation

IOCTL_TTY(2) Manual del Programador de Linux IOCTL_TTY(2)

NOMBRE

ioctl_tty - ioctls para terminales y líneas serie

SINOPSIS

#include <termios.h>
#include <sys/ioctl.h>

int ioctl(int fd, int cmd, ...);

DESCRIPCIÓN

La llamada ioctl(2) para terminales y puertos serie acepta muchas órdenes que se pasan como argumentos. La mayoría necesita un tercer argumento, de tipo variable, que aquí llamamos argp o arg.

El uso de ioctl hace que un programa no sea (trans)portable. Use la interfaz POSIX descrita en termios(3) siempre que sea posible.

Obtener y establecer los atributos de un terminal

Equivalente a tcgetattr(fd, argp).
Obtiene la configuración actual de un puerto serie.
Equivalente a tcsetattr(fd, TCSANOW, argp).
Establece la configuración actual de un puerto serie.
Equivalente a tcsetattr(fd, TCSADRAIN, argp).
Permite vaciar el buffer de salida y establecer la configuración actual de un puerto serie.
Equivalente a tcsetattr(fd, TCSAFLUSH, argp).
Permite vaciar el buffer de salida, descartar la entrada pendiente y establecer la configuración actual de un puerto serie.

Las siguientes cuatro ioctls son exactamente iguales a TCGETS, TCSETS, TCSETSW y TCSETSF, excepto en que toman un argumento struct termio * en lugar de un argumento struct termios *.

TCGETA struct termio *argp
TCSETA const struct termio *argp
TCSETAW const struct termio *argp
TCSETAF const struct termio *argp

Bloqueo de una estructura termios

La estructura termios de un tty se puede bloquear. El propio bloqueo es una estructura termios con bits o campos distintos de cero indicando un valor bloqueado.

Obtiene el estado de bloqueo de la estructura termios del terminal.
Sets the locking status of the termios structure of the terminal. Only a process with the CAP_SYS_ADMIN capability can do this.

Obtener y establecer el tamaño de la ventana

Los tamaños de las ventanas se guardan en el núcleo pero éste no los usa (excepto en el caso de las consolas virtuales, donde el núcleo actualizará el tamaño de la ventana cuando el tamaño de la consola virtual cambie, por ejemplo, al cargar una nueva fuente).

The following constants and structure are defined in <sys/ioctl.h>.

Obtiene el tamaño de la ventana.
Establece el tamaño de la ventana.

La estructura usada por estas ioctls se define como


struct winsize {

unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel; /* sin usar */
unsigned short ws_ypixel; /* sin usar */ };

Cuando el tamaño de la ventana cambia, se envía una señal SIGWINCH al grupo de procesos en primer plano.

Envío de una pausa (break)

Equivalente a tcsendbreak(fd, arg).
Si la termina usa una transmisión asíncrona serie de datos y si el argumento arg es cero, entonces envía una pausa (un flujo de bits a cero) con una duración de entre 0'25 y 0'5 segundos. Si el terminal no usa una transmisión asíncrona serie de datos, entonces o se envía una pausa o la función regresa sin hacer nada. Cuando arg no es cero, nadie sabe qué ocurrirá.
(SVr4, UnixWare, Solaris y Linux tratan tcsendbreak(fd,arg) como tcdrain(fd) cuando el argumento arg es distinto de cero. SunOS trata arg como un multiplicador y envía arg veces un flujo de bits tan largo como el que se envía para un valor de arg igual a cero. DG/UX y AIX tratan a arg (cuando no es cero) como un intervalo de tiempo medido en milisegundos. HP-UX ignora arg.)
Conocida como la "versión POSIX" de TCSBRK. Trata un arg distinto de cero como un intervalo de tiempo medido en décimas de segundo y no hace nada cuando el driver no soporta pausas.
Activa la pausa, es decir, empieza a enviar bits a cero.
Desactiva la pausa, es decir, deja de enviar bits a cero.

Control de flujo software

Equivalente a tcflow(fd, arg).
Vea tcflow(3) para los valores de argumento TCOOFF, TCOON, TCIOFF y TCION.

Escrutinio y vaciado de buffers

Obtiene el número de bytes en el buffer de entrada.
Igual que FIONREAD.
Obtienen el número de bytes en el buffer de salida.
Equivalente a tcflush(fd, arg).
Vea tcflush(3) para los valores de argumento TCIFLUSH, TCOFLUSH y TCIOFLUSH.

Falsificación de la entrada

Inserta el byte dado en la cola de entrada.

Redirección de la salida de consola

Redirect output that would have gone to /dev/console or /dev/tty0 to the given terminal. If that was a pseudoterminal master, send it to the slave. In Linux before version 2.6.10, anybody can do this as long as the output was not redirected yet; since version 2.6.10, only a process with the CAP_SYS_ADMIN capability may do this. If output was redirected already EBUSY is returned, but redirection can be stopped by using this ioctl with fd pointing at /dev/console or /dev/tty0.

Controlling terminal

Make the given terminal the controlling terminal of the calling process. The calling process must be a session leader and not have a controlling terminal already. For this case, arg should be specified as zero.
If this terminal is already the controlling terminal of a different session group, then the ioctl fails with EPERM, unless the caller has the CAP_SYS_ADMIN capability and arg equals 1, in which case the terminal is stolen, and all processes that had it as controlling terminal lose it.
If the given terminal was the controlling terminal of the calling process, give up this controlling terminal. If the process was session leader, then send SIGHUP and SIGCONT to the foreground process group and all processes in the current session lose their controlling terminal.

(Número) identificador (ID) de grupo de procesos y sesión

Cuando tiene éxito, equivale a *argp = tcgetpgrp(fd).
Get the process group ID of the foreground process group on this terminal.
Equivalente a tcsetpgrp(fd, *argp).
Set the foreground process group ID of this terminal.
Get the session ID of the given terminal. This fails with the error ENOTTY if the terminal is not a master pseudoterminal and not our controlling terminal. Strange.

Modo exclusivo

Put the terminal into exclusive mode. No further open(2) operations on the terminal are permitted. (They fail with EBUSY, except for a process with the CAP_SYS_ADMIN capability.)
(since Linux 3.8) If the terminal is currently in exclusive mode, place a nonzero value in the location pointed to by argp; otherwise, place zero in *argp.
Desactiva el modo exclusivo.

Disciplina de línea

Get the line discipline of the terminal.
Set the line discipline of the terminal.

Pseudoterminal ioctls

Enable (when *argp is nonzero) or disable packet mode. Can be applied to the master side of a pseudoterminal only (and will return ENOTTY otherwise). In packet mode, each subsequent read(2) will return a packet that either contains a single nonzero control byte, or has a single byte containing zero (' ') followed by data written on the slave side of the pseudoterminal. If the first byte is not TIOCPKT_DATA (0), it is an OR of one or more of the following bits:
TIOCPKT_FLUSHREAD   The read queue for the terminal is flushed.
TIOCPKT_FLUSHWRITE  The write queue for the terminal is flushed.
TIOCPKT_STOP        Output to the terminal is stopped.
TIOCPKT_START       Output to the terminal is restarted.
TIOCPKT_DOSTOP      The start and stop characters are ^S/^Q.
TIOCPKT_NOSTOP      The start and stop characters are not ^S/^Q.
While this mode is in use, the presence of control status information to be read from the master side may be detected by a select(2) for exceptional conditions or a poll(2) for the POLLPRI event.
Este modo lo usan rlogin(1) y rlogind(8) para implementar un login remoto con un flujo controlado localmente mediante ^S/^Q y un eco remoto.
(since Linux 3.8) Return the current packet mode setting in the integer pointed to by argp.
Set (if *argp is nonzero) or remove (if *argp is zero) the pseudoterminal slave device. (See also unlockpt(3).)
(since Linux 3.8) Place the current lock state of the pseudoterminal slave device in the location pointed to by argp.
(since Linux 4.13) Given a file descriptor in fd that refers to a pseudoterminal master, open (with the given open(2)-style flags) and return a new file descriptor that refers to the peer pseudoterminal slave device. This operation can be performed regardless of whether the pathname of the slave device is accessible through the calling process's mount namespace.
Security-conscious programs interacting with namespaces may wish to use this operation rather than open(2) with the pathname returned by ptsname(3), and similar library functions that have insecure APIs. (For example, confusion can occur in some cases using ptsname(3) with a pathname where a devpts filesystem has been mounted in a different mount namespace.)

Las ioctls de BSD TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE no se han implementado en Linux.

Control del modem

Obtiene el estado de los bits del modem.
Configura el estado de los bits del modem.
Borra los bits del modem que se indican.
Activa los bits del modem que se indican.

The following bits are used by the above ioctls:

TIOCM_LE        DSR (data set ready/line enable)
TIOCM_DTR       DTR (data terminal ready)
TIOCM_RTS       RTS (request to send)
TIOCM_ST        TXD secundario (transmitir)
TIOCM_SR        RXD secundario (recibir)
TIOCM_CTS       CTS (clear to send)
TIOCM_CAR       DCD (data carrier detect)
TIOCM_CD         vea TIOCM_CAR
TIOCM_RNG       RNG (ring)
TIOCM_RI         vea TIOCM_RNG
TIOCM_DSR       DSR (data set ready)
Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change. The bits of interest are specified as a bit mask in arg, by ORing together any of the bit values, TIOCM_RNG, TIOCM_DSR, TIOCM_CD, and TIOCM_CTS. The caller should use TIOCGICOUNT to see which bit has changed.
Get counts of input serial line interrupts (DCD, RI, DSR, CTS). The counts are written to the serial_icounter_struct structure pointed to by argp.
Note: both 1->0 and 0->1 transitions are counted, except for RI, where only 0->1 transitions are counted.

Marcar una línea como local

("Get software carrier flag") Obtiene el estado de la bandera CLOCAL del campo c_cflag de la estructura termios.
("Set software carrier flag") Activa la bandera CLOCAL de la estructura termios cuando *argp es distinto de cero y la borra en caso contrario.

If the CLOCAL flag for a line is off, the hardware carrier detect (DCD) signal is significant, and an open(2) of the corresponding terminal will block until DCD is asserted, unless the O_NONBLOCK flag is given. If CLOCAL is set, the line behaves as if DCD is always asserted. The software carrier flag is usually turned on for local devices, and is off for lines with modems.

Específico de Linux

Para la ioctl TIOCLINUX vea ioctl_console(2).

Depuración del núcleo

#include <linux/tty.h>

Get the tty_struct corresponding to fd. This command was removed in Linux 2.5.67.

VALOR DEVUELTO

La llamada al sistema ioctl(2) devuelve 0 en caso de éxito. En caso de error devuelve -1 y asigna a errno un valor adecuado.

ERRORES

Parámetro de orden inválido.
Orden desconocida.
fd inapropiado.
Permiso insuficiente.

EJEMPLO

Comprueba el estado de la línea DTR del puerto serie.

#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int
main(void)
{

int fd, serial;
fd = open("/dev/ttyS0", O_RDONLY);
ioctl(fd, TIOCMGET, &serial);
if (serial & TIOCM_DTR)
puts("TIOCM_DTR is set");
else
puts("TIOCM_DTR is not set");
close(fd); }

VÉASE TAMBIÉN

ldattach(1), ioctl(2), ioctl_console(2), termios(3), pty(7)

COLOFÓN

Esta página es parte de la versión 4.16 del proyecto Linux man-pages. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en https://www.kernel.org/doc/man-pages/.

TRADUCCIÓN

La traducción al español de esta página del manual fue creada por Juan Piernas <piernas@ditec.um.es>

Esta traducción es documentación libre; lea la GNU General Public License Version 3 o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD.

Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a debian-l10n-spanish@lists.debian.org.

15 Septiembre 2017 Linux