comparison 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
comparison
equal deleted inserted replaced
90:dd1d9ea1b7b5 91:b5ddf6fb0a6d
12 #include "proc.h" 12 #include "proc.h"
13 #include "fs.h" 13 #include "fs.h"
14 #include "file.h" 14 #include "file.h"
15 #include "fcntl.h" 15 #include "fcntl.h"
16 16
17 #interface "CbCFile.h"
18
17 #define __ncode __code 19 #define __ncode __code
18 20
19 // Fetch the nth word-sized system call argument as a file descriptor 21 // Fetch the nth word-sized system call argument as a file descriptor
20 // and return both the descriptor and the corresponding struct file. 22 // and return both the descriptor and the corresponding struct file.
21 static int argfd(int n, int *pfd, struct file **pf) 23 static int argfd(int n, int *pfd, struct file **pf)
85 goto next(-1); 87 goto next(-1);
86 } 88 }
87 goto cbc_fileread(f, p, n, next); 89 goto cbc_fileread(f, p, n, next);
88 } 90 }
89 91
90 __code file_read(struct file *f, int n, char *p, __code next(...)){ 92 struct CbCFile* initial_cbc_file(struct Context* cbc_context) {
93 struct CbCFile* cbc_file = new CbCFile();
94 cbc_file->read = C_cbc_fileread;
95 return cbc_file;
96 }
97
98 __code file_read(struct file *f, char *p, int n, __code next(...)){
91 goto cbc_fileread(f, p, n, next); 99 goto cbc_fileread(f, p, n, next);
92 } 100 }
93 101
94 __code file_read_stub(struct Context* cbc_context){ 102 __code file_read_stub(struct Context* cbc_context, __code next(...)){
103 struct CbCFile* cbc_file = initial_cbc_file(cbc_context);
95 struct file *f; 104 struct file *f;
96 int n; 105 int n;
97 char *p; 106 char *p;
98 if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) { 107 if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) {
99 goto next(-1); 108 goto next(-1);
100 } 109 }
101 goto cbc_fileread(f, p, n, next); 110 goto file_read(cbc_context,f, p, n, next);
102 } 111 }
103 112
104 int sys_read(void) 113 int sys_read(void)
105 { 114 {
106 struct file *f; 115 struct file *f;
328 ip->minor = minor; 337 ip->minor = minor;
329 ip->nlink = 1; 338 ip->nlink = 1;
330 iupdate(ip); 339 iupdate(ip);
331 340
332 if(type == T_DIR){ // Create . and .. entries. 341 if(type == T_DIR){ // Create . and .. entries.
333 dp->nlink++; // for ".."
334 iupdate(dp);
335 342
336 // No ip->nlink++ for ".": avoid cyclic ref count. 343 // No ip->nlink++ for ".": avoid cyclic ref count.
337 if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0) { 344 if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0) {
338 panic("create dots"); 345 panic("create dots");
339 } 346 }