STRUCT TTY_PORT(9)
π struct tty_port(9) π
okay bestie, welcome to the struct tty_port(9) page from the Kernel API Manual β¨ this is the port-level information situation, and it is literally main character energy for TTY drivers. no cap.
πΈ NAME πΈ
struct tty_port β port level information. periodt π
β¨ SYNOPSIS β¨
struct tty_port {
struct tty_bufhead buf;
struct tty_struct *tty;
struct tty_struct *itty;
const struct tty_port_operations *ops;
const struct tty_port_client_operations *client_ops;
spinlock_t lock;
int blocked_open;
int count;
wait_queue_head_t open_wait;
wait_queue_head_t delta_msr_wait;
unsigned long flags;
unsigned long iflags;
unsigned char console:1;
struct mutex mutex;
struct mutex buf_mutex;
u8 *xmit_buf;
u8 *xmit_fifo;
unsigned int close_delay;
unsigned int closing_wait;
int drain_delay;
struct kref kref;
void *client_data;
};
π MEMBERS π
vibe check on every single member, no skips, no cap π«Ά
bufβ buffer for this port, locked internally.ttyβ back pointer tostruct tty_struct, valid only if the tty is open. Usetty_port_tty_getto obtain it (andtty_kref_putto release).ittyβ internal back pointer tostruct tty_struct. Avoid this. It should be eliminated in the long term. not me warning you bestie πopsβ tty port operations (likeactivate,shutdown), seestruct tty_port_operations.client_opsβ tty port client operations (likereceive_buf,write_wakeup). By default,tty_port_default_client_opsis used.lockβ lock protectingtty.blocked_openβ#of procs waiting for open intty_port_block_til_ready.countβ usage count.open_waitβ open waiters queue (waiting e.g. for a carrier).delta_msr_waitβ modem status change queue (waiting for MSR changes).flagsβ user TTY flags (ASYNC_).iflagsβ internal flags (TTY_PORT_).consoleβ when set, the port is a console.mutexβ locking, for open, shutdown and other port operations.buf_mutexβxmit_bufalloc lock.xmit_bufβ optional xmit buffer used by some drivers.xmit_fifoβ optional xmit buffer used by some drivers.close_delayβ delay in jiffies to wait when closing the port.closing_waitβ delay in jiffies for output to be sent before closing.drain_delayβ set to zero if no pure time based drain is needed else set to size of fifo.krefβ references counter. Reaching zero callsops->destructif non-NULLor frees the port otherwise.client_dataβ pointer to private data, forclient_ops.
π¦ DESCRIPTION π¦
Each device keeps its own port level information. struct tty_port was introduced as a common structure for such information. As every TTY device shall have a backing tty_port structure, every driver can use these members. iconic behavior, honestly π
β οΈ The tty port has a different lifetime to the tty so must be kept apart. In addition be careful astty -> portmappings are valid for the life of the tty object but in many casesport -> ttymappings are valid only until a hangup so donβt use the wrong path. fr fr, this is the danger zone π
Tty port shall be initialized by tty_port_init and shut down either by tty_port_destroy (refcounting not used), or tty_port_put (refcounting).
There is a lot of helpers around struct tty_port too. To name the most significant ones: tty_port_open, tty_port_close (or tty_port_close_start and tty_port_close_end separately if need be), and tty_port_hangup. These call ops->activate and ops->shutdown as needed. slay π₯
π SEE ALSO π
- Kernel file
./include/linux/tty_port.h struct tty_port_operations(9)
and thatβs the whole page, bestie π«Ά source/version situation: ./include/linux, dated October 2026, page struct tty_port(9) β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms