- * 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.
+ * Last reference to an inode, write the inode out and if necessary,
+ * truncate and deallocate the file.
+ */
+ufs_inactive(vp)
+ struct vnode *vp;
+{
+ register struct inode *ip = VTOI(vp);
+ int mode, error = 0;
+
+ if (prtactive && vp->v_count != 0)
+ printf("ufs_inactive: pushing active ino %d dev 0x%x\n",
+ ip->i_number, ip->i_dev);
+ /*
+ * Get rid of inodes related to stale file handles.
+ */
+ if (ip->i_mode == 0) {
+ vgone(vp);
+ return (0);
+ }
+ ILOCK(ip);
+ if (ip->i_nlink <= 0 && (vp->v_mount->m_flag & M_RDONLY) == 0) {
+ error = 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;
+ /*
+ * If we are done with the inode, reclaim it
+ * so that it can be reused immediately.
+ */
+ if (vp->v_count == 0 && ip->i_mode == 0)
+ vgone(vp);
+ return (error);
+}
+
+/*
+ * Reclaim an inode so that it can be used for other purposes.
+ */
+ufs_reclaim(vp)
+ register struct vnode *vp;
+{
+ register struct inode *ip = VTOI(vp);
+
+ if (prtactive && vp->v_count != 0)
+ printf("ufs_reclaim: pushing active ino %d dev 0x%x\n",
+ ip->i_number, ip->i_dev);
+ /*
+ * Remove the inode from its hash chain.
+ */
+ remque(ip);
+ ip->i_forw = ip;
+ ip->i_back = ip;
+ /*
+ * Purge old data structures associated with the inode.
+ */
+ cache_purge(vp);
+ if (ip->i_devvp) {
+ vrele(ip->i_devvp);
+ ip->i_devvp = 0;
+ }
+#ifdef QUOTA
+ dqrele(ip->i_dquot);
+ ip->i_dquot = NODQUOT;
+#endif
+ ip->i_flag = 0;
+ return (0);
+}
+
+/*
+ * 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 ensure I/O order,
+ * so wait for write to complete.