2019-05-29 00:57:18 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-11-04 23:20:24 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Werner Fink, Jiri Slaby
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/tty_driver.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is handler for /proc/consoles
|
|
|
|
*/
|
|
|
|
static int show_console_dev(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
short flag;
|
|
|
|
char name;
|
|
|
|
} con_flags[] = {
|
|
|
|
{ CON_ENABLED, 'E' },
|
|
|
|
{ CON_CONSDEV, 'C' },
|
|
|
|
{ CON_BOOT, 'B' },
|
|
|
|
{ CON_PRINTBUFFER, 'p' },
|
|
|
|
{ CON_BRL, 'b' },
|
|
|
|
{ CON_ANYTIME, 'a' },
|
|
|
|
};
|
|
|
|
char flags[ARRAY_SIZE(con_flags) + 1];
|
|
|
|
struct console *con = v;
|
|
|
|
unsigned int a;
|
|
|
|
dev_t dev = 0;
|
|
|
|
|
|
|
|
if (con->device) {
|
|
|
|
const struct tty_driver *driver;
|
|
|
|
int index;
|
|
|
|
driver = con->device(con, &index);
|
|
|
|
if (driver) {
|
|
|
|
dev = MKDEV(driver->major, driver->minor_start);
|
|
|
|
dev += index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (a = 0; a < ARRAY_SIZE(con_flags); a++)
|
|
|
|
flags[a] = (con->flags & con_flags[a].flag) ?
|
|
|
|
con_flags[a].name : ' ';
|
|
|
|
flags[a] = 0;
|
|
|
|
|
2013-11-15 06:31:57 +08:00
|
|
|
seq_setwidth(m, 21 - 1);
|
|
|
|
seq_printf(m, "%s%d", con->name, con->index);
|
|
|
|
seq_pad(m, ' ');
|
|
|
|
seq_printf(m, "%c%c%c (%s)", con->read ? 'R' : '-',
|
2010-11-04 23:20:24 +08:00
|
|
|
con->write ? 'W' : '-', con->unblank ? 'U' : '-',
|
|
|
|
flags);
|
|
|
|
if (dev)
|
|
|
|
seq_printf(m, " %4d:%d", MAJOR(dev), MINOR(dev));
|
|
|
|
|
2018-02-07 07:37:34 +08:00
|
|
|
seq_putc(m, '\n');
|
2010-11-04 23:20:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *c_start(struct seq_file *m, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct console *con;
|
|
|
|
loff_t off = 0;
|
|
|
|
|
2011-01-26 07:07:35 +08:00
|
|
|
console_lock();
|
2010-11-04 23:20:24 +08:00
|
|
|
for_each_console(con)
|
|
|
|
if (off++ == *pos)
|
|
|
|
break;
|
|
|
|
|
|
|
|
return con;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct console *con = v;
|
|
|
|
++*pos;
|
|
|
|
return con->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void c_stop(struct seq_file *m, void *v)
|
|
|
|
{
|
2011-01-26 07:07:35 +08:00
|
|
|
console_unlock();
|
2010-11-04 23:20:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct seq_operations consoles_op = {
|
|
|
|
.start = c_start,
|
|
|
|
.next = c_next,
|
|
|
|
.stop = c_stop,
|
|
|
|
.show = show_console_dev
|
|
|
|
};
|
|
|
|
|
2011-01-13 09:00:36 +08:00
|
|
|
static int __init proc_consoles_init(void)
|
2010-11-04 23:20:24 +08:00
|
|
|
{
|
2018-04-14 01:44:18 +08:00
|
|
|
proc_create_seq("consoles", 0, NULL, &consoles_op);
|
2010-11-04 23:20:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-24 07:55:45 +08:00
|
|
|
fs_initcall(proc_consoles_init);
|