annotate src/impl/fs_impl.cbc @ 319:71c7bd0d047e

build success
author menikon
date Thu, 06 Feb 2020 17:21:04 +0900 (2020-02-06)
parents d4ff2fb275b5
children 40e9dd5ff084
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;
306
menikon
parents: 305
diff changeset
38 fs_impl->lockinode1 = C_lockinode1;
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
39 fs_impl->lockinode2 = C_lockinode2;
306
menikon
parents: 305
diff changeset
40 fs_impl->lockinode_sleepcheck = C_lockinode_sleepcheck;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
41 fs->iunlock = C_iunlockfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
42 fs->iput = C_iputfs_impl;
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
43 fs_impl->iput_check = C_iput_check;
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
44 fs_impl->iput_inode_nolink = C_iput_inode_nolink;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
45 fs->iunlockput = C_iunlockputfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
46 fs->stati = C_statifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
47 fs->readi = C_readifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
48 fs->writei = C_writeifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
49 fs->namecmp = C_namecmpfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
50 fs->dirlookup = C_dirlookupfs_impl;
296
menikon
parents: 295
diff changeset
51 fs->dirlink = C_dirlinkfs_impl;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
52 fs->namei = C_nameifs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
53 fs->nameiparent = C_nameiparentfs_impl;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
54 return fs;
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
55 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 296
diff changeset
56
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
57 typedef struct superblock superblock;
296
menikon
parents: 295
diff changeset
58 __code readsbfs_impl(struct fs_impl* fs, uint dev, struct superblock* sb, __code next(...)) { //:skip
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
59
301
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
60 struct buf* bp;
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
61
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
62 bp = bread(dev, 1);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
63 memmove(sb, bp->data, sizeof(*sb));
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
64 brelse(bp);
7ec574dfe64f fix readsb
menikon
parents: 299
diff changeset
65
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
66 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
67 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
68
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
69 struct {
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
70 struct spinlock lock;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
71 struct inode inode[NINODE];
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
72 } icache;
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
73
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
74 __code iinitfs_impl(struct fs_impl* fs, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
75
302
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
76 initlock(&icache.lock, "icache");
bc2f3d24faa9 add fs_impl_private
menikon
parents: 301
diff changeset
77
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
78 goto next(...);
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 iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
82 goto allocinode(fs, dev, sb, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
83 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
84
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
85 __code iupdatefs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
86
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
87 struct buf *bp;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
88 struct dinode *dip;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
89
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
90 bp = bread(ip->dev, IBLOCK(ip->inum));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
91
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
92 dip = (struct dinode*) bp->data + ip->inum % IPB;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
93 dip->type = ip->type;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
94 dip->major = ip->major;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
95 dip->minor = ip->minor;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
96 dip->nlink = ip->nlink;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
97 dip->size = ip->size;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
98
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
99 memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
100 log_write(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
101 brelse(bp);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
102
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
103
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
104 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
105 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
106
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
107 __code idupfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
108
305
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
109 acquire(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
110 ip->ref++;
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
111 release(&icache.lock);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
112
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
113 goto next(ip, ...);
a101eb88b1cd ~add lockinode CodeGear
menikon
parents: 303
diff changeset
114
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
115 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
116
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
117 __code ilockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
118
306
menikon
parents: 305
diff changeset
119 goto lockinode1(fs, ip, bp, dip, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
120 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
121
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
122 __code iunlockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
123
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
124 if (ip == 0 || !(ip->flags & I_BUSY) || ip->ref < 1) {
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
125 /*
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
126 panic("iunlock");
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
127 goto panic();
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
128 */
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
129 }
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
130
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
131 acquire(&icache.lock);
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
132 ip->flags &= ~I_BUSY;
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
133 wakeup(ip);
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
134 release(&icache.lock);
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 iputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
316
menikon
parents: 315
diff changeset
140 if (next == C_iputfs_impl) {
menikon
parents: 315
diff changeset
141 next = fs->next2;
menikon
parents: 315
diff changeset
142 }
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
143 goto iput_check(fs, ip, next(...));
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
144
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
145 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
146
316
menikon
parents: 315
diff changeset
147 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
menikon
parents: 315
diff changeset
148 fs->next2 = next;
menikon
parents: 315
diff changeset
149 goto iunlockfs_impl(ip, fs->iput, ...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
150 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
151
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
152 typedef struct stat stat;
296
menikon
parents: 295
diff changeset
153 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
308
menikon
parents: 307
diff changeset
154 st->dev = ip->dev;
menikon
parents: 307
diff changeset
155 st->ino = ip->inum;
menikon
parents: 307
diff changeset
156 st->type = ip->type;
menikon
parents: 307
diff changeset
157 st->nlink = ip->nlink;
menikon
parents: 307
diff changeset
158 st->size = ip->size;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
159 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
160 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
161
319
71c7bd0d047e build success
menikon
parents: 318
diff changeset
162 __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
163 if (ip->type == T_DEV) {
318
menikon
parents: 317
diff changeset
164 goto readi_check_diskinode(fs, ip, dst, n, next(...));
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
165 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
166
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
167 if (off > ip->size || off + n < off) {
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
168 ret = -1;
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
169 goto next(ret, ...);
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
170 }
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
171
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
172 if (off + n > ip->size) {
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
173 n = ip->size - off;
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
174 }
319
71c7bd0d047e build success
menikon
parents: 318
diff changeset
175 Gearef(cbc_context, fs)->tot = 0;
317
20294366d1f9 add readi CodeGear
menikon
parents: 316
diff changeset
176 goto readi_loopcheck(fs, tot, m, dst, off, n, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
177 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
178
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
179 __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
180
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
181 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
182 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
183
310
menikon
parents: 309
diff changeset
184 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(int strncmp_val, ...)) {
menikon
parents: 309
diff changeset
185 strncmp_val = strncmp(s, t, DIRSIZ);
menikon
parents: 309
diff changeset
186 goto next(strncmp_val, ...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
187 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
188
312
menikon
parents: 311
diff changeset
189 __code dirlookupfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint off, uint* poff, dirent* de, __code next(...)) { //:skip
311
b40deb55b7db build success
menikon
parents: 310
diff changeset
190 if (dp->type != T_DIR) {
b40deb55b7db build success
menikon
parents: 310
diff changeset
191 /*
b40deb55b7db build success
menikon
parents: 310
diff changeset
192 panic("dirlookup not DIR");
b40deb55b7db build success
menikon
parents: 310
diff changeset
193 */
b40deb55b7db build success
menikon
parents: 310
diff changeset
194 }
312
menikon
parents: 311
diff changeset
195 Gearef(cbc_context, fs)->off = 0;
menikon
parents: 311
diff changeset
196 goto dirlookup_loopcheck(fs, dp, name, off, poff, de, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
197 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
198
315
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
199 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* ip, struct dirent* de, struct inode* dp, char* name, uint off, uint inum, __code next(...)) { //:skip
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
200 // Check that name is not present.
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
201 if ((ip = dirlookup(dp, name, 0)) != 0) {
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
202 goto dirlink_namecheck(fs, ip, next(...));
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
203 }
316
menikon
parents: 315
diff changeset
204 Gearef(cbc_context, fs)->off = 0;
315
66a6aedf60f9 add CodeGear dirlink_loopcheck etc
menikon
parents: 312
diff changeset
205 goto dirlink_loopcheck(fs, de, dp, off, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
206 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
207
309
menikon
parents: 308
diff changeset
208 static struct inode* iget (uint dev, uint inum)
menikon
parents: 308
diff changeset
209 {
menikon
parents: 308
diff changeset
210 struct inode *ip, *empty;
menikon
parents: 308
diff changeset
211
menikon
parents: 308
diff changeset
212 acquire(&icache.lock);
menikon
parents: 308
diff changeset
213
menikon
parents: 308
diff changeset
214 // Is the inode already cached?
menikon
parents: 308
diff changeset
215 empty = 0;
menikon
parents: 308
diff changeset
216
menikon
parents: 308
diff changeset
217 for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) {
menikon
parents: 308
diff changeset
218 if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) {
menikon
parents: 308
diff changeset
219 ip->ref++;
menikon
parents: 308
diff changeset
220 release(&icache.lock);
menikon
parents: 308
diff changeset
221 return ip;
menikon
parents: 308
diff changeset
222 }
menikon
parents: 308
diff changeset
223
menikon
parents: 308
diff changeset
224 if (empty == 0 && ip->ref == 0) { // Remember empty slot.
menikon
parents: 308
diff changeset
225 empty = ip;
menikon
parents: 308
diff changeset
226 }
menikon
parents: 308
diff changeset
227 }
menikon
parents: 308
diff changeset
228
menikon
parents: 308
diff changeset
229 // Recycle an inode cache entry.
menikon
parents: 308
diff changeset
230 if (empty == 0) {
menikon
parents: 308
diff changeset
231 panic("iget: no inodes");
menikon
parents: 308
diff changeset
232 }
menikon
parents: 308
diff changeset
233
menikon
parents: 308
diff changeset
234 ip = empty;
menikon
parents: 308
diff changeset
235 ip->dev = dev;
menikon
parents: 308
diff changeset
236 ip->inum = inum;
menikon
parents: 308
diff changeset
237 ip->ref = 1;
menikon
parents: 308
diff changeset
238 ip->flags = 0;
menikon
parents: 308
diff changeset
239 release(&icache.lock);
menikon
parents: 308
diff changeset
240
menikon
parents: 308
diff changeset
241 return ip;
menikon
parents: 308
diff changeset
242 }
308
menikon
parents: 307
diff changeset
243
menikon
parents: 307
diff changeset
244 static char* skipelem (char *path, char *name)
menikon
parents: 307
diff changeset
245 {
menikon
parents: 307
diff changeset
246 char *s;
menikon
parents: 307
diff changeset
247 int len;
menikon
parents: 307
diff changeset
248
menikon
parents: 307
diff changeset
249 while (*path == '/') {
menikon
parents: 307
diff changeset
250 path++;
menikon
parents: 307
diff changeset
251 }
menikon
parents: 307
diff changeset
252
menikon
parents: 307
diff changeset
253 if (*path == 0) {
menikon
parents: 307
diff changeset
254 return 0;
menikon
parents: 307
diff changeset
255 }
menikon
parents: 307
diff changeset
256
menikon
parents: 307
diff changeset
257 s = path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
258
308
menikon
parents: 307
diff changeset
259 while (*path != '/' && *path != 0) {
menikon
parents: 307
diff changeset
260 path++;
menikon
parents: 307
diff changeset
261 }
menikon
parents: 307
diff changeset
262
menikon
parents: 307
diff changeset
263 len = path - s;
menikon
parents: 307
diff changeset
264
menikon
parents: 307
diff changeset
265 if (len >= DIRSIZ) {
menikon
parents: 307
diff changeset
266 memmove(name, s, DIRSIZ);
menikon
parents: 307
diff changeset
267 } else {
menikon
parents: 307
diff changeset
268 memmove(name, s, len);
menikon
parents: 307
diff changeset
269 name[len] = 0;
menikon
parents: 307
diff changeset
270 }
menikon
parents: 307
diff changeset
271
menikon
parents: 307
diff changeset
272 while (*path == '/') {
menikon
parents: 307
diff changeset
273 path++;
menikon
parents: 307
diff changeset
274 }
menikon
parents: 307
diff changeset
275
menikon
parents: 307
diff changeset
276 return path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
277 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
278
308
menikon
parents: 307
diff changeset
279
menikon
parents: 307
diff changeset
280 static struct inode* namex (char *path, int nameiparent, char *name)
menikon
parents: 307
diff changeset
281 {
menikon
parents: 307
diff changeset
282 struct inode *ip, *next;
menikon
parents: 307
diff changeset
283
menikon
parents: 307
diff changeset
284 if (*path == '/') {
menikon
parents: 307
diff changeset
285 ip = iget(ROOTDEV, ROOTINO);
menikon
parents: 307
diff changeset
286 } else {
menikon
parents: 307
diff changeset
287 ip = idup(proc->cwd);
menikon
parents: 307
diff changeset
288 }
menikon
parents: 307
diff changeset
289
menikon
parents: 307
diff changeset
290 while ((path = skipelem(path, name)) != 0) {
menikon
parents: 307
diff changeset
291 ilock(ip);
menikon
parents: 307
diff changeset
292
menikon
parents: 307
diff changeset
293 if (ip->type != T_DIR) {
menikon
parents: 307
diff changeset
294 iunlockput(ip);
menikon
parents: 307
diff changeset
295 return 0;
menikon
parents: 307
diff changeset
296 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
297
308
menikon
parents: 307
diff changeset
298 if (nameiparent && *path == '\0') {
menikon
parents: 307
diff changeset
299 // Stop one level early.
menikon
parents: 307
diff changeset
300 iunlock(ip);
menikon
parents: 307
diff changeset
301 return ip;
menikon
parents: 307
diff changeset
302 }
menikon
parents: 307
diff changeset
303
menikon
parents: 307
diff changeset
304 if ((next = dirlookup(ip, name, 0)) == 0) {
menikon
parents: 307
diff changeset
305 iunlockput(ip);
menikon
parents: 307
diff changeset
306 return 0;
menikon
parents: 307
diff changeset
307 }
menikon
parents: 307
diff changeset
308
menikon
parents: 307
diff changeset
309 iunlockput(ip);
menikon
parents: 307
diff changeset
310 ip = next;
menikon
parents: 307
diff changeset
311 }
menikon
parents: 307
diff changeset
312
menikon
parents: 307
diff changeset
313 if (nameiparent) {
menikon
parents: 307
diff changeset
314 iput(ip);
menikon
parents: 307
diff changeset
315 return 0;
menikon
parents: 307
diff changeset
316 }
menikon
parents: 307
diff changeset
317
menikon
parents: 307
diff changeset
318 return ip;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
319 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
320
308
menikon
parents: 307
diff changeset
321 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
322 char name[DIRSIZ];
menikon
parents: 307
diff changeset
323 namex_val = namex(path, 0, name);
menikon
parents: 307
diff changeset
324 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
325 }
menikon
parents: 307
diff changeset
326
menikon
parents: 307
diff changeset
327 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
328
menikon
parents: 307
diff changeset
329 namex_val = namex(path, 1, name);
menikon
parents: 307
diff changeset
330 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
331
menikon
parents: 307
diff changeset
332 }
menikon
parents: 307
diff changeset
333