consoles.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_putc(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 __init proc_consoles_init(void)
  82. {
  83. proc_create_seq("consoles", 0, NULL, &consoles_op);
  84. return 0;
  85. }
  86. fs_initcall(proc_consoles_init);