ctrlchar.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 void
  17. ctrlchar_handle_sysrq(struct work_struct *work)
  18. {
  19. handle_sysrq(ctrlchar_sysrq_key);
  20. }
  21. static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
  22. #endif
  23. /**
  24. * Check for special chars at start of input.
  25. *
  26. * @param buf Console input buffer.
  27. * @param len Length of valid data in buffer.
  28. * @param tty The tty struct for this console.
  29. * @return CTRLCHAR_NONE, if nothing matched,
  30. * CTRLCHAR_SYSRQ, if sysrq was encountered
  31. * otherwise char to be inserted logically or'ed
  32. * with CTRLCHAR_CTRL
  33. */
  34. unsigned int
  35. ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
  36. {
  37. if ((len < 2) || (len > 3))
  38. return CTRLCHAR_NONE;
  39. /* hat is 0xb1 in codepage 037 (US etc.) and thus */
  40. /* converted to 0x5e in ascii ('^') */
  41. if ((buf[0] != '^') && (buf[0] != '\252'))
  42. return CTRLCHAR_NONE;
  43. #ifdef CONFIG_MAGIC_SYSRQ
  44. /* racy */
  45. if (len == 3 && buf[1] == '-') {
  46. ctrlchar_sysrq_key = buf[2];
  47. schedule_work(&ctrlchar_work);
  48. return CTRLCHAR_SYSRQ;
  49. }
  50. #endif
  51. if (len != 2)
  52. return CTRLCHAR_NONE;
  53. switch (tolower(buf[1])) {
  54. case 'c':
  55. return INTR_CHAR(tty) | CTRLCHAR_CTRL;
  56. case 'd':
  57. return EOF_CHAR(tty) | CTRLCHAR_CTRL;
  58. case 'z':
  59. return SUSP_CHAR(tty) | CTRLCHAR_CTRL;
  60. }
  61. return CTRLCHAR_NONE;
  62. }