AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
27
struct
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
45
static
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) {
59
vfs_close
(
tty
->
vnode
);
60
file
->vnode =
vnode
;
61
return
err;
62
}
63
64
vfs_close
(
vnode
);
65
return
0;
66
}
67
68
static
struct
dev
cttydev
= {
69
.name =
"ctty"
,
70
.fops = {
71
.open =
ctty_open
,
72
},
73
};
74
81
struct
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
109
int
ttydev_probe
()
110
{
111
kdev_chrdev_register
(4, &
sttydev
);
112
kdev_chrdev_register
(5, &
ttydev
);
113
return
0;
114
}
115
116
struct
dev
sttydev
= {
117
.name =
"sttydev"
,
118
.mux =
sttydev_mux
,
119
};
120
121
struct
dev
ttydev
= {
122
.name =
"ttydev"
,
123
.mux =
ttydev_mux
,
124
};
125
126
MODULE_INIT
(
ttydev
,
ttydev_probe
,
NULL
)
vfs_close
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
Definition
close.c:18
VNODE_DEV
#define VNODE_DEV(vnode)
Definition
dev.h:79
system.h
kdev_chrdev_register
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
kdev_file_open
int kdev_file_open(struct devid *dd, struct file *file)
Opens a device, through its driver's file operations.
Definition
kdev.c:381
module.h
MODULE_INIT
#define MODULE_INIT(name, i, f)
Definition
module.h:10
posix.h
ptmdev
struct dev ptmdev
Definition
pty.c:60
sched.h
curproc
#define curproc
Definition
sched.h:13
NULL
#define NULL
Definition
stddef.h:27
dev
A device driver: its operations, any of which may be NULL.
Definition
dev.h:28
devid
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
Definition
dev.h:21
devid::minor
devid_t minor
Definition
dev.h:24
file
An open file (POSIX's "open file description", fs/file.c).
Definition
vfs.h:157
tty
A terminal, and its line discipline's state.
Definition
tty.h:25
tty::vnode
struct vnode * vnode
the device's vnode, which /dev/tty opens in its place
Definition
tty.h:66
uart
A serial port.
Definition
uart.h:17
vnode
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition
vfs.h:113
vnode::ref
size_t ref
how many references there are to it
Definition
vfs.h:133
ttydev
struct dev ttydev
Definition
tty.c:121
ttydev_mux
struct dev * ttydev_mux(struct devid *dd)
Picks the driver of a terminal device of major 5, by its minor.
Definition
tty.c:81
cttydev
static struct dev cttydev
Definition
tty.c:68
ttydev_probe
int ttydev_probe()
Registers the terminal devices, majors 4 and 5.
Definition
tty.c:109
sttydev
struct dev sttydev
Definition
tty.c:116
sttydev_mux
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
ctty_open
static int ctty_open(struct file *file)
Opens /dev/tty: the file is made the controlling terminal's device instead.
Definition
tty.c:45
tty.h
ttydev.h
vfs.h
vtdev
struct dev vtdev
Definition
vt.c:774
vt.h
VT_COUNT
#define VT_COUNT
Definition
vt.h:22
kernel
dev
tty
tty.c
Generated by
1.18.0