Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Adapt ffs, lfs, and ext2fs to use genfs_rename.



details:   https://anonhg.NetBSD.org/src/rev/0901a2b85d86
branches:  trunk
changeset: 779185:0901a2b85d86
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed May 09 00:21:17 2012 +0000

description:
Adapt ffs, lfs, and ext2fs to use genfs_rename.

ok dholland, rmind

diffstat:

 sys/rump/fs/lib/libext2fs/Makefile |     6 +-
 sys/rump/fs/lib/libffs/Makefile    |     4 +-
 sys/ufs/ext2fs/ext2fs_dir.h        |     4 +-
 sys/ufs/ext2fs/ext2fs_extern.h     |     3 +-
 sys/ufs/ext2fs/ext2fs_rename.c     |  1012 +++++++++++++++++++++++++++++++++
 sys/ufs/ext2fs/ext2fs_vnops.c      |   424 +--------------
 sys/ufs/files.ufs                  |     4 +-
 sys/ufs/lfs/lfs_vnops.c            |   933 +++---------------------------
 sys/ufs/ufs/ufs_extern.h           |    25 +-
 sys/ufs/ufs/ufs_lookup.c           |     6 +-
 sys/ufs/ufs/ufs_rename.c           |  1080 ++++++++++++++++++++++++++++++++++++
 sys/ufs/ufs/ufs_vnops.c            |  1022 +----------------------------------
 sys/ufs/ufs/ufsmount.h             |     8 +-
 13 files changed, 2238 insertions(+), 2293 deletions(-)

diffs (truncated from 4758 to 300 lines):

diff -r a644de51972d -r 0901a2b85d86 sys/rump/fs/lib/libext2fs/Makefile
--- a/sys/rump/fs/lib/libext2fs/Makefile        Wed May 09 00:16:07 2012 +0000
+++ b/sys/rump/fs/lib/libext2fs/Makefile        Wed May 09 00:21:17 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 2010/02/16 20:42:46 pooka Exp $
+#      $NetBSD: Makefile,v 1.4 2012/05/09 00:21:17 riastradh Exp $
 #
 
 .PATH:  ${.CURDIR}/../../../../ufs/ext2fs
@@ -6,8 +6,8 @@
 LIB=   rumpfs_ext2fs
 
 SRCS=  ext2fs_alloc.c ext2fs_balloc.c ext2fs_bmap.c ext2fs_bswap.c     \
-       ext2fs_inode.c ext2fs_lookup.c ext2fs_readwrite.c ext2fs_subr.c \
-       ext2fs_vfsops.c ext2fs_vnops.c
+       ext2fs_inode.c ext2fs_lookup.c ext2fs_readwrite.c               \
+       ext2fs_rename.c ext2fs_subr.c ext2fs_vfsops.c ext2fs_vnops.c
 
 .include <bsd.lib.mk>
 .include <bsd.klinks.mk>
diff -r a644de51972d -r 0901a2b85d86 sys/rump/fs/lib/libffs/Makefile
--- a/sys/rump/fs/lib/libffs/Makefile   Wed May 09 00:16:07 2012 +0000
+++ b/sys/rump/fs/lib/libffs/Makefile   Wed May 09 00:21:17 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.13 2011/03/06 17:08:37 bouyer Exp $
+#      $NetBSD: Makefile,v 1.14 2012/05/09 00:21:17 riastradh Exp $
 #
 
 .PATH:  ${.CURDIR}/../../../../ufs/ffs ${.CURDIR}/../../../../ufs/ufs
@@ -10,7 +10,7 @@
        ffs_wapbl.c ffs_quota2.c
 
 SRCS+= ufs_bmap.c ufs_dirhash.c ufs_extattr.c ufs_ihash.c ufs_inode.c  \
-       ufs_lookup.c ufs_vfsops.c ufs_vnops.c ufs_wapbl.c \
+       ufs_lookup.c ufs_rename.c ufs_vfsops.c ufs_vnops.c ufs_wapbl.c \
        ufs_quota.c ufs_quota2.c quota2_subr.c
 
 CPPFLAGS+=     -DFFS_EI -DUFS_DIRHASH -DWAPBL -DAPPLE_UFS -DUFS_EXTATTR \
diff -r a644de51972d -r 0901a2b85d86 sys/ufs/ext2fs/ext2fs_dir.h
--- a/sys/ufs/ext2fs/ext2fs_dir.h       Wed May 09 00:16:07 2012 +0000
+++ b/sys/ufs/ext2fs/ext2fs_dir.h       Wed May 09 00:21:17 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_dir.h,v 1.18 2009/10/19 18:41:17 bouyer Exp $   */
+/*     $NetBSD: ext2fs_dir.h,v 1.19 2012/05/09 00:21:18 riastradh Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,6 +67,8 @@
 #ifndef _UFS_EXT2FS_EXT2FS_DIR_H_
 #define        _UFS_EXT2FS_EXT2FS_DIR_H_
 
+#include <ufs/ext2fs/ext2fs_dinode.h>
+
 /*
  * Theoretically, directories can be more than 2Gb in length, however, in
  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
diff -r a644de51972d -r 0901a2b85d86 sys/ufs/ext2fs/ext2fs_extern.h
--- a/sys/ufs/ext2fs/ext2fs_extern.h    Wed May 09 00:16:07 2012 +0000
+++ b/sys/ufs/ext2fs/ext2fs_extern.h    Wed May 09 00:21:17 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_extern.h,v 1.43 2011/07/12 16:59:48 dholland Exp $      */
+/*     $NetBSD: ext2fs_extern.h,v 1.44 2012/05/09 00:21:18 riastradh Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -77,6 +77,7 @@
 struct vnode;
 struct mbuf;
 struct componentname;
+struct ufs_lookup_results;
 
 extern struct pool ext2fs_inode_pool;          /* memory pool for inodes */
 extern struct pool ext2fs_dinode_pool;         /* memory pool for dinodes */
diff -r a644de51972d -r 0901a2b85d86 sys/ufs/ext2fs/ext2fs_rename.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/ufs/ext2fs/ext2fs_rename.c    Wed May 09 00:21:17 2012 +0000
@@ -0,0 +1,1012 @@
+/*     $NetBSD: ext2fs_rename.c,v 1.1 2012/05/09 00:21:18 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.
+ */
+
+/*
+ * Ext2fs Rename
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_rename.c,v 1.1 2012/05/09 00:21:18 riastradh Exp $");
+
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/errno.h>
+#include <sys/kauth.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/vnode.h>
+#include <sys/vnode_if.h>
+
+#include <miscfs/genfs/genfs.h>
+
+#include <ufs/ext2fs/ext2fs.h>
+#include <ufs/ext2fs/ext2fs_dir.h>
+#include <ufs/ext2fs/ext2fs_extern.h>
+#include <ufs/ufs/inode.h>
+#include <ufs/ufs/ufs_extern.h>
+#include <ufs/ufs/ufsmount.h>
+
+/*
+ * Forward declarations
+ */
+static int ext2fs_sane_rename(struct vnode *, struct componentname *,
+    struct vnode *, struct componentname *,
+    kauth_cred_t, bool);
+static bool ext2fs_rename_ulr_overlap_p(const struct ufs_lookup_results *,
+    const struct ufs_lookup_results *);
+static int ext2fs_rename_recalculate_fulr(struct vnode *,
+    struct ufs_lookup_results *, const struct ufs_lookup_results *,
+    const struct componentname *);
+static bool ext2fs_rmdired_p(struct vnode *);
+static int ext2fs_read_dotdot(struct vnode *, kauth_cred_t, ino_t *);
+static int ext2fs_rename_replace_dotdot(struct vnode *,
+    struct vnode *, struct vnode *, kauth_cred_t);
+static int ext2fs_gro_lock_directory(struct mount *, struct vnode *);
+
+static const struct genfs_rename_ops ext2fs_genfs_rename_ops;
+
+/*
+ * ext2fs_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
+ext2fs_sane_rename(
+    struct vnode *fdvp, struct componentname *fcnp,
+    struct vnode *tdvp, struct componentname *tcnp,
+    kauth_cred_t cred, bool posixly_correct)
+{
+       struct ufs_lookup_results fulr, tulr;
+
+       return genfs_sane_rename(&ext2fs_genfs_rename_ops,
+           fdvp, fcnp, &fulr, tdvp, tcnp, &tulr,
+           cred, posixly_correct);
+}
+
+/*
+ * ext2fs_rename: The hairiest vop, with the insanest API.  Defer to
+ * genfs_insane_rename immediately.
+ */
+int
+ext2fs_rename(void *v)
+{
+
+       return genfs_insane_rename(v, &ext2fs_sane_rename);
+}
+
+/*
+ * ext2fs_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
+ext2fs_gro_directory_empty_p(struct mount *mp, kauth_cred_t cred,
+    struct vnode *vp, struct vnode *dvp)
+{
+
+       (void)mp;
+       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 ext2fs_dirempty(VTOI(vp), VTOI(dvp)->i_number, cred);
+}
+
+/*
+ * ext2fs_gro_rename_check_possible: Check whether a rename is possible
+ * independent of credentials.
+ */
+static int
+ext2fs_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(
+           VTOI(fdvp)->i_e2fs_flags, VTOI(fvp)->i_e2fs_flags,
+           VTOI(tdvp)->i_e2fs_flags, (tvp? VTOI(tvp)->i_e2fs_flags : 0),
+           (tvp != NULL),
+           EXT2_IMMUTABLE, EXT2_APPEND);
+}
+
+/*
+ * ext2fs_gro_rename_check_permitted: Check whether a rename is
+ * permitted given our credentials.
+ */
+static int
+ext2fs_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, VTOI(fdvp)->i_e2fs_mode, VTOI(fdvp)->i_uid,
+           fvp, VTOI(fvp)->i_uid,
+           tdvp, VTOI(tdvp)->i_e2fs_mode, VTOI(tdvp)->i_uid,
+           tvp, (tvp? VTOI(tvp)->i_uid : 0));
+}
+
+/*
+ * ext2fs_gro_remove_check_possible: Check whether a remove is possible
+ * independent of credentials.
+ */
+static int
+ext2fs_gro_remove_check_possible(struct mount *mp,
+    struct vnode *dvp, struct vnode *vp)
+{
+
+       (void)mp;



Home | Main Index | Thread Index | Old Index