TTY Drivers

A tty (teletype) device provides the means for handling text-based input and output to and from the user. A higher-level system component, typically a user-space process, treats a tty as a regular file. It thus uses file operations to open and close a tty, and to read input from and write output to a tty. The lower-level-facing end of a tty is receiving input or feeding the output to the lower-level system components.

Terminology

  • tty: teletype – in a rather general meaning

  • tty device: the concrete instance of the component implementing a tty

  • tty driver: the component implementing the device

  • tty subsystem: the system component managing ttys

Note

This terminology is preliminary and subject to change.

General Considerations

While a console just provides a means to write output to the screen, a tty device needs to handle output from a user-space process and provide input to that process. Consequently, more components are involved. The following diagram provides an overview of a tty device and its interaction with its surroundings:

../../../_images/ditaa-fdc934c31fcbcbe36cbdceb6a4b12c7baad1283b.svg

From the outside – as seen by a higher-level system component like a user-space proces – a tty device behaves like a file: It can be opened and closed, it can be written to and read from. Consequently, a higher-level system component interacts with the tty device via file operations. Input is provided to the higher-level system component via the tty device from the tty subsystem. The input can be read from the tty device.

A lower-level component is connected to the tty device via a set of operations specific to the lower-level component. Thel lower level component can, for instane, be a console, but also – hopefully someday – a serial port or even an ssh connection. Output is written to the tty device which is then passed to the lower-level component.

Taking one step closer, the tty device – like a console driver – consists of two parts: the tty frontend implementing the file operations provided to the higher-level system component, and the backend dealing with the respective lower-level system component. Typically, the tty front-end is provided by the subsystem.