Mercurial > hg > Members > menikon > CbC_xv6
annotate src/file_read.cbc @ 146:fd166dda4361
tweak return value at file_read.cbc
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Dec 2019 14:15:27 +0900 |
parents | f70c4ec3fb8a |
children | 06449f2ae0c7 |
rev | line source |
---|---|
143 | 1 #include "../context.h" |
2 #interface "SysRead.h" | |
3 | |
4 // ---- | |
5 // typedef struct FileRead<Type, Isa> impl SysRead { | |
6 // struct file* f; | |
7 // int r; | |
8 // __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...)); | |
9 // __code next(...); | |
10 // } FileRead; | |
11 // ---- | |
12 | |
13 SysRead* createFileRead(struct Context* cbc_context) { | |
14 struct SysRead* sys_read = new SysRead(); | |
15 struct FileRead* file_read = new FileRead(); | |
16 sys_read->sys_read = (union Data*)file_read; | |
17 file_read->f = NULL; | |
18 file_read->r = 0; | |
19 sys_read->impl = NULL; | |
20 sys_read->addr = NULL; | |
21 sys_read->n = 0; | |
22 sys_read->read = C_readFileRead; | |
23 sys_read->next = C_nextFileRead; | |
24 return sys_read; | |
25 } | |
26 | |
27 SysRead* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) { | |
28 if (f->type == FD_PIPE) { | |
146
fd166dda4361
tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
29 return create_piperead(cbc_context, f->pipe, addr, n, next); |
143 | 30 } |
31 | |
32 if (f->type == FD_INODE) { | |
33 ilock(f->ip); | |
146
fd166dda4361
tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
34 return create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1); |
143 | 35 } |
146
fd166dda4361
tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
36 return NULL; //Error? |
143 | 37 } |
38 | |
39 | |
40 __code cbc_fileread1FileRead(struct FileRead* file_read, struct file* f,int r,__code next(r,...)) { | |
41 | |
42 goto next(r,...); | |
43 } | |
44 | |
45 __code nextFileRead(...) { | |
46 | |
47 } | |
48 | |
49 __code readFileRead(struct FileRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) { | |
50 | |
51 goto next(int ret,...); | |
52 } | |
53 | |
54 __code selectReadInstance(struct file* f) { | |
55 if (f->readable == 0) { | |
56 goto next(-1); | |
57 } | |
58 SysRead* read = createFileReadInstFromFile(proc->cbc_context, f); | |
146
fd166dda4361
tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
59 goto read->read(f,addr,n); |
143 | 60 } |
61 | |
62 __code nextFileRead(...) { | |
63 | |
64 } | |
65 |