ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / fs / proc / proc_tty.c
blob21f490f5d65ce1f96eb37095516eddb3c80aa4f8
1 /*
2 * proc_tty.c -- handles /proc/tty
4 * Copyright 1997, Theodore Ts'o
5 */
7 #include <asm/uaccess.h>
8 #include <linux/module.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 <linux/bitops.h>
19 * The /proc/tty directory inodes...
21 static struct proc_dir_entry *proc_tty_ldisc, *proc_tty_driver;
24 * This is the handler for /proc/tty/drivers
26 static void show_tty_range(struct seq_file *m, struct tty_driver *p,
27 dev_t from, int num)
29 seq_printf(m, "%-20s ", p->driver_name ? p->driver_name : "unknown");
30 seq_printf(m, "/dev/%-8s ", p->name);
31 if (p->num > 1) {
32 seq_printf(m, "%3d %d-%d ", MAJOR(from), MINOR(from),
33 MINOR(from) + num - 1);
34 } else {
35 seq_printf(m, "%3d %7d ", MAJOR(from), MINOR(from));
37 switch (p->type) {
38 case TTY_DRIVER_TYPE_SYSTEM:
39 seq_printf(m, "system");
40 if (p->subtype == SYSTEM_TYPE_TTY)
41 seq_printf(m, ":/dev/tty");
42 else if (p->subtype == SYSTEM_TYPE_SYSCONS)
43 seq_printf(m, ":console");
44 else if (p->subtype == SYSTEM_TYPE_CONSOLE)
45 seq_printf(m, ":vtmaster");
46 break;
47 case TTY_DRIVER_TYPE_CONSOLE:
48 seq_printf(m, "console");
49 break;
50 case TTY_DRIVER_TYPE_SERIAL:
51 seq_printf(m, "serial");
52 break;
53 case TTY_DRIVER_TYPE_PTY:
54 if (p->subtype == PTY_TYPE_MASTER)
55 seq_printf(m, "pty:master");
56 else if (p->subtype == PTY_TYPE_SLAVE)
57 seq_printf(m, "pty:slave");
58 else
59 seq_printf(m, "pty");
60 break;
61 default:
62 seq_printf(m, "type:%d.%d", p->type, p->subtype);
64 seq_putc(m, '\n');
67 static int show_tty_driver(struct seq_file *m, void *v)
69 struct tty_driver *p = list_entry(v, struct tty_driver, tty_drivers);
70 dev_t from = MKDEV(p->major, p->minor_start);
71 dev_t to = from + p->num;
73 if (&p->tty_drivers == tty_drivers.next) {
74 /* pseudo-drivers first */
75 seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty");
76 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0);
77 seq_printf(m, "system:/dev/tty\n");
78 seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console");
79 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1);
80 seq_printf(m, "system:console\n");
81 #ifdef CONFIG_UNIX98_PTYS
82 seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx");
83 seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2);
84 seq_printf(m, "system\n");
85 #endif
86 #ifdef CONFIG_VT
87 seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0");
88 seq_printf(m, "%3d %7d ", TTY_MAJOR, 0);
89 seq_printf(m, "system:vtmaster\n");
90 #endif
93 while (MAJOR(from) < MAJOR(to)) {
94 dev_t next = MKDEV(MAJOR(from)+1, 0);
95 show_tty_range(m, p, from, next - from);
96 from = next;
98 if (from != to)
99 show_tty_range(m, p, from, to - from);
100 return 0;
103 /* iterator */
104 static void *t_start(struct seq_file *m, loff_t *pos)
106 mutex_lock(&tty_mutex);
107 return seq_list_start(&tty_drivers, *pos);
110 static void *t_next(struct seq_file *m, void *v, loff_t *pos)
112 return seq_list_next(v, &tty_drivers, pos);
115 static void t_stop(struct seq_file *m, void *v)
117 mutex_unlock(&tty_mutex);
120 static const struct seq_operations tty_drivers_op = {
121 .start = t_start,
122 .next = t_next,
123 .stop = t_stop,
124 .show = show_tty_driver
127 static int tty_drivers_open(struct inode *inode, struct file *file)
129 return seq_open(file, &tty_drivers_op);
132 static const struct file_operations proc_tty_drivers_operations = {
133 .open = tty_drivers_open,
134 .read = seq_read,
135 .llseek = seq_lseek,
136 .release = seq_release,
139 static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
141 return (*pos < NR_LDISCS) ? pos : NULL;
144 static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
146 (*pos)++;
147 return (*pos < NR_LDISCS) ? pos : NULL;
150 static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
154 static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
156 int i = *(loff_t *)v;
157 struct tty_ldisc *ld;
159 ld = tty_ldisc_get(i);
160 if (ld == NULL)
161 return 0;
162 seq_printf(m, "%-10s %2d\n", ld->name ? ld->name : "???", i);
163 tty_ldisc_put(i);
164 return 0;
167 static const struct seq_operations tty_ldiscs_seq_ops = {
168 .start = tty_ldiscs_seq_start,
169 .next = tty_ldiscs_seq_next,
170 .stop = tty_ldiscs_seq_stop,
171 .show = tty_ldiscs_seq_show,
174 static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
176 return seq_open(file, &tty_ldiscs_seq_ops);
179 static const struct file_operations tty_ldiscs_proc_fops = {
180 .owner = THIS_MODULE,
181 .open = proc_tty_ldiscs_open,
182 .read = seq_read,
183 .llseek = seq_lseek,
184 .release = seq_release,
188 * This function is called by tty_register_driver() to handle
189 * registering the driver's /proc handler into /proc/tty/driver/<foo>
191 void proc_tty_register_driver(struct tty_driver *driver)
193 struct proc_dir_entry *ent;
195 if (!driver->ops->read_proc || !driver->driver_name ||
196 driver->proc_entry)
197 return;
199 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
200 if (!ent)
201 return;
202 ent->read_proc = driver->ops->read_proc;
203 ent->owner = driver->owner;
204 ent->data = driver;
206 driver->proc_entry = ent;
210 * This function is called by tty_unregister_driver()
212 void proc_tty_unregister_driver(struct tty_driver *driver)
214 struct proc_dir_entry *ent;
216 ent = driver->proc_entry;
217 if (!ent)
218 return;
220 remove_proc_entry(driver->driver_name, proc_tty_driver);
222 driver->proc_entry = NULL;
226 * Called by proc_root_init() to initialize the /proc/tty subtree
228 void __init proc_tty_init(void)
230 if (!proc_mkdir("tty", NULL))
231 return;
232 proc_tty_ldisc = proc_mkdir("tty/ldisc", NULL);
234 * /proc/tty/driver/serial reveals the exact character counts for
235 * serial links which is just too easy to abuse for inferring
236 * password lengths and inter-keystroke timings during password
237 * entry.
239 proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
240 proc_create("tty/ldiscs", 0, NULL, &tty_ldiscs_proc_fops);
241 proc_create("tty/drivers", 0, NULL, &proc_tty_drivers_operations);