Mercurial > hg > CbC > CbC_xv6
comparison src/file.c @ 24:36bd61f5c847
rewrite sys_read cbc
author | mir3636 |
---|---|
date | Thu, 17 Jan 2019 19:11:19 +0900 |
parents | 83c23a36980d |
children | 1a64b5645cdd |
comparison
equal
deleted
inserted
replaced
23:ee58360d0e99 | 24:36bd61f5c847 |
---|---|
94 | 94 |
95 return 0; | 95 return 0; |
96 } | 96 } |
97 | 97 |
98 return -1; | 98 return -1; |
99 } | |
100 | |
101 __code cbc_fileread1 (int r, struct file *f, char *addr, int n, __code (*next)(int ret)) | |
102 { | |
103 if (r > 0) | |
104 f->off += r; | |
105 iunlock(f->ip); | |
106 goto next(r); | |
107 } | |
108 | |
109 __code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) | |
110 { | |
111 int r; | |
112 | |
113 if (f->readable == 0) { | |
114 goto next(-1); | |
115 } | |
116 | |
117 if (f->type == FD_PIPE) { | |
118 goto cbc_piperead(f->pipe, addr, n, next); | |
119 } | |
120 | |
121 if (f->type == FD_INODE) { | |
122 ilock(f->ip); | |
123 | |
124 goto cbc_readi(f->ip, addr, f->off, n); | |
125 } | |
126 | |
127 goto cbc_panic("fileread"); | |
99 } | 128 } |
100 | 129 |
101 // Read from file f. | 130 // Read from file f. |
102 int fileread (struct file *f, char *addr, int n) | 131 int fileread (struct file *f, char *addr, int n) |
103 { | 132 { |