Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

/sys/class/tty

FieldValue
SubsystemTTY core; drivers/tty/tty_io.c (tty_class, console/active), drivers/tty/serial/serial_core.c (ttyS<x> serial attributes)
Config gateCONFIG_TTY (drivers/tty/Makefile obj-$(CONFIG_TTY) += tty_io.o); serial group: CONFIG_SERIAL_CORE; tty0-63: CONFIG_VT
ABI documentationDocumentation/ABI/testing/sysfs-tty (17 What: entries)
SinceNovember 2010 (console/active, tty<x>/active); October 2012 (TIOCGSERIAL group); February 2020 (ttyS<x>/console)
Live (5.10.134 host)70 entries: console, ptmx, tty, ttyprintk, tty0-63, ttyS0-1; console/active = ttyS1; ttyS0 uartclk = 1843200, type = 4
Ledger IDSYSC-tty

What it represents

Every tty device the core knows about: the controlling terminals and their helpers (tty at 5:0, console at 5:1, ptmx at 5:2), the 64 virtual consoles tty0-63 registered by the VT driver, and serial ports ttyS<x> registered by serial_core. The class mixes two very different populations: entries with device-specific attributes (serial ports expose the TIOCGSERIAL state) and bare class entries (tty, ptmx, ttyprintk) that carry only the core files dev, uevent, power/, subsystem. Note the class covers console state but there is no /sys/class/serial: serial ports surface only through this class.

Relationship to the device model

tty_class is registered in tty_io.c (postcore_initcall) with a devnode callback that marks the tty (5:0) and ptmx (5:2) nodes 0666 for devtmpfs. tty_init() creates tty and console directly; console is created with cons_dev_groups so it carries the active attribute. The VT console driver (drivers/tty/vt/vt.c, CONFIG_VT) registers tty0 with vt_dev_groups (also carrying active) and tty1-63 via tty_register_driver. serial_core attaches tty_dev_attrs[] (14 attributes) to each ttyS<x>. The active files support poll() to watch virtual-console switches (ABI, November 2010).

Attributes (representative)

AttributeR/WValue and unitSource
console/activeROconfigured console list, active device last; live: ttyS1; pollableABI, November 2010; tty_io.c DEVICE_ATTR(active)
tty<x>/activeROcurrent active virtual console; live tty0/active = tty1ABI, November 2010
ttyS<x>/uartclkROuartclk = 16 x baud_base; live ttyS0 = 1843200ABI, September 2012
ttyS<x>/typeROport type number; live ttyS0 = 4 = PORT_16550A (include/uapi/linux/serial.h)ABI, October 2012
ttyS<x>/lineROtty line numberABI, October 2012
ttyS<x>/portROport I/O addressABI, October 2012
ttyS<x>/irqROinterrupt numberABI, October 2012
ttyS<x>/flags, xmit_fifo_size, custom_divisorROport state fieldsABI, October 2012
ttyS<x>/close_delay, closing_waitROhundredths of a second; live close_delay = 50ABI, October 2012
ttyS<x>/io_type, iomem_base, iomem_reg_shiftROregister access shapeABI, October 2012
ttyS<x>/rx_trig_bytesRWRX FIFO trigger; 16550A allows 1/4/8/14, nearest lower winsABI, May 2014
ttyS<x>/consoleRWboolean: attach/detach port as kernel consoleABI, February 2020
devROmajor:minor; live console 5:1, ptmx 5:2tty_io.c device_create calls
(serial group source)13 RO + 1 RWexposed “via sysfs rather than via ioctls” per the ABI fileserial_core.c tty_dev_attrs[]

All 14 serial attributes are read-only except console. The ABI file documents 17 paths; the group table above covers them.

Safety and writes

Reads are safe. Writes are console-relevant: ttyS<x>/console detaches or re-attaches a kernel console (February 2020) and rx_trig_bytes retunes the UART FIFO, so both change where kernel messages and serial input flow. The active files are read-only but pollable, which is what exit-on-console-switch daemons use. Entries without attributes (ptmx, tty) are not tunable here; their behavior is ioctl/termios territory, not sysfs.

References

  • Documentation/ABI/testing/sysfs-tty (cached at source-cache/linux-sparse)
  • drivers/tty/tty_io.c, drivers/tty/serial/serial_core.c, drivers/tty/vt/vt.c, fetched from raw.githubusercontent.com/torvalds/linux/master
  • include/uapi/linux/serial.h (PORT_16550A = 4)
  • Live enumeration /sys/class/tty incl. console/active, ttyS0/* (read-only, kernel 5.10.134)
  • Sibling pages: net, mem; coverage: ledger