From: Randy Dunlap Add /proc/consoles to list all registered consoles by name, along with their I/O capabilities and flags. Signed-off-by: Randy Dunlap --- kernel/printk.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+) --- linux-2616-rc6.orig/kernel/printk.c +++ linux-2616-rc6/kernel/printk.c @@ -27,8 +27,10 @@ #include /* For in_interrupt() */ #include #include +#include #include #include +#include #include #include @@ -1049,3 +1051,65 @@ int printk_ratelimit(void) printk_ratelimit_burst); } EXPORT_SYMBOL(printk_ratelimit); + +#ifdef CONFIG_PROC_FS +static int con_show(struct seq_file *m, void *v) +{ + struct console *con; + + acquire_console_sem(); + for (con = console_drivers; con; con = con->next) + printk("%d: %-8s %c:%c:%c flags:%s%s%s%s%s\n", + con->index, con->name, + con->read ? 'R' : 'x', + con->write ? 'W' : 'x', + con->unblank ? 'U' : 'x', + !con->flags ? " none" : "", + con->flags & CON_PRINTBUFFER ? " print" : "", + con->flags & CON_CONSDEV ? " consoledev" : "", + con->flags & CON_ENABLED ? " enabled" : "", + con->flags & CON_BOOT ? " boot" : ""); + + release_console_sem(); + return 0; +} + +static int consoles_open(struct inode *inode, struct file *file) +{ + struct seq_file *m; + int res; + char *buf; + unsigned int size = PAGE_SIZE; + + buf = kmalloc(size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + res = single_open(file, con_show, NULL); + if (!res) { + m = file->private_data; + m->buf = buf; + m->size = size; + } else + kfree(buf); + return res; +} + +static struct file_operations proc_consoles_operations = { + .open = consoles_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init consoles_init(void) +{ + struct proc_dir_entry *entry; + + entry = create_proc_entry("consoles", 0, NULL); + if (entry) + entry->proc_fops = &proc_consoles_operations; + return 0; +} +__initcall(consoles_init); +#endif /* CONFIG_PROC_FS */