STRUCT TTY_DRIVER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME

struct tty_driver β€” the driver for TTY devices, bestie. That's it, that's the whole vibe. It's the manual page for this struct from the Kernel API Manual, and we're gonna go through every single field together 🫢


✨ SYNOPSIS ✨

Okay so here's the whole struct, no cap, copied exactly:

struct tty_driver {
    struct kref kref;
    struct cdev **cdevs;
    struct module   *owner;
    const char      *driver_name;
    const char      *name;
    int name_base;
    int major;
    int minor_start;
    unsigned int    num;
    enum tty_driver_type type;
    enum tty_driver_subtype subtype;
    struct ktermios init_termios;
    unsigned long   flags;
    struct proc_dir_entry *proc_entry;
    struct tty_driver *other;
    struct workqueue_struct *flip_wq;
    struct tty_struct **ttys;
    struct tty_port **ports;
    struct ktermios **termios;
    void *driver_state;
    const struct tty_operations *ops;
    struct list_head tty_drivers;
 };

πŸŽ€ Members

Every field, one by one, let's go πŸ’–

  • kref β€” reference counting, literally its whole job. When it hits zero, all the internals and the driver get freed. Zero = cleanup era πŸ’€
  • cdevs β€” the allocated/registered character /dev devices. The actual device nodes living their lives.
  • owner β€” the modules owning this driver. Used drivers cannot be rmmod'ed, periodt. This one gets set automatically by tty_alloc_driver, so don't stress.
  • driver_name β€” name of the driver, the one that shows up in /proc/tty.
  • name β€” used for constructing the /dev node name. Yep, that name.
  • name_base β€” used as a number base for constructing the /dev node name πŸ”’
  • major β€” major /dev device number. Zero means autoassignment, so the kernel picks for you slay.
  • minor_start β€” the first minor /dev device number.
  • num β€” number of devices allocated. Count 'em.
  • type β€” type of tty driver (that's enum tty_driver_type).
  • subtype β€” subtype of tty driver (that's enum tty_driver_subtype). Yes there's a subtype, we love layers.
  • init_termios β€” the termios to set to each tty initially (e.g. tty_std_termios). First-impression termios.
  • flags β€” tty driver flags (TTY_DRIVER_).
  • proc_entry β€” proc fs entry, used internally. Don't touch, it's doing internals things πŸ™ˆ
  • other β€” driver of the linked tty; only used for the PTY driver. Very exclusive, very main character.
  • flip_wq β€” workqueue to queue flip buffer work on.
  • ttys β€” array of active struct tty_struct, set by tty_standard_install.
  • ports β€” array of struct tty_port; can be set during initialization by tty_port_link_device and similar.
  • termios β€” storage for termios at each TTY close, for the next open. Saving it for later, we love foresight ✨
  • driver_state β€” pointer to driver's arbitrary data. Whatever you want, it's your data bestie.
  • ops β€” driver hooks for TTYs. Set them using tty_set_operations. And please, use struct tty_port helpers in them as much as possible β€” that's the assignment πŸ’…
  • tty_drivers β€” used internally to link tty_drivers together. Chain 'em up.

πŸ’– DESCRIPTION πŸ’–

So the usual handling of struct tty_driver goes like this, in order, no skipping steps:

  1. Allocate it with tty_alloc_driver.
  2. Set up all the necessary members.
  3. Register it with tty_register_driver.
  4. At last, tear the driver down by calling tty_unregister_driver, followed by tty_driver_kref_put.

That's the whole lifecycle arc, literally character development.

The fields required to be set before calling tty_register_driver include driver_name, name, type, subtype, init_termios, and ops. Don't skip these, fr fr β€” they're mandatory and the registration will not be cute if you forget them 😭

πŸ‘‘ SEE ALSO πŸ‘‘

Go read these next, iykyk:

  • Kernel file ./include/linux/tty_driver.h
  • enum tty_driver_flag(9)
  • struct tty_operations(9)
  • tty_alloc_driver(9)

Okay that's the whole page bestie, you ate it up 🌈 This one came from ./include/linux, dated October 2026, and it's struct tty_driver(9) β€” go forth and register those TTY drivers responsibly, mwah πŸ’œπŸŽ€

πŸ“¦ where this page comes from