Section 10.4. The tty Structure

   


10.4. The tty Structure

Each hardware or pseudo-terminal has a data structure to contain its state. This structure, the tty structure (see Table 10.2), contains state information, the input and output queues, the modes and options set by the ioctl operations listed in Section 10.3, and the line-discipline number. The tty structure is shared by the pseudo-terminal or hardware driver and the line discipline. The calls to the line discipline all require a tty structure as a parameter; the driver locates the correct tty according to its identity.

Table 10.2. The tty structure.

Type

Description

character queues

raw input queue canonical input queue device output queue high/low watermarks

hardware parameters

device identifier start/stop output functions set hardware state function

polling

thread polling for reading thread polling for writing

state

termios state process group session terminal column number number of rows and columns


The sections of the tty structure include the following:

  • State information about the terminal. The t_state field includes major file options (e.g., signal-driven I/O) and transient state for flow control and synchronization. For hardware-based terminals, it includes line state (open, carrier present, or waiting for carrier).

  • Input and output queues. The output driver transmits characters placed in the output queue, t_outq. Line disciplines generally use the t_rawq and t_canq (noncanonical and canonical queues) for input; in line mode, the canonical queue contains full lines, and the noncanonical queue contains any current partial line. In addition, t_hiwat provides the boundary where threads attempting to write to the terminal will be put to sleep, waiting for the output queue to drain; t_lowat provides the boundary where sleeping threads waiting to write to the terminal will be awakened.

  • Hardware and software modes and parameters, and special characters. The t_termios structure contains the information set by TIOCSETA, TIOCSETAF, and TIOCSETAW. Specifically, line speed appears in the c_ispeed and c_ospeed fields of the t_termios structure, control information in the c_iflag, c_oflag, c_cflag and c_lflag fields, and special characters (end-of-file, end-of-line, alternate end-of-line, erase, word-erase, kill, reprint, interrupt, quit, suspend, start, stop, escape-next-character, status-interrupt, flush-output and VMIN and VTIME information) in the c_cc field.

  • Hardware driver information. This information includes t_oproc and t_stop, the driver procedures that start and stop transmissions after data are placed in the output queue; t_param, the driver procedure that sets the hardware state; and t_kdev, the device associated with the terminal line.

  • Terminal line-discipline software state. This state includes the terminal column number and counts for tab and erase processing (t_column, t_rocount, and t_rocol), the process group of the terminal (t_pgrp), the session associated with the terminal (t_session), and information about any processes selecting for input or output (t_rsel and t_wsel).

  • Terminal or window size (t_winsize). This information is not used by the kernel, but it is stored here to present consistent and correct information to applications. In addition, FreeBSD supplies the SIGWINCH signal (derived from Sun Microsystems' SunOS) that can be sent when the size of a window changes. This signal is useful for windowing packages such as X Window System [Scheifler & Gettys, 1986] that allow users to resize windows dynamically; programs such as text editors running in such a window need to be informed that something has changed and that they should recheck the window size.

The tty structure is initialized by the terminal driver's open routine and by the line-discipline open routine.


   
 


The Design and Implementation of the FreeBSD Operating System
The Design and Implementation of the FreeBSD Operating System
ISBN: 0201702452
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net