2012-11-05 21:27:37 +04:00
|
|
|
/* $NetBSD: tmpfs_vnops.c,v 1.100 2012/11/05 17:27:39 dholland Exp $ */
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/*
|
2008-01-02 14:48:20 +03:00
|
|
|
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
|
2005-09-10 23:20:48 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2005-09-23 19:36:15 +04:00
|
|
|
* by Julio M. Merino Vidal, developed as part of Google's Summer of Code
|
|
|
|
* 2005 program.
|
2005-09-10 23:20:48 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tmpfs vnode interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2012-11-05 21:27:37 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.100 2012/11/05 17:27:39 dholland Exp $");
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/event.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/vnode.h>
|
2005-09-29 23:48:21 +04:00
|
|
|
#include <sys/lockf.h>
|
2006-05-15 04:05:16 +04:00
|
|
|
#include <sys/kauth.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
|
|
|
|
|
|
|
#include <miscfs/fifofs/fifo.h>
|
2009-06-23 23:36:38 +04:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
#include <fs/tmpfs/tmpfs_vnops.h>
|
|
|
|
#include <fs/tmpfs/tmpfs.h>
|
|
|
|
|
|
|
|
/*
|
2005-09-11 02:28:57 +04:00
|
|
|
* vnode operations vector used for files stored in a tmpfs file system.
|
2005-09-10 23:20:48 +04:00
|
|
|
*/
|
|
|
|
int (**tmpfs_vnodeop_p)(void *);
|
|
|
|
const struct vnodeopv_entry_desc tmpfs_vnodeop_entries[] = {
|
|
|
|
{ &vop_default_desc, vn_default_error },
|
|
|
|
{ &vop_lookup_desc, tmpfs_lookup },
|
|
|
|
{ &vop_create_desc, tmpfs_create },
|
|
|
|
{ &vop_mknod_desc, tmpfs_mknod },
|
|
|
|
{ &vop_open_desc, tmpfs_open },
|
|
|
|
{ &vop_close_desc, tmpfs_close },
|
|
|
|
{ &vop_access_desc, tmpfs_access },
|
|
|
|
{ &vop_getattr_desc, tmpfs_getattr },
|
|
|
|
{ &vop_setattr_desc, tmpfs_setattr },
|
|
|
|
{ &vop_read_desc, tmpfs_read },
|
|
|
|
{ &vop_write_desc, tmpfs_write },
|
|
|
|
{ &vop_ioctl_desc, tmpfs_ioctl },
|
|
|
|
{ &vop_fcntl_desc, tmpfs_fcntl },
|
|
|
|
{ &vop_poll_desc, tmpfs_poll },
|
|
|
|
{ &vop_kqfilter_desc, tmpfs_kqfilter },
|
|
|
|
{ &vop_revoke_desc, tmpfs_revoke },
|
|
|
|
{ &vop_mmap_desc, tmpfs_mmap },
|
|
|
|
{ &vop_fsync_desc, tmpfs_fsync },
|
|
|
|
{ &vop_seek_desc, tmpfs_seek },
|
|
|
|
{ &vop_remove_desc, tmpfs_remove },
|
|
|
|
{ &vop_link_desc, tmpfs_link },
|
|
|
|
{ &vop_rename_desc, tmpfs_rename },
|
|
|
|
{ &vop_mkdir_desc, tmpfs_mkdir },
|
|
|
|
{ &vop_rmdir_desc, tmpfs_rmdir },
|
|
|
|
{ &vop_symlink_desc, tmpfs_symlink },
|
|
|
|
{ &vop_readdir_desc, tmpfs_readdir },
|
|
|
|
{ &vop_readlink_desc, tmpfs_readlink },
|
|
|
|
{ &vop_abortop_desc, tmpfs_abortop },
|
|
|
|
{ &vop_inactive_desc, tmpfs_inactive },
|
|
|
|
{ &vop_reclaim_desc, tmpfs_reclaim },
|
|
|
|
{ &vop_lock_desc, tmpfs_lock },
|
|
|
|
{ &vop_unlock_desc, tmpfs_unlock },
|
|
|
|
{ &vop_bmap_desc, tmpfs_bmap },
|
|
|
|
{ &vop_strategy_desc, tmpfs_strategy },
|
|
|
|
{ &vop_print_desc, tmpfs_print },
|
|
|
|
{ &vop_pathconf_desc, tmpfs_pathconf },
|
|
|
|
{ &vop_islocked_desc, tmpfs_islocked },
|
|
|
|
{ &vop_advlock_desc, tmpfs_advlock },
|
|
|
|
{ &vop_bwrite_desc, tmpfs_bwrite },
|
|
|
|
{ &vop_getpages_desc, tmpfs_getpages },
|
|
|
|
{ &vop_putpages_desc, tmpfs_putpages },
|
2011-01-13 16:35:11 +03:00
|
|
|
{ &vop_whiteout_desc, tmpfs_whiteout },
|
2005-09-10 23:20:48 +04:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2011-05-25 00:17:49 +04:00
|
|
|
|
|
|
|
const struct vnodeopv_desc tmpfs_vnodeop_opv_desc = {
|
|
|
|
&tmpfs_vnodeop_p, tmpfs_vnodeop_entries
|
|
|
|
};
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2010-07-02 07:29:47 +04:00
|
|
|
/*
|
2011-05-19 07:13:58 +04:00
|
|
|
* tmpfs_lookup: path name traversal routine.
|
2010-07-02 07:29:47 +04:00
|
|
|
*
|
|
|
|
* Arguments: dvp (directory being searched), vpp (result),
|
|
|
|
* cnp (component name - path).
|
|
|
|
*
|
|
|
|
* => Caller holds a reference and lock on dvp.
|
|
|
|
* => We return looked-up vnode (vpp) locked, with a reference held.
|
|
|
|
*/
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_lookup(void *v)
|
|
|
|
{
|
2010-07-02 07:29:47 +04:00
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp;
|
2010-07-02 07:29:47 +04:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
2011-05-25 03:16:16 +04:00
|
|
|
const bool lastcn = (cnp->cn_flags & ISLASTCN) != 0;
|
|
|
|
tmpfs_node_t *dnode, *tnode;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_dirent_t *de;
|
2012-11-05 21:24:09 +04:00
|
|
|
int cachefound, iswhiteout;
|
2010-07-02 07:29:47 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
|
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
*vpp = NULL;
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Check accessibility of directory. */
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error) {
|
2005-09-10 23:20:48 +04:00
|
|
|
goto out;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2011-05-30 02:29:06 +04:00
|
|
|
|
2010-07-02 07:29:47 +04:00
|
|
|
/*
|
|
|
|
* If requesting the last path component on a read-only file system
|
|
|
|
* with a write operation, deny it.
|
|
|
|
*/
|
2011-05-25 03:16:16 +04:00
|
|
|
if (lastcn && (dvp->v_mount->mnt_flag & MNT_RDONLY) != 0 &&
|
2005-09-10 23:20:48 +04:00
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
|
|
|
|
error = EROFS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-07-02 07:29:47 +04:00
|
|
|
/*
|
|
|
|
* Avoid doing a linear scan of the directory if the requested
|
|
|
|
* directory/name couple is already in the cache.
|
|
|
|
*/
|
2012-11-05 21:27:37 +04:00
|
|
|
cachefound = cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
|
|
|
|
cnp->cn_nameiop, cnp->cn_flags,
|
|
|
|
&iswhiteout, vpp);
|
2012-11-05 21:24:09 +04:00
|
|
|
if (iswhiteout) {
|
|
|
|
cnp->cn_flags |= ISWHITEOUT;
|
|
|
|
}
|
|
|
|
if (cachefound && *vpp == NULLVP) {
|
|
|
|
/* Negative cache hit. */
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
} else if (cachefound) {
|
|
|
|
error = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
goto out;
|
2011-05-19 07:13:58 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_node_t *pnode;
|
2011-05-30 02:29:06 +04:00
|
|
|
|
2011-05-19 07:13:58 +04:00
|
|
|
/*
|
|
|
|
* Lookup of ".." case.
|
|
|
|
*/
|
2011-05-30 02:29:06 +04:00
|
|
|
if (lastcn && cnp->cn_nameiop == RENAME) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
KASSERT(dnode->tn_type == VDIR);
|
2011-05-19 07:13:58 +04:00
|
|
|
pnode = dnode->tn_spec.tn_dir.tn_parent;
|
2011-05-30 02:29:06 +04:00
|
|
|
if (pnode == NULL) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/*
|
|
|
|
* Lock the parent tn_vlock before releasing the vnode lock,
|
|
|
|
* and thus prevents parent from disappearing.
|
|
|
|
*/
|
|
|
|
mutex_enter(&pnode->tn_vlock);
|
|
|
|
VOP_UNLOCK(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/*
|
|
|
|
* Get a vnode of the '..' entry and re-acquire the lock.
|
|
|
|
* Release the tn_vlock.
|
|
|
|
*/
|
|
|
|
error = tmpfs_vnode_get(dvp->v_mount, pnode, vpp);
|
2006-12-09 19:11:50 +03:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
2011-05-19 07:13:58 +04:00
|
|
|
goto out;
|
2010-07-02 07:29:47 +04:00
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
} else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
|
2011-05-19 07:13:58 +04:00
|
|
|
/*
|
|
|
|
* Lookup of "." case.
|
|
|
|
*/
|
2011-05-25 03:16:16 +04:00
|
|
|
if (lastcn && cnp->cn_nameiop == RENAME) {
|
2010-07-14 20:03:49 +04:00
|
|
|
error = EISDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
*vpp = dvp;
|
|
|
|
error = 0;
|
2010-07-02 07:29:47 +04:00
|
|
|
goto done;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-19 07:13:58 +04:00
|
|
|
/*
|
|
|
|
* Other lookup cases: perform directory scan.
|
|
|
|
*/
|
2010-07-02 07:29:47 +04:00
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
2011-01-13 16:35:11 +03:00
|
|
|
if (de == NULL || de->td_node == TMPFS_NODE_WHITEOUT) {
|
2010-07-02 07:29:47 +04:00
|
|
|
/*
|
|
|
|
* The entry was not found in the directory. This is valid
|
|
|
|
* if we are creating or renaming an entry and are working
|
|
|
|
* on the last component of the path name.
|
|
|
|
*/
|
2011-05-25 03:16:16 +04:00
|
|
|
if (lastcn && (cnp->cn_nameiop == CREATE ||
|
2010-07-02 07:29:47 +04:00
|
|
|
cnp->cn_nameiop == RENAME)) {
|
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
|
|
|
|
if (error) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
error = EJUSTRETURN;
|
2005-09-10 23:20:48 +04:00
|
|
|
} else {
|
2010-07-02 07:29:47 +04:00
|
|
|
error = ENOENT;
|
|
|
|
}
|
2011-01-13 16:35:11 +03:00
|
|
|
if (de) {
|
|
|
|
KASSERT(de->td_node == TMPFS_NODE_WHITEOUT);
|
|
|
|
cnp->cn_flags |= ISWHITEOUT;
|
|
|
|
}
|
2011-05-25 03:16:16 +04:00
|
|
|
goto done;
|
|
|
|
}
|
2010-07-02 07:29:47 +04:00
|
|
|
|
2011-05-25 03:16:16 +04:00
|
|
|
tnode = de->td_node;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 03:16:16 +04:00
|
|
|
/*
|
|
|
|
* If it is not the last path component and found a non-directory
|
|
|
|
* or non-link entry (which may itself be pointing to a directory),
|
|
|
|
* raise an error.
|
|
|
|
*/
|
|
|
|
if (!lastcn && tnode->tn_type != VDIR && tnode->tn_type != VLNK) {
|
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 03:16:16 +04:00
|
|
|
/* Check the permissions. */
|
|
|
|
if (lastcn && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
|
2012-03-13 22:40:26 +04:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
|
|
|
|
if (error)
|
2011-05-25 03:16:16 +04:00
|
|
|
goto out;
|
2012-03-13 22:40:26 +04:00
|
|
|
|
|
|
|
if ((dnode->tn_mode & S_ISTXT) != 0) {
|
|
|
|
error = kauth_authorize_vnode(cnp->cn_cred,
|
|
|
|
KAUTH_VNODE_DELETE, tnode->tn_vnode,
|
|
|
|
dnode->tn_vnode, genfs_can_sticky(cnp->cn_cred,
|
|
|
|
dnode->tn_uid, tnode->tn_uid));
|
|
|
|
if (error) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
}
|
2011-05-25 03:16:16 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Get a vnode for the matching entry. */
|
|
|
|
mutex_enter(&tnode->tn_vlock);
|
|
|
|
error = tmpfs_vnode_get(dvp->v_mount, tnode, vpp);
|
2010-07-02 07:29:47 +04:00
|
|
|
done:
|
|
|
|
/*
|
2011-05-19 07:13:58 +04:00
|
|
|
* Cache the result, unless request was for creation (as it does
|
|
|
|
* not improve the performance).
|
2010-07-02 07:29:47 +04:00
|
|
|
*/
|
2012-07-22 04:53:18 +04:00
|
|
|
if (cnp->cn_nameiop != CREATE) {
|
2012-11-05 21:27:37 +04:00
|
|
|
cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen,
|
|
|
|
cnp->cn_flags);
|
2011-05-19 07:13:58 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
out:
|
2011-05-25 00:17:49 +04:00
|
|
|
KASSERT((*vpp && VOP_ISLOCKED(*vpp)) || error);
|
2006-12-09 19:11:50 +03:00
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
2011-01-13 16:35:11 +03:00
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_create(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_create_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_mknod(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_mknod_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
enum vtype vt = vap->va_type;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
if (vt != VBLK && vt != VCHR && vt != VFIFO) {
|
2009-03-19 16:47:32 +03:00
|
|
|
vput(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
return EINVAL;
|
2009-03-19 16:47:32 +03:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_open(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
mode_t mode = ap->a_mode;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2006-11-09 18:36:30 +03:00
|
|
|
if (node->tn_links < 1) {
|
2011-05-25 00:17:49 +04:00
|
|
|
/*
|
|
|
|
* The file is still active, but all its names have been
|
|
|
|
* removed (e.g. by a "rmdir $(pwd)"). It cannot be opened
|
|
|
|
* any more, as it is about to be destroyed.
|
|
|
|
*/
|
|
|
|
return ENOENT;
|
2006-11-09 18:36:30 +03:00
|
|
|
}
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
/* If the file is marked append-only, deny write requests. */
|
2011-05-25 00:17:49 +04:00
|
|
|
if ((node->tn_flags & APPEND) != 0 &&
|
|
|
|
(mode & (FWRITE | O_APPEND)) == FWRITE) {
|
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_close(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
|
2005-11-02 15:38:58 +03:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2012-01-22 07:13:19 +04:00
|
|
|
int
|
|
|
|
tmpfs_access(void *v)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2012-01-22 07:13:19 +04:00
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
mode_t mode = ap->a_mode;
|
|
|
|
kauth_cred_t cred = ap->a_cred;
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
|
2011-05-25 00:17:49 +04:00
|
|
|
const bool writing = (mode & VWRITE) != 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2012-01-22 07:13:19 +04:00
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
/* Possible? */
|
2005-09-10 23:20:48 +04:00
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
case VLNK:
|
|
|
|
case VREG:
|
2011-05-25 00:17:49 +04:00
|
|
|
if (writing && (vp->v_mount->mnt_flag & MNT_RDONLY) != 0) {
|
|
|
|
return EROFS;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VBLK:
|
|
|
|
case VCHR:
|
|
|
|
case VSOCK:
|
|
|
|
case VFIFO:
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-25 00:17:49 +04:00
|
|
|
return EINVAL;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2012-01-22 07:13:19 +04:00
|
|
|
if (writing && (node->tn_flags & IMMUTABLE) != 0) {
|
|
|
|
return EPERM;
|
|
|
|
}
|
2009-07-04 01:17:40 +04:00
|
|
|
|
2012-03-13 22:40:26 +04:00
|
|
|
return kauth_authorize_vnode(cred, kauth_access_action(mode,
|
|
|
|
vp->v_type, node->tn_mode), vp, NULL, genfs_can_access(vp->v_type,
|
|
|
|
node->tn_mode, node->tn_uid, node->tn_gid, mode, cred));
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_getattr(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2010-01-08 14:35:07 +03:00
|
|
|
vattr_null(vap);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 23:22:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, 0);
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
vap->va_type = vp->v_type;
|
|
|
|
vap->va_mode = node->tn_mode;
|
|
|
|
vap->va_nlink = node->tn_links;
|
|
|
|
vap->va_uid = node->tn_uid;
|
|
|
|
vap->va_gid = node->tn_gid;
|
|
|
|
vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
|
|
|
|
vap->va_fileid = node->tn_id;
|
|
|
|
vap->va_size = node->tn_size;
|
|
|
|
vap->va_blocksize = PAGE_SIZE;
|
|
|
|
vap->va_atime = node->tn_atime;
|
|
|
|
vap->va_mtime = node->tn_mtime;
|
|
|
|
vap->va_ctime = node->tn_ctime;
|
|
|
|
vap->va_birthtime = node->tn_birthtime;
|
2011-05-30 02:29:06 +04:00
|
|
|
vap->va_gen = TMPFS_NODE_GEN(node);
|
2005-09-10 23:20:48 +04:00
|
|
|
vap->va_flags = node->tn_flags;
|
|
|
|
vap->va_rdev = (vp->v_type == VBLK || vp->v_type == VCHR) ?
|
2011-05-25 00:17:49 +04:00
|
|
|
node->tn_spec.tn_dev.tn_rdev : VNOVAL;
|
2005-09-10 23:20:48 +04:00
|
|
|
vap->va_bytes = round_page(node->tn_size);
|
|
|
|
vap->va_filerev = VNOVAL;
|
|
|
|
vap->va_vaflags = 0;
|
|
|
|
vap->va_spare = VNOVAL; /* XXX */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-19 23:03:44 +04:00
|
|
|
#define GOODTIME(tv) ((tv)->tv_sec != VNOVAL || (tv)->tv_nsec != VNOVAL)
|
2005-09-10 23:20:48 +04:00
|
|
|
/* XXX Should this operation be atomic? I think it should, but code in
|
|
|
|
* XXX other places (e.g., ufs) doesn't seem to be... */
|
|
|
|
int
|
|
|
|
tmpfs_setattr(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
kauth_cred_t cred = ap->a_cred;
|
|
|
|
lwp_t *l = curlwp;
|
|
|
|
int error = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
/* Abort if any unsettable attribute is given. */
|
2011-05-25 00:17:49 +04:00
|
|
|
if (vap->va_type != VNON || vap->va_nlink != VNOVAL ||
|
|
|
|
vap->va_fsid != VNOVAL || vap->va_fileid != VNOVAL ||
|
|
|
|
vap->va_blocksize != VNOVAL || GOODTIME(&vap->va_ctime) ||
|
|
|
|
vap->va_gen != VNOVAL || vap->va_rdev != VNOVAL ||
|
|
|
|
vap->va_bytes != VNOVAL) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
if (error == 0 && (vap->va_flags != VNOVAL))
|
2006-07-24 02:06:03 +04:00
|
|
|
error = tmpfs_chflags(vp, vap->va_flags, cred, l);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
if (error == 0 && (vap->va_size != VNOVAL))
|
2006-07-24 02:06:03 +04:00
|
|
|
error = tmpfs_chsize(vp, vap->va_size, cred, l);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL))
|
2006-07-24 02:06:03 +04:00
|
|
|
error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred, l);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
if (error == 0 && (vap->va_mode != VNOVAL))
|
2006-07-24 02:06:03 +04:00
|
|
|
error = tmpfs_chmod(vp, vap->va_mode, cred, l);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-06-19 23:03:44 +04:00
|
|
|
if (error == 0 && (GOODTIME(&vap->va_atime) || GOODTIME(&vap->va_mtime)
|
2011-05-25 00:17:49 +04:00
|
|
|
|| GOODTIME(&vap->va_birthtime))) {
|
|
|
|
error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
|
|
|
|
&vap->va_birthtime, vap->va_vaflags, cred, l);
|
|
|
|
if (error == 0)
|
2008-06-19 23:03:44 +04:00
|
|
|
return 0;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, 0);
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_read(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
const int ioflag = ap->a_ioflag;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-13 18:29:18 +04:00
|
|
|
struct uvm_object *uobj;
|
2011-05-25 00:17:49 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
2005-09-13 18:27:29 +04:00
|
|
|
if (vp->v_type != VREG) {
|
2011-05-25 00:17:49 +04:00
|
|
|
return EISDIR;
|
2005-09-13 18:27:29 +04:00
|
|
|
}
|
|
|
|
if (uio->uio_offset < 0) {
|
2011-05-25 00:17:49 +04:00
|
|
|
return EINVAL;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED;
|
2006-02-16 17:57:50 +03:00
|
|
|
uobj = node->tn_spec.tn_reg.tn_aobj;
|
2005-09-13 18:29:18 +04:00
|
|
|
error = 0;
|
2011-05-25 00:17:49 +04:00
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
while (error == 0 && uio->uio_resid > 0) {
|
2005-09-13 18:29:18 +04:00
|
|
|
vsize_t len;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
if (node->tn_size <= uio->uio_offset) {
|
2005-09-14 14:40:49 +04:00
|
|
|
break;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2005-09-13 18:29:18 +04:00
|
|
|
len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (len == 0) {
|
2005-09-13 18:29:18 +04:00
|
|
|
break;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2008-11-26 23:17:33 +03:00
|
|
|
error = ubc_uiomove(uobj, uio, len, IO_ADV_DECODE(ioflag),
|
|
|
|
UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
|
2005-09-13 18:29:18 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_write(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_write_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
const int ioflag = ap->a_ioflag;
|
|
|
|
tmpfs_node_t *node;
|
|
|
|
struct uvm_object *uobj;
|
|
|
|
off_t oldsize;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool extended;
|
2005-09-10 23:20:48 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
oldsize = node->tn_size;
|
|
|
|
|
|
|
|
if (uio->uio_offset < 0 || vp->v_type != VREG) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (uio->uio_resid == 0) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
if (ioflag & IO_APPEND) {
|
2005-09-10 23:20:48 +04:00
|
|
|
uio->uio_offset = node->tn_size;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
extended = uio->uio_offset + uio->uio_resid > node->tn_size;
|
|
|
|
if (extended) {
|
|
|
|
error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error)
|
2005-09-10 23:20:48 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2006-02-16 17:57:50 +03:00
|
|
|
uobj = node->tn_spec.tn_reg.tn_aobj;
|
2005-09-13 18:29:18 +04:00
|
|
|
error = 0;
|
2005-09-14 00:02:05 +04:00
|
|
|
while (error == 0 && uio->uio_resid > 0) {
|
2005-09-13 18:29:18 +04:00
|
|
|
vsize_t len;
|
|
|
|
|
|
|
|
len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (len == 0) {
|
2005-09-13 18:29:18 +04:00
|
|
|
break;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2008-11-26 23:17:33 +03:00
|
|
|
error = ubc_uiomove(uobj, uio, len, IO_ADV_DECODE(ioflag),
|
|
|
|
UBC_WRITE | UBC_UNMAP_FLAG(vp));
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error) {
|
|
|
|
(void)tmpfs_reg_resize(vp, oldsize);
|
|
|
|
}
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
|
|
|
|
(extended ? TMPFS_NODE_CHANGED : 0);
|
2006-11-09 18:06:03 +03:00
|
|
|
VN_KNOTE(vp, NOTE_WRITE);
|
2005-09-10 23:20:48 +04:00
|
|
|
out:
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error) {
|
|
|
|
KASSERT(oldsize == node->tn_size);
|
|
|
|
} else {
|
|
|
|
KASSERT(uio->uio_resid == 0);
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_fsync(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_fsync_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
int a_flags;
|
|
|
|
off_t a_offlo;
|
|
|
|
off_t a_offhi;
|
|
|
|
struct lwp *a_l;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/* Nothing to do. Just update. */
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, 0);
|
2005-11-02 15:38:58 +03:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/*
|
|
|
|
* tmpfs_remove: unlink a file.
|
|
|
|
*
|
|
|
|
* => Both directory (dvp) and file (vp) are locked.
|
|
|
|
* => We unlock and drop the reference on both.
|
|
|
|
*/
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_remove(void *v)
|
|
|
|
{
|
2011-05-19 07:13:58 +04:00
|
|
|
struct vop_remove_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *dvp = ap->a_dvp, *vp = ap->a_vp;
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_node_t *node;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_dirent_t *de;
|
2011-05-19 07:13:58 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
2007-01-02 14:02:19 +03:00
|
|
|
if (vp->v_type == VDIR) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
/* Files marked as immutable or append-only cannot be deleted. */
|
|
|
|
if (node->tn_flags & (IMMUTABLE | APPEND)) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Lookup the directory entry (check the cached hint first). */
|
|
|
|
de = tmpfs_dir_cached(node);
|
|
|
|
if (de == NULL) {
|
|
|
|
tmpfs_node_t *dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
|
|
|
}
|
2011-05-19 07:13:58 +04:00
|
|
|
KASSERT(de && de->td_node == node);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-19 07:13:58 +04:00
|
|
|
/*
|
2011-05-30 02:29:06 +04:00
|
|
|
* Remove the entry from the directory (drops the link count) and
|
2011-08-27 19:32:28 +04:00
|
|
|
* destroy it or replace it with a whiteout.
|
|
|
|
* Note: the inode referred by it will not be destroyed
|
2011-05-30 02:29:06 +04:00
|
|
|
* until the vnode is reclaimed/recycled.
|
2011-05-19 07:13:58 +04:00
|
|
|
*/
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_dir_detach(dvp, de);
|
2011-08-27 19:32:28 +04:00
|
|
|
if (ap->a_cnp->cn_flags & DOWHITEOUT)
|
|
|
|
tmpfs_dir_attach(dvp, de, TMPFS_NODE_WHITEOUT);
|
|
|
|
else
|
|
|
|
tmpfs_free_dirent(VFS_TO_TMPFS(vp->v_mount), de);
|
2005-09-10 23:20:48 +04:00
|
|
|
error = 0;
|
|
|
|
out:
|
2011-05-25 00:17:49 +04:00
|
|
|
/* Drop the references and unlock the vnodes. */
|
2005-09-10 23:20:48 +04:00
|
|
|
vput(vp);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (dvp == vp) {
|
2007-01-02 14:02:19 +03:00
|
|
|
vrele(dvp);
|
2011-05-25 00:17:49 +04:00
|
|
|
} else {
|
2007-01-02 14:02:19 +03:00
|
|
|
vput(dvp);
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-04-25 01:35:29 +04:00
|
|
|
/*
|
2011-05-25 00:17:49 +04:00
|
|
|
* tmpfs_link: create a hard link.
|
2011-04-25 01:35:29 +04:00
|
|
|
*/
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_link(void *v)
|
|
|
|
{
|
2011-04-25 01:35:29 +04:00
|
|
|
struct vop_link_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *dvp = ap->a_dvp;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
2011-05-19 07:13:58 +04:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_node_t *dnode, *node;
|
|
|
|
tmpfs_dirent_t *de;
|
2011-04-25 01:35:29 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-04-25 01:35:29 +04:00
|
|
|
KASSERT(dvp != vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
2011-04-25 01:35:29 +04:00
|
|
|
KASSERT(vp->v_type != VDIR);
|
|
|
|
KASSERT(dvp->v_mount == vp->v_mount);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2009-10-06 04:17:24 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 03:16:16 +04:00
|
|
|
/* Check for maximum number of links limit. */
|
2005-09-10 23:20:48 +04:00
|
|
|
if (node->tn_links == LINK_MAX) {
|
|
|
|
error = EMLINK;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-05-30 02:29:06 +04:00
|
|
|
KASSERT(node->tn_links < LINK_MAX);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* We cannot create links of files marked immutable or append-only. */
|
|
|
|
if (node->tn_flags & (IMMUTABLE | APPEND)) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Allocate a new directory entry to represent the inode. */
|
|
|
|
error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount),
|
2005-09-10 23:20:48 +04:00
|
|
|
cnp->cn_nameptr, cnp->cn_namelen, &de);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error) {
|
2005-09-10 23:20:48 +04:00
|
|
|
goto out;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/*
|
|
|
|
* Insert the entry into the directory.
|
|
|
|
* It will increase the inode link count.
|
|
|
|
*/
|
|
|
|
tmpfs_dir_attach(dvp, de, node);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Update the timestamps and trigger the event. */
|
|
|
|
if (node->tn_vnode) {
|
|
|
|
VN_KNOTE(node->tn_vnode, NOTE_LINK);
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_CHANGED;
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, 0);
|
2005-09-10 23:20:48 +04:00
|
|
|
error = 0;
|
|
|
|
out:
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
vput(dvp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_mkdir(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_mkdir_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp;
|
|
|
|
vnode_t **vpp = ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(vap->va_type == VDIR);
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_rmdir(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_rmdir_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
tmpfs_mount_t *tmp = VFS_TO_TMPFS(dvp->v_mount);
|
|
|
|
tmpfs_node_t *dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_DIR(vp);
|
|
|
|
tmpfs_dirent_t *de;
|
|
|
|
int error = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
2011-05-25 00:17:49 +04:00
|
|
|
KASSERT(node->tn_spec.tn_dir.tn_parent == dnode);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/*
|
2011-08-27 19:32:28 +04:00
|
|
|
* Directories with more than two non-whiteout
|
|
|
|
* entries ('.' and '..') cannot be removed.
|
2011-05-25 00:17:49 +04:00
|
|
|
*/
|
2007-01-02 14:02:19 +03:00
|
|
|
if (node->tn_size > 0) {
|
2011-08-27 19:32:28 +04:00
|
|
|
KASSERT(error == 0);
|
|
|
|
TAILQ_FOREACH(de, &node->tn_spec.tn_dir.tn_dir, td_entries) {
|
|
|
|
if (de->td_node != TMPFS_NODE_WHITEOUT) {
|
|
|
|
error = ENOTEMPTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
goto out;
|
2007-01-02 14:02:19 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Lookup the directory entry (check the cached hint first). */
|
|
|
|
de = tmpfs_dir_cached(node);
|
|
|
|
if (de == NULL) {
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
KASSERT(de && de->td_node == node);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Check flags to see if we are allowed to remove the directory. */
|
|
|
|
if (dnode->tn_flags & APPEND || node->tn_flags & (IMMUTABLE | APPEND)) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/* Decrement the link count for the virtual '.' entry. */
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_links--;
|
2011-05-25 00:17:49 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_STATUSALL;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 23:22:44 +04:00
|
|
|
/* Detach the directory entry from the directory. */
|
|
|
|
tmpfs_dir_detach(dvp, de);
|
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/* Purge the cache for parent. */
|
|
|
|
cache_purge(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/*
|
2011-08-27 19:32:28 +04:00
|
|
|
* Destroy the directory entry or replace it with a whiteout.
|
|
|
|
* Note: the inode referred by it will not be destroyed
|
|
|
|
* until the vnode is reclaimed.
|
2011-05-25 00:17:49 +04:00
|
|
|
*/
|
2011-08-27 19:32:28 +04:00
|
|
|
if (ap->a_cnp->cn_flags & DOWHITEOUT)
|
|
|
|
tmpfs_dir_attach(dvp, de, TMPFS_NODE_WHITEOUT);
|
|
|
|
else
|
|
|
|
tmpfs_free_dirent(tmp, de);
|
|
|
|
|
|
|
|
/* Destroy the whiteout entries from the node. */
|
|
|
|
while ((de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir)) != NULL) {
|
|
|
|
KASSERT(de->td_node == TMPFS_NODE_WHITEOUT);
|
|
|
|
tmpfs_dir_detach(vp, de);
|
|
|
|
tmpfs_free_dirent(tmp, de);
|
|
|
|
}
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(node->tn_links == 0);
|
2011-05-25 00:17:49 +04:00
|
|
|
out:
|
2007-10-23 23:49:01 +04:00
|
|
|
/* Release the nodes. */
|
|
|
|
vput(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
vput(vp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_symlink(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_symlink_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp;
|
|
|
|
vnode_t **vpp = ap->a_vpp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
char *target = ap->a_target;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(vap->va_type == VLNK);
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_readdir(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
int *a_eofflag;
|
|
|
|
off_t **a_cookies;
|
|
|
|
int *ncookies;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
int *eofflag = ap->a_eofflag;
|
|
|
|
off_t **cookies = ap->a_cookies;
|
|
|
|
int *ncookies = ap->a_ncookies;
|
|
|
|
off_t startoff, cnt;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-10 23:20:48 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
/* This operation only makes sense on directory nodes. */
|
|
|
|
if (vp->v_type != VDIR) {
|
2011-05-25 00:17:49 +04:00
|
|
|
return ENOTDIR;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
node = VP_TO_TMPFS_DIR(vp);
|
|
|
|
startoff = uio->uio_offset;
|
2005-09-15 16:34:35 +04:00
|
|
|
cnt = 0;
|
2012-02-27 20:10:56 +04:00
|
|
|
if (node->tn_links == 0) {
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
|
2005-09-15 16:34:35 +04:00
|
|
|
if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
|
2005-09-10 23:20:48 +04:00
|
|
|
error = tmpfs_dir_getdotdent(node, uio);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error != 0) {
|
|
|
|
if (error == -1)
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-15 16:34:35 +04:00
|
|
|
cnt++;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2005-09-15 16:34:35 +04:00
|
|
|
if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
|
2005-09-10 23:20:48 +04:00
|
|
|
error = tmpfs_dir_getdotdotdent(node, uio);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error != 0) {
|
|
|
|
if (error == -1)
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-15 16:34:35 +04:00
|
|
|
cnt++;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2005-09-15 16:34:35 +04:00
|
|
|
error = tmpfs_dir_getdents(node, uio, &cnt);
|
2011-05-25 00:17:49 +04:00
|
|
|
if (error == -1) {
|
2005-09-10 23:20:48 +04:00
|
|
|
error = 0;
|
2011-05-25 00:17:49 +04:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(error >= 0);
|
2011-05-25 00:17:49 +04:00
|
|
|
out:
|
|
|
|
if (eofflag != NULL) {
|
|
|
|
*eofflag = (!error && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
|
|
|
|
}
|
|
|
|
if (error || cookies == NULL || ncookies == NULL) {
|
|
|
|
return error;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
/* Update NFS-related variables, if any. */
|
|
|
|
off_t i, off = startoff;
|
|
|
|
tmpfs_dirent_t *de = NULL;
|
2005-09-15 16:34:35 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
*cookies = malloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
|
|
|
|
*ncookies = cnt;
|
2005-09-15 16:34:35 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
KASSERT(off != TMPFS_DIRCOOKIE_EOF);
|
|
|
|
if (off != TMPFS_DIRCOOKIE_DOT) {
|
|
|
|
if (off == TMPFS_DIRCOOKIE_DOTDOT) {
|
|
|
|
de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir);
|
|
|
|
} else if (de != NULL) {
|
|
|
|
de = TAILQ_NEXT(de, td_entries);
|
2005-09-15 16:34:35 +04:00
|
|
|
} else {
|
2011-05-25 00:17:49 +04:00
|
|
|
de = tmpfs_dir_lookupbycookie(node, off);
|
|
|
|
KASSERT(de != NULL);
|
|
|
|
de = TAILQ_NEXT(de, td_entries);
|
2005-09-15 16:34:35 +04:00
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
if (de == NULL) {
|
|
|
|
off = TMPFS_DIRCOOKIE_EOF;
|
|
|
|
} else {
|
|
|
|
off = tmpfs_dircookie(de);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
off = TMPFS_DIRCOOKIE_DOTDOT;
|
2005-09-15 16:34:35 +04:00
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
(*cookies)[i] = off;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
KASSERT(uio->uio_offset == off);
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_readlink(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_readlink_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
kauth_cred_t a_cred;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-10 23:20:48 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
KASSERT(uio->uio_offset == 0);
|
|
|
|
KASSERT(vp->v_type == VLNK);
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2006-02-16 17:57:50 +03:00
|
|
|
error = uiomove(node->tn_spec.tn_lnk.tn_link,
|
|
|
|
MIN(node->tn_size, uio->uio_resid), uio);
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_inactive(void *v)
|
|
|
|
{
|
2011-05-19 07:13:58 +04:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
bool *a_recycle;
|
|
|
|
} */ *ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2011-05-19 07:13:58 +04:00
|
|
|
*ap->a_recycle = (node->tn_links == 0);
|
2010-06-24 16:58:48 +04:00
|
|
|
VOP_UNLOCK(vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_reclaim(void *v)
|
|
|
|
{
|
2011-05-19 07:13:58 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
tmpfs_mount_t *tmp = VFS_TO_TMPFS(vp->v_mount);
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
|
2011-05-30 02:29:06 +04:00
|
|
|
bool racing;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-19 07:13:58 +04:00
|
|
|
/* Disassociate inode from vnode. */
|
2011-05-30 02:29:06 +04:00
|
|
|
mutex_enter(&node->tn_vlock);
|
|
|
|
node->tn_vnode = NULL;
|
|
|
|
vp->v_data = NULL;
|
|
|
|
/* Check if tmpfs_vnode_get() is racing with us. */
|
|
|
|
racing = TMPFS_NODE_RECLAIMING(node);
|
|
|
|
mutex_exit(&node->tn_vlock);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
/*
|
|
|
|
* If inode is not referenced, i.e. no links, then destroy it.
|
|
|
|
* Note: if racing - inode is about to get a new vnode, leave it.
|
|
|
|
*/
|
|
|
|
if (node->tn_links == 0 && !racing) {
|
2011-05-19 07:13:58 +04:00
|
|
|
tmpfs_free_node(tmp, node);
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_pathconf(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_name;
|
|
|
|
register_t *a_retval;
|
|
|
|
} */ *ap = v;
|
|
|
|
const int name = ap->a_name;
|
|
|
|
register_t *retval = ap->a_retval;
|
|
|
|
int error = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*retval = LINK_MAX;
|
|
|
|
break;
|
|
|
|
case _PC_NAME_MAX:
|
2011-09-27 05:32:21 +04:00
|
|
|
*retval = TMPFS_MAXNAMLEN;
|
2005-09-10 23:20:48 +04:00
|
|
|
break;
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
*retval = PATH_MAX;
|
|
|
|
break;
|
|
|
|
case _PC_PIPE_BUF:
|
|
|
|
*retval = PIPE_BUF;
|
|
|
|
break;
|
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*retval = 1;
|
|
|
|
break;
|
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
*retval = 1;
|
|
|
|
break;
|
|
|
|
case _PC_SYNC_IO:
|
|
|
|
*retval = 1;
|
|
|
|
break;
|
|
|
|
case _PC_FILESIZEBITS:
|
2011-05-30 02:29:06 +04:00
|
|
|
*retval = sizeof(off_t) * CHAR_BIT;
|
2005-09-10 23:20:48 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-09-29 23:48:21 +04:00
|
|
|
int
|
|
|
|
tmpfs_advlock(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_advlock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
void * a_id;
|
|
|
|
int a_op;
|
|
|
|
struct flock *a_fl;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
|
2005-09-29 23:48:21 +04:00
|
|
|
|
|
|
|
return lf_advlock(v, &node->tn_lockf, node->tn_size);
|
|
|
|
}
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_getpages(void *v)
|
|
|
|
{
|
2011-05-03 03:42:10 +04:00
|
|
|
struct vop_getpages_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
voff_t a_offset;
|
|
|
|
struct vm_page **a_m;
|
|
|
|
int *a_count;
|
|
|
|
int a_centeridx;
|
|
|
|
vm_prot_t a_access_type;
|
|
|
|
int a_advice;
|
|
|
|
int a_flags;
|
|
|
|
} */ * const ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *vp = ap->a_vp;
|
2011-05-03 03:42:10 +04:00
|
|
|
const voff_t offset = ap->a_offset;
|
|
|
|
struct vm_page **pgs = ap->a_m;
|
|
|
|
const int centeridx = ap->a_centeridx;
|
|
|
|
const vm_prot_t access_type = ap->a_access_type;
|
|
|
|
const int advice = ap->a_advice;
|
|
|
|
const int flags = ap->a_flags;
|
|
|
|
int error, npages = *ap->a_count;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_node_t *node;
|
2005-09-14 00:02:05 +04:00
|
|
|
struct uvm_object *uobj;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
KASSERT(vp->v_type == VREG);
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(mutex_owned(vp->v_interlock));
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2006-02-16 17:57:50 +03:00
|
|
|
uobj = node->tn_spec.tn_reg.tn_aobj;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-03 03:42:10 +04:00
|
|
|
/*
|
|
|
|
* Currently, PGO_PASTEOF is not supported.
|
|
|
|
*/
|
2005-09-15 00:27:26 +04:00
|
|
|
if (vp->v_size <= offset + (centeridx << PAGE_SHIFT)) {
|
|
|
|
if ((flags & PGO_LOCKED) == 0)
|
2011-06-12 07:35:36 +04:00
|
|
|
mutex_exit(vp->v_interlock);
|
2005-09-15 00:27:26 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vp->v_size < offset + (npages << PAGE_SHIFT)) {
|
|
|
|
npages = (round_page(vp->v_size) - offset) >> PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
if ((flags & PGO_LOCKED) != 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
if ((flags & PGO_NOTIMESTAMP) == 0) {
|
2005-09-14 00:02:05 +04:00
|
|
|
if ((vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED;
|
2005-09-14 00:02:05 +04:00
|
|
|
|
2011-11-19 01:18:50 +04:00
|
|
|
if ((access_type & VM_PROT_WRITE) != 0) {
|
2005-09-13 18:29:18 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_MODIFIED;
|
2011-11-19 01:18:50 +04:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RELATIME)
|
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2006-11-02 18:35:25 +03:00
|
|
|
/*
|
2011-05-03 03:42:10 +04:00
|
|
|
* Invoke the pager.
|
2008-02-06 14:22:12 +03:00
|
|
|
*
|
2011-05-03 03:42:10 +04:00
|
|
|
* Clean the array of pages before. XXX: PR/32166
|
|
|
|
* Note that vnode lock is shared with underlying UVM object.
|
2006-11-02 18:35:25 +03:00
|
|
|
*/
|
2011-05-03 03:42:10 +04:00
|
|
|
if (pgs) {
|
|
|
|
memset(pgs, 0, sizeof(struct vm_pages *) * npages);
|
|
|
|
}
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(vp->v_interlock == uobj->vmobjlock);
|
|
|
|
|
2011-05-03 03:42:10 +04:00
|
|
|
error = (*uobj->pgops->pgo_get)(uobj, offset, pgs, &npages, centeridx,
|
2006-11-02 18:35:25 +03:00
|
|
|
access_type, advice, flags | PGO_ALLPAGES);
|
2011-05-03 03:42:10 +04:00
|
|
|
|
2006-11-02 18:35:25 +03:00
|
|
|
#if defined(DEBUG)
|
2011-05-03 03:42:10 +04:00
|
|
|
if (!error && pgs) {
|
2011-05-10 04:34:26 +04:00
|
|
|
for (int i = 0; i < npages; i++) {
|
2011-05-03 03:42:10 +04:00
|
|
|
KASSERT(pgs[i] != NULL);
|
|
|
|
}
|
2006-11-02 18:35:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
2005-09-13 18:29:18 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_putpages(void *v)
|
|
|
|
{
|
2011-05-03 03:42:10 +04:00
|
|
|
struct vop_putpages_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
voff_t a_offlo;
|
|
|
|
voff_t a_offhi;
|
|
|
|
int a_flags;
|
|
|
|
} */ * const ap = v;
|
2011-05-25 00:17:49 +04:00
|
|
|
vnode_t *vp = ap->a_vp;
|
2011-05-03 03:42:10 +04:00
|
|
|
const voff_t offlo = ap->a_offlo;
|
|
|
|
const voff_t offhi = ap->a_offhi;
|
|
|
|
const int flags = ap->a_flags;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_node_t *node;
|
2005-09-14 00:02:05 +04:00
|
|
|
struct uvm_object *uobj;
|
2011-05-03 03:42:10 +04:00
|
|
|
int error;
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(mutex_owned(vp->v_interlock));
|
2005-09-14 00:02:05 +04:00
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
if (vp->v_type != VREG) {
|
2011-06-12 07:35:36 +04:00
|
|
|
mutex_exit(vp->v_interlock);
|
2005-09-13 18:29:18 +04:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2006-02-16 17:57:50 +03:00
|
|
|
uobj = node->tn_spec.tn_reg.tn_aobj;
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
KASSERT(vp->v_interlock == uobj->vmobjlock);
|
2005-09-14 00:02:05 +04:00
|
|
|
error = (*uobj->pgops->pgo_put)(uobj, offlo, offhi, flags);
|
2005-09-13 18:29:18 +04:00
|
|
|
|
|
|
|
/* XXX mtime */
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2011-01-13 16:35:11 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_whiteout(void *v)
|
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
struct vop_whiteout_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *dvp = ap->a_dvp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
const int flags = ap->a_flags;
|
|
|
|
tmpfs_mount_t *tmp = VFS_TO_TMPFS(dvp->v_mount);
|
|
|
|
tmpfs_dirent_t *de;
|
2011-01-13 16:35:11 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (flags) {
|
|
|
|
case LOOKUP:
|
|
|
|
break;
|
|
|
|
case CREATE:
|
2011-05-30 02:29:06 +04:00
|
|
|
error = tmpfs_alloc_dirent(tmp, cnp->cn_nameptr,
|
|
|
|
cnp->cn_namelen, &de);
|
2011-01-13 16:35:11 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_dir_attach(dvp, de, TMPFS_NODE_WHITEOUT);
|
2011-01-13 16:35:11 +03:00
|
|
|
break;
|
|
|
|
case DELETE:
|
|
|
|
cnp->cn_flags &= ~DOWHITEOUT; /* when in doubt, cargo cult */
|
|
|
|
de = tmpfs_dir_lookup(VP_TO_TMPFS_DIR(dvp), cnp);
|
|
|
|
if (de == NULL)
|
|
|
|
return ENOENT;
|
|
|
|
tmpfs_dir_detach(dvp, de);
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_free_dirent(tmp, de);
|
2011-01-13 16:35:11 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_print(void *v)
|
|
|
|
{
|
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap = v;
|
|
|
|
vnode_t *vp = ap->a_vp;
|
|
|
|
tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
printf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n"
|
|
|
|
"\tmode 0%o, owner %d, group %d, size %" PRIdMAX ", status 0x%x",
|
|
|
|
node, node->tn_flags, node->tn_links, node->tn_mode, node->tn_uid,
|
|
|
|
node->tn_gid, (uintmax_t)node->tn_size, node->tn_status);
|
|
|
|
if (vp->v_type == VFIFO) {
|
|
|
|
VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return 0;
|
|
|
|
}
|