1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2010 Werner Fink, Jiri Slaby
6 #include <linux/console.h>
7 #include <linux/kernel.h>
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <linux/tty_driver.h>
13 * This is handler for /proc/consoles
15 static int show_console_dev(struct seq_file *m, void *v)
25 { CON_PRINTBUFFER, 'p' },
29 char flags[ARRAY_SIZE(con_flags) + 1];
30 struct console *con = v;
35 const struct tty_driver *driver;
39 * Take console_lock to serialize device() callback with
40 * other console operations. For example, fg_console is
41 * modified under console_lock when switching vt.
44 driver = con->device(con, &index);
48 dev = MKDEV(driver->major, driver->minor_start);
53 for (a = 0; a < ARRAY_SIZE(con_flags); a++)
54 flags[a] = (con->flags & con_flags[a].flag) ?
55 con_flags[a].name : ' ';
58 seq_setwidth(m, 21 - 1);
59 seq_printf(m, "%s%d", con->name, con->index);
61 seq_printf(m, "%c%c%c (%s)", con->read ? 'R' : '-',
62 ((con->flags & CON_NBCON) || con->write) ? 'W' : '-',
63 con->unblank ? 'U' : '-', flags);
65 seq_printf(m, " %4d:%d", MAJOR(dev), MINOR(dev));
71 static void *c_start(struct seq_file *m, loff_t *pos)
72 __acquires(&console_mutex)
78 * Hold the console_list_lock to guarantee safe traversal of the
79 * console list. SRCU cannot be used because there is no
80 * place to store the SRCU cookie.
90 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
92 struct console *con = v;
95 return hlist_entry_safe(con->node.next, struct console, node);
98 static void c_stop(struct seq_file *m, void *v)
99 __releases(&console_mutex)
101 console_list_unlock();
104 static const struct seq_operations consoles_op = {
108 .show = show_console_dev
111 static int __init proc_consoles_init(void)
113 proc_create_seq("consoles", 0, NULL, &consoles_op);
116 fs_initcall(proc_consoles_init);