2 * proc_tty.c -- handles /proc/tty
4 * Copyright 1997, Theodore Ts'o
7 #include <asm/uaccess.h>
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/time.h>
12 #include <linux/proc_fs.h>
13 #include <linux/stat.h>
14 #include <linux/tty.h>
15 #include <linux/seq_file.h>
16 #include <asm/bitops.h>
18 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
19 int count, int *eof, void *data);
22 * The /proc/tty directory inodes...
24 static struct proc_dir_entry *proc_tty_ldisc, *proc_tty_driver;
27 * This is the handler for /proc/tty/drivers
29 static void show_tty_range(struct seq_file *m, struct tty_driver *p,
32 seq_printf(m, "%-20s ", p->driver_name ? p->driver_name : "unknown");
33 seq_printf(m, "/dev/%-8s ", p->name);
36 sprintf(range, "%d-%d", MINOR(from),
37 MINOR(from) + num - 1);
38 seq_printf(m, "%3d %7s ", MAJOR(from), range);
40 seq_printf(m, "%3d %7d ", MAJOR(from), MINOR(from));
43 case TTY_DRIVER_TYPE_SYSTEM:
44 seq_printf(m, "system");
45 if (p->subtype == SYSTEM_TYPE_TTY)
46 seq_printf(m, ":/dev/tty");
47 else if (p->subtype == SYSTEM_TYPE_SYSCONS)
48 seq_printf(m, ":console");
49 else if (p->subtype == SYSTEM_TYPE_CONSOLE)
50 seq_printf(m, ":vtmaster");
52 case TTY_DRIVER_TYPE_CONSOLE:
53 seq_printf(m, "console");
55 case TTY_DRIVER_TYPE_SERIAL:
56 seq_printf(m, "serial");
58 case TTY_DRIVER_TYPE_PTY:
59 if (p->subtype == PTY_TYPE_MASTER)
60 seq_printf(m, "pty:master");
61 else if (p->subtype == PTY_TYPE_SLAVE)
62 seq_printf(m, "pty:slave");
67 seq_printf(m, "type:%d.%d", p->type, p->subtype);
72 static int show_tty_driver(struct seq_file *m, void *v)
74 struct tty_driver *p = v;
75 dev_t from = MKDEV(p->major, p->minor_start);
76 dev_t to = from + p->num;
78 if (&p->tty_drivers == tty_drivers.next) {
79 /* pseudo-drivers first */
80 seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty");
81 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0);
82 seq_printf(m, "system:/dev/tty\n");
83 seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console");
84 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1);
85 seq_printf(m, "system:console\n");
86 #ifdef CONFIG_UNIX98_PTYS
87 seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx");
88 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2);
89 seq_printf(m, "system\n");
92 seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0");
93 seq_printf(m, "%3d %7d ", TTY_MAJOR, 0);
94 seq_printf(m, "system:vtmaster\n");
98 while (MAJOR(from) < MAJOR(to)) {
99 dev_t next = MKDEV(MAJOR(from)+1, 0);
100 show_tty_range(m, p, from, next - from);
104 show_tty_range(m, p, from, to - from);
109 static void *t_start(struct seq_file *m, loff_t *pos)
113 list_for_each(p, &tty_drivers)
115 return list_entry(p, struct tty_driver, tty_drivers);
119 static void *t_next(struct seq_file *m, void *v, loff_t *pos)
121 struct list_head *p = ((struct tty_driver *)v)->tty_drivers.next;
123 return p==&tty_drivers ? NULL :
124 list_entry(p, struct tty_driver, tty_drivers);
127 static void t_stop(struct seq_file *m, void *v)
131 static struct seq_operations tty_drivers_op = {
135 .show = show_tty_driver
138 static int tty_drivers_open(struct inode *inode, struct file *file)
140 return seq_open(file, &tty_drivers_op);
143 static struct file_operations proc_tty_drivers_operations = {
144 .open = tty_drivers_open,
147 .release = seq_release,
151 * This is the handler for /proc/tty/ldiscs
153 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
154 int count, int *eof, void *data)
159 struct tty_ldisc *ld;
161 for (i=0; i < NR_LDISCS; i++) {
162 ld = tty_ldisc_get(i);
165 len += sprintf(page+len, "%-10s %2d\n",
166 ld->name ? ld->name : "???", i);
168 if (len+begin > off+count)
170 if (len+begin < off) {
177 if (off >= len+begin)
179 *start = page + (off-begin);
180 return ((count < begin+len-off) ? count : begin+len-off);
184 * This function is called by tty_register_driver() to handle
185 * registering the driver's /proc handler into /proc/tty/driver/<foo>
187 void proc_tty_register_driver(struct tty_driver *driver)
189 struct proc_dir_entry *ent;
191 if ((!driver->read_proc && !driver->write_proc) ||
192 !driver->driver_name ||
196 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
199 ent->read_proc = driver->read_proc;
200 ent->write_proc = driver->write_proc;
201 ent->owner = driver->owner;
204 driver->proc_entry = ent;
208 * This function is called by tty_unregister_driver()
210 void proc_tty_unregister_driver(struct tty_driver *driver)
212 struct proc_dir_entry *ent;
214 ent = driver->proc_entry;
218 remove_proc_entry(driver->driver_name, proc_tty_driver);
220 driver->proc_entry = NULL;
224 * Called by proc_root_init() to initialize the /proc/tty subtree
226 void __init proc_tty_init(void)
228 struct proc_dir_entry *entry;
229 if (!proc_mkdir("tty", NULL))
231 proc_tty_ldisc = proc_mkdir("tty/ldisc", NULL);
233 * /proc/tty/driver/serial reveals the exact character counts for
234 * serial links which is just too easy to abuse for inferring
235 * password lengths and inter-keystroke timings during password
238 proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR | S_IXUSR, NULL);
240 create_proc_read_entry("tty/ldiscs", 0, NULL, tty_ldiscs_read_proc, NULL);
241 entry = create_proc_entry("tty/drivers", 0, NULL);
243 entry->proc_fops = &proc_tty_drivers_operations;