/* * sfs_create_inode - alloc a inode in memroy, and init din/ino/dirty/reclian_count/sem fields in sfs_inode in inode */ static int sfs_create_inode(struct sfs_fs *sfs, struct sfs_disk_inode *din, uint32_t ino, struct inode **node_store) { struct inode *node; if ((node = alloc_inode(sfs_inode)) != NULL) { vop_init(node, sfs_get_ops(din->type), info2fs(sfs, sfs)); struct sfs_inode *sin = vop_info(node, sfs_inode); sin->din = din, sin->ino = ino, sin->dirty = 0, sin->reclaim_count = 1; sem_init(&(sin->sem), 1); *node_store = node; return 0; } return -E_NO_MEM; }
// Find the inode with number inum on device dev // and return the in-memory copy. Does not lock // the inode and does not read it from disk. struct inode* sfs_iget(uint dev, uint inum, short type) { struct inode *ip, *empty; struct sfs_inode *sip; // struct buf *bp; // struct sfs_dinode *dip; acquire(&icache.lock); // Is the inode already cached? empty = 0; for(ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++){ sip = vop_info(ip, sfs_inode); // cprintf("IGET: fstype = %d, ref = %d, dev = %d, inum = %d\n", ip->fstype, sip->ref, sip->dev, sip->inum); if(ip->fstype == SFS_INODE && sip->ref > 0 && sip->dev == dev && sip->inum == inum){ sip->ref++; release(&icache.lock); return ip; } if(empty == 0 && sip->ref == 0) // Remember empty slot. empty = ip; } // Recycle an inode cache entry. if(empty == 0) panic("iget: no inodes"); // cprintf("inum1 = %d\n", inum); ip = empty; sip = vop_info(ip, sfs_inode); // cprintf("inum2 = %d\n", inum); sip->dev = dev; sip->inum = inum; sip->ref = 1; sip->flags = 0; release(&icache.lock); if(type != 0){ sip->type = type; }else{ // bp = bread(dev, IBLOCK(inum)); // dip = (struct sfs_dinode*)bp->data + inum%IPB; // sip->type = dip->type; // brelse(bp); sfs_ilock(ip); sfs_iunlock(ip); } // cprintf("tip type = %d, major = %d, minor = %d, nlink = %d, inum = %d\n", sip -> type, sip->major,sip->minor,sip->nlink, sip->inum); // cprintf("inum3 = %d\n", inum); vop_init(ip, sfs_get_ops(sip->type), SFS_INODE); // cprintf("inum4 = %d\n", inum); return ip; }