commit d38fcc52b2502815653d1d40512dfd1a68233281
parent e5cb30ea6d186112267c66d4746ed35be04d3c67
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 30 Aug 2020 22:46:44 +0200
devcons: Add raw mode
Console was always working in cooked mode, which
is desirable in a lot of situations, but it was
a bit nasty in hosted mode in unix system with
their own cooked mode. This patch adds a raw mode
where the console is passed directly to the device.
Change-Id: If8704b0726b46d5b5eaf1a4b8ea7a40706b87dde
Diffstat:
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/src/kernel/dev/devcons.c b/src/kernel/dev/devcons.c
@@ -14,6 +14,9 @@
#define NAMESIZE 15
#define CONSSTATUS 128
+#define RAW 0
+#define COOKED 1
+
#define CTRL(x) ((x) & 0x1f)
enum Orootqid {
@@ -35,6 +38,7 @@ static char outname[CONSOUT][NAMESIZE];
static char buffer[LINELEN];
static int head;
static int tail;
+static int mode;
static int
conswalk(Chan *c, const char *name)
@@ -154,6 +158,23 @@ consdelout(void *buf, int n)
}
static int
+consmode(void *buf, int n)
+{
+ char *arg = buf;
+
+ if (!strcmp(arg, "raw")) {
+ mode = RAW;
+ } else if(!strcmp(arg, "cooked")) {
+ mode = COOKED;
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
conswriteraw(char *buf, int n)
{
int i, idx, r;
@@ -203,7 +224,8 @@ conswrite(Chan *c, void *buf, int n)
{"addin", consaddin},
{"addout", consaddout},
{"delin", consdelin},
- {"delout", consdelout}
+ {"delout", consdelout},
+ {"mode", consmode},
};
switch (c->qid.path) {
@@ -253,8 +275,12 @@ consreadediting(Chan *c)
int i;
char editingchar;
+
+ if (mode == RAW)
+ return 0;
+
/*
- * XXX: it relies on the fact that head is incremented in the
+ * it relies on the fact that head is incremented in the
* calling function after exiting this one. For example, head is
* briefly equal to -1 when backspace is hit on an empty line.
*/
@@ -283,9 +309,6 @@ consreadediting(Chan *c)
conswrite(c, &editingchar, 1);
head = -1;
return 0;
- case '\r':
- buffer[head] = '\n';
- break;
case CTRL('W'):
i = 0;
head--;
@@ -296,13 +319,11 @@ consreadediting(Chan *c)
conserase(c, i);
head -= i;
return 0;
+ case '\r':
+ buffer[head] = '\n';
default:
- break;
+ return conswrite(c, &buffer[head], 1);
}
-
- conswrite(c, &buffer[head], 1);
-
- return 0;
}
static int