commit d161f802d0bc25cac4a783fdf53eba79005f4cf8
parent e9fc35505315a91658da2e39cec12d3b04c872f5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 8 Sep 2020 14:25:50 +0200
devcons: Add flushraw()
Devcons was discarding all the input that didn't fit in the
internal buffer, genrating truncation of the output reading
proc/x/attr.
Change-Id: If44d6cf533bd2b7bf4c7c80f75a79a352e6ed79c
Diffstat:
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/src/kernel/dev/devcons.c b/src/kernel/dev/devcons.c
@@ -85,37 +85,52 @@ consstatus(void *buf, Chan *c, int n)
}
static int
-conswriteraw(char *buf, int n)
+flushraw(char *buf, int n)
{
- int i, idx, r;
- char wrtbuf[LINELEN];
- Chan **pp;
-
- idx = 0;
- for (i = 0; i < n; i++) {
- if (idx + 2 > sizeof(wrtbuf))
- break;
- if (buf[i] == '\n')
- wrtbuf[idx++] = '\r';
- wrtbuf[idx++] = buf[i];
- }
+ Chan **pp, *p;
+ int r, w;
r = 0;
for (pp = out; pp < &out[CONSOUT]; pp++) {
- int w;
- Chan *p;
-
if ((p = *pp) == NULL)
continue;
- w = devtab[p->type]->write(p, wrtbuf, idx);
+ w = devtab[p->type]->write(p, buf, n);
if (w < 0) {
r = -1;
- } else if (w != idx) {
+ } else if (w != n) {
errno = EIO;
r = -1;
}
}
- return r < 0 ? r : idx;
+
+ return (r < 0) ? r : n;
+}
+
+static int
+conswriteraw(char *buf, int n)
+{
+ int i, idx;
+ char wrtbuf[LINELEN];
+
+ idx = 0;
+ for (i = 0; i < n; i++) {
+ if (idx + 2 > sizeof(wrtbuf)) {
+ if (flushraw(wrtbuf, idx) < 0)
+ return -1;
+ idx = 0;
+ }
+
+ if (buf[i] == '\n')
+ wrtbuf[idx++] = '\r';
+
+ wrtbuf[idx++] = buf[i];
+ }
+
+ if (idx > 0) {
+ if (flushraw(wrtbuf, idx) < 0)
+ return -1;
+ }
+ return n;
}
static int