Source-Changes-HG archive

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

[src/trunk]: src/sys Move msdosfs_rename() and doscheckpath() to new file msd...



details:   https://anonhg.NetBSD.org/src/rev/1f6ae14e61ee
branches:  trunk
changeset: 989997:1f6ae14e61ee
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sat Oct 23 07:41:37 2021 +0000

description:
Move msdosfs_rename() and doscheckpath() to new file msdosfs_rename.c.

No functional change.

diffstat:

 sys/fs/msdosfs/files.msdosfs      |    3 +-
 sys/fs/msdosfs/msdosfs_lookup.c   |  114 +--------
 sys/fs/msdosfs/msdosfs_rename.c   |  513 ++++++++++++++++++++++++++++++++++++++
 sys/fs/msdosfs/msdosfs_vnops.c    |  387 +----------------------------
 sys/modules/msdos/Makefile        |    4 +-
 sys/rump/fs/lib/libmsdos/Makefile |    4 +-
 6 files changed, 523 insertions(+), 502 deletions(-)

diffs (truncated from 1113 to 300 lines):

diff -r de22a13fc7c0 -r 1f6ae14e61ee sys/fs/msdosfs/files.msdosfs
--- a/sys/fs/msdosfs/files.msdosfs      Sat Oct 23 07:38:33 2021 +0000
+++ b/sys/fs/msdosfs/files.msdosfs      Sat Oct 23 07:41:37 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.msdosfs,v 1.3 2016/02/06 10:40:58 mlelstv Exp $
+#      $NetBSD: files.msdosfs,v 1.4 2021/10/23 07:41:37 hannken Exp $
 
 deffs  MSDOSFS
 
@@ -7,6 +7,7 @@
 file   fs/msdosfs/msdosfs_denode.c             msdosfs
 file   fs/msdosfs/msdosfs_fat.c                msdosfs
 file   fs/msdosfs/msdosfs_lookup.c             msdosfs
+file   fs/msdosfs/msdosfs_rename.c             msdosfs
 file   fs/msdosfs/msdosfs_vfsops.c             msdosfs
 file   fs/msdosfs/msdosfs_vnops.c              msdosfs
 file   fs/msdosfs/msdosfs_unicode.c            msdosfs
diff -r de22a13fc7c0 -r 1f6ae14e61ee sys/fs/msdosfs/msdosfs_lookup.c
--- a/sys/fs/msdosfs/msdosfs_lookup.c   Sat Oct 23 07:38:33 2021 +0000
+++ b/sys/fs/msdosfs/msdosfs_lookup.c   Sat Oct 23 07:41:37 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_lookup.c,v 1.38 2021/10/23 07:38:33 hannken Exp $      */
+/*     $NetBSD: msdosfs_lookup.c,v 1.39 2021/10/23 07:41:37 hannken Exp $      */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -52,7 +52,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.38 2021/10/23 07:38:33 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_lookup.c,v 1.39 2021/10/23 07:41:37 hannken Exp $");
 
 #include <sys/param.h>
 
@@ -830,116 +830,6 @@
 }
 
 /*
- * Check to see if the directory described by target is in some
- * subdirectory of source.  This prevents something like the following from
- * succeeding and leaving a bunch or files and directories orphaned. mv
- * /a/b/c /a/b/c/d/e/f Where c and f are directories.
- *
- * source - the inode for /a/b/c
- * target - the inode for /a/b/c/d/e/f
- *
- * Returns 0 if target is NOT a subdirectory of source.
- * Otherwise returns a non-zero error number.
- * The target inode is always unlocked on return.
- */
-int
-doscheckpath(struct denode *source, struct denode *target)
-{
-       u_long scn;
-       struct msdosfsmount *pmp;
-       struct direntry *ep;
-       struct denode *dep;
-       struct buf *bp = NULL;
-       int error = 0;
-
-       dep = target;
-       if ((target->de_Attributes & ATTR_DIRECTORY) == 0 ||
-           (source->de_Attributes & ATTR_DIRECTORY) == 0) {
-               error = ENOTDIR;
-               goto out;
-       }
-       if (dep->de_StartCluster == source->de_StartCluster) {
-               error = EEXIST;
-               goto out;
-       }
-       if (dep->de_StartCluster == MSDOSFSROOT)
-               goto out;
-       pmp = dep->de_pmp;
-#ifdef DIAGNOSTIC
-       if (pmp != source->de_pmp)
-               panic("doscheckpath: source and target on different filesystems");
-#endif
-       if (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)
-               goto out;
-
-       for (;;) {
-               if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
-                       error = ENOTDIR;
-                       break;
-               }
-               scn = dep->de_StartCluster;
-               error = bread(pmp->pm_devvp, de_bn2kb(pmp, cntobn(pmp, scn)),
-                             pmp->pm_bpcluster, 0, &bp);
-               if (error)
-                       break;
-
-               ep = (struct direntry *) bp->b_data + 1;
-               if ((ep->deAttributes & ATTR_DIRECTORY) == 0 ||
-                   memcmp(ep->deName, "..         ", 11) != 0) {
-                       error = ENOTDIR;
-                       break;
-               }
-               scn = getushort(ep->deStartCluster);
-               if (FAT32(pmp))
-                       scn |= getushort(ep->deHighClust) << 16;
-
-               if (scn == source->de_StartCluster) {
-                       error = EINVAL;
-                       break;
-               }
-               if (scn == MSDOSFSROOT)
-                       break;
-               if (FAT32(pmp) && scn == pmp->pm_rootdirblk) {
-                       /*
-                        * scn should be 0 in this case,
-                        * but we silently ignore the error.
-                        */
-                       break;
-               }
-
-               vput(DETOV(dep));
-               brelse(bp, 0);
-               bp = NULL;
-#ifdef MAKEFS
-               /* NOTE: deget() clears dep on error */
-               if ((error = deget(pmp, scn, 0, &dep)) != 0)
-                       break;
-#else
-               struct vnode *vp;
-
-               dep = NULL;
-               error = deget(pmp, scn, 0, &vp);
-               if (error)
-                       break;
-               error = vn_lock(vp, LK_EXCLUSIVE);
-               if (error) {
-                       vrele(vp);
-                       break;
-               }
-               dep = VTODE(vp);
-#endif
-       }
-out:
-       if (bp)
-               brelse(bp, 0);
-       if (error == ENOTDIR)
-               printf("doscheckpath(): .. not a directory?\n");
-       if (dep != NULL)
-               vput(DETOV(dep));
-       return (error);
-}
-
-/*
  * Read in the disk block containing the directory entry (dirclu, dirofs)
  * and return the address of the buf header, and the address of the
  * directory entry within the block.
diff -r de22a13fc7c0 -r 1f6ae14e61ee sys/fs/msdosfs/msdosfs_rename.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/fs/msdosfs/msdosfs_rename.c   Sat Oct 23 07:41:37 2021 +0000
@@ -0,0 +1,513 @@
+/*     $NetBSD: msdosfs_rename.c,v 1.1 2021/10/23 07:41:37 hannken Exp $       */
+
+/*-
+ * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
+ * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
+ * All rights reserved.
+ * Original code by Paul Popelka (paulp%uts.amdahl.com@localhost) (see below).
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+/*
+ * Written by Paul Popelka (paulp%uts.amdahl.com@localhost)
+ *
+ * You can do anything you want with this software, just don't say you wrote
+ * it, and don't remove this notice.
+ *
+ * This software is provided "as is".
+ *
+ * The author supplies this software to be publicly redistributed on the
+ * understanding that the author is not responsible for the correct
+ * functioning of this software in any circumstances and is not liable for
+ * any damages caused by this software.
+ *
+ * October 1992
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/namei.h>
+#include <sys/resourcevar.h>   /* defines plimit structure in proc struct */
+#include <sys/kernel.h>
+#include <sys/file.h>          /* define FWRITE ... */
+#include <sys/stat.h>
+#include <sys/buf.h>
+#include <sys/proc.h>
+#include <sys/mount.h>
+#include <sys/vnode.h>
+#include <sys/signalvar.h>
+#include <sys/malloc.h>
+#include <sys/dirent.h>
+#include <sys/lockf.h>
+#include <sys/kauth.h>
+
+#include <miscfs/genfs/genfs.h>
+#include <miscfs/specfs/specdev.h> /* XXX */   /* defines v_rdev */
+
+#include <uvm/uvm_extern.h>
+
+#include <fs/msdosfs/bpb.h>
+#include <fs/msdosfs/direntry.h>
+#include <fs/msdosfs/denode.h>
+#include <fs/msdosfs/msdosfsmount.h>
+#include <fs/msdosfs/fat.h>
+
+int
+msdosfs_rename(void *v)
+{
+       struct vop_rename_args /* {
+               struct vnode *a_fdvp;
+               struct vnode *a_fvp;
+               struct componentname *a_fcnp;
+               struct vnode *a_tdvp;
+               struct vnode *a_tvp;
+               struct componentname *a_tcnp;
+       } */ *ap = v;
+       struct vnode *tvp = ap->a_tvp;
+       struct vnode *tdvp = ap->a_tdvp;
+       struct vnode *fvp = ap->a_fvp;
+       struct vnode *fdvp = ap->a_fdvp;
+       struct componentname *tcnp = ap->a_tcnp;
+       struct componentname *fcnp = ap->a_fcnp;
+       struct denode *ip, *xp, *dp, *zp;
+       u_char toname[12], oldname[12];
+       u_long from_diroffset, to_diroffset;
+       u_char to_count;
+       int doingdirectory = 0, newparent = 0;
+       int error;
+       u_long cn;
+       daddr_t bn;
+       struct msdosfsmount *pmp;
+       struct direntry *dotdotp;
+       struct buf *bp;
+
+       pmp = VFSTOMSDOSFS(fdvp->v_mount);
+
+       /*
+        * Check for cross-device rename.
+        */
+       if ((fvp->v_mount != tdvp->v_mount) ||
+           (tvp && (fvp->v_mount != tvp->v_mount))) {
+               error = EXDEV;
+abortit:
+               VOP_ABORTOP(tdvp, tcnp);
+               if (tdvp == tvp)
+                       vrele(tdvp);
+               else
+                       vput(tdvp);
+               if (tvp)
+                       vput(tvp);
+               VOP_ABORTOP(fdvp, fcnp);
+               vrele(fdvp);
+               vrele(fvp);
+               return (error);
+       }
+
+       /*
+        * If source and dest are the same, do nothing.
+        */
+       if (tvp == fvp) {
+               error = 0;
+               goto abortit;
+       }
+
+       /*
+        * XXX: This can deadlock since we hold tdvp/tvp locked.
+        * But I'm not going to fix it now.
+        */
+       if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
+               goto abortit;
+       dp = VTODE(fdvp);
+       ip = VTODE(fvp);



Home | Main Index | Thread Index | Old Index