aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/char/ctrlchar.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/s390/char/ctrlchar.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/s390/char/ctrlchar.c')
-rw-r--r--drivers/s390/char/ctrlchar.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/drivers/s390/char/ctrlchar.c b/drivers/s390/char/ctrlchar.c
new file mode 100644
index 000000000000..be463242cf0f
--- /dev/null
+++ b/drivers/s390/char/ctrlchar.c
@@ -0,0 +1,75 @@
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
10#include <linux/config.h>
11#include <linux/stddef.h>
12#include <asm/errno.h>
13#include <linux/sysrq.h>
14#include <linux/ctype.h>
15
16#include "ctrlchar.h"
17
18#ifdef CONFIG_MAGIC_SYSRQ
19static int ctrlchar_sysrq_key;
20
21static void
22ctrlchar_handle_sysrq(void *tty)
23{
24 handle_sysrq(ctrlchar_sysrq_key, NULL, (struct tty_struct *) tty);
25}
26
27static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq, 0);
28#endif
29
30
31/**
32 * Check for special chars at start of input.
33 *
34 * @param buf Console input buffer.
35 * @param len Length of valid data in buffer.
36 * @param tty The tty struct for this console.
37 * @return CTRLCHAR_NONE, if nothing matched,
38 * CTRLCHAR_SYSRQ, if sysrq was encountered
39 * otherwise char to be inserted logically or'ed
40 * with CTRLCHAR_CTRL
41 */
42unsigned int
43ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
44{
45 if ((len < 2) || (len > 3))
46 return CTRLCHAR_NONE;
47
48 /* hat is 0xb1 in codepage 037 (US etc.) and thus */
49 /* converted to 0x5e in ascii ('^') */
50 if ((buf[0] != '^') && (buf[0] != '\252'))
51 return CTRLCHAR_NONE;
52
53#ifdef CONFIG_MAGIC_SYSRQ
54 /* racy */
55 if (len == 3 && buf[1] == '-') {
56 ctrlchar_sysrq_key = buf[2];
57 ctrlchar_work.data = tty;
58 schedule_work(&ctrlchar_work);
59 return CTRLCHAR_SYSRQ;
60 }
61#endif
62
63 if (len != 2)
64 return CTRLCHAR_NONE;
65
66 switch (tolower(buf[1])) {
67 case 'c':
68 return INTR_CHAR(tty) | CTRLCHAR_CTRL;
69 case 'd':
70 return EOF_CHAR(tty) | CTRLCHAR_CTRL;
71 case 'z':
72 return SUSP_CHAR(tty) | CTRLCHAR_CTRL;
73 }
74 return CTRLCHAR_NONE;
75}