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/sched.h>
12 #include <linux/proc_fs.h>
13 #include <linux/stat.h>
14 #include <linux/tty.h>
15 #include <asm/bitops.h>
17 extern struct tty_driver *tty_drivers; /* linked list of tty drivers */
19 static int tty_drivers_read_proc(char *page, char **start, off_t off,
20 int count, int *eof, void *data);
21 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
22 int count, int *eof, void *data);
25 * The /proc/tty directory inodes...
27 static struct proc_dir_entry *proc_tty_ldisc, *proc_tty_driver;
30 * This is the handler for /proc/tty/drivers
32 static int tty_drivers_read_proc(char *page, char **start, off_t off,
33 int count, int *eof, void *data)
38 char range[20], deftype[20];
41 for (p = tty_drivers; p; p = p->next) {
43 sprintf(range, "%d-%d", p->minor_start,
44 p->minor_start + p->num - 1);
46 sprintf(range, "%d", p->minor_start);
48 case TTY_DRIVER_TYPE_SYSTEM:
49 if (p->subtype == SYSTEM_TYPE_TTY)
50 type = "system:/dev/tty";
51 else if (p->subtype == SYSTEM_TYPE_SYSCONS)
52 type = "system:console";
53 else if (p->subtype == SYSTEM_TYPE_CONSOLE)
54 type = "system:vtmaster";
58 case TTY_DRIVER_TYPE_CONSOLE:
61 case TTY_DRIVER_TYPE_SERIAL:
63 type = "serial:callout";
67 case TTY_DRIVER_TYPE_PTY:
68 if (p->subtype == PTY_TYPE_MASTER)
70 else if (p->subtype == PTY_TYPE_SLAVE)
76 sprintf(deftype, "type:%d.%d", p->type, p->subtype);
80 len += sprintf(page+len, "%-20s /dev/%-8s %3d %7s %s\n",
81 p->driver_name ? p->driver_name : "unknown",
82 p->name, p->major, range, type);
83 if (len+begin > off+count)
85 if (len+begin < off) {
94 *start = page + (off-begin);
95 return ((count < begin+len-off) ? count : begin+len-off);
99 * This is the handler for /proc/tty/ldiscs
101 static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
102 int count, int *eof, void *data)
107 struct tty_ldisc *ld;
109 for (i=0; i < NR_LDISCS; i++) {
110 ld = tty_ldisc_get(i);
113 len += sprintf(page+len, "%-10s %2d\n",
114 ld->name ? ld->name : "???", i);
116 if (len+begin > off+count)
118 if (len+begin < off) {
125 if (off >= len+begin)
127 *start = page + (off-begin);
128 return ((count < begin+len-off) ? count : begin+len-off);
132 * This function is called by tty_register_driver() to handle
133 * registering the driver's /proc handler into /proc/tty/driver/<foo>
135 void proc_tty_register_driver(struct tty_driver *driver)
137 struct proc_dir_entry *ent;
139 if ((!driver->read_proc && !driver->write_proc) ||
140 !driver->driver_name ||
144 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
147 ent->read_proc = driver->read_proc;
148 ent->write_proc = driver->write_proc;
151 driver->proc_entry = ent;
155 * This function is called by tty_unregister_driver()
157 void proc_tty_unregister_driver(struct tty_driver *driver)
159 struct proc_dir_entry *ent;
161 ent = driver->proc_entry;
165 remove_proc_entry(driver->driver_name, proc_tty_driver);
167 driver->proc_entry = 0;
171 * Called by proc_root_init() to initialize the /proc/tty subtree
173 void __init proc_tty_init(void)
175 if (!proc_mkdir("tty", 0))
177 proc_tty_ldisc = proc_mkdir("tty/ldisc", 0);
179 * /proc/tty/driver/serial reveals the exact character counts for
180 * serial links which is just too easy to abuse for inferring
181 * password lengths and inter-keystroke timings during password
184 proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR | S_IXUSR, 0);
186 create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL);
187 create_proc_read_entry("tty/drivers", 0, 0, tty_drivers_read_proc,NULL);