annotate src/impl/fs_impl.cbc @ 338:2cbaa4c74d15

remove_skip
author anatofuz
date Sun, 16 Feb 2020 18:30:06 +0900
parents cb6045bce1d5
children
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"
326
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
11 #interface "Err.h"
295
menikon
parents: 294
diff changeset
12 #interface "fs.dg"
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
13
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
14 // ----
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
15 // typedef struct fs_impl<Impl, Isa> impl fs{
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
16 // union Data* fs_impl;
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 //
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
21 // } fs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
22 // ----
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
23
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
24 fs* createfs_impl(struct Context* cbc_context) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
25 struct fs* fs = new fs();
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
26 struct fs_impl* fs_impl = new fs_impl();
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
27 fs->fs = (union Data*)fs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
28 fs_impl->fs_impl = NULL;
321
98902fad1e2e final fix
menikon
parents: 320
diff changeset
29 fs_impl->sb = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
30 fs_impl->ret = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
31 fs_impl->dev = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
32 fs_impl->type = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
33 fs_impl->bp = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
34 fs_impl->dip = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
35 fs_impl->inum = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
36 fs_impl->dp = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
37 fs_impl->name = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
38 fs_impl->off = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
39 fs_impl->poff = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
40 fs_impl->de = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
41 fs_impl->tot = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
42 fs_impl->m = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
43 fs_impl->dst = NULL;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
44 fs_impl->n = 0;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
45 fs_impl->src = NULL;
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
46 fs_impl->allocinode = C_allocinode;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
47 fs_impl->allocinode_loop = C_allocinode_loop;
303
5217253368ad rewrite ialloc
menikon
parents: 302
diff changeset
48 fs_impl->allocinode_loopcheck = C_allocinode_loopcheck;
5217253368ad rewrite ialloc
menikon
parents: 302
diff changeset
49 fs_impl->allocinode_noloop = C_allocinode_noloop;
321
98902fad1e2e final fix
menikon
parents: 320
diff changeset
50 fs_impl->lockinode1 = C_lockinode1;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
51 fs_impl->lockinode2 = C_lockinode2;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
52 fs_impl->lockinode_sleepcheck = C_lockinode_sleepcheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
53 fs_impl->iput_check = C_iput_check;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
54 fs_impl->iput_inode_nolink = C_iput_inode_nolink;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
55 fs_impl->readi_check_diskinode = C_readi_check_diskinode;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
56 fs_impl->readi_loopcheck = C_readi_loopcheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
57 fs_impl->readi_loop = C_readi_loop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
58 fs_impl->readi_noloop = C_readi_noloop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
59 fs_impl->writei_check_diskinode = C_writei_check_diskinode;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
60 fs_impl->writei_loopcheck = C_writei_loopcheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
61 fs_impl->writei_loop = C_writei_loop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
62 fs_impl->writei_noloop = C_writei_noloop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
63 fs_impl->dirlookup_loopcheck = C_dirlookup_loopcheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
64 fs_impl->dirlookup_loop = C_dirlookup_loop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
65 fs_impl->dirlookup_noloop = C_dirlookup_noloop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
66 fs_impl->dirlink_namecheck = C_dirlink_namecheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
67 fs_impl->dirlink_loopcheck = C_dirlink_loopcheck;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
68 fs_impl->dirlink_loop = C_dirlink_loop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
69 fs_impl->dirlink_noloop = C_dirlink_noloop;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
70 fs->readsb = C_readsbfs_impl;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
71 fs->iinit = C_iinitfs_impl;
98902fad1e2e final fix
menikon
parents: 320
diff changeset
72 fs->ialloc = C_iallocfs_impl;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
73 fs->iupdate = C_iupdatefs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
74 fs->idup = C_idupfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
75 fs->ilock = C_ilockfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
76 fs->iunlock = C_iunlockfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
77 fs->iput = C_iputfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
78 fs->iunlockput = C_iunlockputfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
79 fs->stati = C_statifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
80 fs->readi = C_readifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
81 fs->writei = C_writeifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
82 fs->namecmp = C_namecmpfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
83 fs->dirlookup = C_dirlookupfs_impl;
296
menikon
parents: 295
diff changeset
84 fs->dirlink = C_dirlinkfs_impl;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
85 fs->namei = C_nameifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
86 fs->nameiparent = C_nameiparentfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
87 return fs;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
88 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 296
diff changeset
89
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
90 typedef struct superblock superblock;
338
2cbaa4c74d15 remove_skip
anatofuz
parents: 337
diff changeset
91 __code readsbfs_impl(struct fs_impl* fs, uint dev, struct superblock* sb, __code next(...)) {
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
92
301
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
93 struct buf* bp;
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
94
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
95 bp = bread(dev, 1);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
96 memmove(sb, bp->data, sizeof(*sb));
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
97 brelse(bp);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
98
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
99 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
100 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
101
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
102 struct {
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
103 struct spinlock lock;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
104 struct inode inode[NINODE];
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
105 } icache;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
106
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
107 __code iinitfs_impl(struct fs_impl* fs, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
108
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
109 initlock(&icache.lock, "icache");
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
110
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
111 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
112 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
113
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
114 __code iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
115 goto allocinode(fs, dev, sb, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
116 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
117
337
cb6045bce1d5 fix_build_about_inode
anatofuz
parents: 326
diff changeset
118 typedef struct inode inode;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
119 __code iupdatefs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
120
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
121 struct buf *bp;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
122 struct dinode *dip;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
123
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
124 bp = bread(ip->dev, IBLOCK(ip->inum));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
125
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
126 dip = (struct dinode*) bp->data + ip->inum % IPB;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
127 dip->type = ip->type;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
128 dip->major = ip->major;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
129 dip->minor = ip->minor;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
130 dip->nlink = ip->nlink;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
131 dip->size = ip->size;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
132
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
133 memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
134 log_write(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
135 brelse(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
136
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
137
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
138 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
139 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
140
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
141 __code idupfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
142
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
143 acquire(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
144 ip->ref++;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
145 release(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
146
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
147 goto next(ip, ...);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
148
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
149 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
150
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
151 __code ilockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
152
306
menikon
parents: 305
diff changeset
153 goto lockinode1(fs, ip, bp, dip, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
154 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
155
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
156 __code iunlockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
157
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
158 if (ip == 0 || !(ip->flags & I_BUSY) || ip->ref < 1) {
326
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
159 char* msg = "iunlock";
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
160 struct Err* err = createKernelError(&proc->cbc_context);
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
161 Gearef(cbc_context, Err)->msg = msg;
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
162 goto meta(cbc_context, err->panic);
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
163 }
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
164
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
165 acquire(&icache.lock);
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
166 ip->flags &= ~I_BUSY;
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
167 wakeup(ip);
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
168 release(&icache.lock);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
169
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
170 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
171 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
172
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
173 __code iputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
316
menikon
parents: 315
diff changeset
174 if (next == C_iputfs_impl) {
menikon
parents: 315
diff changeset
175 next = fs->next2;
menikon
parents: 315
diff changeset
176 }
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
177 goto iput_check(fs, ip, next(...));
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
178
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
179 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
180
316
menikon
parents: 315
diff changeset
181 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
menikon
parents: 315
diff changeset
182 fs->next2 = next;
menikon
parents: 315
diff changeset
183 goto iunlockfs_impl(ip, fs->iput, ...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
184 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
185
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
186 typedef struct stat stat;
338
2cbaa4c74d15 remove_skip
anatofuz
parents: 337
diff changeset
187 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) {
308
menikon
parents: 307
diff changeset
188 st->dev = ip->dev;
menikon
parents: 307
diff changeset
189 st->ino = ip->inum;
menikon
parents: 307
diff changeset
190 st->type = ip->type;
menikon
parents: 307
diff changeset
191 st->nlink = ip->nlink;
menikon
parents: 307
diff changeset
192 st->size = ip->size;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
193 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
194 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
195
319
71c7bd0d047e build success
menikon
parents: 318
diff changeset
196 __code readifs_impl(struct fs_impl* fs, struct inode* ip, char* dst, uint off, uint tot, uint n, __code next(int ret, ...)) {
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
197 if (ip->type == T_DEV) {
318
menikon
parents: 317
diff changeset
198 goto readi_check_diskinode(fs, ip, dst, n, next(...));
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
199 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
200
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
201 if (off > ip->size || off + n < off) {
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
202 ret = -1;
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
203 goto next(ret, ...);
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
204 }
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
205
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
206 if (off + n > ip->size) {
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
207 n = ip->size - off;
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
208 }
319
71c7bd0d047e build success
menikon
parents: 318
diff changeset
209 Gearef(cbc_context, fs)->tot = 0;
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
210 goto readi_loopcheck(fs, tot, m, dst, off, n, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
211 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
212
320
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
213 __code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint tot, uint n, __code next(int ret, ...)) {
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
214 if (ip->type == T_DEV) {
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
215 goto writei_check_diskinode(fs, ip, src, n, next(...));
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
216 }
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
217
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
218 if (off > ip->size || off + n < off) {
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
219 ret = -1;
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
220 goto next(ret, ...);
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
221 }
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
222
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
223 if (off + n > MAXFILE * BSIZE) {
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
224 ret = -1;
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
225 goto next(ret, ...);
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
226 }
321
98902fad1e2e final fix
menikon
parents: 320
diff changeset
227 Gearef(cbc_context, fs)->tot = 0;
320
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
228 goto writei_loopcheck(fs, tot, m, src, off, n, next(...));
40e9dd5ff084 build success
menikon
parents: 319
diff changeset
229 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
230
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
231
310
menikon
parents: 309
diff changeset
232 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(int strncmp_val, ...)) {
menikon
parents: 309
diff changeset
233 strncmp_val = strncmp(s, t, DIRSIZ);
menikon
parents: 309
diff changeset
234 goto next(strncmp_val, ...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
235 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
236
338
2cbaa4c74d15 remove_skip
anatofuz
parents: 337
diff changeset
237 __code dirlookupfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint off, uint* poff, dirent* de, __code next(...)) {
311
b40deb55b7db build success
menikon
parents: 310
diff changeset
238 if (dp->type != T_DIR) {
326
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
239 char* msg = "dirlookup not DIR";
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
240 struct Err* err = createKernelError(&proc->cbc_context);
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
241 Gearef(cbc_context, Err)->msg = msg;
f0b337cb6024 use goto err->panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 321
diff changeset
242 goto meta(cbc_context, err->panic);
311
b40deb55b7db build success
menikon
parents: 310
diff changeset
243 }
312
menikon
parents: 311
diff changeset
244 Gearef(cbc_context, fs)->off = 0;
menikon
parents: 311
diff changeset
245 goto dirlookup_loopcheck(fs, dp, name, off, poff, de, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
246 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
247
338
2cbaa4c74d15 remove_skip
anatofuz
parents: 337
diff changeset
248 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* ip, struct dirent* de, struct inode* dp, char* name, uint off, uint inum, __code next(...)) {
315
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
249 // Check that name is not present.
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
250 if ((ip = dirlookup(dp, name, 0)) != 0) {
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
251 goto dirlink_namecheck(fs, ip, next(...));
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
252 }
316
menikon
parents: 315
diff changeset
253 Gearef(cbc_context, fs)->off = 0;
315
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
254 goto dirlink_loopcheck(fs, de, dp, off, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
255 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
256
309
menikon
parents: 308
diff changeset
257 static struct inode* iget (uint dev, uint inum)
menikon
parents: 308
diff changeset
258 {
menikon
parents: 308
diff changeset
259 struct inode *ip, *empty;
menikon
parents: 308
diff changeset
260
menikon
parents: 308
diff changeset
261 acquire(&icache.lock);
menikon
parents: 308
diff changeset
262
menikon
parents: 308
diff changeset
263 // Is the inode already cached?
menikon
parents: 308
diff changeset
264 empty = 0;
menikon
parents: 308
diff changeset
265
menikon
parents: 308
diff changeset
266 for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) {
menikon
parents: 308
diff changeset
267 if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) {
menikon
parents: 308
diff changeset
268 ip->ref++;
menikon
parents: 308
diff changeset
269 release(&icache.lock);
menikon
parents: 308
diff changeset
270 return ip;
menikon
parents: 308
diff changeset
271 }
menikon
parents: 308
diff changeset
272
menikon
parents: 308
diff changeset
273 if (empty == 0 && ip->ref == 0) { // Remember empty slot.
menikon
parents: 308
diff changeset
274 empty = ip;
menikon
parents: 308
diff changeset
275 }
menikon
parents: 308
diff changeset
276 }
menikon
parents: 308
diff changeset
277
menikon
parents: 308
diff changeset
278 // Recycle an inode cache entry.
menikon
parents: 308
diff changeset
279 if (empty == 0) {
menikon
parents: 308
diff changeset
280 panic("iget: no inodes");
menikon
parents: 308
diff changeset
281 }
menikon
parents: 308
diff changeset
282
menikon
parents: 308
diff changeset
283 ip = empty;
menikon
parents: 308
diff changeset
284 ip->dev = dev;
menikon
parents: 308
diff changeset
285 ip->inum = inum;
menikon
parents: 308
diff changeset
286 ip->ref = 1;
menikon
parents: 308
diff changeset
287 ip->flags = 0;
menikon
parents: 308
diff changeset
288 release(&icache.lock);
menikon
parents: 308
diff changeset
289
menikon
parents: 308
diff changeset
290 return ip;
menikon
parents: 308
diff changeset
291 }
308
menikon
parents: 307
diff changeset
292
menikon
parents: 307
diff changeset
293 static char* skipelem (char *path, char *name)
menikon
parents: 307
diff changeset
294 {
menikon
parents: 307
diff changeset
295 char *s;
menikon
parents: 307
diff changeset
296 int len;
menikon
parents: 307
diff changeset
297
menikon
parents: 307
diff changeset
298 while (*path == '/') {
menikon
parents: 307
diff changeset
299 path++;
menikon
parents: 307
diff changeset
300 }
menikon
parents: 307
diff changeset
301
menikon
parents: 307
diff changeset
302 if (*path == 0) {
menikon
parents: 307
diff changeset
303 return 0;
menikon
parents: 307
diff changeset
304 }
menikon
parents: 307
diff changeset
305
menikon
parents: 307
diff changeset
306 s = path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
307
308
menikon
parents: 307
diff changeset
308 while (*path != '/' && *path != 0) {
menikon
parents: 307
diff changeset
309 path++;
menikon
parents: 307
diff changeset
310 }
menikon
parents: 307
diff changeset
311
menikon
parents: 307
diff changeset
312 len = path - s;
menikon
parents: 307
diff changeset
313
menikon
parents: 307
diff changeset
314 if (len >= DIRSIZ) {
menikon
parents: 307
diff changeset
315 memmove(name, s, DIRSIZ);
menikon
parents: 307
diff changeset
316 } else {
menikon
parents: 307
diff changeset
317 memmove(name, s, len);
menikon
parents: 307
diff changeset
318 name[len] = 0;
menikon
parents: 307
diff changeset
319 }
menikon
parents: 307
diff changeset
320
menikon
parents: 307
diff changeset
321 while (*path == '/') {
menikon
parents: 307
diff changeset
322 path++;
menikon
parents: 307
diff changeset
323 }
menikon
parents: 307
diff changeset
324
menikon
parents: 307
diff changeset
325 return path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
326 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
327
308
menikon
parents: 307
diff changeset
328
menikon
parents: 307
diff changeset
329 static struct inode* namex (char *path, int nameiparent, char *name)
menikon
parents: 307
diff changeset
330 {
menikon
parents: 307
diff changeset
331 struct inode *ip, *next;
menikon
parents: 307
diff changeset
332
menikon
parents: 307
diff changeset
333 if (*path == '/') {
menikon
parents: 307
diff changeset
334 ip = iget(ROOTDEV, ROOTINO);
menikon
parents: 307
diff changeset
335 } else {
menikon
parents: 307
diff changeset
336 ip = idup(proc->cwd);
menikon
parents: 307
diff changeset
337 }
menikon
parents: 307
diff changeset
338
menikon
parents: 307
diff changeset
339 while ((path = skipelem(path, name)) != 0) {
menikon
parents: 307
diff changeset
340 ilock(ip);
menikon
parents: 307
diff changeset
341
menikon
parents: 307
diff changeset
342 if (ip->type != T_DIR) {
menikon
parents: 307
diff changeset
343 iunlockput(ip);
menikon
parents: 307
diff changeset
344 return 0;
menikon
parents: 307
diff changeset
345 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
346
308
menikon
parents: 307
diff changeset
347 if (nameiparent && *path == '\0') {
menikon
parents: 307
diff changeset
348 // Stop one level early.
menikon
parents: 307
diff changeset
349 iunlock(ip);
menikon
parents: 307
diff changeset
350 return ip;
menikon
parents: 307
diff changeset
351 }
menikon
parents: 307
diff changeset
352
menikon
parents: 307
diff changeset
353 if ((next = dirlookup(ip, name, 0)) == 0) {
menikon
parents: 307
diff changeset
354 iunlockput(ip);
menikon
parents: 307
diff changeset
355 return 0;
menikon
parents: 307
diff changeset
356 }
menikon
parents: 307
diff changeset
357
menikon
parents: 307
diff changeset
358 iunlockput(ip);
menikon
parents: 307
diff changeset
359 ip = next;
menikon
parents: 307
diff changeset
360 }
menikon
parents: 307
diff changeset
361
menikon
parents: 307
diff changeset
362 if (nameiparent) {
menikon
parents: 307
diff changeset
363 iput(ip);
menikon
parents: 307
diff changeset
364 return 0;
menikon
parents: 307
diff changeset
365 }
menikon
parents: 307
diff changeset
366
menikon
parents: 307
diff changeset
367 return ip;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
368 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
369
308
menikon
parents: 307
diff changeset
370 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
371 char name[DIRSIZ];
menikon
parents: 307
diff changeset
372 namex_val = namex(path, 0, name);
menikon
parents: 307
diff changeset
373 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
374 }
menikon
parents: 307
diff changeset
375
menikon
parents: 307
diff changeset
376 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
377
menikon
parents: 307
diff changeset
378 namex_val = namex(path, 1, name);
menikon
parents: 307
diff changeset
379 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
380
menikon
parents: 307
diff changeset
381 }
menikon
parents: 307
diff changeset
382