-/*
- * Last reference to an inode, write the inode out and if necessary,
- * truncate and deallocate the file.
- */
-int
-ffs_inactive(ap)
- struct vop_inactive_args /* {
- struct vnode *a_vp;
- } */ *ap;
-{
- register struct vnode *vp = ap->a_vp;
- register struct inode *ip = VTOI(vp);
- struct timeval tv;
- int mode, error;
- extern int prtactive;
-
- if (prtactive && vp->v_usecount != 0)
- vprint("ffs_inactive: pushing active", vp);
-
- /* Get rid of inodes related to stale file handles. */
- if (ip->i_mode == 0) {
- if ((vp->v_flag & VXLOCK) == 0)
- vgone(vp);
- return (0);
- }
-
- error = 0;
- ILOCK(ip);
- if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
-#ifdef QUOTA
- if (!getinoquota(ip))
- (void)chkiq(ip, -1, NOCRED, 0);
-#endif
- error = VOP_TRUNCATE(vp, (off_t)0, 0, NOCRED, NULL);
- mode = ip->i_mode;
- ip->i_mode = 0;
- ip->i_rdev = 0;
- ip->i_flag |= IUPD|ICHG;
- VOP_VFREE(vp, ip->i_number, mode);
- }
- if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) {
- tv = time;
- VOP_UPDATE(vp, &tv, &tv, 0);
- }
- IUNLOCK(ip);
- ip->i_flag = 0;
- /*
- * If we are done with the inode, reclaim it
- * so that it can be reused immediately.
- */
- if (vp->v_usecount == 0 && ip->i_mode == 0)
- vgone(vp);
- return (error);
-}