ctrlchar.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * drivers/s390/char/ctrlchar.c
  3. * Unified handling of special chars.
  4. *
  5. * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Fritz Elfert <felfert@millenux.com> <elfert@de.ibm.com>
  7. *
  8. */
  9. #include <linux/stddef.h>
  10. #include <asm/errno.h>
  11. #include <linux/sysrq.h>
  12. #include <linux/ctype.h>
  13. #include "ctrlchar.h"
  14. #ifdef CONFIG_MAGIC_SYSRQ
  15. static int ctrlchar_sysrq_key;
  16. static struct tty_struct *sysrq_tty;
  17. static void
  18. ctrlchar_handle_sysrq(struct work_struct *work)
  19. {
  20. handle_sysrq(ctrlchar_sysrq_key, sysrq_tty);
  21. }
  22. static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
  23. #endif
  24. /**
  25. * Check for special chars at start of input.
  26. *
  27. * @param buf Console input buffer.
  28. * @param len Length of valid data in buffer.
  29. * @param tty The tty struct for this console.
  30. * @return CTRLCHAR_NONE, if nothing matched,
  31. * CTRLCHAR_SYSRQ, if sysrq was encountered
  32. * otherwise char to be inserted logically or'ed
  33. * with CTRLCHAR_CTRL
  34. */
  35. unsigned int
  36. ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
  37. {
  38. if ((len < 2) || (len > 3))
  39. return CTRLCHAR_NONE;
  40. /* hat is 0xb1 in codepage 037 (US etc.) and thus */
  41. /* converted to 0x5e in ascii ('^') */
  42. if ((buf[0] != '^') && (buf[0] != '\252'))
  43. return CTRLCHAR_NONE;
  44. #ifdef CONFIG_MAGIC_SYSRQ
  45. /* racy */
  46. if (len == 3 && buf[1] == '-') {
  47. ctrlchar_sysrq_key = buf[2];
  48. sysrq_tty = tty;
  49. schedule_work(&ctrlchar_work);
  50. return CTRLCHAR_SYSRQ;
  51. }
  52. #endif
  53. if (len != 2)
  54. return CTRLCHAR_NONE;
  55. switch (tolower(buf[1])) {
  56. case 'c':
  57. return INTR_CHAR(tty) | CTRLCHAR_CTRL;
  58. case 'd':
  59. return EOF_CHAR(tty) | CTRLCHAR_CTRL;
  60. case 'z':
  61. return SUSP_CHAR(tty) | CTRLCHAR_CTRL;
  62. }
  63. return CTRLCHAR_NONE;
  64. }