AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
tty.c
Go to the documentation of this file.
1
10
11#include <core/system.h>
12#include <core/module.h>
13#include <dev/ttydev.h>
14#include <fs/posix.h>
15#include <sys/sched.h>
16#include <dev/tty.h>
17#include <dev/vt.h>
18#include <fs/vfs.h>
19
27struct dev *sttydev_mux(struct devid *dd)
28{
29#ifdef CONFIG_DEV_UART
30 if (dd->minor >= 64)
31 return &uart;
32#endif
33
34#ifdef CONFIG_DEV_CONSOLE
35 if (dd->minor <= VT_COUNT)
36 return &vtdev;
37#endif
38
39 return NULL;
40}
41
45static int ctty_open(struct file *file)
46{
47 struct tty *tty = curproc->pgrp->session->ctty;
48 struct vnode *vnode = file->vnode;
49
50 if (!tty || !tty->vnode)
51 return -ENXIO;
52
53 tty->vnode->ref++;
54 file->vnode = tty->vnode;
55
56 int err = kdev_file_open(&VNODE_DEV(tty->vnode), file);
57
58 if (err) {
60 file->vnode = vnode;
61 return err;
62 }
63
65 return 0;
66}
67
68static struct dev cttydev = {
69 .name = "ctty",
70 .fops = {
71 .open = ctty_open,
72 },
73};
74
81struct dev *ttydev_mux(struct devid *dd)
82{
83 switch (dd->minor) {
84 case 0: /* /dev/tty */
85 return &cttydev;
86 case 1: /* /dev/console: the first virtual terminal or, without
87 * them, the first UART (uart_get()) */
88#if defined(CONFIG_DEV_CONSOLE)
89 return &vtdev;
90#elif defined(CONFIG_DEV_UART)
91 return &uart;
92#else
93 return NULL;
94#endif
95#ifdef CONFIG_DEV_PTY
96 case 2: /* /dev/ptmx */
97 return &ptmdev;
98#endif
99 }
100
101 return NULL;
102}
103
110{
113 return 0;
114}
115
116struct dev sttydev = {
117 .name = "sttydev",
118 .mux = sttydev_mux,
119};
120
121struct dev ttydev = {
122 .name = "ttydev",
123 .mux = ttydev_mux,
124};
125
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
Definition close.c:18
#define VNODE_DEV(vnode)
Definition dev.h:79
void kdev_chrdev_register(devid_t major, struct dev *dev)
Registers a driver as the character device of a major number.
Definition kdev.c:575
int kdev_file_open(struct devid *dd, struct file *file)
Opens a device, through its driver's file operations.
Definition kdev.c:381
#define MODULE_INIT(name, i, f)
Definition module.h:10
struct dev ptmdev
Definition pty.c:60
#define curproc
Definition sched.h:13
#define NULL
Definition stddef.h:27
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition dev.h:21
devid_t minor
Definition dev.h:24
An open file (POSIX's "open file description", fs/file.c).
Definition vfs.h:157
A terminal, and its line discipline's state.
Definition tty.h:25
struct vnode * vnode
the device's vnode, which /dev/tty opens in its place
Definition tty.h:66
A serial port.
Definition uart.h:17
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
size_t ref
how many references there are to it
Definition vfs.h:133
struct dev ttydev
Definition tty.c:121
struct dev * ttydev_mux(struct devid *dd)
Picks the driver of a terminal device of major 5, by its minor.
Definition tty.c:81
static struct dev cttydev
Definition tty.c:68
int ttydev_probe()
Registers the terminal devices, majors 4 and 5.
Definition tty.c:109
struct dev sttydev
Definition tty.c:116
struct dev * sttydev_mux(struct devid *dd)
Picks the driver of a terminal of major 4, by its minor: the virtual terminals' for minors up to VT_C...
Definition tty.c:27
static int ctty_open(struct file *file)
Opens /dev/tty: the file is made the controlling terminal's device instead.
Definition tty.c:45
struct dev vtdev
Definition vt.c:774
#define VT_COUNT
Definition vt.h:22