Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Adapt tmpfs_rename to use genfs_rename.
details: https://anonhg.NetBSD.org/src/rev/a644de51972d
branches: trunk
changeset: 779184:a644de51972d
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed May 09 00:16:07 2012 +0000
description:
Adapt tmpfs_rename to use genfs_rename.
diffstat:
sys/fs/tmpfs/files.tmpfs | 3 +-
sys/fs/tmpfs/tmpfs_rename.c | 589 +++++++++++++++++
sys/fs/tmpfs/tmpfs_vnops.c | 1272 +------------------------------------
sys/rump/fs/lib/libtmpfs/Makefile | 4 +-
4 files changed, 595 insertions(+), 1273 deletions(-)
diffs (truncated from 1919 to 300 lines):
diff -r 448f71e94cc6 -r a644de51972d sys/fs/tmpfs/files.tmpfs
--- a/sys/fs/tmpfs/files.tmpfs Tue May 08 23:53:26 2012 +0000
+++ b/sys/fs/tmpfs/files.tmpfs Wed May 09 00:16:07 2012 +0000
@@ -1,9 +1,10 @@
-# $NetBSD: files.tmpfs,v 1.4 2010/06/22 18:32:07 rmind Exp $
+# $NetBSD: files.tmpfs,v 1.5 2012/05/09 00:16:07 riastradh Exp $
deffs TMPFS
file fs/tmpfs/tmpfs_fifoops.c tmpfs
file fs/tmpfs/tmpfs_mem.c tmpfs
+file fs/tmpfs/tmpfs_rename.c tmpfs
file fs/tmpfs/tmpfs_specops.c tmpfs
file fs/tmpfs/tmpfs_subr.c tmpfs
file fs/tmpfs/tmpfs_vfsops.c tmpfs
diff -r 448f71e94cc6 -r a644de51972d sys/fs/tmpfs/tmpfs_rename.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/fs/tmpfs/tmpfs_rename.c Wed May 09 00:16:07 2012 +0000
@@ -0,0 +1,589 @@
+/* $NetBSD: tmpfs_rename.c,v 1.1 2012/05/09 00:16:07 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R Campbell.
+ *
+ * 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 rename
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.1 2012/05/09 00:16:07 riastradh Exp $");
+
+#include <sys/param.h>
+#include <sys/errno.h>
+#include <sys/kauth.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/stat.h>
+#include <sys/vnode.h>
+#include <sys/vnode_if.h>
+
+#include <miscfs/genfs/genfs.h>
+
+#include <fs/tmpfs/tmpfs_vnops.h>
+#include <fs/tmpfs/tmpfs.h>
+
+/*
+ * Forward declarations
+ */
+
+static int tmpfs_sane_rename(struct vnode *, struct componentname *,
+ struct vnode *, struct componentname *,
+ kauth_cred_t, bool);
+static bool tmpfs_rmdired_p(struct vnode *);
+static int tmpfs_gro_lock_directory(struct mount *, struct vnode *);
+
+static const struct genfs_rename_ops tmpfs_genfs_rename_ops;
+
+/*
+ * tmpfs_sane_rename: The hairiest vop, with the saner API.
+ *
+ * Arguments:
+ *
+ * . fdvp (from directory vnode),
+ * . fcnp (from component name),
+ * . tdvp (to directory vnode),
+ * . tcnp (to component name),
+ * . cred (credentials structure), and
+ * . posixly_correct (flag for behaviour if target & source link same file).
+ *
+ * fdvp and tdvp may be the same, and must be referenced and unlocked.
+ */
+static int
+tmpfs_sane_rename(
+ struct vnode *fdvp, struct componentname *fcnp,
+ struct vnode *tdvp, struct componentname *tcnp,
+ kauth_cred_t cred, bool posixly_correct)
+{
+ struct tmpfs_dirent *fdirent, *tdirent;
+
+ return genfs_sane_rename(&tmpfs_genfs_rename_ops,
+ fdvp, fcnp, &fdirent, tdvp, tcnp, &tdirent,
+ cred, posixly_correct);
+}
+
+/*
+ * tmpfs_rename: The hairiest vop, with the insanest API. Defer to
+ * genfs_insane_rename immediately.
+ */
+int
+tmpfs_rename(void *v)
+{
+
+ return genfs_insane_rename(v, &tmpfs_sane_rename);
+}
+
+/*
+ * tmpfs_gro_directory_empty_p: Return true if the directory vp is
+ * empty. dvp is its parent.
+ *
+ * vp and dvp must be locked and referenced.
+ */
+static bool
+tmpfs_gro_directory_empty_p(struct mount *mp, kauth_cred_t cred,
+ struct vnode *vp, struct vnode *dvp)
+{
+
+ (void)mp;
+ (void)cred;
+ (void)dvp;
+ KASSERT(mp != NULL);
+ KASSERT(vp != NULL);
+ KASSERT(dvp != NULL);
+ KASSERT(vp != dvp);
+ KASSERT(vp->v_mount == mp);
+ KASSERT(dvp->v_mount == mp);
+ KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+
+ return (VP_TO_TMPFS_NODE(vp)->tn_size == 0);
+}
+
+/*
+ * tmpfs_gro_rename_check_possible: Check whether a rename is possible
+ * independent of credentials.
+ */
+static int
+tmpfs_gro_rename_check_possible(struct mount *mp,
+ struct vnode *fdvp, struct vnode *fvp,
+ struct vnode *tdvp, struct vnode *tvp)
+{
+
+ (void)mp;
+ KASSERT(mp != NULL);
+ KASSERT(fdvp != NULL);
+ KASSERT(fvp != NULL);
+ KASSERT(tdvp != NULL);
+ KASSERT(fdvp != fvp);
+ KASSERT(fdvp != tvp);
+ KASSERT(tdvp != fvp);
+ KASSERT(tdvp != tvp);
+ KASSERT(fvp != tvp);
+ KASSERT(fdvp->v_type == VDIR);
+ KASSERT(tdvp->v_type == VDIR);
+ KASSERT(fdvp->v_mount == mp);
+ KASSERT(fvp->v_mount == mp);
+ KASSERT(tdvp->v_mount == mp);
+ KASSERT((tvp == NULL) || (tvp->v_mount == mp));
+ KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
+ KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
+
+ return genfs_ufslike_rename_check_possible(
+ VP_TO_TMPFS_NODE(fdvp)->tn_flags, VP_TO_TMPFS_NODE(fvp)->tn_flags,
+ VP_TO_TMPFS_NODE(tdvp)->tn_flags,
+ (tvp? VP_TO_TMPFS_NODE(tvp)->tn_flags : 0), (tvp != NULL),
+ IMMUTABLE, APPEND);
+}
+
+/*
+ * tmpfs_gro_rename_check_permitted: Check whether a rename is
+ * permitted given our credentials.
+ */
+static int
+tmpfs_gro_rename_check_permitted(struct mount *mp, kauth_cred_t cred,
+ struct vnode *fdvp, struct vnode *fvp,
+ struct vnode *tdvp, struct vnode *tvp)
+{
+
+ (void)mp;
+ KASSERT(mp != NULL);
+ KASSERT(fdvp != NULL);
+ KASSERT(fvp != NULL);
+ KASSERT(tdvp != NULL);
+ KASSERT(fdvp != fvp);
+ KASSERT(fdvp != tvp);
+ KASSERT(tdvp != fvp);
+ KASSERT(tdvp != tvp);
+ KASSERT(fvp != tvp);
+ KASSERT(fdvp->v_type == VDIR);
+ KASSERT(tdvp->v_type == VDIR);
+ KASSERT(fdvp->v_mount == mp);
+ KASSERT(fvp->v_mount == mp);
+ KASSERT(tdvp->v_mount == mp);
+ KASSERT((tvp == NULL) || (tvp->v_mount == mp));
+ KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
+ KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
+
+ return genfs_ufslike_rename_check_permitted(cred,
+ fdvp, VP_TO_TMPFS_NODE(fdvp)->tn_mode,
+ VP_TO_TMPFS_NODE(fdvp)->tn_uid,
+ fvp, VP_TO_TMPFS_NODE(fvp)->tn_uid,
+ tdvp, VP_TO_TMPFS_NODE(tdvp)->tn_mode,
+ VP_TO_TMPFS_NODE(tdvp)->tn_uid,
+ tvp, (tvp? VP_TO_TMPFS_NODE(tvp)->tn_uid : 0));
+}
+
+/*
+ * tmpfs_gro_remove_check_possible: Check whether a remove is possible
+ * independent of credentials.
+ */
+static int
+tmpfs_gro_remove_check_possible(struct mount *mp,
+ struct vnode *dvp, struct vnode *vp)
+{
+
+ (void)mp;
+ KASSERT(mp != NULL);
+ KASSERT(dvp != NULL);
+ KASSERT(vp != NULL);
+ KASSERT(dvp != vp);
+ KASSERT(dvp->v_type == VDIR);
+ KASSERT(vp->v_type != VDIR);
+ KASSERT(dvp->v_mount == mp);
+ KASSERT(vp->v_mount == mp);
+ KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+ return genfs_ufslike_remove_check_possible(
+ VP_TO_TMPFS_NODE(dvp)->tn_flags, VP_TO_TMPFS_NODE(vp)->tn_flags,
+ IMMUTABLE, APPEND);
+}
+
+/*
+ * tmpfs_gro_remove_check_permitted: Check whether a remove is
+ * permitted given our credentials.
+ */
+static int
+tmpfs_gro_remove_check_permitted(struct mount *mp, kauth_cred_t cred,
+ struct vnode *dvp, struct vnode *vp)
+{
+
+ (void)mp;
+ KASSERT(mp != NULL);
+ KASSERT(dvp != NULL);
+ KASSERT(vp != NULL);
+ KASSERT(dvp != vp);
+ KASSERT(dvp->v_type == VDIR);
+ KASSERT(vp->v_type != VDIR);
+ KASSERT(dvp->v_mount == mp);
+ KASSERT(vp->v_mount == mp);
+ KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
+ KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+ return genfs_ufslike_remove_check_permitted(cred,
+ dvp, VP_TO_TMPFS_NODE(dvp)->tn_mode, VP_TO_TMPFS_NODE(dvp)->tn_uid,
+ vp, VP_TO_TMPFS_NODE(vp)->tn_uid);
+}
+
+/*
+ * tmpfs_gro_rename: Actually perform the rename operation.
+ */
+static int
+tmpfs_gro_rename(struct mount *mp, kauth_cred_t cred,
+ struct vnode *fdvp, struct componentname *fcnp,
+ void *fde, struct vnode *fvp,
+ struct vnode *tdvp, struct componentname *tcnp,
+ void *tde, struct vnode *tvp)
+{
+ struct tmpfs_dirent **fdep = fde;
+ struct tmpfs_dirent **tdep = tde;
+ char *newname;
+
+ (void)cred;
+ KASSERT(mp != NULL);
+ KASSERT(fdvp != NULL);
+ KASSERT(fcnp != NULL);
+ KASSERT(fdep != NULL);
+ KASSERT(fvp != NULL);
+ KASSERT(tdvp != NULL);
+ KASSERT(tcnp != NULL);
+ KASSERT(tdep != NULL);
Home |
Main Index |
Thread Index |
Old Index