tty subsystem
AIX® is a multiuser operating system that allows user access from local or remotely attached devices. The communication layer that supports this function is the tty subsystem.
The communication between terminal devices and the programs that read and write to them is controlled by the tty interface. Examples of tty devices are:
- Modems
- ASCII terminals
- System consoles
- Serial printers
- Xterms or aixterms under X-Windows
This overview provides information on the following topics:
TTY subsystem objectives
The tty subsystem is responsible for:
- Controlling the physical flow of data on asynchronous lines (including the transmission speed, character size, and line availability)
- Interpreting the data by recognizing special characters and adapting to national languages
- Controlling jobs and terminal access by using the concept of controlling terminal
A controlling terminal manages the input and output operations of a group of processes. The tty special file supports the controlling terminal interface. In practice, user programs seldom open terminal files, such as dev/tty5. These files are opened by a getty or rlogind command and become the user's standard input and output devices.
tty subsystem modules
To perform its tasks, the tty subsystem is composed of modules, or disciplines. A module is a set of processing rules that govern the interface for communication between the computer and an asynchronous device. Modules can be added and removed dynamically for each tty.
The tty subsystem supports three main types of modules:
tty drivers
tty drivers, or hardware disciplines, directly control the hardware (tty devices) or pseudo-hardware (pty devices). They perform the actual input and output to the adapter by providing services to the modules above it. The services are flow control and special semantics when a port is being opened.
The following tty drivers are provided:
Driver | Description |
---|---|
cxma | 128-port asynchronous PCI controller. |
cxpa | 8-port asynchronous PCI controller. |
lft | Low-function terminal. The tty name is /dev/lftY, where Y >= 0. |
sa | 2-port asynchronous EIA-232 PCI adapter. |
sf | Universal asynchronous receiver/transceivers (UARTs) on system planar. |
The TTY drivers section provides more information.
Line disciplines
Line disciplines provide editing, job control, and special character interpretation. They perform all transformations that occur on the inbound and outbound data streams. Line disciplines also perform most of the error handling and status monitoring for the tty driver.
The following line disciplines are provided:
Subroutine | Description |
---|---|
ldterm | Terminal devices |
sptr | Serial printer (splp command) |
slip | Serial Line Internet Protocol (slattach command) |
Converter modules
Converter modules, or mapping disciplines, translate, or map, input and output characters.
The following converter modules are provided:
Converter | Description |
---|---|
nls | National language support for terminal mapping; this converter translates incoming and outgoing characters on the data stream, based on the input and output maps defined for the port (see the setmaps command) |
lc_sjis and uc_sjis | Upper and lower converter used to translate multibyte characters between the Shifted Japanese Industrial Standard (SJIS) and the Advanced Japanese EUC Code (AJEC) handled by the ldterm line discipline. |
Converter modules provides more information on converters.
TTY subsystem structure
The tty subsystem is based on STREAMS. This STREAMS-based structure provides modularity and flexibility, and enables the following features:
- Easy customizing; users can customize their terminal subsystem environment by adding and removing modules of their choice.
- Reusable modules; for example, the same line discipline module can be used on many tty devices with different configurations.
- Easy addition of new features to the terminal subsystem.
- Providing an homogeneous tty interface on heterogeneous devices.
The structure of a tty stream is made up of the following modules:
- The stream head, processing the user's requests. The stream head is the same for all tty devices, regardless of what line discipline or tty driver is in use.
- An optional upper converter (uc_sjis for example), a converter module pushed above the line discipline to convert upstream and downstream data.
- The line discipline.
- An optional lower converter (lc_sjis for example), a converter module pushed below the line discipline to convert upstream and downstream data.
- An optional character mapping module (nls), a converter module pushed above the tty driver to support input and output terminal mapping.
- The stream end: a tty driver.
Unless required, the internationalization modules are not present in the tty stream.
For a serial printer, the internationalization modules are usually not present on the stream; therefore, the structure is simpler.
Common services
The /usr/include/sys/ioctl.h and /usr/include/termios.h files describe the interface to the common services provided by the tty subsystem. The ioctl.h file, which is used by all of the modules, includes the winsize structure, as well as several ioctl commands. The termios.h file includes the POSIX compliant subroutines and data types.
The provided services are grouped and discussed here according to their specific functions.
Hardware control services
The following subroutines are provided for hardware control:
Subroutine | Description |
---|---|
cfgetispeed | Gets input baud rate |
cfgetospeed | Gets output baud rate |
cfsetispeed | Sets input baud rate |
cfsetospeed | Sets output baud rate |
tcsendbreak | Sends a break on an asynchronous serial data line |
Flow control services
The following subroutines are provided for flow control:
Subroutine | Description |
---|---|
tcdrain | Waits for output to complete |
tcflow | Performs flow control functions |
tcflush | Discards data from the specified queue |
Terminal information and control
The following subroutines are provided for terminal information and control:
Subroutine | Description |
---|---|
isatty | Determines if the device is a terminal |
setcsmap | Reads a code set map file and assigns it to the standard input device |
tcgetattr | Gets terminal state |
tcsetattr | Sets terminal state |
ttylock, ttywait, ttyunlock, or ttylocked | Controls tty locking functions |
ttyname | Gets the name of a terminal |
Window and terminal size services
The kernel stores the winsize structure to provide a consistent interface for the current terminal or window size. The winsize structure contains the following fields:
Field | Description |
---|---|
ws_row | Indicates the number of rows (in characters) on the window or terminal |
ws_col | Indicates the number of columns (in characters) on the window or terminal |
ws_xpixel | Indicates the horizontal size (in pixels) of the window or terminal |
ws_ypixel | Indicates the vertical size (in pixels) of the window or terminal |
By convention, a value of 0 in all of the winsize structure fields indicates that the structure has not yet been set up.
Subroutine | Description |
---|---|
termdef | Queries terminal characteristics. |
TIOCGWINSZ | Gets the window size. The argument to this ioctl operation is a pointer to a winsize structure, into which the current terminal or window size is placed. |
TIOCSWINSZ | Sets the window size. The argument to this ioctl operation is a pointer to a winsize structure, which is used to set the current terminal or window size information. If the new information differs from the previous, a SIGWINCH signal is sent to the terminal process group. |
Process group management services
The following subroutines are provided for process group management:
Subroutine | Description |
---|---|
tcgetpgrp | Gets foreground process group ID |
tcsetpgrp | Sets foreground process group ID |
Buffer size operations
The following ioctl operations are used for setting the size of the terminal input and output buffers. The argument to these operations is a pointer to an integer specifying the size of the buffer.
Operations | Description |
---|---|
TXSETIHOG | Sets the hog limit for the number of input characters that can be received and stored in the internal tty buffers before the process reads them. The default hog limit is 8192 characters. Once the hog limit plus one character is reached, an error is logged in the error log and the input buffer is flushed. The hog number should not be too large, since the buffer is allocated from the system-pinned memory. |
TXSETOHOG | Sets the hog limit for the number of output characters buffered to echo input. The default hog limit is 8192 characters. Once the hog output limit is reached, input characters are no longer echoed. The hog number should not be too large, since the buffer is allocated from the system-pinned memory. |
Synchronization
The tty subsystem takes advantage of the synchronization provided by STREAMS. The tty stream modules are configured with the queue pair level synchronization. This synchronization allows the parallelization of the processing for two different streams.