annotate src/impl/fs_impl.cbc @ 312:b527f27761bf

tweak
author menikon
date Wed, 05 Feb 2020 15:35:04 +0900
parents b40deb55b7db
children 66a6aedf60f9
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(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
140
307
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
141 goto iput_check(fs, ip, next(...));
4cf83e6ce534 add iput codeGear
menikon
parents: 306
diff changeset
142
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
143 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
144
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
145 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
146
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
147 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
148 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
149
299
e825c247ab24 build success
menikon
parents: 298
diff changeset
150 typedef struct stat stat;
296
menikon
parents: 295
diff changeset
151 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
308
menikon
parents: 307
diff changeset
152 st->dev = ip->dev;
menikon
parents: 307
diff changeset
153 st->ino = ip->inum;
menikon
parents: 307
diff changeset
154 st->type = ip->type;
menikon
parents: 307
diff changeset
155 st->nlink = ip->nlink;
menikon
parents: 307
diff changeset
156 st->size = ip->size;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
157 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
158 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
159
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
160 __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
161
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
162 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
163 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
164
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
165 __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
166
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
167 goto next(...);
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
168 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
169
310
menikon
parents: 309
diff changeset
170 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(int strncmp_val, ...)) {
menikon
parents: 309
diff changeset
171 strncmp_val = strncmp(s, t, DIRSIZ);
menikon
parents: 309
diff changeset
172 goto next(strncmp_val, ...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
173 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
174
312
menikon
parents: 311
diff changeset
175 __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
176 if (dp->type != T_DIR) {
b40deb55b7db build success
menikon
parents: 310
diff changeset
177 /*
b40deb55b7db build success
menikon
parents: 310
diff changeset
178 panic("dirlookup not DIR");
b40deb55b7db build success
menikon
parents: 310
diff changeset
179 */
b40deb55b7db build success
menikon
parents: 310
diff changeset
180 }
312
menikon
parents: 311
diff changeset
181 Gearef(cbc_context, fs)->off = 0;
menikon
parents: 311
diff changeset
182 goto dirlookup_loopcheck(fs, dp, name, off, poff, de, next(...));
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
183 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
184
296
menikon
parents: 295
diff changeset
185 __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
186
296
menikon
parents: 295
diff changeset
187 goto next(...);
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
188 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
189
309
menikon
parents: 308
diff changeset
190 static struct inode* iget (uint dev, uint inum)
menikon
parents: 308
diff changeset
191 {
menikon
parents: 308
diff changeset
192 struct inode *ip, *empty;
menikon
parents: 308
diff changeset
193
menikon
parents: 308
diff changeset
194 acquire(&icache.lock);
menikon
parents: 308
diff changeset
195
menikon
parents: 308
diff changeset
196 // Is the inode already cached?
menikon
parents: 308
diff changeset
197 empty = 0;
menikon
parents: 308
diff changeset
198
menikon
parents: 308
diff changeset
199 for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) {
menikon
parents: 308
diff changeset
200 if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) {
menikon
parents: 308
diff changeset
201 ip->ref++;
menikon
parents: 308
diff changeset
202 release(&icache.lock);
menikon
parents: 308
diff changeset
203 return ip;
menikon
parents: 308
diff changeset
204 }
menikon
parents: 308
diff changeset
205
menikon
parents: 308
diff changeset
206 if (empty == 0 && ip->ref == 0) { // Remember empty slot.
menikon
parents: 308
diff changeset
207 empty = ip;
menikon
parents: 308
diff changeset
208 }
menikon
parents: 308
diff changeset
209 }
menikon
parents: 308
diff changeset
210
menikon
parents: 308
diff changeset
211 // Recycle an inode cache entry.
menikon
parents: 308
diff changeset
212 if (empty == 0) {
menikon
parents: 308
diff changeset
213 panic("iget: no inodes");
menikon
parents: 308
diff changeset
214 }
menikon
parents: 308
diff changeset
215
menikon
parents: 308
diff changeset
216 ip = empty;
menikon
parents: 308
diff changeset
217 ip->dev = dev;
menikon
parents: 308
diff changeset
218 ip->inum = inum;
menikon
parents: 308
diff changeset
219 ip->ref = 1;
menikon
parents: 308
diff changeset
220 ip->flags = 0;
menikon
parents: 308
diff changeset
221 release(&icache.lock);
menikon
parents: 308
diff changeset
222
menikon
parents: 308
diff changeset
223 return ip;
menikon
parents: 308
diff changeset
224 }
308
menikon
parents: 307
diff changeset
225
menikon
parents: 307
diff changeset
226 static char* skipelem (char *path, char *name)
menikon
parents: 307
diff changeset
227 {
menikon
parents: 307
diff changeset
228 char *s;
menikon
parents: 307
diff changeset
229 int len;
menikon
parents: 307
diff changeset
230
menikon
parents: 307
diff changeset
231 while (*path == '/') {
menikon
parents: 307
diff changeset
232 path++;
menikon
parents: 307
diff changeset
233 }
menikon
parents: 307
diff changeset
234
menikon
parents: 307
diff changeset
235 if (*path == 0) {
menikon
parents: 307
diff changeset
236 return 0;
menikon
parents: 307
diff changeset
237 }
menikon
parents: 307
diff changeset
238
menikon
parents: 307
diff changeset
239 s = path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
240
308
menikon
parents: 307
diff changeset
241 while (*path != '/' && *path != 0) {
menikon
parents: 307
diff changeset
242 path++;
menikon
parents: 307
diff changeset
243 }
menikon
parents: 307
diff changeset
244
menikon
parents: 307
diff changeset
245 len = path - s;
menikon
parents: 307
diff changeset
246
menikon
parents: 307
diff changeset
247 if (len >= DIRSIZ) {
menikon
parents: 307
diff changeset
248 memmove(name, s, DIRSIZ);
menikon
parents: 307
diff changeset
249 } else {
menikon
parents: 307
diff changeset
250 memmove(name, s, len);
menikon
parents: 307
diff changeset
251 name[len] = 0;
menikon
parents: 307
diff changeset
252 }
menikon
parents: 307
diff changeset
253
menikon
parents: 307
diff changeset
254 while (*path == '/') {
menikon
parents: 307
diff changeset
255 path++;
menikon
parents: 307
diff changeset
256 }
menikon
parents: 307
diff changeset
257
menikon
parents: 307
diff changeset
258 return path;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
259 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
260
308
menikon
parents: 307
diff changeset
261
menikon
parents: 307
diff changeset
262 static struct inode* namex (char *path, int nameiparent, char *name)
menikon
parents: 307
diff changeset
263 {
menikon
parents: 307
diff changeset
264 struct inode *ip, *next;
menikon
parents: 307
diff changeset
265
menikon
parents: 307
diff changeset
266 if (*path == '/') {
menikon
parents: 307
diff changeset
267 ip = iget(ROOTDEV, ROOTINO);
menikon
parents: 307
diff changeset
268 } else {
menikon
parents: 307
diff changeset
269 ip = idup(proc->cwd);
menikon
parents: 307
diff changeset
270 }
menikon
parents: 307
diff changeset
271
menikon
parents: 307
diff changeset
272 while ((path = skipelem(path, name)) != 0) {
menikon
parents: 307
diff changeset
273 ilock(ip);
menikon
parents: 307
diff changeset
274
menikon
parents: 307
diff changeset
275 if (ip->type != T_DIR) {
menikon
parents: 307
diff changeset
276 iunlockput(ip);
menikon
parents: 307
diff changeset
277 return 0;
menikon
parents: 307
diff changeset
278 }
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
279
308
menikon
parents: 307
diff changeset
280 if (nameiparent && *path == '\0') {
menikon
parents: 307
diff changeset
281 // Stop one level early.
menikon
parents: 307
diff changeset
282 iunlock(ip);
menikon
parents: 307
diff changeset
283 return ip;
menikon
parents: 307
diff changeset
284 }
menikon
parents: 307
diff changeset
285
menikon
parents: 307
diff changeset
286 if ((next = dirlookup(ip, name, 0)) == 0) {
menikon
parents: 307
diff changeset
287 iunlockput(ip);
menikon
parents: 307
diff changeset
288 return 0;
menikon
parents: 307
diff changeset
289 }
menikon
parents: 307
diff changeset
290
menikon
parents: 307
diff changeset
291 iunlockput(ip);
menikon
parents: 307
diff changeset
292 ip = next;
menikon
parents: 307
diff changeset
293 }
menikon
parents: 307
diff changeset
294
menikon
parents: 307
diff changeset
295 if (nameiparent) {
menikon
parents: 307
diff changeset
296 iput(ip);
menikon
parents: 307
diff changeset
297 return 0;
menikon
parents: 307
diff changeset
298 }
menikon
parents: 307
diff changeset
299
menikon
parents: 307
diff changeset
300 return ip;
294
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
301 }
08a367c3124a add FileSystem files
menikon
parents:
diff changeset
302
308
menikon
parents: 307
diff changeset
303 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
304 char name[DIRSIZ];
menikon
parents: 307
diff changeset
305 namex_val = namex(path, 0, name);
menikon
parents: 307
diff changeset
306 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
307 }
menikon
parents: 307
diff changeset
308
menikon
parents: 307
diff changeset
309 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(int namex_val, ...)) {
menikon
parents: 307
diff changeset
310
menikon
parents: 307
diff changeset
311 namex_val = namex(path, 1, name);
menikon
parents: 307
diff changeset
312 goto next(namex_val, ...);
menikon
parents: 307
diff changeset
313
menikon
parents: 307
diff changeset
314 }
menikon
parents: 307
diff changeset
315