blob: 954caf0b7fee0321b09372fd5d27ce00b43da6a7 [file] [log] [blame]
Jiri Slaby23308ba2010-11-04 16:20:24 +01001/*
2 * Copyright (c) 2010 Werner Fink, Jiri Slaby
3 *
4 * Licensed under GPLv2
5 */
6
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>
12
13/*
14 * This is handler for /proc/consoles
15 */
16static int show_console_dev(struct seq_file *m, void *v)
17{
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' },
28 };
29 char flags[ARRAY_SIZE(con_flags) + 1];
30 struct console *con = v;
31 unsigned int a;
Jiri Slaby23308ba2010-11-04 16:20:24 +010032 dev_t dev = 0;
33
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;
41 }
42 }
43
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;
48
Tetsuo Handa652586d2013-11-14 14:31:57 -080049 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' : '-',
Jiri Slaby23308ba2010-11-04 16:20:24 +010053 con->write ? 'W' : '-', con->unblank ? 'U' : '-',
54 flags);
55 if (dev)
56 seq_printf(m, " %4d:%d", MAJOR(dev), MINOR(dev));
57
Markus Elfring4bf8ba82018-02-06 15:37:34 -080058 seq_putc(m, '\n');
Jiri Slaby23308ba2010-11-04 16:20:24 +010059 return 0;
60}
61
62static void *c_start(struct seq_file *m, loff_t *pos)
63{
64 struct console *con;
65 loff_t off = 0;
66
Torben Hohnac751ef2011-01-25 15:07:35 -080067 console_lock();
Jiri Slaby23308ba2010-11-04 16:20:24 +010068 for_each_console(con)
69 if (off++ == *pos)
70 break;
71
72 return con;
73}
74
75static void *c_next(struct seq_file *m, void *v, loff_t *pos)
76{
77 struct console *con = v;
78 ++*pos;
79 return con->next;
80}
81
82static void c_stop(struct seq_file *m, void *v)
83{
Torben Hohnac751ef2011-01-25 15:07:35 -080084 console_unlock();
Jiri Slaby23308ba2010-11-04 16:20:24 +010085}
86
87static const struct seq_operations consoles_op = {
88 .start = c_start,
89 .next = c_next,
90 .stop = c_stop,
91 .show = show_console_dev
92};
93
Alexey Dobriyanbf33cbd2011-01-12 17:00:36 -080094static int __init proc_consoles_init(void)
Jiri Slaby23308ba2010-11-04 16:20:24 +010095{
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020096 proc_create_seq("consoles", 0, NULL, &consoles_op);
Jiri Slaby23308ba2010-11-04 16:20:24 +010097 return 0;
98}
Paul Gortmakerabaf3782014-01-23 15:55:45 -080099fs_initcall(proc_consoles_init);