AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
tty.h
Go to the documentation of this file.
1#ifndef _DEV_TTY_H
2#define _DEV_TTY_H
3
4#include <core/system.h>
5
6struct tty;
7
8#include <aquila/termios.h>
9#include <aquila/ioctl.h>
10#include <sys/proc.h>
11#include <fs/iobuf.h>
12
13/*
14 * Terminals (dev/tty/generic.c): the line discipline that every terminal
15 * shares, the virtual terminals, the serial ports and the
16 * pseudo-terminals. A terminal has two sides: the master, the device
17 * (keyboard and screen, a serial port, a pty's master), and the slave,
18 * what programs read and write. See docs/kernel/devices.md.
19 */
20
21/* A terminal's write function, for one of its sides. */
22typedef ssize_t (*ttyio)(struct tty *tty, size_t size, void *buf);
23
25struct tty {
27 char *cook;
28
30 size_t size;
31
33 size_t pos;
34
37 int eof;
38
42 size_t col;
44
45 struct termios tios;
46 struct winsize ws;
47
54 int gone;
55
57 struct dev *dev;
58
61
63 struct pgroup *fg;
64
66 struct vnode *vnode;
67
68 /* the device's side */
69
71 void *p;
72
75
78
80 void (*input_flush)(struct tty *tty);
81};
82
83/* The size of a terminal's line buffer. */
84#define TTY_BUF_SIZE 512
85
86/* The line discipline's operations (dev/tty/generic.c). */
87int tty_new(struct proc *proc, size_t buf_size, ttyio master, ttyio slave, void *p, struct tty **ref);
88int tty_free(struct tty *tty);
89ssize_t tty_master_write(struct tty *tty, size_t size, void *buf);
90ssize_t tty_slave_write(struct tty *tty, size_t size, void *buf);
91ssize_t tty_write_iobuf(struct tty *tty, struct iobuf *io, ttyio write);
92int tty_ioctl(struct tty *tty, int request, void *argp);
93void tty_open(struct tty *tty, struct file *file);
94void tty_hangup(struct tty *tty);
95void tty_flush(struct tty *tty, int which);
96int tty_eof(struct tty *tty);
98int tty_can_read(struct tty *tty, size_t buffered);
99int tty_background(struct tty *tty, int sig);
100
101#endif /* ! _DEV_TTY_H */
void tty_hangup(struct tty *tty)
Hangs up a controlling terminal, when its session ends (its leader exited) or the terminal goes away:...
Definition generic.c:668
ssize_t tty_slave_write(struct tty *tty, size_t size, void *_buf)
Takes what programs write to the terminal, and sends it to the device through output processing (OPOS...
Definition generic.c:297
int tty_ioctl(struct tty *tty, int request, void *argp)
Handles a terminal's ioctl()s: its modes (TCGETS, TCSETS, ...), flushing, its session and foreground ...
Definition generic.c:455
int tty_free(struct tty *tty)
Ends a terminal: it is hung up, and freed.
Definition generic.c:718
ssize_t tty_write_iobuf(struct tty *tty, struct iobuf *io, ttyio write)
Writes to a terminal from an iobuf (user memory), to either side: a piece at a time through a kernel ...
Definition generic.c:408
int tty_new(struct proc *proc, size_t buf_size, ttyio master, ttyio slave, void *p, struct tty **ref)
Makes a new terminal, with the default modes (canonical, echo, signals, ICRNL, IXON,...
Definition generic.c:584
ssize_t tty_master_write(struct tty *tty, size_t size, void *buf)
Takes input from the terminal's device (the keyboard, a UART, or a pseudo-terminal's master),...
Definition generic.c:111
int tty_can_read(struct tty *tty, size_t buffered)
Says whether the terminal is readable, for select() and poll(): there is input, or an end-of-file.
Definition generic.c:240
int tty_eof(struct tty *tty)
Says whether a read that found nothing to return should return 0 at once: at an end-of-file (VEOF at ...
Definition generic.c:200
int tty_background(struct tty *tty, int sig)
Stops a background process that reads the terminal, writes it or changes it: if the current process i...
Definition generic.c:259
uint64_t tty_read_timeout(struct tty *tty)
Says how long a read waits for input: VTIME tenths of a second with VMIN 0 in non-canonical mode,...
Definition generic.c:221
void tty_open(struct tty *tty, struct file *file)
Handles a terminal device being opened: it becomes the controlling terminal of a session leader that ...
Definition generic.c:646
void tty_flush(struct tty *tty, int which)
Drops a terminal's input (TCIFLUSH, TCIOFLUSH): the line being edited, what the device holds for read...
Definition generic.c:691
unsigned long long int uint64_t
Definition stddef.h:23
An open file (POSIX's "open file description", fs/file.c).
Definition vfs.h:157
An iobuf.
Definition iobuf.h:35
A process group: the processes of a job.
Definition proc.h:56
A process.
Definition proc.h:75
A terminal, and its line discipline's state.
Definition tty.h:25
struct pgroup * fg
the foreground process group, or NULL
Definition tty.h:63
size_t size
the size of cook
Definition tty.h:30
int gone
Definition tty.h:54
int nl_owed
Definition tty.h:43
struct dev * dev
the terminal's device
Definition tty.h:57
ttyio master_write
writes to the master side: input, as if typed
Definition tty.h:74
size_t col
the output's column (for OPOST's ONOCR and ONLRET), and whether an ONLCR newline's CR was sent but no...
Definition tty.h:42
struct waitq start_wait
Definition tty.h:52
size_t pos
how much of cook is used
Definition tty.h:33
struct session * session
the session it is the controlling terminal of, or NULL
Definition tty.h:60
char * cook
the line being edited, in canonical mode
Definition tty.h:27
struct termios tios
Definition tty.h:45
struct winsize ws
Definition tty.h:46
int stopped
whether output is stopped (IXON: VSTOP came); writes wait on start_wait for VSTART.
Definition tty.h:51
void * p
the device's own data
Definition tty.h:71
int start_waiters
Definition tty.h:53
struct vnode * vnode
the device's vnode, which /dev/tty opens in its place
Definition tty.h:66
ttyio slave_write
writes to the slave side: output, for the device
Definition tty.h:77
void(*) input_flush(struct tty *tty)
discards the input that readers haven't read yet
Definition tty.h:80
int eof
how many end-of-files (VEOF at the start of a line) reads still have to return
Definition tty.h:37
Definition waitq.h:19
ssize_t(*) ttyio(struct tty *tty, size_t size, void *buf)
Definition tty.h:22
long int ssize_t
Definition types.h:12