From 8baac760500980d4b83e8de2e90265bfaa19df13 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 4 Jun 2019 05:57:47 -0400 Subject: support read() and write() bigger than one page --- console.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'console.c') diff --git a/console.c b/console.c index 56817d8..c7e1852 100644 --- a/console.c +++ b/console.c @@ -155,10 +155,11 @@ struct { #define C(x) ((x)-'@') // Contro int -consoleread(struct inode *ip, char *dst, int n) +consoleread(struct inode *ip, int user_dst, uint64 dst, int n) { uint target; int c; + char buf[1]; iunlock(ip); target = n; @@ -181,7 +182,10 @@ consoleread(struct inode *ip, char *dst, int n) } break; } - *dst++ = c; + buf[0] = c; + if(either_copyout(user_dst, dst, &buf[0], 1) == -1) + break; + dst++; --n; if(c == '\n') break; @@ -193,14 +197,18 @@ consoleread(struct inode *ip, char *dst, int n) } int -consolewrite(struct inode *ip, char *buf, int n) +consolewrite(struct inode *ip, int user_src, uint64 src, int n) { int i; iunlock(ip); acquire(&cons.lock); - for(i = 0; i < n; i++) - consputc(buf[i] & 0xff); + for(i = 0; i < n; i++){ + char c; + if(either_copyin(&c, user_src, src, 1) == -1) + break; + consputc(c); + } release(&cons.lock); ilock(ip); -- cgit v1.2.3