annotate src/impl/file_impl_inode.cbc @ 198:6e28bd30e8a7

fix
author menikon <e165723@ie.u-ryukyu.ac.jp>
date Wed, 22 Jan 2020 20:28:26 +0900
parents 4cfff673e1f6
children 696c6bdc1074
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
194
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "../context.h"
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #interface "file.h"
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // ----
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // typedef struct inode<Impl, Isa> impl file {
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // } inode;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 // ----
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 file* createinode(struct Context* cbc_context) {
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 struct file* file = new file();
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 struct inode* inode = new inode();
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 file->file = (union Data*)inode;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 file->st = NULL;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 file->addr = NULL;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 file->n = 0;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 file->fd = 0;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 file->read = C_readinode;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 file->write = C_writeinode;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 file->close = C_closeinode;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 return file;
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 __code readinode(struct inode* file, char* addr, __code next(...)) {
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 goto next(...);
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 __code writeinode(struct inode* file, char* addr, int n, __code next(...)) {
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 goto next(...);
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 __code closeinode(struct inode* file,int fd, __code next(...)) {
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
198
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
35 goto file->cbc_inodecolse(file->file, next);
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
36 }
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
37
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
38 __code cbc_inodeclose(struct inode* inode, struct file* file, __code next(...)){
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
39 struct file ff;
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
40 acquire(*ftable.loc)
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
41
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
42 if (f->ref < 1) {
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
43 goto cbc_context->kernel_error->panic("file close");
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
44 }
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
45 goto inode->cbc_inodeclose2(f,ff,next);
194
4cfff673e1f6 add inodefiles
menikon <e165723@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
198
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
47
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
48 __code cbc_inodeclose2(struct inode* inode, struct file* file, struct file* ff, __code next(...)){
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
49 if (--f->ref > 0) {
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
50 release(&ftable.lock);
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
51 goto cbc_context->return();
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
52 }
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
53 goto inode->cbc_inodeclose3(f,ff,next);
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
54 }
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
55
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
56 __code cbc_inodeclose3(struct inode* inode, struct file* file, struct file* ff, __code next(...)){
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
57 *ff = *f;
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
58 f->ref = 0;
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
59 f->type = FD_NONE;
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
60 relsease(&ftable.lock);
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
61 struct inode* i = ff.inode;
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
62
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
63 goto inode->cbc_inodeclose4(i,next);
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
64 }
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
65
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
66 __code cbc_inodeclose4(struct inode* inode,__code next(...)){
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
67
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
68
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
69
menikon <e165723@ie.u-ryukyu.ac.jp>
parents: 194
diff changeset
70 }