comparison src/impl/fs_impl.cbc @ 309:c6cbe4711e02

tweak
author menikon
date Mon, 03 Feb 2020 15:29:54 +0900
parents 1ba0ca4113e1
children f26b3dcbc6db
comparison
equal deleted inserted replaced
308:1ba0ca4113e1 309:c6cbe4711e02
180 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint inum, __code next(...)) { 180 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint inum, __code next(...)) {
181 181
182 goto next(...); 182 goto next(...);
183 } 183 }
184 184
185 static struct inode* iget (uint dev, uint inum); 185 static struct inode* iget (uint dev, uint inum)
186 {
187 struct inode *ip, *empty;
188
189 acquire(&icache.lock);
190
191 // Is the inode already cached?
192 empty = 0;
193
194 for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) {
195 if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) {
196 ip->ref++;
197 release(&icache.lock);
198 return ip;
199 }
200
201 if (empty == 0 && ip->ref == 0) { // Remember empty slot.
202 empty = ip;
203 }
204 }
205
206 // Recycle an inode cache entry.
207 if (empty == 0) {
208 panic("iget: no inodes");
209 }
210
211 ip = empty;
212 ip->dev = dev;
213 ip->inum = inum;
214 ip->ref = 1;
215 ip->flags = 0;
216 release(&icache.lock);
217
218 return ip;
219 }
186 220
187 static char* skipelem (char *path, char *name) 221 static char* skipelem (char *path, char *name)
188 { 222 {
189 char *s; 223 char *s;
190 int len; 224 int len;