194
|
1 #include "../context.h"
|
|
2 #interface "file.h"
|
|
3
|
|
4 // ----
|
|
5 // typedef struct inode<Impl, Isa> impl file {
|
|
6 //
|
|
7 // } inode;
|
|
8 // ----
|
|
9
|
|
10 file* createinode(struct Context* cbc_context) {
|
|
11 struct file* file = new file();
|
|
12 struct inode* inode = new inode();
|
|
13 file->file = (union Data*)inode;
|
|
14 file->st = NULL;
|
|
15 file->addr = NULL;
|
|
16 file->n = 0;
|
|
17 file->fd = 0;
|
|
18 file->read = C_readinode;
|
|
19 file->write = C_writeinode;
|
|
20 file->close = C_closeinode;
|
|
21 return file;
|
|
22 }
|
|
23 __code readinode(struct inode* file, char* addr, __code next(...)) {
|
|
24
|
|
25 goto next(...);
|
|
26 }
|
|
27
|
|
28 __code writeinode(struct inode* file, char* addr, int n, __code next(...)) {
|
|
29
|
|
30 goto next(...);
|
|
31 }
|
|
32
|
|
33 __code closeinode(struct inode* file,int fd, __code next(...)) {
|
|
34
|
198
|
35 goto file->cbc_inodecolse(file->file, next);
|
|
36 }
|
|
37
|
|
38 __code cbc_inodeclose(struct inode* inode, struct file* file, __code next(...)){
|
|
39 struct file ff;
|
|
40 acquire(*ftable.loc)
|
|
41
|
|
42 if (f->ref < 1) {
|
|
43 goto cbc_context->kernel_error->panic("file close");
|
|
44 }
|
|
45 goto inode->cbc_inodeclose2(f,ff,next);
|
194
|
46 }
|
198
|
47
|
|
48 __code cbc_inodeclose2(struct inode* inode, struct file* file, struct file* ff, __code next(...)){
|
|
49 if (--f->ref > 0) {
|
|
50 release(&ftable.lock);
|
|
51 goto cbc_context->return();
|
|
52 }
|
|
53 goto inode->cbc_inodeclose3(f,ff,next);
|
|
54 }
|
|
55
|
|
56 __code cbc_inodeclose3(struct inode* inode, struct file* file, struct file* ff, __code next(...)){
|
|
57 *ff = *f;
|
|
58 f->ref = 0;
|
|
59 f->type = FD_NONE;
|
|
60 relsease(&ftable.lock);
|
|
61 struct inode* i = ff.inode;
|
|
62
|
|
63 goto inode->cbc_inodeclose4(i,next);
|
|
64 }
|
|
65
|
|
66 __code cbc_inodeclose4(struct inode* inode,__code next(...)){
|
|
67
|
|
68
|
|
69
|
|
70 }
|