2 * Unified handling of special chars.
4 * Copyright IBM Corp. 2001
5 * Author(s): Fritz Elfert <felfert@millenux.com> <elfert@de.ibm.com>
9 #include <linux/stddef.h>
10 #include <asm/errno.h>
11 #include <linux/sysrq.h>
12 #include <linux/ctype.h>
16 #ifdef CONFIG_MAGIC_SYSRQ
17 static int ctrlchar_sysrq_key
;
20 ctrlchar_handle_sysrq(struct work_struct
*work
)
22 handle_sysrq(ctrlchar_sysrq_key
);
25 static DECLARE_WORK(ctrlchar_work
, ctrlchar_handle_sysrq
);
30 * Check for special chars at start of input.
32 * @param buf Console input buffer.
33 * @param len Length of valid data in buffer.
34 * @param tty The tty struct for this console.
35 * @return CTRLCHAR_NONE, if nothing matched,
36 * CTRLCHAR_SYSRQ, if sysrq was encountered
37 * otherwise char to be inserted logically or'ed
41 ctrlchar_handle(const unsigned char *buf
, int len
, struct tty_struct
*tty
)
43 if ((len
< 2) || (len
> 3))
46 /* hat is 0xb1 in codepage 037 (US etc.) and thus */
47 /* converted to 0x5e in ascii ('^') */
48 if ((buf
[0] != '^') && (buf
[0] != '\252'))
51 #ifdef CONFIG_MAGIC_SYSRQ
53 if (len
== 3 && buf
[1] == '-') {
54 ctrlchar_sysrq_key
= buf
[2];
55 schedule_work(&ctrlchar_work
);
56 return CTRLCHAR_SYSRQ
;
63 switch (tolower(buf
[1])) {
65 return INTR_CHAR(tty
) | CTRLCHAR_CTRL
;
67 return EOF_CHAR(tty
) | CTRLCHAR_CTRL
;
69 return SUSP_CHAR(tty
) | CTRLCHAR_CTRL
;