Mercurial > hg > CbC > CbC_xv6
comparison src/file.cbc @ 113:ef44d384ad9d
rollback rev 52
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 02 Dec 2019 11:17:04 +0900 |
parents | 239bd73abac6 |
children | 7c200a8328fa |
comparison
equal
deleted
inserted
replaced
112:b9df8ea87b42 | 113:ef44d384ad9d |
---|---|
9 #include "file.h" | 9 #include "file.h" |
10 #include "spinlock.h" | 10 #include "spinlock.h" |
11 #include "proc.h" | 11 #include "proc.h" |
12 | 12 |
13 #define __ncode __code | 13 #define __ncode __code |
14 | 14 # |
15 #interface "SysRead.h" | |
16 | |
17 | |
18 struct devsw devsw[NDEV]; | 15 struct devsw devsw[NDEV]; |
19 struct cbc_devsw cbc_devsw[NDEV]; | 16 struct cbc_devsw cbc_devsw[NDEV]; |
20 | 17 |
21 struct { | 18 struct { |
22 struct spinlock lock; | 19 struct spinlock lock; |
24 } ftable; | 21 } ftable; |
25 | 22 |
26 void fileinit (void) | 23 void fileinit (void) |
27 { | 24 { |
28 initlock(&ftable.lock, "ftable"); | 25 initlock(&ftable.lock, "ftable"); |
29 } | |
30 | |
31 SysRead* createFileRead(struct Context* cbc_context) { | |
32 struct SysRead* sys_read = new SysRead(); | |
33 struct FileRead* file_read = new FileRead(); | |
34 sys_read->sys_read = (union Data*)file_read; | |
35 file_read->f = NULL; | |
36 sys_read->num = NULL; | |
37 sys_read->read = C_readFileRead; | |
38 sys_read->next = C_nextFileRead; | |
39 return sys_read; | |
40 } | 26 } |
41 | 27 |
42 // Allocate a file structure. | 28 // Allocate a file structure. |
43 struct file* filealloc (void) | 29 struct file* filealloc (void) |
44 { | 30 { |
125 f->off += r; | 111 f->off += r; |
126 iunlock(f->ip); | 112 iunlock(f->ip); |
127 goto next(r); | 113 goto next(r); |
128 } | 114 } |
129 | 115 |
130 | 116 __ncode cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) |
131 // Skip: generate_context | |
132 __code cbc_fileread(struct file *f, char *addr, int n, __code next(int ret, ...)) | |
133 { | 117 { |
134 if (f->readable == 0) { | 118 if (f->readable == 0) { |
135 goto next(-1); | 119 goto next(-1); |
136 } | 120 } |
137 | 121 |
138 if (f->type == FD_PIPE) { | 122 if (f->type == FD_PIPE) { |
139 piperead(f->pipe, addr, n); | 123 goto cbc_piperead(f->pipe, addr, n, next); |
140 goto next(-1); | 124 goto next(-1); |
141 } | 125 } |
142 | 126 |
143 if (f->type == FD_INODE) { | 127 if (f->type == FD_INODE) { |
144 ilock(f->ip); | 128 ilock(f->ip); |
236 } | 220 } |
237 | 221 |
238 panic("filewrite"); | 222 panic("filewrite"); |
239 } | 223 } |
240 | 224 |
241 __code readFileRead(__code next(...)) { | |
242 | |
243 goto next(...); | |
244 } | |
245 | |
246 __code nextFileRead(...) { | |
247 | |
248 } |