comparison src/file.c @ 32:96af12a50fdb

fix cbc_read
author mir3636
date Tue, 22 Jan 2019 15:48:35 +0900
parents 96a5833d0d82
children 7a63dacab7f8
comparison
equal deleted inserted replaced
31:96a5833d0d82 32:96af12a50fdb
6 #include "defs.h" 6 #include "defs.h"
7 #include "param.h" 7 #include "param.h"
8 #include "fs.h" 8 #include "fs.h"
9 #include "file.h" 9 #include "file.h"
10 #include "spinlock.h" 10 #include "spinlock.h"
11 #include "proc.h"
11 12
12 struct devsw devsw[NDEV]; 13 struct devsw devsw[NDEV];
13 struct cbc_devsw cbc_devsw[NDEV]; 14 struct cbc_devsw cbc_devsw[NDEV];
14 15
15 struct { 16 struct {
98 } 99 }
99 100
100 return -1; 101 return -1;
101 } 102 }
102 103
103 __code cbc_fileread1 (int r, struct file *f, char *addr, int n, __code (*next)(int ret)) 104 __code cbc_fileread1 (int r, struct file *f, __code (*next)(int ret))
104 { 105 {
105 if (r > 0) 106 if (r > 0)
106 f->off += r; 107 f->off += r;
107 iunlock(f->ip); 108 iunlock(f->ip);
108 goto next(r); 109 goto next(r);
109 } 110 }
110 111
111 __code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) 112 __code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret))
112 { 113 {
113 int r;
114
115 if (f->readable == 0) { 114 if (f->readable == 0) {
116 goto next(-1); 115 goto next(-1);
117 } 116 }
118 117
119 if (f->type == FD_PIPE) { 118 if (f->type == FD_PIPE) {
121 goto next(-1); 120 goto next(-1);
122 } 121 }
123 122
124 if (f->type == FD_INODE) { 123 if (f->type == FD_INODE) {
125 ilock(f->ip); 124 ilock(f->ip);
126
127 goto cbc_readi(f->ip, addr, f->off, n, f, next); 125 goto cbc_readi(f->ip, addr, f->off, n, f, next);
128 } 126 }
129 127
130 goto cbc_panic("fileread"); 128 goto cbc_panic("fileread");
131 } 129 }