Mercurial > hg > Members > anatofuz > CbC_xv6
diff src/console.c @ 31:96a5833d0d82
fix
author | mir3636 |
---|---|
date | Fri, 18 Jan 2019 18:20:02 +0900 |
parents | 6a7ab1d7001c |
children | 96af12a50fdb |
line wrap: on
line diff
--- a/src/console.c Fri Jan 18 11:50:48 2019 +0900 +++ b/src/console.c Fri Jan 18 18:20:02 2019 +0900 @@ -12,6 +12,9 @@ #include "mmu.h" #include "proc.h" +__code cbc_consoleread1 (__code(*)(int)); +__code cbc_consoleread2 (__code(*)(int)); + static void consputc (int); static int panicked = 0; @@ -230,6 +233,30 @@ release(&input.lock); } +__code cbc_consoleread2 (__code(*next)(int ret)) +{ + int n = proc->cbc_arg.cbc_console_arg.n; + int target = proc->cbc_arg.cbc_console_arg.target; + char* dst = proc->cbc_arg.cbc_console_arg.dst; + struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; + struct file *f = proc->cbc_arg.cbc_console_arg.f; + proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; + proc->cbc_arg.cbc_console_arg.dst = dst; + proc->cbc_arg.cbc_console_arg.ip = ip; + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + if (input.r == input.w) { + if (proc->killed) { + release(&input.lock); + ilock(ip); + goto next(-1); + } + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); + } + goto cbc_consoleread1(0); +} + __code cbc_consoleread1 (__code(*next)(int ret)) { int cont = 1; @@ -237,41 +264,51 @@ int target = proc->cbc_arg.cbc_console_arg.target; char* dst = proc->cbc_arg.cbc_console_arg.dst; struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; + struct file *f = proc->cbc_arg.cbc_console_arg.f; int c = input.buf[input.r++ % INPUT_BUF]; - if (c == C('D')) { // EOF - if (n < target) { - // Save ^D for next time, to make sure - // caller gets a 0-byte result. - input.r--; - } - cont = 0; - } + if (c == C('D')) { // EOF + if (n < target) { + // Save ^D for next time, to make sure + // caller gets a 0-byte result. + input.r--; + } + cont = 0; + } - *dst++ = c; - --n; + *dst++ = c; + --n; - if (c == '\n') { - cont = 0; - } - + if (c == '\n') { + cont = 0; + } - if (cont){ + if (n > 0) { proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; proc->cbc_arg.cbc_console_arg.dst = dst; proc->cbc_arg.cbc_console_arg.ip = ip; - proc->cbc_arg.cbc_console_arg.next = next; - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); } release(&input.lock); ilock(ip); - goto next(target - n); + int r = target - n; + + if (r > 0) + f->off += r; + iunlock(f->ip); + + //goto next(target - n); + + goto cbc_ret(r); } -__code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret)) +__code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret)) { uint target; @@ -280,21 +317,23 @@ target = n; acquire(&input.lock); - while (n > 0) { - while (input.r == input.w) { + if (n > 0) { + proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; + proc->cbc_arg.cbc_console_arg.dst = dst; + proc->cbc_arg.cbc_console_arg.ip = ip; + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + if (input.r == input.w) { if (proc->killed) { release(&input.lock); ilock(ip); goto next(-1); } - proc->cbc_arg.cbc_console_arg.n = n; - proc->cbc_arg.cbc_console_arg.target = target; - proc->cbc_arg.cbc_console_arg.dst = dst; - proc->cbc_arg.cbc_console_arg.ip = ip; - proc->cbc_arg.cbc_console_arg.next = next; - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); } + goto cbc_consoleread1(0); } }