2010-06-22 22:32:07 +04:00
|
|
|
/* $NetBSD: tmpfs_vnops.c,v 1.70 2010/06/22 18:32:08 rmind 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>
|
2010-06-22 22:32:07 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.70 2010/06/22 18:32:08 rmind 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/proc.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 },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct vnodeopv_desc tmpfs_vnodeop_opv_desc =
|
|
|
|
{ &tmpfs_vnodeop_p, tmpfs_vnodeop_entries };
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_lookup(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_lookup_args *)v)->a_dvp;
|
|
|
|
struct vnode **vpp = ((struct vop_lookup_args *)v)->a_vpp;
|
|
|
|
struct componentname *cnp = ((struct vop_lookup_args *)v)->a_cnp;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_dirent *de;
|
|
|
|
struct tmpfs_node *dnode;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
|
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
*vpp = NULL;
|
|
|
|
|
|
|
|
/* Check accessibility of requested node as a first step. */
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred);
|
2005-09-10 23:20:48 +04:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
2005-09-11 02:28:57 +04:00
|
|
|
/* If requesting the last path component on a read-only file system
|
2005-09-10 23:20:48 +04:00
|
|
|
* with a write operation, deny it. */
|
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(dvp->v_mount->mnt_flag & MNT_RDONLY) &&
|
|
|
|
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
|
|
|
|
error = EROFS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Avoid doing a linear scan of the directory if the requested
|
|
|
|
* directory/name couple is already in the cache. */
|
|
|
|
error = cache_lookup(dvp, vpp, cnp);
|
|
|
|
if (error >= 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* We cannot be requesting the parent directory of the root node. */
|
|
|
|
KASSERT(IMPLIES(dnode->tn_type == VDIR &&
|
2006-02-16 17:57:50 +03:00
|
|
|
dnode->tn_spec.tn_dir.tn_parent == dnode,
|
|
|
|
!(cnp->cn_flags & ISDOTDOT)));
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
if (cnp->cn_flags & ISDOTDOT) {
|
|
|
|
VOP_UNLOCK(dvp, 0);
|
|
|
|
|
|
|
|
/* Allocate a new vnode on the matching entry. */
|
2006-02-16 17:57:50 +03:00
|
|
|
error = tmpfs_alloc_vp(dvp->v_mount,
|
|
|
|
dnode->tn_spec.tn_dir.tn_parent, vpp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2006-12-09 19:11:50 +03:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
|
2005-09-10 23:20:48 +04:00
|
|
|
} else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
|
2010-01-08 14:35:07 +03:00
|
|
|
vref(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
*vpp = dvp;
|
|
|
|
error = 0;
|
|
|
|
} else {
|
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
|
|
|
if (de == NULL) {
|
|
|
|
/* The entry was not found in the directory.
|
|
|
|
* This is OK iff we are creating or renaming an
|
|
|
|
* entry and are working on the last component of
|
|
|
|
* the path name. */
|
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(cnp->cn_nameiop == CREATE || \
|
|
|
|
cnp->cn_nameiop == RENAME)) {
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
|
2005-09-10 23:20:48 +04:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Keep the component name in the buffer for
|
|
|
|
* future uses. */
|
|
|
|
cnp->cn_flags |= SAVENAME;
|
|
|
|
|
|
|
|
error = EJUSTRETURN;
|
|
|
|
} else
|
|
|
|
error = ENOENT;
|
|
|
|
} else {
|
|
|
|
struct tmpfs_node *tnode;
|
|
|
|
|
|
|
|
/* The entry was found, so get its associated
|
|
|
|
* tmpfs_node. */
|
|
|
|
tnode = de->td_node;
|
|
|
|
|
|
|
|
/* If we are not at the last path component and
|
2005-10-03 23:36:42 +04:00
|
|
|
* found a non-directory or non-link entry (which
|
|
|
|
* may itself be pointing to a directory), raise
|
|
|
|
* an error. */
|
|
|
|
if ((tnode->tn_type != VDIR &&
|
|
|
|
tnode->tn_type != VLNK) &&
|
2005-09-10 23:20:48 +04:00
|
|
|
!(cnp->cn_flags & ISLASTCN)) {
|
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-04-29 15:01:50 +04:00
|
|
|
/* Check permissions */
|
2005-09-10 23:20:48 +04:00
|
|
|
if ((cnp->cn_flags & ISLASTCN) &&
|
|
|
|
(cnp->cn_nameiop == DELETE ||
|
|
|
|
cnp->cn_nameiop == RENAME)) {
|
2009-09-03 08:45:27 +04:00
|
|
|
kauth_action_t action = 0;
|
|
|
|
|
|
|
|
/* This is the file-system's decision. */
|
2006-02-21 06:19:45 +03:00
|
|
|
if ((dnode->tn_mode & S_ISTXT) != 0 &&
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_geteuid(cnp->cn_cred) != dnode->tn_uid &&
|
|
|
|
kauth_cred_geteuid(cnp->cn_cred) != tnode->tn_uid)
|
2009-09-03 08:45:27 +04:00
|
|
|
error = EPERM;
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
/* Only bother if we're not already failing it. */
|
|
|
|
if (!error) {
|
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnp->cn_nameiop == DELETE)
|
|
|
|
action |= KAUTH_VNODE_DELETE;
|
|
|
|
else /* if (cnp->cn_nameiop == RENAME) */
|
|
|
|
action |= KAUTH_VNODE_RENAME;
|
|
|
|
|
|
|
|
error = kauth_authorize_vnode(cnp->cn_cred,
|
|
|
|
action, *vpp, dvp, error);
|
2005-09-10 23:20:48 +04:00
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
2009-09-03 08:45:27 +04:00
|
|
|
|
2009-04-11 04:21:57 +04:00
|
|
|
cnp->cn_flags |= SAVENAME;
|
2008-01-02 14:48:20 +03:00
|
|
|
} else
|
|
|
|
de = NULL;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Allocate a new vnode on the matching entry. */
|
|
|
|
error = tmpfs_alloc_vp(dvp->v_mount, tnode, vpp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store the result of this lookup in the cache. Avoid this if the
|
|
|
|
* request was for creation, as it does not improve timings on
|
|
|
|
* emprical tests. */
|
2008-01-02 14:48:20 +03:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE &&
|
|
|
|
(cnp->cn_flags & ISDOTDOT) == 0)
|
2005-09-10 23:20:48 +04:00
|
|
|
cache_enter(dvp, *vpp, cnp);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* If there were no errors, *vpp cannot be null and it must be
|
|
|
|
* locked. */
|
|
|
|
KASSERT(IFF(error == 0, *vpp != NULL && VOP_ISLOCKED(*vpp)));
|
|
|
|
|
2006-12-09 19:11:50 +03:00
|
|
|
/* dvp must always be locked. */
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_create(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_create_args *)v)->a_dvp;
|
|
|
|
struct vnode **vpp = ((struct vop_create_args *)v)->a_vpp;
|
|
|
|
struct componentname *cnp = ((struct vop_create_args *)v)->a_cnp;
|
|
|
|
struct vattr *vap = ((struct vop_create_args *)v)->a_vap;
|
|
|
|
|
|
|
|
KASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
|
|
|
|
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_mknod(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_mknod_args *)v)->a_dvp;
|
|
|
|
struct vnode **vpp = ((struct vop_mknod_args *)v)->a_vpp;
|
|
|
|
struct componentname *cnp = ((struct vop_mknod_args *)v)->a_cnp;
|
|
|
|
struct vattr *vap = ((struct vop_mknod_args *)v)->a_vap;
|
|
|
|
|
|
|
|
if (vap->va_type != VBLK && vap->va_type != VCHR &&
|
2009-03-19 16:47:32 +03:00
|
|
|
vap->va_type != VFIFO) {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_open_args *)v)->a_vp;
|
|
|
|
int mode = ((struct vop_open_args *)v)->a_mode;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2006-11-09 18:36:30 +03: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 die. */
|
|
|
|
if (node->tn_links < 1) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
/* If the file is marked append-only, deny write requests. */
|
|
|
|
if (node->tn_flags & APPEND && (mode & (FWRITE | O_APPEND)) == FWRITE)
|
|
|
|
error = EPERM;
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
|
2006-11-09 18:36:30 +03:00
|
|
|
out:
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_close(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_close_args *)v)->a_vp;
|
|
|
|
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
if (node->tn_links > 0) {
|
|
|
|
/* Update node times. No need to do it if the node has
|
|
|
|
* been deleted, because it will vanish after we return. */
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
|
2005-11-02 15:38:58 +03:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-11-02 15:38:58 +03:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2009-07-04 01:17:40 +04:00
|
|
|
static int
|
|
|
|
tmpfs_check_possible(struct vnode *vp, struct tmpfs_node *node, mode_t mode)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2009-07-04 01:17:40 +04:00
|
|
|
int error = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case VLNK:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case VREG:
|
|
|
|
if (mode & VWRITE && vp->v_mount->mnt_flag & MNT_RDONLY) {
|
|
|
|
error = EROFS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VBLK:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case VCHR:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case VSOCK:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case VFIFO:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode & VWRITE && node->tn_flags & IMMUTABLE) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-07-04 01:17:40 +04:00
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tmpfs_check_permitted(struct vnode *vp, struct tmpfs_node *node, mode_t mode,
|
|
|
|
kauth_cred_t cred)
|
|
|
|
{
|
|
|
|
|
|
|
|
return genfs_can_access(vp->v_type, node->tn_mode, node->tn_uid,
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_gid, mode, cred);
|
2009-07-04 01:17:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_access(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_access_args *)v)->a_vp;
|
|
|
|
int mode = ((struct vop_access_args *)v)->a_mode;
|
|
|
|
kauth_cred_t cred = ((struct vop_access_args *)v)->a_cred;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
error = tmpfs_check_possible(vp, node, mode);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = tmpfs_check_permitted(vp, node, mode, cred);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2009-09-03 08:45:27 +04:00
|
|
|
error = kauth_authorize_vnode(cred, kauth_mode_to_action(mode), vp,
|
|
|
|
NULL, error);
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
out:
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_getattr(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_getattr_args *)v)->a_vp;
|
|
|
|
struct vattr *vap = ((struct vop_getattr_args *)v)->a_vap;
|
|
|
|
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2010-01-08 14:35:07 +03:00
|
|
|
vattr_null(vap);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_itimes(vp, NULL, NULL, NULL);
|
2005-09-29 03:42:14 +04:00
|
|
|
|
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;
|
|
|
|
vap->va_gen = node->tn_gen;
|
|
|
|
vap->va_flags = node->tn_flags;
|
|
|
|
vap->va_rdev = (vp->v_type == VBLK || vp->v_type == VCHR) ?
|
2006-02-16 17:57:50 +03: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)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_setattr_args *)v)->a_vp;
|
|
|
|
struct vattr *vap = ((struct vop_setattr_args *)v)->a_vap;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred = ((struct vop_setattr_args *)v)->a_cred;
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-11-02 15:38:58 +03:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
/* Abort if any unsettable attribute is given. */
|
|
|
|
if (vap->va_type != VNON ||
|
|
|
|
vap->va_nlink != VNOVAL ||
|
|
|
|
vap->va_fsid != VNOVAL ||
|
|
|
|
vap->va_fileid != VNOVAL ||
|
|
|
|
vap->va_blocksize != VNOVAL ||
|
2008-06-19 23:03:44 +04:00
|
|
|
GOODTIME(&vap->va_ctime) ||
|
2005-09-10 23:20:48 +04:00
|
|
|
vap->va_gen != VNOVAL ||
|
|
|
|
vap->va_rdev != VNOVAL ||
|
|
|
|
vap->va_bytes != VNOVAL)
|
|
|
|
error = EINVAL;
|
|
|
|
|
|
|
|
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)
|
|
|
|
|| GOODTIME(&vap->va_birthtime)))
|
|
|
|
if ((error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
|
|
|
|
&vap->va_birthtime, vap->va_vaflags, cred, l)) == 0)
|
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Update the node times. We give preference to the error codes
|
|
|
|
* generated by this function rather than the ones that may arise
|
|
|
|
* from tmpfs_update. */
|
2008-06-19 23:03:44 +04:00
|
|
|
tmpfs_update(vp, NULL, NULL, NULL, 0);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_read(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_read_args *)v)->a_vp;
|
|
|
|
struct uio *uio = ((struct vop_read_args *)v)->a_uio;
|
2008-11-26 23:17:33 +03:00
|
|
|
int ioflag = ((struct vop_read_args *)v)->a_ioflag;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
struct tmpfs_node *node;
|
2005-09-13 18:29:18 +04:00
|
|
|
struct uvm_object *uobj;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2005-09-13 18:27:29 +04:00
|
|
|
if (vp->v_type != VREG) {
|
|
|
|
error = EISDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uio->uio_offset < 0) {
|
2005-09-10 23:20:48 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
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
|
|
|
|
2005-09-14 14:40:49 +04:00
|
|
|
if (node->tn_size <= uio->uio_offset)
|
|
|
|
break;
|
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid);
|
2005-09-14 00:02:05 +04:00
|
|
|
if (len == 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
break;
|
2005-09-14 00:02:05 +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
|
|
|
|
|
|
|
out:
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_write(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_write_args *)v)->a_vp;
|
|
|
|
struct uio *uio = ((struct vop_write_args *)v)->a_uio;
|
|
|
|
int ioflag = ((struct vop_write_args *)v)->a_ioflag;
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
bool extended;
|
2005-09-10 23:20:48 +04:00
|
|
|
int error;
|
|
|
|
off_t oldsize;
|
|
|
|
struct tmpfs_node *node;
|
2005-09-13 18:29:18 +04:00
|
|
|
struct uvm_object *uobj;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioflag & IO_APPEND)
|
|
|
|
uio->uio_offset = node->tn_size;
|
|
|
|
|
|
|
|
extended = uio->uio_offset + uio->uio_resid > node->tn_size;
|
|
|
|
if (extended) {
|
|
|
|
error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid);
|
|
|
|
if (error != 0)
|
|
|
|
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);
|
2005-09-14 00:02:05 +04:00
|
|
|
if (len == 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
break;
|
2005-09-14 00:02:05 +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
|
|
|
}
|
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);
|
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
if (error != 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
(void)tmpfs_reg_resize(vp, oldsize);
|
|
|
|
|
2006-11-09 18:06:03 +03:00
|
|
|
VN_KNOTE(vp, NOTE_WRITE);
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
out:
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
KASSERT(IMPLIES(error == 0, uio->uio_resid == 0));
|
|
|
|
KASSERT(IMPLIES(error != 0, oldsize == node->tn_size));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_fsync(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_fsync_args *)v)->a_vp;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_remove(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_remove_args *)v)->a_dvp;
|
|
|
|
struct vnode *vp = ((struct vop_remove_args *)v)->a_vp;
|
2008-01-02 14:48:20 +03:00
|
|
|
struct componentname *cnp = (((struct vop_remove_args *)v)->a_cnp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_dirent *de;
|
|
|
|
struct tmpfs_mount *tmp;
|
|
|
|
struct tmpfs_node *dnode;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
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
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
tmp = VFS_TO_TMPFS(vp->v_mount);
|
2008-01-02 14:48:20 +03:00
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
2009-04-05 19:10:41 +04:00
|
|
|
KASSERT(de);
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(de->td_node == node);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Files marked as immutable or append-only cannot be deleted. */
|
|
|
|
if (node->tn_flags & (IMMUTABLE | APPEND)) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the entry from the directory; as it is a file, we do not
|
|
|
|
* have to change the number of hard links of the directory. */
|
|
|
|
tmpfs_dir_detach(dvp, de);
|
|
|
|
|
|
|
|
/* Free the directory entry we just deleted. Note that the node
|
|
|
|
* referred by it will not be removed until the vnode is really
|
|
|
|
* reclaimed. */
|
2007-02-22 09:34:42 +03:00
|
|
|
tmpfs_free_dirent(tmp, de, true);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
vput(vp);
|
2007-01-02 14:02:19 +03:00
|
|
|
if (dvp == vp)
|
|
|
|
vrele(dvp);
|
|
|
|
else
|
|
|
|
vput(dvp);
|
2009-11-22 20:09:58 +03:00
|
|
|
if (cnp->cn_flags & HASBUF) {
|
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
|
|
|
cnp->cn_flags &= ~HASBUF;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_link(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_link_args *)v)->a_dvp;
|
|
|
|
struct vnode *vp = ((struct vop_link_args *)v)->a_vp;
|
|
|
|
struct componentname *cnp = ((struct vop_link_args *)v)->a_cnp;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_dirent *de;
|
|
|
|
struct tmpfs_node *dnode;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
KASSERT(cnp->cn_flags & HASBUF);
|
|
|
|
KASSERT(dvp != vp); /* XXX When can this be false? */
|
|
|
|
|
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2005-11-02 15:38:58 +03:00
|
|
|
/* Lock vp because we will need to run tmpfs_update over it, which
|
2005-09-10 23:20:48 +04:00
|
|
|
* needs the vnode to be locked. */
|
2009-10-06 04:17:24 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* XXX: Why aren't the following two tests done by the caller? */
|
|
|
|
|
|
|
|
/* Hard links of directories are forbidden. */
|
|
|
|
if (vp->v_type == VDIR) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cannot create cross-device links. */
|
|
|
|
if (dvp->v_mount != vp->v_mount) {
|
|
|
|
error = EXDEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure that we do not overflow the maximum number of links imposed
|
|
|
|
* by the system. */
|
|
|
|
KASSERT(node->tn_links <= LINK_MAX);
|
|
|
|
if (node->tn_links == LINK_MAX) {
|
|
|
|
error = EMLINK;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We cannot create links of files marked immutable or append-only. */
|
|
|
|
if (node->tn_flags & (IMMUTABLE | APPEND)) {
|
|
|
|
error = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new directory entry to represent the node. */
|
|
|
|
error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node,
|
|
|
|
cnp->cn_nameptr, cnp->cn_namelen, &de);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Insert the new directory entry into the appropriate directory. */
|
|
|
|
tmpfs_dir_attach(dvp, de);
|
|
|
|
|
|
|
|
/* vp link count has changed, so update node times. */
|
|
|
|
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:
|
2008-01-02 14:48:20 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2005-09-13 16:11:27 +04:00
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
2005-09-10 23:20:48 +04:00
|
|
|
vput(dvp);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-10-06 04:17:24 +04:00
|
|
|
/*
|
|
|
|
* tmpfs_rename: rename routine.
|
|
|
|
*
|
|
|
|
* Arguments: fdvp (from-parent vnode), fvp (from-leaf), tdvp (to-parent)
|
|
|
|
* and tvp (to-leaf), if exists (NULL if not).
|
|
|
|
*
|
|
|
|
* => Caller holds a reference on fdvp and fvp, they are unlocked.
|
|
|
|
* Note: fdvp and fvp can refer to the same object (i.e. when it is root).
|
|
|
|
*
|
|
|
|
* => Both tdvp and tvp are referenced and locked. It is our responsibility
|
|
|
|
* to release the references and unlock them (or destroy).
|
|
|
|
*/
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_rename(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *fdvp = ((struct vop_rename_args *)v)->a_fdvp;
|
|
|
|
struct vnode *fvp = ((struct vop_rename_args *)v)->a_fvp;
|
|
|
|
struct componentname *fcnp = ((struct vop_rename_args *)v)->a_fcnp;
|
|
|
|
struct vnode *tdvp = ((struct vop_rename_args *)v)->a_tdvp;
|
|
|
|
struct vnode *tvp = ((struct vop_rename_args *)v)->a_tvp;
|
|
|
|
struct componentname *tcnp = ((struct vop_rename_args *)v)->a_tcnp;
|
|
|
|
|
|
|
|
char *newname;
|
|
|
|
int error;
|
2008-01-02 14:48:20 +03:00
|
|
|
struct tmpfs_dirent *de, *de2;
|
2005-09-10 23:20:48 +04:00
|
|
|
struct tmpfs_mount *tmp;
|
|
|
|
struct tmpfs_node *fdnode;
|
|
|
|
struct tmpfs_node *fnode;
|
2007-07-23 19:41:01 +04:00
|
|
|
struct tmpfs_node *tnode;
|
2005-09-10 23:20:48 +04:00
|
|
|
struct tmpfs_node *tdnode;
|
2008-01-02 14:48:20 +03:00
|
|
|
size_t namelen;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(tdvp));
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
|
2005-09-10 23:20:48 +04:00
|
|
|
KASSERT(fcnp->cn_flags & HASBUF);
|
|
|
|
KASSERT(tcnp->cn_flags & HASBUF);
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
newname = NULL;
|
|
|
|
namelen = 0;
|
|
|
|
tmp = NULL;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
/* Disallow cross-device renames. */
|
2005-09-10 23:20:48 +04:00
|
|
|
if (fvp->v_mount != tdvp->v_mount ||
|
|
|
|
(tvp != NULL && fvp->v_mount != tvp->v_mount)) {
|
|
|
|
error = EXDEV;
|
2008-01-02 14:48:20 +03:00
|
|
|
goto out_unlocked;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
fnode = VP_TO_TMPFS_NODE(fvp);
|
|
|
|
fdnode = VP_TO_TMPFS_DIR(fdvp);
|
|
|
|
tnode = (tvp == NULL) ? NULL : VP_TO_TMPFS_NODE(tvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
tdnode = VP_TO_TMPFS_DIR(tdvp);
|
2008-01-02 14:48:20 +03:00
|
|
|
tmp = VFS_TO_TMPFS(tdvp->v_mount);
|
|
|
|
|
2009-02-07 22:42:57 +03:00
|
|
|
if (fdvp == tvp) {
|
|
|
|
error = 0;
|
|
|
|
goto out_unlocked;
|
|
|
|
}
|
|
|
|
|
2010-06-22 22:32:07 +04:00
|
|
|
/* Allocate memory, if necessary, for a new name. */
|
|
|
|
namelen = tcnp->cn_namelen;
|
|
|
|
if (tmpfs_strname_neqlen(fcnp, tcnp)) {
|
|
|
|
newname = tmpfs_strname_alloc(tmp, namelen);
|
|
|
|
if (newname == NULL) {
|
|
|
|
error = ENOSPC;
|
|
|
|
goto out_unlocked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
/* If we need to move the directory between entries, lock the
|
|
|
|
* source so that we can safely operate on it. */
|
|
|
|
|
|
|
|
/* XXX: this is a potential locking order violation! */
|
|
|
|
if (fdnode != tdnode) {
|
2009-10-06 04:17:24 +04:00
|
|
|
vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY);
|
2008-01-02 14:48:20 +03:00
|
|
|
}
|
|
|
|
|
2009-04-03 18:47:40 +04:00
|
|
|
/*
|
|
|
|
* If the node we were renaming has scarpered, just give up.
|
|
|
|
*/
|
2008-01-02 14:48:20 +03:00
|
|
|
de = tmpfs_dir_lookup(fdnode, fcnp);
|
2009-04-03 18:47:40 +04:00
|
|
|
if (de == NULL || de->td_node != fnode) {
|
2008-01-02 14:48:20 +03:00
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2009-10-06 04:17:24 +04:00
|
|
|
/* If source and target is the same vnode, remove the source link. */
|
2005-09-10 23:20:48 +04:00
|
|
|
if (fvp == tvp) {
|
2009-10-06 04:17:24 +04:00
|
|
|
/*
|
|
|
|
* Detach and free the directory entry. Drops the link
|
|
|
|
* count on the node.
|
|
|
|
*/
|
|
|
|
tmpfs_dir_detach(fdvp, de);
|
|
|
|
tmpfs_free_dirent(VFS_TO_TMPFS(fvp->v_mount), de, true);
|
|
|
|
VN_KNOTE(fdvp, NOTE_WRITE);
|
|
|
|
goto out_ok;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2007-07-23 19:41:01 +04:00
|
|
|
/* If replacing an existing entry, ensure we can do the operation. */
|
|
|
|
if (tvp != NULL) {
|
|
|
|
KASSERT(tnode != NULL);
|
|
|
|
if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) {
|
|
|
|
if (tnode->tn_size > 0) {
|
|
|
|
error = ENOTEMPTY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) {
|
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
} else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) {
|
|
|
|
error = EISDIR;
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
KASSERT(fnode->tn_type != VDIR &&
|
|
|
|
tnode->tn_type != VDIR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
/* If the node is being moved to another directory, we have to do
|
|
|
|
* the move. */
|
|
|
|
if (fdnode != tdnode) {
|
|
|
|
/* In case we are moving a directory, we have to adjust its
|
|
|
|
* parent to point to the new parent. */
|
|
|
|
if (de->td_node->tn_type == VDIR) {
|
|
|
|
struct tmpfs_node *n;
|
|
|
|
|
|
|
|
/* Ensure the target directory is not a child of the
|
|
|
|
* directory being moved. Otherwise, we'd end up
|
|
|
|
* with stale nodes. */
|
|
|
|
n = tdnode;
|
2006-02-16 17:57:50 +03:00
|
|
|
while (n != n->tn_spec.tn_dir.tn_parent) {
|
2005-09-10 23:20:48 +04:00
|
|
|
if (n == fnode) {
|
|
|
|
error = EINVAL;
|
2008-01-02 14:48:20 +03:00
|
|
|
goto out;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2006-02-16 17:57:50 +03:00
|
|
|
n = n->tn_spec.tn_dir.tn_parent;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the parent pointer. */
|
|
|
|
TMPFS_VALIDATE_DIR(fnode);
|
2006-02-16 17:57:50 +03:00
|
|
|
de->td_node->tn_spec.tn_dir.tn_parent = tdnode;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* As a result of changing the target of the '..'
|
|
|
|
* entry, the link count of the source and target
|
|
|
|
* directories has to be adjusted. */
|
|
|
|
fdnode->tn_links--;
|
|
|
|
tdnode->tn_links++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the move: just remove the entry from the source directory
|
|
|
|
* and insert it into the target one. */
|
|
|
|
tmpfs_dir_detach(fdvp, de);
|
|
|
|
tmpfs_dir_attach(tdvp, de);
|
|
|
|
|
|
|
|
/* Notify listeners of fdvp about the change in the directory.
|
|
|
|
* We can do it at this point because we aren't touching fdvp
|
|
|
|
* any more below. */
|
|
|
|
VN_KNOTE(fdvp, NOTE_WRITE);
|
|
|
|
}
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
/* If we are overwriting an entry, we have to remove the old one
|
|
|
|
* from the target directory. */
|
|
|
|
if (tvp != NULL) {
|
|
|
|
KASSERT(tnode != NULL);
|
|
|
|
|
|
|
|
/* Remove the old entry from the target directory.
|
|
|
|
* Note! This relies on tmpfs_dir_attach() putting the new
|
|
|
|
* node on the end of the target's node list. */
|
|
|
|
de2 = tmpfs_dir_lookup(tdnode, tcnp);
|
|
|
|
KASSERT(de2 != NULL);
|
|
|
|
KASSERT(de2->td_node == tnode);
|
|
|
|
tmpfs_dir_detach(tdvp, de2);
|
|
|
|
|
|
|
|
/* Free the directory entry we just deleted. Note that the
|
|
|
|
* node referred by it will not be removed until the vnode is
|
|
|
|
* really reclaimed. */
|
|
|
|
tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), de2, true);
|
|
|
|
}
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
/* If the name has changed, we need to make it effective by changing
|
|
|
|
* it in the directory entry. */
|
|
|
|
if (newname != NULL) {
|
|
|
|
KASSERT(tcnp->cn_namelen < MAXNAMLEN);
|
|
|
|
KASSERT(tcnp->cn_namelen < 0xffff);
|
|
|
|
|
2010-06-22 22:32:07 +04:00
|
|
|
tmpfs_strname_free(tmp, de->td_name, de->td_namelen);
|
2008-01-02 14:48:20 +03:00
|
|
|
de->td_namelen = (uint16_t)namelen;
|
|
|
|
memcpy(newname, tcnp->cn_nameptr, namelen);
|
2005-09-10 23:20:48 +04:00
|
|
|
de->td_name = newname;
|
2008-01-02 14:48:20 +03:00
|
|
|
newname = NULL;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2006-10-30 18:23:20 +03:00
|
|
|
fnode->tn_status |= TMPFS_NODE_CHANGED;
|
2006-10-30 18:09:47 +03:00
|
|
|
tdnode->tn_status |= TMPFS_NODE_MODIFIED;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2009-10-06 04:17:24 +04:00
|
|
|
out_ok:
|
2005-09-10 23:20:48 +04:00
|
|
|
/* Notify listeners of tdvp about the change in the directory (either
|
2006-11-09 18:06:03 +03:00
|
|
|
* because a new entry was added or because one was removed) and
|
|
|
|
* listeners of fvp about the rename. */
|
2005-09-10 23:20:48 +04:00
|
|
|
VN_KNOTE(tdvp, NOTE_WRITE);
|
2006-11-09 18:06:03 +03:00
|
|
|
VN_KNOTE(fvp, NOTE_RENAME);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
out:
|
2005-09-23 18:27:55 +04:00
|
|
|
if (fdnode != tdnode)
|
|
|
|
VOP_UNLOCK(fdvp, 0);
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
out_unlocked:
|
2005-09-10 23:20:48 +04:00
|
|
|
/* Release target nodes. */
|
|
|
|
if (tdvp == tvp)
|
|
|
|
vrele(tdvp);
|
|
|
|
else
|
|
|
|
vput(tdvp);
|
|
|
|
if (tvp != NULL)
|
|
|
|
vput(tvp);
|
|
|
|
|
|
|
|
/* Release source nodes. */
|
|
|
|
vrele(fdvp);
|
|
|
|
vrele(fvp);
|
|
|
|
|
2010-06-22 22:32:07 +04:00
|
|
|
if (newname != NULL) {
|
|
|
|
tmpfs_strname_free(tmp, newname, namelen);
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_mkdir(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_mkdir_args *)v)->a_dvp;
|
|
|
|
struct vnode **vpp = ((struct vop_mkdir_args *)v)->a_vpp;
|
|
|
|
struct componentname *cnp = ((struct vop_mkdir_args *)v)->a_cnp;
|
|
|
|
struct vattr *vap = ((struct vop_mkdir_args *)v)->a_vap;
|
|
|
|
|
|
|
|
KASSERT(vap->va_type == VDIR);
|
|
|
|
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_rmdir(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_rmdir_args *)v)->a_dvp;
|
|
|
|
struct vnode *vp = ((struct vop_rmdir_args *)v)->a_vp;
|
2008-01-02 14:48:20 +03:00
|
|
|
struct componentname *cnp = ((struct vop_rmdir_args *)v)->a_cnp;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_dirent *de;
|
|
|
|
struct tmpfs_mount *tmp;
|
|
|
|
struct tmpfs_node *dnode;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(dvp));
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
tmp = VFS_TO_TMPFS(dvp->v_mount);
|
|
|
|
dnode = VP_TO_TMPFS_DIR(dvp);
|
|
|
|
node = VP_TO_TMPFS_DIR(vp);
|
2007-10-23 23:49:01 +04:00
|
|
|
error = 0;
|
2007-01-02 14:02:19 +03:00
|
|
|
|
|
|
|
/* Directories with more than two entries ('.' and '..') cannot be
|
|
|
|
* removed. */
|
|
|
|
if (node->tn_size > 0) {
|
|
|
|
error = ENOTEMPTY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This invariant holds only if we are not trying to remove "..".
|
|
|
|
* We checked for that above so this is safe now. */
|
2006-02-16 17:57:50 +03:00
|
|
|
KASSERT(node->tn_spec.tn_dir.tn_parent == dnode);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
/* Get the directory entry associated with node (vp). */
|
|
|
|
de = tmpfs_dir_lookup(dnode, cnp);
|
2009-04-05 19:10:41 +04:00
|
|
|
KASSERT(de);
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach the directory entry from the directory (dnode). */
|
|
|
|
tmpfs_dir_detach(dvp, de);
|
|
|
|
|
|
|
|
node->tn_links--;
|
|
|
|
node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
|
|
|
|
TMPFS_NODE_MODIFIED;
|
2006-02-16 17:57:50 +03:00
|
|
|
node->tn_spec.tn_dir.tn_parent->tn_links--;
|
|
|
|
node->tn_spec.tn_dir.tn_parent->tn_status |= TMPFS_NODE_ACCESSED | \
|
2005-09-10 23:20:48 +04:00
|
|
|
TMPFS_NODE_CHANGED | TMPFS_NODE_MODIFIED;
|
|
|
|
|
2006-11-09 18:06:03 +03:00
|
|
|
/* Release the parent. */
|
2005-09-10 23:20:48 +04:00
|
|
|
cache_purge(dvp); /* XXX Is this needed? */
|
|
|
|
|
|
|
|
/* Free the directory entry we just deleted. Note that the node
|
|
|
|
* referred by it will not be removed until the vnode is really
|
|
|
|
* reclaimed. */
|
2007-02-22 09:34:42 +03:00
|
|
|
tmpfs_free_dirent(tmp, de, true);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(node->tn_links == 0);
|
2007-10-23 23:49:01 +04:00
|
|
|
out:
|
|
|
|
/* Release the nodes. */
|
|
|
|
vput(dvp);
|
2005-09-10 23:20:48 +04:00
|
|
|
vput(vp);
|
2009-04-15 15:41:25 +04:00
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_symlink(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *dvp = ((struct vop_symlink_args *)v)->a_dvp;
|
|
|
|
struct vnode **vpp = ((struct vop_symlink_args *)v)->a_vpp;
|
|
|
|
struct componentname *cnp = ((struct vop_symlink_args *)v)->a_cnp;
|
|
|
|
struct vattr *vap = ((struct vop_symlink_args *)v)->a_vap;
|
|
|
|
char *target = ((struct vop_symlink_args *)v)->a_target;
|
|
|
|
|
|
|
|
KASSERT(vap->va_type == VLNK);
|
|
|
|
|
|
|
|
return tmpfs_alloc_file(dvp, vpp, vap, cnp, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_readdir(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_readdir_args *)v)->a_vp;
|
|
|
|
struct uio *uio = ((struct vop_readdir_args *)v)->a_uio;
|
|
|
|
int *eofflag = ((struct vop_readdir_args *)v)->a_eofflag;
|
|
|
|
off_t **cookies = ((struct vop_readdir_args *)v)->a_cookies;
|
|
|
|
int *ncookies = ((struct vop_readdir_args *)v)->a_ncookies;
|
|
|
|
|
|
|
|
int error;
|
2005-09-15 16:34:35 +04:00
|
|
|
off_t startoff;
|
|
|
|
off_t cnt;
|
2005-09-10 23:20:48 +04:00
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
/* This operation only makes sense on directory nodes. */
|
|
|
|
if (vp->v_type != VDIR) {
|
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_DIR(vp);
|
|
|
|
|
|
|
|
startoff = uio->uio_offset;
|
|
|
|
|
2005-09-15 16:34:35 +04:00
|
|
|
cnt = 0;
|
|
|
|
if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
|
2005-09-10 23:20:48 +04:00
|
|
|
error = tmpfs_dir_getdotdent(node, uio);
|
|
|
|
if (error == -1) {
|
|
|
|
error = 0;
|
|
|
|
goto outok;
|
|
|
|
} else if (error != 0)
|
|
|
|
goto outok;
|
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);
|
|
|
|
if (error == -1) {
|
|
|
|
error = 0;
|
|
|
|
goto outok;
|
|
|
|
} else if (error != 0)
|
|
|
|
goto outok;
|
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);
|
2005-09-10 23:20:48 +04:00
|
|
|
if (error == -1)
|
|
|
|
error = 0;
|
|
|
|
KASSERT(error >= 0);
|
|
|
|
|
|
|
|
outok:
|
2005-09-15 16:34:35 +04:00
|
|
|
/* This label assumes that startoff has been
|
2005-09-10 23:20:48 +04:00
|
|
|
* initialized. If the compiler didn't spit out warnings, we'd
|
|
|
|
* simply make this one be 'out' and drop 'outok'. */
|
|
|
|
|
|
|
|
if (eofflag != NULL)
|
|
|
|
*eofflag =
|
2005-09-15 16:34:35 +04:00
|
|
|
(error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Update NFS-related variables. */
|
|
|
|
if (error == 0 && cookies != NULL && ncookies != NULL) {
|
|
|
|
off_t i;
|
2005-09-15 16:34:35 +04:00
|
|
|
off_t off = startoff;
|
|
|
|
struct tmpfs_dirent *de = NULL;
|
|
|
|
|
|
|
|
*ncookies = cnt;
|
|
|
|
*cookies = malloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
KASSERT(off != TMPFS_DIRCOOKIE_EOF);
|
|
|
|
if (off == TMPFS_DIRCOOKIE_DOT) {
|
|
|
|
off = TMPFS_DIRCOOKIE_DOTDOT;
|
|
|
|
} else {
|
|
|
|
if (off == TMPFS_DIRCOOKIE_DOTDOT) {
|
2006-02-16 17:57:50 +03:00
|
|
|
de = TAILQ_FIRST(&node->tn_spec.
|
|
|
|
tn_dir.tn_dir);
|
2005-09-15 16:34:35 +04:00
|
|
|
} else if (de != NULL) {
|
|
|
|
de = TAILQ_NEXT(de, td_entries);
|
|
|
|
} else {
|
|
|
|
de = tmpfs_dir_lookupbycookie(node,
|
|
|
|
off);
|
|
|
|
KASSERT(de != NULL);
|
|
|
|
de = TAILQ_NEXT(de, td_entries);
|
|
|
|
}
|
|
|
|
if (de == NULL) {
|
|
|
|
off = TMPFS_DIRCOOKIE_EOF;
|
|
|
|
} else {
|
2006-11-05 19:59:18 +03:00
|
|
|
off = tmpfs_dircookie(de);
|
2005-09-15 16:34:35 +04:00
|
|
|
}
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-09-15 16:34:35 +04:00
|
|
|
(*cookies)[i] = off;
|
|
|
|
}
|
|
|
|
KASSERT(uio->uio_offset == off);
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_readlink(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_readlink_args *)v)->a_vp;
|
|
|
|
struct uio *uio = ((struct vop_readlink_args *)v)->a_uio;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_inactive(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_inactive_args *)v)->a_vp;
|
|
|
|
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
KASSERT(VOP_ISLOCKED(vp));
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
2008-01-02 14:48:20 +03:00
|
|
|
*((struct vop_inactive_args *)v)->a_recycle = (node->tn_links == 0);
|
2005-09-10 23:20:48 +04:00
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_reclaim(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_reclaim_args *)v)->a_vp;
|
|
|
|
|
|
|
|
struct tmpfs_mount *tmp;
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
tmp = VFS_TO_TMPFS(vp->v_mount);
|
|
|
|
|
|
|
|
cache_purge(vp);
|
|
|
|
tmpfs_free_vp(vp);
|
|
|
|
|
|
|
|
/* If the node referenced by this vnode was deleted by the user,
|
|
|
|
* we must free its associated data structures (now that the vnode
|
|
|
|
* is being reclaimed). */
|
|
|
|
if (node->tn_links == 0)
|
|
|
|
tmpfs_free_node(tmp, node);
|
|
|
|
|
|
|
|
KASSERT(vp->v_data == NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_print(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_print_args *)v)->a_vp;
|
|
|
|
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
printf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n",
|
|
|
|
node, node->tn_flags, node->tn_links);
|
|
|
|
printf("\tmode 0%o, owner %d, group %d, size %" PRIdMAX
|
2010-03-27 05:37:34 +03:00
|
|
|
", status 0x%x",
|
2005-09-10 23:20:48 +04:00
|
|
|
node->tn_mode, node->tn_uid, node->tn_gid,
|
|
|
|
(uintmax_t)node->tn_size, node->tn_status);
|
|
|
|
if (vp->v_type == VFIFO)
|
2010-03-29 17:11:32 +04:00
|
|
|
VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v);
|
2005-09-10 23:20:48 +04:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_pathconf(void *v)
|
|
|
|
{
|
|
|
|
int name = ((struct vop_pathconf_args *)v)->a_name;
|
|
|
|
register_t *retval = ((struct vop_pathconf_args *)v)->a_retval;
|
|
|
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*retval = LINK_MAX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*retval = NAME_MAX;
|
|
|
|
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:
|
|
|
|
*retval = 0; /* XXX Don't know which value should I return. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-09-29 23:48:21 +04:00
|
|
|
int
|
|
|
|
tmpfs_advlock(void *v)
|
|
|
|
{
|
|
|
|
struct vnode *vp = ((struct vop_advlock_args *)v)->a_vp;
|
|
|
|
|
|
|
|
struct tmpfs_node *node;
|
|
|
|
|
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
|
|
|
return lf_advlock(v, &node->tn_lockf, node->tn_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
int
|
|
|
|
tmpfs_getpages(void *v)
|
|
|
|
{
|
2005-09-14 00:02:05 +04:00
|
|
|
struct vnode *vp = ((struct vop_getpages_args *)v)->a_vp;
|
|
|
|
voff_t offset = ((struct vop_getpages_args *)v)->a_offset;
|
|
|
|
struct vm_page **m = ((struct vop_getpages_args *)v)->a_m;
|
|
|
|
int *count = ((struct vop_getpages_args *)v)->a_count;
|
|
|
|
int centeridx = ((struct vop_getpages_args *)v)->a_centeridx;
|
|
|
|
vm_prot_t access_type = ((struct vop_getpages_args *)v)->a_access_type;
|
|
|
|
int advice = ((struct vop_getpages_args *)v)->a_advice;
|
|
|
|
int flags = ((struct vop_getpages_args *)v)->a_flags;
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
int error;
|
2006-11-02 18:35:25 +03:00
|
|
|
int i;
|
2005-09-14 00:02:05 +04:00
|
|
|
struct tmpfs_node *node;
|
|
|
|
struct uvm_object *uobj;
|
2005-09-15 00:27:26 +04:00
|
|
|
int npages = *count;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
KASSERT(vp->v_type == VREG);
|
2008-01-02 14:48:20 +03: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
|
|
|
|
2005-09-15 00:27:26 +04:00
|
|
|
/* We currently don't rely on PGO_PASTEOF. */
|
|
|
|
|
|
|
|
if (vp->v_size <= offset + (centeridx << PAGE_SHIFT)) {
|
|
|
|
if ((flags & PGO_LOCKED) == 0)
|
2008-01-02 14:48:20 +03: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
|
|
|
|
|
|
|
if ((access_type & VM_PROT_WRITE) != 0)
|
2005-09-13 18:29:18 +04:00
|
|
|
node->tn_status |= TMPFS_NODE_MODIFIED;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_exit(&vp->v_interlock);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2006-11-02 18:35:25 +03:00
|
|
|
/*
|
|
|
|
* Make sure that the array on which we will store the
|
|
|
|
* gotten pages is clean. Otherwise uao_get (pointed to by
|
|
|
|
* the pgo_get below) gets confused and does not return the
|
|
|
|
* appropriate pages.
|
2008-02-06 14:22:12 +03:00
|
|
|
*
|
2006-11-02 18:35:25 +03:00
|
|
|
* XXX This shall be revisited when kern/32166 is addressed
|
|
|
|
* because the loop to clean m[i] will most likely be redundant
|
|
|
|
* as well as the PGO_ALLPAGES flag.
|
|
|
|
*/
|
|
|
|
if (m != NULL)
|
|
|
|
for (i = 0; i < npages; i++)
|
|
|
|
m[i] = NULL;
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_enter(&uobj->vmobjlock);
|
2005-09-15 00:27:26 +04:00
|
|
|
error = (*uobj->pgops->pgo_get)(uobj, offset, m, &npages, centeridx,
|
2006-11-02 18:35:25 +03:00
|
|
|
access_type, advice, flags | PGO_ALLPAGES);
|
|
|
|
#if defined(DEBUG)
|
|
|
|
{
|
|
|
|
/* Make sure that all the pages we return are valid. */
|
|
|
|
int dbgi;
|
|
|
|
if (error == 0 && m != NULL)
|
|
|
|
for (dbgi = 0; dbgi < npages; dbgi++)
|
|
|
|
KASSERT(m[dbgi] != NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-13 18:29:18 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
tmpfs_putpages(void *v)
|
|
|
|
{
|
2005-09-14 00:02:05 +04:00
|
|
|
struct vnode *vp = ((struct vop_putpages_args *)v)->a_vp;
|
|
|
|
voff_t offlo = ((struct vop_putpages_args *)v)->a_offlo;
|
|
|
|
voff_t offhi = ((struct vop_putpages_args *)v)->a_offhi;
|
|
|
|
int flags = ((struct vop_putpages_args *)v)->a_flags;
|
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
int error;
|
2005-09-14 00:02:05 +04:00
|
|
|
struct tmpfs_node *node;
|
|
|
|
struct uvm_object *uobj;
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(mutex_owned(&vp->v_interlock));
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2005-09-14 00:02:05 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2005-09-13 18:29:18 +04:00
|
|
|
if (vp->v_type != VREG) {
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_exit(&vp->v_interlock);
|
2005-09-13 18:29:18 +04:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2006-02-16 17:57:50 +03:00
|
|
|
uobj = node->tn_spec.tn_reg.tn_aobj;
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_exit(&vp->v_interlock);
|
2005-09-13 18:29:18 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_enter(&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;
|
|
|
|
}
|