TTY Struct
struct tty_struct is allocated by the TTY layer upon the first open of the TTY device and released after the last close. The TTY layer passes this structure to most of struct tty_operation's hooks. Members of tty_struct are documented in TTY Struct Reference at the bottom.
Initialization #
tty_init_termios() #
void helper for termios setup
Parameters
struct tty_struct *tty: the tty to set up
Description
Initialise the termios structure for this tty. This runs under the
tty_mutex currently so we can be relaxed about ordering.
Name #
tty_name() #
const char * return tty naming
Parameters
const struct tty_struct *tty: tty structure
Description
Convert a tty structure into a name. The name reflects the kernel naming policy and if udev is in use may not reflect user space
Locking: none
Reference counting #
tty_kref_get() #
struct tty_struct * get a tty reference
Parameters
struct tty_struct *tty: tty device
Return
a new reference to a tty object
Description
Locking: The caller must hold sufficient locks/counts to ensure that their existing reference cannot go away.
tty_kref_put() #
void release a tty kref
Parameters
struct tty_struct *tty: tty device
Description
Release a reference to the tty device and if need be let the kref layer destruct the object for us.
Install #
tty_standard_install() #
int usual tty->ops->install
Parameters
struct tty_driver *driver: the driver for the ttystruct tty_struct *tty: the tty
Description
If the driver overrides tty->ops->install, it still can call this function to perform the standard install operations.
Read & Write #
tty_put_char() #
int write one character to a tty
Parameters
struct tty_struct *tty: ttyu8 ch: character to write
Description
Write one byte to the tty using the provided tty->ops->put_char() method if present.
Note
the specific put_char operation in the driver layer may go away soon. Don't call it directly, use this method
Return
the number of characters successfully output.
Start & Stop #
stop_tty() #
void propagate flow control
Parameters
struct tty_struct *tty: tty to stop
Description
Perform flow control to the driver. May be called on an already stopped
device and will not re-call the tty_driver->stop() method.
This functionality is used by both the line disciplines for halting incoming
flow and by the driver. It may therefore be called from any context, may be
under the tty atomic_write_lock but not always.
- Locking: flow.lock
start_tty() #
void propagate flow control
Parameters
struct tty_struct *tty: tty to start
Description
Start a tty that has been stopped if at all possible. If tty was previously
stopped and is now being started, the tty_driver->start() method is invoked
and the line discipline woken.
- Locking: flow.lock
Wakeup #
tty_wakeup() #
void request more data
Parameters
struct tty_struct *tty: terminal
Description
Internal and external helper for wakeups of tty. This function informs the line discipline if present that the driver is ready to receive more output data.
Hangup #
tty_hangup() #
void trigger a hangup event
Parameters
struct tty_struct *tty: tty to hangup
Description
A carrier loss (virtual or otherwise) has occurred on tty. Schedule a hangup sequence to run after this event.
tty_vhangup() #
void process vhangup
Parameters
struct tty_struct *tty: tty to hangup
Description
The user has asked via system call for the terminal to be hung up. We do this synchronously so that when the syscall returns the process is complete. That guarantee is necessary for security reasons.
tty_hung_up_p() #
int was tty hung up
Parameters
struct file *filp: file pointer of tty
Return
true if the tty has been subject to a vhangup or a carrier loss
Misc #
tty_do_resize() #
int resize event
Parameters
struct tty_struct *tty: tty being resizedstruct winsize *ws: new dimensions
Description
Update the termios variables and send the necessary signals to peform a terminal resize correctly.
TTY Struct Flags #
enum tty_struct_flags #
TTY Struct Flags
Constants
TTY_THROTTLED: Driver input is throttled. The ldisc should calltty_driver.unthrottle()in order to resume reception when it is ready to process more data (at threshold min).TTY_IO_ERROR: If set, causes all subsequent userspace read/write calls on the tty to fail, returning -EIO. (May be no ldisc too.)TTY_OTHER_CLOSED: Device is a pty and the other side has closed.TTY_EXCLUSIVE: Exclusive open mode (a single opener).TTY_DO_WRITE_WAKEUP: If set, causes the driver to call thetty_ldisc_ops.write_wakeup()method in order to resume transmission when it can accept more data to transmit.TTY_LDISC_OPEN: Indicates that a line discipline is open. For debugging purposes only.TTY_PTY_LOCK: A flag private to pty code to implementTIOCSPTLCK/TIOCGPTLCKlogic.TTY_NO_WRITE_SPLIT: Prevent driver from splitting up writes into smaller chunks (preserve write boundaries to driver).TTY_HUPPED: The TTY was hung up. This is set posttty_driver.hangup().TTY_HUPPING: The TTY is in the process of hanging up to abort potential readers.TTY_LDISC_CHANGING: Line discipline for this TTY is being changed. I/O should not block when this is set. Usetty_io_nonblock()to check.TTY_LDISC_HALTED: Line discipline for this TTY was stopped. No work should be queued to this ldisc.
Description
These bits are used in the tty_struct.flags field.
So that interrupts won't be able to mess up the queues,
copy_to_cooked must be atomic with respect to itself, as must
tty->write. Thus, you must use the inline functions set_bit() and
clear_bit() to make things atomic.
TTY Struct Reference #
struct tty_struct #
state associated with a tty while open
Definition
;
Members
kref: reference counting bytty_kref_get()andtty_kref_put(), reaching zero frees the structureindex: index of this tty (e.g. to construct name like tty12)dev: class device orNULL(e.g. ptys, serdev)driver:struct tty_driveroperating this ttyport: persistent storage for this device (i.e.struct tty_port)ops:struct tty_operationsof driver for this tty (open, close, etc.)ldisc: the current line discipline for this tty (n_tty by default)ldisc_sem: protects line discipline changes (ldisc) -- lock tty not ptyatomic_write_lock: protects against concurrent writers, i.e. locks write_cnt, write_buf and similarlegacy_mutex: leftover from history (BKL -> BTM -> legacy_mutex), protecting several operations on this ttythrottle_mutex: protects against concurrenttty_throttle_safe()andtty_unthrottle_safe()(but nottty_unthrottle())termios_rwsem: protects termios and termios_lockedwinsize_mutex: protects winsizetermios: termios for the current tty, copied from/to driver.termiostermios_locked: locked termios (byTIOCGLCKTRMIOSandTIOCSLCKTRMIOSioctls)name: name of the tty constructed bytty_line_name()(e.g. ttyS3)flags: bitwise OR ofTTY_THROTTLED,TTY_IO_ERROR, ...count: count of open processes, reaching zero cancels all the work for this tty and drops a kref too (but does not free this tty)receive_room: bytes permitted to feed to ldisc without any being lostwinsize: size of the terminal "window" (cf. winsize_mutex)flow: flow settings grouped togetherflow.lock: lock for flow membersflow.stopped: tty stopped/started bystop_tty()/start_tty()flow.tco_stopped: tty stopped/started byTCOOFF/TCOONioctls (it has precedence over flow.stopped)ctrl: control settings grouped togetherctrl.pgrp: process group of this tty (setpgrp(2))ctrl.session: session of this tty (setsid(2)). Writes are protected by both ctrl.lock and legacy_mutex, readers must use at least one of them.ctrl.lock: lock for ctrl membersctrl.pktstatus: packet mode status (bitwise OR ofTIOCPKT_constants)ctrl.packet: packet mode enabledhw_stopped: not controlled by the tty layer, under driver's control for CTS handlingclosing: when set during close, n_tty processes only START & STOP charsflow_change: controls behavior of throttling, seetty_throttle_safe()andtty_unthrottle_safe()link: link to another pty (master -> slave and vice versa)fasync: state forO_ASYNC(forSIGIO); managed byfasync_helper()write_wait: concurrent writers are waiting in this queue until they are allowed to writeread_wait: readers wait for data in this queuehangup_work: normally a work to perform a hangup (do_tty_hangup()); while freeing the tty, (re)used torelease_one_tty()disc_data: pointer to ldisc's private data (e.g. tostruct n_tty_data)driver_data: pointer to driver's private data (e.g.struct uart_state)files_lock: protects tty_files listwrite_cnt: count of bytes written intty_write()to write_bufwrite_buf: temporary buffer used duringtty_write()to copy user data totty_files: list of (re)openers of this tty (i.e. linkedstruct tty_file_private)SAK_work: if the tty has a pending do_SAK, it is queued here
Description
All of the state associated with a tty while the tty is open. Persistent
storage for tty devices is referenced here as port and is documented in
struct tty_port.