Blame view
fs/proc/proc_tty.c
4.47 KB
b24413180
|
1 |
// SPDX-License-Identifier: GPL-2.0 |
1da177e4c
|
2 3 4 5 6 |
/* * proc_tty.c -- handles /proc/tty * * Copyright 1997, Theodore Ts'o */ |
7c0f6ba68
|
7 |
#include <linux/uaccess.h> |
b640a89dd
|
8 |
#include <linux/module.h> |
1da177e4c
|
9 10 11 12 13 14 15 16 |
#include <linux/init.h> #include <linux/errno.h> #include <linux/time.h> #include <linux/proc_fs.h> #include <linux/stat.h> #include <linux/tty.h> #include <linux/seq_file.h> #include <linux/bitops.h> |
c79dde629
|
17 |
#include "internal.h" |
1da177e4c
|
18 |
|
1da177e4c
|
19 20 21 |
/* * The /proc/tty directory inodes... */ |
849d20a12
|
22 |
static struct proc_dir_entry *proc_tty_driver; |
1da177e4c
|
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* * This is the handler for /proc/tty/drivers */ static void show_tty_range(struct seq_file *m, struct tty_driver *p, dev_t from, int num) { seq_printf(m, "%-20s ", p->driver_name ? p->driver_name : "unknown"); seq_printf(m, "/dev/%-8s ", p->name); if (p->num > 1) { seq_printf(m, "%3d %d-%d ", MAJOR(from), MINOR(from), MINOR(from) + num - 1); } else { seq_printf(m, "%3d %7d ", MAJOR(from), MINOR(from)); } switch (p->type) { case TTY_DRIVER_TYPE_SYSTEM: |
9d6de12f7
|
40 |
seq_puts(m, "system"); |
1da177e4c
|
41 |
if (p->subtype == SYSTEM_TYPE_TTY) |
9d6de12f7
|
42 |
seq_puts(m, ":/dev/tty"); |
1da177e4c
|
43 |
else if (p->subtype == SYSTEM_TYPE_SYSCONS) |
9d6de12f7
|
44 |
seq_puts(m, ":console"); |
1da177e4c
|
45 |
else if (p->subtype == SYSTEM_TYPE_CONSOLE) |
9d6de12f7
|
46 |
seq_puts(m, ":vtmaster"); |
1da177e4c
|
47 48 |
break; case TTY_DRIVER_TYPE_CONSOLE: |
9d6de12f7
|
49 |
seq_puts(m, "console"); |
1da177e4c
|
50 51 |
break; case TTY_DRIVER_TYPE_SERIAL: |
9d6de12f7
|
52 |
seq_puts(m, "serial"); |
1da177e4c
|
53 54 55 |
break; case TTY_DRIVER_TYPE_PTY: if (p->subtype == PTY_TYPE_MASTER) |
9d6de12f7
|
56 |
seq_puts(m, "pty:master"); |
1da177e4c
|
57 |
else if (p->subtype == PTY_TYPE_SLAVE) |
9d6de12f7
|
58 |
seq_puts(m, "pty:slave"); |
1da177e4c
|
59 |
else |
9d6de12f7
|
60 |
seq_puts(m, "pty"); |
1da177e4c
|
61 62 63 64 65 66 67 68 69 70 |
break; default: seq_printf(m, "type:%d.%d", p->type, p->subtype); } seq_putc(m, ' '); } static int show_tty_driver(struct seq_file *m, void *v) { |
25216b003
|
71 |
struct tty_driver *p = list_entry(v, struct tty_driver, tty_drivers); |
1da177e4c
|
72 73 74 75 76 77 78 |
dev_t from = MKDEV(p->major, p->minor_start); dev_t to = from + p->num; if (&p->tty_drivers == tty_drivers.next) { /* pseudo-drivers first */ seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty"); seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0); |
9d6de12f7
|
79 80 |
seq_puts(m, "system:/dev/tty "); |
1da177e4c
|
81 82 |
seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console"); seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1); |
9d6de12f7
|
83 84 |
seq_puts(m, "system:console "); |
1da177e4c
|
85 86 87 |
#ifdef CONFIG_UNIX98_PTYS seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx"); seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2); |
9d6de12f7
|
88 89 |
seq_puts(m, "system "); |
1da177e4c
|
90 91 92 93 |
#endif #ifdef CONFIG_VT seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0"); seq_printf(m, "%3d %7d ", TTY_MAJOR, 0); |
9d6de12f7
|
94 95 |
seq_puts(m, "system:vtmaster "); |
1da177e4c
|
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#endif } while (MAJOR(from) < MAJOR(to)) { dev_t next = MKDEV(MAJOR(from)+1, 0); show_tty_range(m, p, from, next - from); from = next; } if (from != to) show_tty_range(m, p, from, to - from); return 0; } /* iterator */ static void *t_start(struct seq_file *m, loff_t *pos) { |
ca509f69d
|
112 |
mutex_lock(&tty_mutex); |
25216b003
|
113 |
return seq_list_start(&tty_drivers, *pos); |
1da177e4c
|
114 115 116 117 |
} static void *t_next(struct seq_file *m, void *v, loff_t *pos) { |
25216b003
|
118 |
return seq_list_next(v, &tty_drivers, pos); |
1da177e4c
|
119 120 121 122 |
} static void t_stop(struct seq_file *m, void *v) { |
ca509f69d
|
123 |
mutex_unlock(&tty_mutex); |
1da177e4c
|
124 |
} |
03a44825b
|
125 |
static const struct seq_operations tty_drivers_op = { |
1da177e4c
|
126 127 128 129 130 |
.start = t_start, .next = t_next, .stop = t_stop, .show = show_tty_driver }; |
1da177e4c
|
131 132 133 134 135 136 137 138 |
/* * This function is called by tty_register_driver() to handle * registering the driver's /proc handler into /proc/tty/driver/<foo> */ void proc_tty_register_driver(struct tty_driver *driver) { struct proc_dir_entry *ent; |
0f043a81e
|
139 |
if (!driver->driver_name || driver->proc_entry || |
8a8dcabff
|
140 |
!driver->ops->proc_show) |
1da177e4c
|
141 |
return; |
8a8dcabff
|
142 143 |
ent = proc_create_single_data(driver->driver_name, 0, proc_tty_driver, driver->ops->proc_show, driver); |
1da177e4c
|
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
driver->proc_entry = ent; } /* * This function is called by tty_unregister_driver() */ void proc_tty_unregister_driver(struct tty_driver *driver) { struct proc_dir_entry *ent; ent = driver->proc_entry; if (!ent) return; |
c79dde629
|
158 |
remove_proc_entry(ent->name, proc_tty_driver); |
1da177e4c
|
159 160 161 162 163 164 165 166 167 |
driver->proc_entry = NULL; } /* * Called by proc_root_init() to initialize the /proc/tty subtree */ void __init proc_tty_init(void) { |
1da177e4c
|
168 169 |
if (!proc_mkdir("tty", NULL)) return; |
849d20a12
|
170 |
proc_mkdir("tty/ldisc", NULL); /* Preserved: it's userspace visible */ |
1da177e4c
|
171 172 173 174 175 176 |
/* * /proc/tty/driver/serial reveals the exact character counts for * serial links which is just too easy to abuse for inferring * password lengths and inter-keystroke timings during password * entry. */ |
b640a89dd
|
177 |
proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL); |
fddda2b7b
|
178 179 |
proc_create_seq("tty/ldiscs", 0, NULL, &tty_ldiscs_seq_ops); proc_create_seq("tty/drivers", 0, NULL, &tty_drivers_op); |
1da177e4c
|
180 |
} |