n_tty_read(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… n_tty_read(9) β€” the kernel API manual, but make it cute

okay so bestie, welcome to n_tty_read(9), straight out of the Kernel API Manual. this is the read function for a tty, and we're gonna get into it 🌸


✨ NAME ✨

n_tty_read β€” the read function for tty, periodt πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

ssize_t n_tty_read (struct tty_struct *tty , struct file *file , u8
*kbuf , size_t nr , void **cookie , unsigned long offset );

πŸŽ€ ARGUMENTS πŸŽ€

  • tty β€” the tty device, bestie. that's the whole vibe.
  • file β€” the file object πŸ“
  • kbuf β€” a pointer to a kernelspace buffer
  • nr β€” the size of the I/O, like how much we're moving around
  • cookie β€” if this is non-NULL, it's a continuation read πŸͺ (iykyk)
  • offset β€” where to continue reading from (lowkey unused in n_tty, don't worry about it)

πŸ’– DESCRIPTION πŸ’–

so this is what performs reads for the line discipline ✨ we are guaranteed that the line discipline will not be closed under us, which is iconic of it, but heads up: we may get multiple parallel readers and we have to handle that ourselves. we may also get a hangup. it's always called in user context, and it may sleep 😴

this code must be sure never to sleep through a hangup β€” no cap, that's a hard rule πŸ’€

Locking: the n_tty_read/consumer path claims the non-exclusive termios_rwsem, and it publishes read_tail πŸ‘‘


🌈 SEE ALSO 🌈

kernel file ./drivers/tty/n_tty.c, plus the whole friend group:

n_tty_kick_worker(9), n_tty_write_wakeup(9), put_tty_queue(9), reset_buffer_flags(9), n_tty_flush_buffer(9), is_utf8_continuation(9), is_continuation(9), do_output_char(9), process_output(9), process_output_block(9), __process_echoes(9), add_echo_byte(9), echo_move_back_col(9), echo_set_canon_col(9), echo_erase_tab(9), echo_char_raw(9), echo_char(9), finish_erasing(9), eraser(9), isig(9), n_tty_receive_break(9), n_tty_receive_overrun(9), n_tty_receive_parity_error(9), n_tty_receive_char_flow_ctrl(9), n_tty_receive_char(9), n_tty_receive_buf_common(9), n_tty_set_termios(9), n_tty_close(9), n_tty_open(9), copy_from_read_buf(9), canon_copy_from_read_buf(9), job_control(9), n_tty_write(9), n_tty_poll(9), n_tty_inherit_ops(9) 🫢


and that's the whole page, bestie πŸ§šπŸ’œ this one lives in ./drivers/tty, dated October 2026, and it's n_tty_read(9) from the Kernel API Manual β€” mwah, slay, go read some tty data πŸ”₯πŸ‘‘

πŸ“¦ where this page comes from