Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Strip trailing / from last mounted strings.



details:   https://anonhg.NetBSD.org/src/rev/6981fbbfc12d
branches:  trunk
changeset: 462161:6981fbbfc12d
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Jul 26 08:18:47 2019 +0000

description:
Strip trailing / from last mounted strings.
No idea how they happen, but for cgd root (init.root = "/altroot")
they have been reported to exist.

diffstat:

 usr.sbin/sysinst/defs.h      |   3 ++-
 usr.sbin/sysinst/disklabel.c |   4 +++-
 usr.sbin/sysinst/gpt.c       |   6 ++++--
 usr.sbin/sysinst/label.c     |  22 ++++++++++++++++++++--
 usr.sbin/sysinst/mbr.c       |   6 ++++--
 5 files changed, 33 insertions(+), 8 deletions(-)

diffs (118 lines):

diff -r 6887443b2d1e -r 6981fbbfc12d usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Fri Jul 26 07:41:22 2019 +0000
+++ b/usr.sbin/sysinst/defs.h   Fri Jul 26 08:18:47 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.41 2019/07/23 18:13:40 martin Exp $ */
+/*     $NetBSD: defs.h,v 1.42 2019/07/26 08:18:47 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -648,6 +648,7 @@
  */
 const char *get_last_mounted(int fd, daddr_t offset, uint *fs_type,
      uint *fs_sub_type, uint flags);
+void   canonicalize_last_mounted(char*);
 int    edit_and_check_label(struct pm_devs *p, struct partition_usage_set *pset);
 int edit_ptn(menudesc *, void *);
 int checkoverlap(struct disk_partitions *parts);
diff -r 6887443b2d1e -r 6981fbbfc12d usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Fri Jul 26 07:41:22 2019 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Fri Jul 26 08:18:47 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.9 2019/07/21 11:56:20 martin Exp $     */
+/*     $NetBSD: disklabel.c,v 1.10 2019/07/26 08:18:47 martin Exp $    */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -245,6 +245,8 @@
                                if (parts->l.d_partitions[part].p_fstype ==
                                    fs_type)
                                        parts->fs_sub_type[part] = fs_sub_type;
+                               canonicalize_last_mounted(
+                                   parts->last_mounted[part]);
                        }
                }
 
diff -r 6887443b2d1e -r 6981fbbfc12d usr.sbin/sysinst/gpt.c
--- a/usr.sbin/sysinst/gpt.c    Fri Jul 26 07:41:22 2019 +0000
+++ b/usr.sbin/sysinst/gpt.c    Fri Jul 26 08:18:47 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gpt.c,v 1.3 2019/07/25 13:16:35 martin Exp $   */
+/*     $NetBSD: gpt.c,v 1.4 2019/07/26 08:18:47 martin Exp $   */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -358,7 +358,9 @@
                        const char *lm = get_last_mounted(fd, p->gp_start,
                            &p->fs_type, &p->fs_sub_type, p->gp_type->fsflags);
                        if (lm != NULL && *lm != 0) {
-                               p->last_mounted = strdup(lm);
+                               char *path = strdup(lm);
+                               canonicalize_last_mounted(path);
+                               p->last_mounted = path;
                        } else {
                                p->fs_type = p->gp_type->default_fs_type;
 #ifdef DEFAULT_UFS2
diff -r 6887443b2d1e -r 6981fbbfc12d usr.sbin/sysinst/label.c
--- a/usr.sbin/sysinst/label.c  Fri Jul 26 07:41:22 2019 +0000
+++ b/usr.sbin/sysinst/label.c  Fri Jul 26 08:18:47 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.9 2019/07/09 16:16:33 martin Exp $ */
+/*     $NetBSD: label.c,v 1.10 2019/07/26 08:18:47 martin Exp $        */
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: label.c,v 1.9 2019/07/09 16:16:33 martin Exp $");
+__RCSID("$NetBSD: label.c,v 1.10 2019/07/26 08:18:47 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -1480,6 +1480,24 @@
 }
 
 /*
+ * strip trailing / to avoid confusion in path comparisions later
+ */
+void
+canonicalize_last_mounted(char *path)
+{
+       char *p;
+
+       for (;;) {
+               p = strrchr(path, '/');
+               if (p == NULL)
+                       return;
+               if (p[1] != 0)
+                       return;
+               p[0] = 0;
+       }
+}
+
+/*
  * Try to get 'last mounted on' (or equiv) from fs superblock.
  */
 const char *
diff -r 6887443b2d1e -r 6981fbbfc12d usr.sbin/sysinst/mbr.c
--- a/usr.sbin/sysinst/mbr.c    Fri Jul 26 07:41:22 2019 +0000
+++ b/usr.sbin/sysinst/mbr.c    Fri Jul 26 08:18:47 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.18 2019/07/25 18:55:40 martin Exp $ */
+/*     $NetBSD: mbr.c,v 1.19 2019/07/26 08:18:47 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -547,7 +547,9 @@
                                            &mbri->fs_type[i],
                                            &mbri->fs_sub_type[i],
                                            flags);
-                                       mbri->last_mounted[i] = strdup(mount);
+                                       char *p = strdup(mount);
+                                       canonicalize_last_mounted(p);
+                                       mbri->last_mounted[i] = p;
                                }
                        }
 #if BOOTSEL



Home | Main Index | Thread Index | Old Index