consoles.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2010 Werner Fink, Jiri Slaby
  3. *
  4. * Licensed under GPLv2
  5. */
  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>
  11. /*
  12. * This is handler for /proc/consoles
  13. */
  14. static int show_console_dev(struct seq_file *m, void *v)
  15. {
  16. static const struct {
  17. short flag;
  18. char name;
  19. } con_flags[] = {
  20. { CON_ENABLED, 'E' },
  21. { CON_CONSDEV, 'C' },
  22. { CON_BOOT, 'B' },
  23. { CON_PRINTBUFFER, 'p' },
  24. { CON_BRL, 'b' },
  25. { CON_ANYTIME, 'a' },
  26. };
  27. char flags[ARRAY_SIZE(con_flags) + 1];
  28. struct console *con = v;
  29. unsigned int a;
  30. dev_t dev = 0;
  31. if (con->device) {
  32. const struct tty_driver *driver;
  33. int index;
  34. driver = con->device(con, &index);
  35. if (driver) {
  36. dev = MKDEV(driver->major, driver->minor_start);
  37. dev += index;
  38. }
  39. }
  40. for (a = 0; a < ARRAY_SIZE(con_flags); a++)
  41. flags[a] = (con->flags & con_flags[a].flag) ?
  42. con_flags[a].name : ' ';
  43. flags[a] = 0;
  44. seq_setwidth(m, 21 - 1);
  45. seq_printf(m, "%s%d", con->name, con->index);
  46. seq_pad(m, ' ');
  47. seq_printf(m, "%c%c%c (%s)", con->read ? 'R' : '-',
  48. con->write ? 'W' : '-', con->unblank ? 'U' : '-',
  49. flags);
  50. if (dev)
  51. seq_printf(m, " %4d:%d", MAJOR(dev), MINOR(dev));
  52. seq_printf(m, "\n");
  53. return 0;
  54. }
  55. static void *c_start(struct seq_file *m, loff_t *pos)
  56. {
  57. struct console *con;
  58. loff_t off = 0;
  59. console_lock();
  60. for_each_console(con)
  61. if (off++ == *pos)
  62. break;
  63. return con;
  64. }
  65. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  66. {
  67. struct console *con = v;
  68. ++*pos;
  69. return con->next;
  70. }
  71. static void c_stop(struct seq_file *m, void *v)
  72. {
  73. console_unlock();
  74. }
  75. static const struct seq_operations consoles_op = {
  76. .start = c_start,
  77. .next = c_next,
  78. .stop = c_stop,
  79. .show = show_console_dev
  80. };
  81. static int consoles_open(struct inode *inode, struct file *file)
  82. {
  83. return seq_open(file, &consoles_op);
  84. }
  85. static const struct file_operations proc_consoles_operations = {
  86. .open = consoles_open,
  87. .read = seq_read,
  88. .llseek = seq_lseek,
  89. .release = seq_release,
  90. };
  91. static int __init proc_consoles_init(void)
  92. {
  93. proc_create("consoles", 0, NULL, &proc_consoles_operations);
  94. return 0;
  95. }
  96. fs_initcall(proc_consoles_init);