/* * Change size of the given vnode. * Caller should execute tmpfs_update on vp after a successful execution. * The vnode must be locked on entry and remain locked on exit. */ int tmpfs_chsize(struct vnode *vp, u_quad_t size, struct ucred *cred) { int error; struct tmpfs_node *node; KKASSERT(vn_islocked(vp)); node = VP_TO_TMPFS_NODE(vp); /* Decide whether this is a valid operation based on the file type. */ error = 0; switch (vp->v_type) { case VDIR: return EISDIR; case VREG: if (vp->v_mount->mnt_flag & MNT_RDONLY) return EROFS; break; case VBLK: /* FALLTHROUGH */ case VCHR: /* FALLTHROUGH */ case VFIFO: /* Allow modifications of special files even if in the file * system is mounted read-only (we are not modifying the * files themselves, but the objects they represent). */ return 0; default: /* Anything else is unsupported. */ return EOPNOTSUPP; } /* Immutable or append-only files cannot be modified, either. */ if (node->tn_flags & (IMMUTABLE | APPEND)) return EPERM; error = tmpfs_truncate(vp, size); /* tmpfs_truncate will raise the NOTE_EXTEND and NOTE_ATTRIB kevents * for us, as will update tn_status; no need to do that here. */ KKASSERT(vn_islocked(vp)); return error; }
/* * fsync is usually a NOP, but we must take action when unmounting or * when recycling. */ static int tmpfs_fsync(struct vop_fsync_args *v) { struct tmpfs_node *node; struct vnode *vp = v->a_vp; node = VP_TO_TMPFS_NODE(vp); tmpfs_update(vp); if (vp->v_type == VREG) { if (vp->v_flag & VRECLAIMED) { if (node->tn_links == 0) tmpfs_truncate(vp, 0); else vfsync(v->a_vp, v->a_waitfor, 1, NULL, NULL); } } return 0; }
static int tmpfs_inactive(struct vop_inactive_args *v) { struct vnode *vp = v->a_vp; struct tmpfs_node *node; struct mount *mp; mp = vp->v_mount; lwkt_gettoken(&mp->mnt_token); node = VP_TO_TMPFS_NODE(vp); /* * Degenerate case */ if (node == NULL) { vrecycle(vp); lwkt_reltoken(&mp->mnt_token); return(0); } /* * Get rid of unreferenced deleted vnodes sooner rather than * later so the data memory can be recovered immediately. * * We must truncate the vnode to prevent the normal reclamation * path from flushing the data for the removed file to disk. */ TMPFS_NODE_LOCK(node); if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 && node->tn_links == 0) { node->tn_vpstate = TMPFS_VNODE_DOOMED; TMPFS_NODE_UNLOCK(node); if (node->tn_type == VREG) tmpfs_truncate(vp, 0); vrecycle(vp); } else { TMPFS_NODE_UNLOCK(node); } lwkt_reltoken(&mp->mnt_token); return 0; }