Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / fs / proc / consoles.c
bloba8ac48aebd59dd2e33fc32539396b2fe98e02f3e
1 /*
2 * Copyright (c) 2010 Werner Fink, Jiri Slaby
4 * Licensed under GPLv2
5 */
7 #include <linux/console.h>
8 #include <linux/kernel.h>
9 #include <linux/proc_fs.h>
10 #include <linux/seq_file.h>
11 #include <linux/tty_driver.h>
14 * This is handler for /proc/consoles
16 static int show_console_dev(struct seq_file *m, void *v)
18 static const struct {
19 short flag;
20 char name;
21 } con_flags[] = {
22 { CON_ENABLED, 'E' },
23 { CON_CONSDEV, 'C' },
24 { CON_BOOT, 'B' },
25 { CON_PRINTBUFFER, 'p' },
26 { CON_BRL, 'b' },
27 { CON_ANYTIME, 'a' },
29 char flags[ARRAY_SIZE(con_flags) + 1];
30 struct console *con = v;
31 unsigned int a;
32 dev_t dev = 0;
34 if (con->device) {
35 const struct tty_driver *driver;
36 int index;
37 driver = con->device(con, &index);
38 if (driver) {
39 dev = MKDEV(driver->major, driver->minor_start);
40 dev += index;
44 for (a = 0; a < ARRAY_SIZE(con_flags); a++)
45 flags[a] = (con->flags & con_flags[a].flag) ?
46 con_flags[a].name : ' ';
47 flags[a] = 0;
49 seq_setwidth(m, 21 - 1);
50 seq_printf(m, "%s%d", con->name, con->index);
51 seq_pad(m, ' ');
52 seq_printf(m, "%c%c%c (%s)", con->read ? 'R' : '-',
53 con->write ? 'W' : '-', con->unblank ? 'U' : '-',
54 flags);
55 if (dev)
56 seq_printf(m, " %4d:%d", MAJOR(dev), MINOR(dev));
58 seq_putc(m, '\n');
59 return 0;
62 static void *c_start(struct seq_file *m, loff_t *pos)
64 struct console *con;
65 loff_t off = 0;
67 console_lock();
68 for_each_console(con)
69 if (off++ == *pos)
70 break;
72 return con;
75 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
77 struct console *con = v;
78 ++*pos;
79 return con->next;
82 static void c_stop(struct seq_file *m, void *v)
84 console_unlock();
87 static const struct seq_operations consoles_op = {
88 .start = c_start,
89 .next = c_next,
90 .stop = c_stop,
91 .show = show_console_dev
94 static int consoles_open(struct inode *inode, struct file *file)
96 return seq_open(file, &consoles_op);
99 static const struct file_operations proc_consoles_operations = {
100 .open = consoles_open,
101 .read = seq_read,
102 .llseek = seq_lseek,
103 .release = seq_release,
106 static int __init proc_consoles_init(void)
108 proc_create("consoles", 0, NULL, &proc_consoles_operations);
109 return 0;
111 fs_initcall(proc_consoles_init);