Mercurial > hg > Members > menikon > CbC_xv6
changeset 248:c6cbe4711e02
tweak
author | menikon |
---|---|
date | Mon, 03 Feb 2020 15:29:54 +0900 |
parents | 1ba0ca4113e1 |
children | f26b3dcbc6db |
files | src/impl/fs_impl.cbc |
diffstat | 1 files changed, 35 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/impl/fs_impl.cbc Sun Feb 02 00:23:12 2020 +0900 +++ b/src/impl/fs_impl.cbc Mon Feb 03 15:29:54 2020 +0900 @@ -182,7 +182,41 @@ goto next(...); } -static struct inode* iget (uint dev, uint inum); +static struct inode* iget (uint dev, uint inum) +{ + struct inode *ip, *empty; + + acquire(&icache.lock); + + // Is the inode already cached? + empty = 0; + + for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) { + if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) { + ip->ref++; + release(&icache.lock); + return ip; + } + + if (empty == 0 && ip->ref == 0) { // Remember empty slot. + empty = ip; + } + } + + // Recycle an inode cache entry. + if (empty == 0) { + panic("iget: no inodes"); + } + + ip = empty; + ip->dev = dev; + ip->inum = inum; + ip->ref = 1; + ip->flags = 0; + release(&icache.lock); + + return ip; +} static char* skipelem (char *path, char *name) {