/* * get an inode into the cache. if no inode exists for this qid, create one * from an unused qid/inode map. */ Ibuf * iget(Icache *ic, Qid qid) { Imap *m, *me; Ibuf *b; /* * find map entry with same qid.path */ for(m = ic->map, me = &ic->map[ic->nino]; m < me; m++) if(m->inuse && m->qid.path==qid.path){ if(m->qid.vers != qid.vers){ /* * our info is old, forget it */ DPRINT(2, "updating old file %llu.%lu\n", qid.path, qid.vers); m->qid = qid; iupdate(ic, m - ic->map, qid); } break; } /* * if an already existing inode, just get it */ if(m != me) return iread(ic, m - ic->map); /* * create a new inode, throw out the least recently used inode * if necessary */ m = (Imap*)ic->mlru.lnext; if(m->inuse){ DPRINT(2, "superceding file %llu.%ld by %llu.%ld\n", m->qid.path, m->qid.vers, qid.path, qid.vers); if(iremove(ic, m - ic->map) < 0) return 0; } if(statson) cfsstat.ninsert++; /* * init inode and write to disk */ DPRINT(2, "new file %llu.%ld ino %ld\n", qid.path, qid.vers, m - ic->map); b = ialloc(ic, m - ic->map); b->inode.inuse = m->inuse = 1; b->inode.qid = qid; b->inode.length = 0x7fffffffffffffffLL; m->qid = qid; b->inode.ptr.bno = Notabno; iwrite(ic, b); return b; }
void devfs_remove(struct inode *i) { rwlock_acquire(&i->rwl, RWL_WRITER); i->count=0; iremove(i); }