annotate src/impl/fs_impl.cbc @ 305:a101eb88b1cd

~add lockinode CodeGear
author menikon
date Fri, 31 Jan 2020 17:51:39 +0900
parents 5217253368ad
children 5ea0b8b12aaf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
1 #include "types.h"
301
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
2 #include "defs.h"
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
3 #include "param.h"
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
4 #include "stat.h"
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
5 #include "mmu.h"
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
6 #include "proc.h"
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
7 #include "spinlock.h"
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
8 #include "buf.h"
301
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
9 #include "fs.h"
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
10 #include "file.h"
295
menikon
parents: 294
diff changeset
11 #interface "fs.dg"
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
12
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
13 // ----
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
14 // typedef struct fs_impl<Impl, Isa> impl fs{
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
15 // union Data* fs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
16 //
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
17 //
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
18 //
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
19 //
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
20 // } fs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
21 // ----
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
22
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
23 fs* createfs_impl(struct Context* cbc_context) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
24 struct fs* fs = new fs();
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
25 struct fs_impl* fs_impl = new fs_impl();
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
26 fs->fs = (union Data*)fs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
27 fs_impl->fs_impl = NULL;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
28 fs->readsb = C_readsbfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
29 fs->iinit = C_iinitfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
30 fs->ialloc = C_iallocfs_impl;
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
31 fs_impl->allocinode = C_allocinode;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
32 fs_impl->allocinode_loop = C_allocinode_loop;
303
5217253368ad rewrite ialloc
menikon
parents: 302
diff changeset
33 fs_impl->allocinode_loopcheck = C_allocinode_loopcheck;
5217253368ad rewrite ialloc
menikon
parents: 302
diff changeset
34 fs_impl->allocinode_noloop = C_allocinode_noloop;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
35 fs->iupdate = C_iupdatefs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
36 fs->idup = C_idupfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
37 fs->ilock = C_ilockfs_impl;
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
38 fs_impl->lockinode = C_lockinode;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
39 fs->iunlock = C_iunlockfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
40 fs->iput = C_iputfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
41 fs->iunlockput = C_iunlockputfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
42 fs->stati = C_statifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
43 fs->readi = C_readifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
44 fs->writei = C_writeifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
45 fs->namecmp = C_namecmpfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
46 fs->dirlookup = C_dirlookupfs_impl;
296
menikon
parents: 295
diff changeset
47 fs->dirlink = C_dirlinkfs_impl;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
48 fs->namei = C_nameifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
49 fs->nameiparent = C_nameiparentfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
50 return fs;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
51 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 296
diff changeset
52
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
53 typedef struct superblock superblock;
296
menikon
parents: 295
diff changeset
54 __code readsbfs_impl(struct fs_impl* fs, uint dev, struct superblock* sb, __code next(...)) { //:skip
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
55
301
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
56 struct buf* bp;
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
57
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
58 bp = bread(dev, 1);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
59 memmove(sb, bp->data, sizeof(*sb));
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
60 brelse(bp);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
61
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
62 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
63 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
64
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
65 struct {
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
66 struct spinlock lock;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
67 struct inode inode[NINODE];
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
68 } icache;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
69
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
70 __code iinitfs_impl(struct fs_impl* fs, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
71
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
72 initlock(&icache.lock, "icache");
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
73
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
74 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
75 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
76
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
77 __code iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
78 goto allocinode(fs, dev, sb, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
79 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
80
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
81 __code iupdatefs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
82
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
83 struct buf *bp;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
84 struct dinode *dip;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
85
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
86 bp = bread(ip->dev, IBLOCK(ip->inum));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
87
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
88 dip = (struct dinode*) bp->data + ip->inum % IPB;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
89 dip->type = ip->type;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
90 dip->major = ip->major;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
91 dip->minor = ip->minor;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
92 dip->nlink = ip->nlink;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
93 dip->size = ip->size;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
94
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
95 memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
96 log_write(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
97 brelse(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
98
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
99
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
100 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
101 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
102
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
103 __code idupfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
104
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
105 acquire(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
106 ip->ref++;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
107 release(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
108
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
109 goto next(ip, ...);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
110
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
111 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
112
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
113 __code ilockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
114
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
115 goto lockinode(fs, ip, bp, dip, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
116 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
117
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
118 __code iunlockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
119
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
120 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
121 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
122
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
123 __code iputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
124
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
125 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
126 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
127
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
128 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
129
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
130 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
131 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
132
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
133 typedef struct stat stat;
296
menikon
parents: 295
diff changeset
134 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
135
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
136 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
137 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
138
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
139 __code readifs_impl(struct fs_impl* fs, struct inode* ip, char* dst, uint off, uint n, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
140
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
141 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
142 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
143
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
144 __code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint n, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
145
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
146 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
147 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
148
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
149 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
150
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
151 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
152 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
153
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
154 __code dirlookupfs_impl(struct inode* dp, char* name, uint* poff, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
155
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
156 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
157 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
158
296
menikon
parents: 295
diff changeset
159 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint inum, __code next(...)) {
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
160
296
menikon
parents: 295
diff changeset
161 goto next(...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
162 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
163
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
164 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
165
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
166 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
167 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
168
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
169 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
170
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
171 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
172 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
173