changeset 50:c276bcc9b245

add
author mir3636
date Mon, 11 Feb 2019 19:05:47 +0900
parents d3ed28a7964f
children 3179b8daa958
files paper/fig/state.graffle paper/fig/state.pdf paper/fig/state.xbb paper/src/fileread.cbc paper/src/readi.cbc
diffstat 5 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file paper/fig/state.graffle has changed
Binary file paper/fig/state.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/fig/state.xbb	Mon Feb 11 19:05:47 2019 +0900
@@ -0,0 +1,8 @@
+%%Title: fig/state.pdf
+%%Creator: extractbb 20160307
+%%BoundingBox: 0 0 1142 382
+%%HiResBoundingBox: 0.000000 0.000000 1142.000000 382.000000
+%%PDFVersion: 1.3
+%%Pages: 1
+%%CreationDate: Mon Feb 11 15:19:04 2019
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/fileread.cbc	Mon Feb 11 19:05:47 2019 +0900
@@ -0,0 +1,30 @@
+__code cbc_fileread1 (int r)
+{   
+    struct file *f = proc->cbc_arg.cbc_console_arg.f;
+    __code (*next)(int ret) = cbc_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))
+{   
+    if (f->readable == 0) {
+        goto next(-1);
+    }
+    
+    if (f->type == FD_PIPE) {
+        goto cbc_piperead(f->pipe, addr, n, next);
+        goto next(-1);
+    }
+    
+    if (f->type == FD_INODE) {
+        ilock(f->ip);
+        proc->cbc_arg.cbc_console_arg.f = f;
+        goto cbc_readi(f->ip, addr, f->off, n, cbc_fileread1);
+    }
+    
+    goto cbc_panic("fileread");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/src/readi.cbc	Mon Feb 11 19:05:47 2019 +0900
@@ -0,0 +1,30 @@
+__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret))
+{
+    uint tot, m;
+    struct buf *bp;
+
+    if (ip->type == T_DEV) {
+        if (ip->major < 0 || ip->major >= NDEV || !cbc_devsw[ip->major].read) {
+            goto next(-1);
+        }
+
+        goto cbc_devsw[ip->major].read(ip, dst, n, next);
+    }
+
+    if (off > ip->size || off + n < off) {
+        goto next(-1);
+    }
+
+    if (off + n > ip->size) {
+        n = ip->size - off;
+    }
+
+    for (tot = 0; tot < n; tot += m, off += m, dst += m) {
+        bp = bread(ip->dev, bmap(ip, off / BSIZE));
+        m = min(n - tot, BSIZE - off%BSIZE);
+        memmove(dst, bp->data + off % BSIZE, m);
+        brelse(bp);
+    }
+
+    goto next(n);
+}