diff src/sysfile.cbc @ 91:b5ddf6fb0a6d

use CbCFile instead of File struct Interface
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Oct 2019 20:39:36 +0900
parents f38d8d39d617
children bc5bcfd2f6d6
line wrap: on
line diff
--- a/src/sysfile.cbc	Thu Oct 17 10:42:54 2019 +0900
+++ b/src/sysfile.cbc	Fri Oct 18 20:39:36 2019 +0900
@@ -14,6 +14,8 @@
 #include "file.h"
 #include "fcntl.h"
 
+#interface "CbCFile.h"
+
 #define __ncode __code
 
 // Fetch the nth word-sized system call argument as a file descriptor
@@ -87,18 +89,25 @@
     goto cbc_fileread(f, p, n, next);
 }
 
-__code file_read(struct file *f, int n, char *p, __code next(...)){
+struct CbCFile* initial_cbc_file(struct Context* cbc_context) {
+  struct CbCFile* cbc_file = new CbCFile();
+  cbc_file->read = C_cbc_fileread;
+  return cbc_file;
+}
+
+__code file_read(struct file *f, char *p, int n, __code next(...)){
    goto cbc_fileread(f, p, n, next);
 }
 
-__code file_read_stub(struct Context* cbc_context){
+__code file_read_stub(struct Context* cbc_context, __code next(...)){
+    struct CbCFile* cbc_file = initial_cbc_file(cbc_context);
     struct file *f;
     int n;
     char *p;
     if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) {
         goto next(-1);
     }
-    goto cbc_fileread(f, p, n, next);
+    goto file_read(cbc_context,f, p, n, next);
 }
 
 int sys_read(void)
@@ -330,8 +339,6 @@
     iupdate(ip);
 
     if(type == T_DIR){  // Create . and .. entries.
-        dp->nlink++;  // for ".."
-        iupdate(dp);
 
         // No ip->nlink++ for ".": avoid cyclic ref count.
         if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0) {