- ip->i_count++;
- ip->i_flag |= ILOCKED;
-}
-
-/*
- * Decrement reference count of
- * an inode structure.
- * On the last reference,
- * write the inode out and if necessary,
- * truncate and deallocate the file.
- */
-iput(ip)
- register struct inode *ip;
-{
-
- if ((ip->i_flag & ILOCKED) == 0)
- panic("iput");
- IUNLOCK(ip);
- irele(ip);
-}
-
-irele(ip)
- register struct inode *ip;
-{
- int mode;
-
- if (ip->i_count == 1) {
- ip->i_flag |= ILOCKED;
- if (ip->i_nlink <= 0) {
- itrunc(ip, (u_long)0);
- mode = ip->i_mode;
- ip->i_mode = 0;
- ip->i_rdev = 0;
- ip->i_flag |= IUPD|ICHG;
- ifree(ip, ip->i_number, mode);
-#ifdef QUOTA
- (void) chkiq(ip->i_dev, ip, ip->i_uid, 0);
- dqrele(ip->i_dquot);
- ip->i_dquot = NODQUOT;
-#endif
- }
- IUPDAT(ip, &time, &time, 0);
- IUNLOCK(ip);
- ip->i_flag = 0;
- /*
- * Put the inode on the end of the free list.
- * Possibly in some cases it would be better to
- * put the inode at the head of the free list,
- * (eg: where i_mode == 0 || i_number == 0)
- * but I will think about that later .. kre
- * (i_number is rarely 0 - only after an i/o error in iget,
- * where i_mode == 0, the inode will probably be wanted
- * again soon for an ialloc, so possibly we should keep it)
- */
- if (ifreeh) {
- *ifreet = ip;
- ip->i_freeb = ifreet;
- } else {
- ifreeh = ip;
- ip->i_freeb = &ifreeh;
- }
- ip->i_freef = NULL;
- ifreet = &ip->i_freef;
- } else if (!(ip->i_flag & ILOCKED))
- ITIMES(ip, &time, &time);
- ip->i_count--;
-}
-
-/*
- * Check accessed and update flags on
- * an inode structure.
- * If any is on, update the inode
- * with the current time.
- * If waitfor is given, then must insure
- * i/o order so wait for write to complete.
- */
-iupdat(ip, ta, tm, waitfor)
- register struct inode *ip;
- struct timeval *ta, *tm;
- int waitfor;
-{
- register struct buf *bp;
- struct dinode *dp;
- register struct fs *fp;
-
- fp = ip->i_fs;
- if ((ip->i_flag & (IUPD|IACC|ICHG|IMOD)) != 0) {
- if (fp->fs_ronly)
- return;
- bp = bread(ip->i_dev, fsbtodb(fp, itod(fp, ip->i_number)),
- (int)fp->fs_bsize);
- if (bp->b_flags & B_ERROR) {
- brelse(bp);
- return;
- }
- if (ip->i_flag&IACC)
- ip->i_atime = ta->tv_sec;
- if (ip->i_flag&IUPD)
- ip->i_mtime = tm->tv_sec;
- if (ip->i_flag&ICHG)
- ip->i_ctime = time.tv_sec;
- ip->i_flag &= ~(IUPD|IACC|ICHG|IMOD);
- dp = bp->b_un.b_dino + itoo(fp, ip->i_number);
- dp->di_ic = ip->i_ic;
- if (waitfor)
- bwrite(bp);
- else
- bdwrite(bp);