Mercurial > hg > CbC > CbC_xv6
diff src/file.c @ 24:36bd61f5c847
rewrite sys_read cbc
author | mir3636 |
---|---|
date | Thu, 17 Jan 2019 19:11:19 +0900 |
parents | 83c23a36980d |
children | 1a64b5645cdd |
line wrap: on
line diff
--- a/src/file.c Mon Dec 17 16:55:22 2018 +0900 +++ b/src/file.c Thu Jan 17 19:11:19 2019 +0900 @@ -98,6 +98,35 @@ return -1; } +__code cbc_fileread1 (int r, struct file *f, char *addr, int n, __code (*next)(int ret)) +{ + if (r > 0) + f->off += r; + iunlock(f->ip); + goto next(r); +} + +__code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) +{ + int r; + + if (f->readable == 0) { + goto next(-1); + } + + if (f->type == FD_PIPE) { + goto cbc_piperead(f->pipe, addr, n, next); + } + + if (f->type == FD_INODE) { + ilock(f->ip); + + goto cbc_readi(f->ip, addr, f->off, n); + } + + goto cbc_panic("fileread"); +} + // Read from file f. int fileread (struct file *f, char *addr, int n) {