Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux-2.6/libata-dev.git] / drivers / s390 / char / ctrlchar.c
blob8de2deb176d716daf043e9c80afd1536043eb94b
1 /*
2 * Unified handling of special chars.
4 * Copyright IBM Corp. 2001
5 * Author(s): Fritz Elfert <felfert@millenux.com> <elfert@de.ibm.com>
7 */
9 #include <linux/stddef.h>
10 #include <asm/errno.h>
11 #include <linux/sysrq.h>
12 #include <linux/ctype.h>
14 #include "ctrlchar.h"
16 #ifdef CONFIG_MAGIC_SYSRQ
17 static int ctrlchar_sysrq_key;
19 static void
20 ctrlchar_handle_sysrq(struct work_struct *work)
22 handle_sysrq(ctrlchar_sysrq_key);
25 static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
26 #endif
29 /**
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
38 * with CTRLCHAR_CTRL
40 unsigned int
41 ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
43 if ((len < 2) || (len > 3))
44 return CTRLCHAR_NONE;
46 /* hat is 0xb1 in codepage 037 (US etc.) and thus */
47 /* converted to 0x5e in ascii ('^') */
48 if ((buf[0] != '^') && (buf[0] != '\252'))
49 return CTRLCHAR_NONE;
51 #ifdef CONFIG_MAGIC_SYSRQ
52 /* racy */
53 if (len == 3 && buf[1] == '-') {
54 ctrlchar_sysrq_key = buf[2];
55 schedule_work(&ctrlchar_work);
56 return CTRLCHAR_SYSRQ;
58 #endif
60 if (len != 2)
61 return CTRLCHAR_NONE;
63 switch (tolower(buf[1])) {
64 case 'c':
65 return INTR_CHAR(tty) | CTRLCHAR_CTRL;
66 case 'd':
67 return EOF_CHAR(tty) | CTRLCHAR_CTRL;
68 case 'z':
69 return SUSP_CHAR(tty) | CTRLCHAR_CTRL;
71 return CTRLCHAR_NONE;