drivers/tty/tty_ioctl.c
Source file repositories/reference/linux-study-clean/drivers/tty/tty_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/tty_ioctl.c- Extension
.c- Size
- 26062 bytes
- Lines
- 986
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/types.hlinux/termios.hlinux/errno.hlinux/sched/signal.hlinux/kernel.hlinux/major.hlinux/tty.hlinux/fcntl.hlinux/string.hlinux/mm.hlinux/module.hlinux/bitops.hlinux/mutex.hlinux/compat.hlinux/termios_internal.htty.hasm/io.hlinux/uaccess.h
Detected Declarations
function Copyrightfunction tty_write_roomfunction tty_driver_flush_bufferfunction tty_unthrottlefunction tty_throttle_safefunction tty_unthrottlefunction occurfunction unset_locked_termiosfunction tty_termios_copy_hwfunction tty_termios_hw_changefunction tty_get_char_sizefunction sizefunction tty_set_termiosfunction user_termio_to_kernel_termiosfunction kernel_termios_to_user_termiofunction user_termios_to_kernel_termiosfunction kernel_termios_to_user_termiosfunction user_termios_to_kernel_termios_1function kernel_termios_to_user_termios_1function user_termios_to_kernel_termiosfunction kernel_termios_to_user_termiosfunction tty_set_termiosfunction copy_termiosfunction copy_termios_lockedfunction get_termiofunction get_sgflagsfunction get_sgttybfunction set_sgflagsfunction set_sgttybfunction get_tcharsfunction set_tcharsfunction get_ltcharsfunction set_ltcharsfunction tty_change_softcarfunction tty_mode_ioctlfunction __tty_perform_flushfunction tty_perform_flushfunction n_tty_ioctl_helperexport tty_chars_in_bufferexport tty_write_roomexport tty_driver_flush_bufferexport tty_unthrottleexport tty_wait_until_sentexport tty_termios_copy_hwexport tty_termios_hw_changeexport tty_get_char_sizeexport tty_get_frame_sizeexport tty_set_termios
Annotated Snippet
if (tty_chars_in_buffer(tty)) {
tty_write_unlock(tty);
goto retry_write_wait;
}
ld = tty_ldisc_ref(tty);
if (ld != NULL) {
if ((opt & TERMIOS_FLUSH) && ld->ops->flush_buffer)
ld->ops->flush_buffer(tty);
tty_ldisc_deref(ld);
}
if ((opt & TERMIOS_WAIT) && tty->ops->wait_until_sent) {
tty->ops->wait_until_sent(tty, 0);
if (signal_pending(current)) {
tty_write_unlock(tty);
return -ERESTARTSYS;
}
}
tty_set_termios(tty, &tmp_termios);
tty_write_unlock(tty);
} else {
tty_set_termios(tty, &tmp_termios);
}
/* FIXME: Arguably if tmp_termios == tty->termios AND the
actual requested termios was not tmp_termios then we may
want to return an error as no user requested change has
succeeded */
return 0;
}
static void copy_termios(struct tty_struct *tty, struct ktermios *kterm)
{
down_read(&tty->termios_rwsem);
*kterm = tty->termios;
up_read(&tty->termios_rwsem);
}
static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm)
{
down_read(&tty->termios_rwsem);
*kterm = tty->termios_locked;
up_read(&tty->termios_rwsem);
}
static int get_termio(struct tty_struct *tty, struct termio __user *termio)
{
struct ktermios kterm;
copy_termios(tty, &kterm);
if (kernel_termios_to_user_termio(termio, &kterm))
return -EFAULT;
return 0;
}
#ifdef TIOCGETP
/*
* These are deprecated, but there is limited support..
*
* The "sg_flags" translation is a joke..
*/
static int get_sgflags(struct tty_struct *tty)
{
int flags = 0;
if (!L_ICANON(tty)) {
if (L_ISIG(tty))
flags |= 0x02; /* cbreak */
else
flags |= 0x20; /* raw */
}
if (L_ECHO(tty))
flags |= 0x08; /* echo */
if (O_OPOST(tty))
if (O_ONLCR(tty))
flags |= 0x10; /* crmod */
return flags;
}
static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
{
struct sgttyb tmp;
down_read(&tty->termios_rwsem);
tmp.sg_ispeed = tty->termios.c_ispeed;
tmp.sg_ospeed = tty->termios.c_ospeed;
tmp.sg_erase = tty->termios.c_cc[VERASE];
tmp.sg_kill = tty->termios.c_cc[VKILL];
Annotation
- Immediate include surface: `linux/bits.h`, `linux/types.h`, `linux/termios.h`, `linux/errno.h`, `linux/sched/signal.h`, `linux/kernel.h`, `linux/major.h`, `linux/tty.h`.
- Detected declarations: `function Copyright`, `function tty_write_room`, `function tty_driver_flush_buffer`, `function tty_unthrottle`, `function tty_throttle_safe`, `function tty_unthrottle`, `function occur`, `function unset_locked_termios`, `function tty_termios_copy_hw`, `function tty_termios_hw_change`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration 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.