Mercurial > hg > Papers > 2019 > mitsuki-master
comparison paper/src/fileread.c @ 49:d3ed28a7964f
update
author | mir3636 |
---|---|
date | Mon, 11 Feb 2019 19:04:56 +0900 |
parents | 675cd2c69450 |
children |
comparison
equal
deleted
inserted
replaced
48:de8210a1f8e4 | 49:d3ed28a7964f |
---|---|
1 __code cbc_fileread1 (int r) | 1 int fileread (struct file *f, char *addr, int n) |
2 { | 2 { |
3 struct file *f = proc->cbc_arg.cbc_console_arg.f; | 3 int r; |
4 __code (*next)(int ret) = cbc_ret; | |
5 if (r > 0) | |
6 f->off += r; | |
7 iunlock(f->ip); | |
8 goto next(r); | |
9 } | |
10 | 4 |
11 __code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) | |
12 { | |
13 if (f->readable == 0) { | |
14 goto next(-1); | |
15 } | |
16 | |
17 if (f->type == FD_PIPE) { | |
18 goto cbc_piperead(f->pipe, addr, n, next); | |
19 goto next(-1); | |
20 } | |
21 | |
22 if (f->type == FD_INODE) { | |
23 ilock(f->ip); | |
24 proc->cbc_arg.cbc_console_arg.f = f; | |
25 goto cbc_readi(f->ip, addr, f->off, n, cbc_fileread1); | |
26 } | |
27 | |
28 goto cbc_panic("fileread"); | |
29 } | |
30 | |
31 // Read from file f. | |
32 int fileread (struct file *f, char *addr, int n) | |
33 { | |
34 int r; | |
35 | |
36 if (f->readable == 0) { | 5 if (f->readable == 0) { |
37 return -1; | 6 return -1; |
38 } | 7 } |
39 | 8 |
40 if (f->type == FD_PIPE) { | 9 if (f->type == FD_PIPE) { |
41 return piperead(f->pipe, addr, n); | 10 return piperead(f->pipe, addr, n); |
42 } | 11 } |
43 | 12 |
44 if (f->type == FD_INODE) { | 13 if (f->type == FD_INODE) { |
45 ilock(f->ip); | 14 ilock(f->ip); |
46 | 15 |
47 if ((r = readi(f->ip, addr, f->off, n)) > 0) { | 16 if ((r = readi(f->ip, addr, f->off, n)) > 0) { |
48 f->off += r; | 17 f->off += r; |
53 return r; | 22 return r; |
54 } | 23 } |
55 | 24 |
56 panic("fileread"); | 25 panic("fileread"); |
57 } | 26 } |
58 |