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