changeset 33:7a63dacab7f8

fix cbc_read
author mir3636
date Tue, 22 Jan 2019 17:32:06 +0900
parents 96af12a50fdb
children a7144583914c
files src/console.c src/defs.h src/file.c src/file.h src/fs.c
diffstat 5 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/console.c	Tue Jan 22 15:48:35 2019 +0900
+++ b/src/console.c	Tue Jan 22 17:32:06 2019 +0900
@@ -255,7 +255,6 @@
     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;
     __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
     
     int c = input.buf[input.r++ % INPUT_BUF];
@@ -282,7 +281,6 @@
             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;
             goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
         }
@@ -291,18 +289,18 @@
     release(&input.lock);
     ilock(ip);
 
-    int r = target - n;
+    //int r = target - n;
 
-    if (r > 0)
-        f->off += r;
-    iunlock(f->ip);
+    //if (r > 0)
+    //    f->off += r;
+    //iunlock(f->ip);
 
-    //goto next(target - n);
+    goto next(target - n);
 
-    goto next(r);
+    //goto next(r);
 }
 
-__code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret))
+__code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret))
 {
     uint target;
 
@@ -316,7 +314,6 @@
         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) {
@@ -327,7 +324,7 @@
 
             goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
         }
-	goto cbc_consoleread1(0);
+	goto cbc_consoleread1();
     }
 }
 
--- a/src/defs.h	Tue Jan 22 15:48:35 2019 +0900
+++ b/src/defs.h	Tue Jan 22 17:32:06 2019 +0900
@@ -90,7 +90,7 @@
 int             namecmp(const char*, const char*);
 struct inode*   namei(char*);
 struct inode*   nameiparent(char*, char*);
-__code 		cbc_readi (struct inode*, char*, uint, uint, struct file*, __code (*)(int));
+__code 		cbc_readi (struct inode*, char*, uint, uint, __code (*)(int));
 int             readi(struct inode*, char*, uint, uint);
 void            stati(struct inode*, struct stat*);
 int             writei(struct inode*, char*, uint, uint);
--- a/src/file.c	Tue Jan 22 15:48:35 2019 +0900
+++ b/src/file.c	Tue Jan 22 17:32:06 2019 +0900
@@ -101,8 +101,10 @@
     return -1;
 }
 
-__code cbc_fileread1 (int r, struct file *f, __code (*next)(int ret))
+__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);
@@ -122,7 +124,8 @@
 
     if (f->type == FD_INODE) {
         ilock(f->ip);
-        goto cbc_readi(f->ip, addr, f->off, n, f, next);
+        proc->cbc_arg.cbc_console_arg.f = f;
+        goto cbc_readi(f->ip, addr, f->off, n, cbc_fileread1);
     }
 
     goto cbc_panic("fileread");
--- a/src/file.h	Tue Jan 22 15:48:35 2019 +0900
+++ b/src/file.h	Tue Jan 22 17:32:06 2019 +0900
@@ -34,7 +34,7 @@
 };
 
 struct cbc_devsw {
-    __code (*read) (struct inode*, char*, int, struct file*, __code (*)(int));
+    __code (*read) (struct inode*, char*, int, __code (*)(int));
     //__code (*write)(struct inode*, char*, int, __code (*)(int));
 };
 
--- a/src/fs.c	Tue Jan 22 15:48:35 2019 +0900
+++ b/src/fs.c	Tue Jan 22 17:32:06 2019 +0900
@@ -453,7 +453,7 @@
     st->size = ip->size;
 }
 
-__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, struct file *f, __code (*next)(int ret))
+__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret))
 {
     uint tot, m;
     struct buf *bp;
@@ -463,7 +463,7 @@
             goto next(-1);
         }
 
-        goto cbc_devsw[ip->major].read(ip, dst, n, f, next);
+        goto cbc_devsw[ip->major].read(ip, dst, n, next);
     }
 
     if (off > ip->size || off + n < off) {
@@ -481,10 +481,6 @@
         brelse(bp);
     }
 
-    if (n > 0)
-        f->off += n;
-    iunlock(f->ip);
-
     goto next(n);
 }