drivers/tty/tty_io.c
Source file repositories/reference/linux-study-clean/drivers/tty/tty_io.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/tty_io.c- Extension
.c- Size
- 91957 bytes
- Lines
- 3673
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/types.hlinux/major.hlinux/errno.hlinux/signal.hlinux/fcntl.hlinux/sched/signal.hlinux/sched/task.hlinux/interrupt.hlinux/tty.hlinux/tty_driver.hlinux/tty_flip.hlinux/devpts_fs.hlinux/file.hlinux/fdtable.hlinux/console.hlinux/timer.hlinux/ctype.hlinux/kd.hlinux/mm.hlinux/string.hlinux/slab.hlinux/poll.hlinux/ppp-ioctl.hlinux/proc_fs.hlinux/init.hlinux/module.hlinux/device.hlinux/wait.hlinux/bitops.hlinux/delay.hlinux/seq_file.hlinux/serial.h
Detected Declarations
struct serial_struct32function free_tty_structfunction tty_alloc_filefunction tty_add_filefunction tty_free_filefunction tty_del_filefunction tty_paranoia_checkfunction check_tty_countfunction list_for_each_entryfunction tty_dev_name_to_numberfunction list_for_each_entryfunction hung_up_tty_readfunction hung_up_tty_writefunction hung_up_tty_pollfunction hung_up_tty_ioctlfunction hung_up_tty_compat_ioctlfunction hung_up_tty_fasyncfunction tty_show_fdinfofunction tty_wakeupfunction __tty_hangupfunction hangupfunction do_tty_hangupfunction lossfunction tty_vhangupfunction tty_vhangup_selffunction tty_vhangup_sessionfunction tty_hung_up_pfunction __stop_ttyfunction stop_ttyfunction __start_ttyfunction start_ttyfunction tty_update_timefunction list_for_each_entryfunction bitsfunction iterate_tty_readfunction tty_readfunction tty_write_unlockfunction tty_write_lockfunction iterate_tty_writefunction tty_write_messagefunction file_tty_writefunction tty_writefunction redirected_tty_writefunction file_tty_writefunction tty_send_xcharfunction pty_line_namefunction tty_line_namefunction tty_driver_lookup_tty
Annotated Snippet
static const struct file_operations tty_fops = {
.read_iter = tty_read,
.write_iter = tty_write,
.splice_read = copy_splice_read,
.splice_write = iter_file_splice_write,
.poll = tty_poll,
.unlocked_ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = tty_open,
.release = tty_release,
.fasync = tty_fasync,
.show_fdinfo = tty_show_fdinfo,
};
static const struct file_operations console_fops = {
.read_iter = tty_read,
.write_iter = redirected_tty_write,
.splice_read = copy_splice_read,
.splice_write = iter_file_splice_write,
.poll = tty_poll,
.unlocked_ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = tty_open,
.release = tty_release,
.fasync = tty_fasync,
};
static const struct file_operations hung_up_tty_fops = {
.read_iter = hung_up_tty_read,
.write_iter = hung_up_tty_write,
.poll = hung_up_tty_poll,
.unlocked_ioctl = hung_up_tty_ioctl,
.compat_ioctl = hung_up_tty_compat_ioctl,
.release = tty_release,
.fasync = hung_up_tty_fasync,
};
static DEFINE_SPINLOCK(redirect_lock);
static struct file *redirect;
/**
* tty_wakeup - request more data
* @tty: terminal
*
* 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.
*/
void tty_wakeup(struct tty_struct *tty)
{
struct tty_ldisc *ld;
if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) {
ld = tty_ldisc_ref(tty);
if (ld) {
if (ld->ops->write_wakeup)
ld->ops->write_wakeup(tty);
tty_ldisc_deref(ld);
}
}
wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT);
}
EXPORT_SYMBOL_GPL(tty_wakeup);
/**
* tty_release_redirect - Release a redirect on a pty if present
* @tty: tty device
*
* This is available to the pty code so if the master closes, if the slave is a
* redirect it can release the redirect.
*/
static struct file *tty_release_redirect(struct tty_struct *tty)
{
guard(spinlock)(&redirect_lock);
if (redirect && file_tty(redirect) == tty) {
struct file *f = redirect;
redirect = NULL;
return f;
}
return NULL;
}
/**
* __tty_hangup - actual handler for hangup events
* @tty: tty device
* @exit_session: if non-zero, signal all foreground group processes
*
* This can be called by a "kworker" kernel thread. That is process synchronous
Annotation
- Immediate include surface: `linux/types.h`, `linux/major.h`, `linux/errno.h`, `linux/signal.h`, `linux/fcntl.h`, `linux/sched/signal.h`, `linux/sched/task.h`, `linux/interrupt.h`.
- Detected declarations: `struct serial_struct32`, `function free_tty_struct`, `function tty_alloc_file`, `function tty_add_file`, `function tty_free_file`, `function tty_del_file`, `function tty_paranoia_check`, `function check_tty_count`, `function list_for_each_entry`, `function tty_dev_name_to_number`.
- 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.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.