drivers/tty/pty.c
Source file repositories/reference/linux-study-clean/drivers/tty/pty.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/pty.c- Extension
.c- Size
- 24170 bytes
- Lines
- 924
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/errno.hlinux/interrupt.hlinux/tty.hlinux/tty_flip.hlinux/fcntl.hlinux/sched/signal.hlinux/string.hlinux/major.hlinux/mm.hlinux/init.hlinux/device.hlinux/uaccess.hlinux/bitops.hlinux/devpts_fs.hlinux/slab.hlinux/mutex.hlinux/poll.hlinux/mount.hlinux/file.hlinux/ioctl.hlinux/compat.htty.h
Detected Declarations
function pty_closefunction pty_unthrottlefunction pty_writefunction pty_write_roomfunction pty_set_lockfunction pty_get_lockfunction pty_set_pktmodefunction pty_get_pktmodefunction pty_signalfunction pty_flush_bufferfunction pty_openfunction pty_set_termiosfunction pty_resizefunction startfunction scoped_guardfunction pty_stopfunction scoped_guardfunction pty_common_installfunction pty_cleanupfunction pty_installfunction pty_removefunction pty_bsd_ioctlfunction pty_bsd_compat_ioctlfunction legacy_pty_initfunction legacy_pty_initfunction ptm_open_peerfunction pty_unix98_ioctlfunction pty_unix98_compat_ioctlfunction pty_unix98_installfunction pty_unix98_removefunction pty_show_fdinfofunction ptmx_openfunction unix98_pty_initfunction unix98_pty_initmodule init pty_init
Annotated Snippet
static struct file_operations ptmx_fops __ro_after_init;
static void __init unix98_pty_init(void)
{
ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
TTY_DRIVER_RESET_TERMIOS |
TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_DEVPTS_MEM |
TTY_DRIVER_DYNAMIC_ALLOC |
TTY_DRIVER_NO_WORKQUEUE);
if (IS_ERR(ptm_driver))
panic("Couldn't allocate Unix98 ptm driver");
pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
TTY_DRIVER_RESET_TERMIOS |
TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV |
TTY_DRIVER_DEVPTS_MEM |
TTY_DRIVER_DYNAMIC_ALLOC |
TTY_DRIVER_NO_WORKQUEUE);
if (IS_ERR(pts_driver))
panic("Couldn't allocate Unix98 pts driver");
ptm_driver->driver_name = "pty_master";
ptm_driver->name = "ptm";
ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
ptm_driver->minor_start = 0;
ptm_driver->type = TTY_DRIVER_TYPE_PTY;
ptm_driver->subtype = PTY_TYPE_MASTER;
ptm_driver->init_termios = tty_std_termios;
ptm_driver->init_termios.c_iflag = 0;
ptm_driver->init_termios.c_oflag = 0;
ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
ptm_driver->init_termios.c_lflag = 0;
ptm_driver->init_termios.c_ispeed = 38400;
ptm_driver->init_termios.c_ospeed = 38400;
ptm_driver->other = pts_driver;
tty_set_operations(ptm_driver, &ptm_unix98_ops);
pts_driver->driver_name = "pty_slave";
pts_driver->name = "pts";
pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
pts_driver->minor_start = 0;
pts_driver->type = TTY_DRIVER_TYPE_PTY;
pts_driver->subtype = PTY_TYPE_SLAVE;
pts_driver->init_termios = tty_std_termios;
pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
pts_driver->init_termios.c_ispeed = 38400;
pts_driver->init_termios.c_ospeed = 38400;
pts_driver->other = ptm_driver;
tty_set_operations(pts_driver, &pty_unix98_ops);
if (tty_register_driver(ptm_driver))
panic("Couldn't register Unix98 ptm driver");
if (tty_register_driver(pts_driver))
panic("Couldn't register Unix98 pts driver");
/* Now create the /dev/ptmx special device */
tty_default_fops(&ptmx_fops);
ptmx_fops.open = ptmx_open;
cdev_init(&ptmx_cdev, &ptmx_fops);
if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
panic("Couldn't register /dev/ptmx driver");
device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
}
#else
static inline void unix98_pty_init(void) { }
#endif
static int __init pty_init(void)
{
legacy_pty_init();
unix98_pty_init();
return 0;
}
device_initcall(pty_init);
Annotation
- Immediate include surface: `linux/module.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/tty.h`, `linux/tty_flip.h`, `linux/fcntl.h`, `linux/sched/signal.h`, `linux/string.h`.
- Detected declarations: `function pty_close`, `function pty_unthrottle`, `function pty_write`, `function pty_write_room`, `function pty_set_lock`, `function pty_get_lock`, `function pty_set_pktmode`, `function pty_get_pktmode`, `function pty_signal`, `function pty_flush_buffer`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.