Module Name:    src
Committed By:   martin
Date:           Tue Jul 23 15:23:14 UTC 2019

Modified Files:
        src/usr.sbin/sysinst: defs.h disks.c target.c upgrade.c

Log Message:
When searching for a partition that may be the root partition for upgrading,
allow "/", "/targetroot" and "/altroot" as potential last mount points.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/sysinst/defs.h \
    src/usr.sbin/sysinst/disks.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/sysinst/target.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/sysinst/upgrade.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.38 src/usr.sbin/sysinst/defs.h:1.39
--- src/usr.sbin/sysinst/defs.h:1.38	Sat Jul 13 17:13:36 2019
+++ src/usr.sbin/sysinst/defs.h	Tue Jul 23 15:23:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.38 2019/07/13 17:13:36 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.39 2019/07/23 15:23:14 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -771,6 +771,7 @@ void	free_install_desc(struct install_pa
 #if defined(DEBUG)  ||	defined(DEBUG_ROOT)
 void	backtowin(void);
 #endif
+bool	is_root_part_mount(const char *);
 const	char *concat_paths(const char *, const char *);
 const	char *target_expand(const char *);
 bool	needs_expanding(const char *, size_t);
Index: src/usr.sbin/sysinst/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.38 src/usr.sbin/sysinst/disks.c:1.39
--- src/usr.sbin/sysinst/disks.c:1.38	Sun Jul 14 11:25:10 2019
+++ src/usr.sbin/sysinst/disks.c	Tue Jul 23 15:23:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.38 2019/07/14 11:25:10 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.39 2019/07/23 15:23:14 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1514,6 +1514,7 @@ mount_disks(struct install_partition_des
 	int   fstabsize;
 	int   error;
 	char devdev[PATH_MAX];
+	size_t i;
 
 	static struct lookfor fstabbuf[] = {
 		{"/dev/", "/dev/%s %s ffs %s", "c", NULL, 0, 0, foundffs},
@@ -1530,10 +1531,18 @@ mount_disks(struct install_partition_des
 		/* avoid needing to call target_already_root() again */
 		targetroot_mnt[0] = 0;
 	else {
-		assert(install != NULL && install->num > 0);
-		assert(strcmp(install->infos[0].mount, "/") == 0);
-		if (!install->infos[0].parts->pscheme->get_part_device(
-		    install->infos[0].parts, install->infos[0].cur_part_id,
+		for (i = 0; i < install->num; i++) {
+			if (is_root_part_mount(install->infos[i].mount))
+				break;
+		}
+
+		if (i >= install->num) {
+			hit_enter_to_continue(MSG_noroot, NULL);
+			return -1;
+		}
+
+		if (!install->infos[i].parts->pscheme->get_part_device(
+		    install->infos[i].parts, install->infos[i].cur_part_id,
 		    devdev, sizeof devdev, NULL, plain_name, true))
 			return -1;
 		error = mount_root(devdev, install);

Index: src/usr.sbin/sysinst/target.c
diff -u src/usr.sbin/sysinst/target.c:1.6 src/usr.sbin/sysinst/target.c:1.7
--- src/usr.sbin/sysinst/target.c:1.6	Sat Jun 15 08:20:33 2019
+++ src/usr.sbin/sysinst/target.c	Tue Jul 23 15:23:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: target.c,v 1.6 2019/06/15 08:20:33 martin Exp $	*/
+/*	$NetBSD: target.c,v 1.7 2019/07/23 15:23:14 martin Exp $	*/
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: target.c,v 1.6 2019/06/15 08:20:33 martin Exp $");
+__RCSID("$NetBSD: target.c,v 1.7 2019/07/23 15:23:14 martin Exp $");
 #endif
 
 /*
@@ -164,13 +164,19 @@ target_already_root(void)
 		return last_res;
 
 	last_pm = pm;
-	last_res = 1;
+	last_res = 0;
 
 	parts = pm->parts;
-	if (pm->no_part || parts == NULL) {
+	if (parts == NULL) {
 		last_res = 0;
 		return 0;
 	}
+
+	if (pm->no_part) {
+		last_res = is_active_rootpart(pm->diskdev, -1);
+		return last_res;
+	}
+
 	if (pm->parts->pscheme->secondary_partitions != NULL)
 		parts = pm->parts->pscheme->secondary_partitions(parts,
 		    pm->ptstart, false);
@@ -180,20 +186,30 @@ target_already_root(void)
 			continue;
 		if (info.nat_type->generic_ptype != PT_root)
 			continue;
-		if (strcmp(info.last_mounted, "/") != 0)
+		if (!is_root_part_mount(info.last_mounted))
 			continue;
-
 		if (!parts->pscheme->get_part_device(parts, ptn,
 		    dev, sizeof dev, &rootpart, plain_name, false))
 			continue;
 
 		last_res = is_active_rootpart(dev, rootpart);
-		return last_res;
-	}
+		break;
+ 	}
 
-	return 1;
+	return last_res;
 }
 
+/*
+ * Could something with this "last mounted on" information be a potential
+ * root partition?
+ */
+bool
+is_root_part_mount(const char *last_mounted)
+{
+	return strcmp(last_mounted, "/") == 0 ||
+	    strcmp(last_mounted, "/targetroot") == 0 ||
+	    strcmp(last_mounted, "/altroot") == 0;
+}
 
 /*
  * Is this device partition (e.g., "sd0a") mounted as root? 

Index: src/usr.sbin/sysinst/upgrade.c
diff -u src/usr.sbin/sysinst/upgrade.c:1.9 src/usr.sbin/sysinst/upgrade.c:1.10
--- src/usr.sbin/sysinst/upgrade.c:1.9	Mon Jun 24 18:48:08 2019
+++ src/usr.sbin/sysinst/upgrade.c	Tue Jul 23 15:23:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: upgrade.c,v 1.9 2019/06/24 18:48:08 martin Exp $	*/
+/*	$NetBSD: upgrade.c,v 1.10 2019/07/23 15:23:14 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -67,6 +67,11 @@ do_upgrade(void)
 	if (find_disks(msg_string(MSG_upgrade)) < 0)
 		return;
 
+	if (pm->parts == NULL) {
+		hit_enter_to_continue(MSG_noroot, NULL);
+		return;
+	}
+
 	if (pm->parts->pscheme->pre_update_verify) {
 		if (pm->parts->pscheme->pre_update_verify(pm->parts))
 			pm->parts->pscheme->write_to_disk(pm->parts);

Reply via email to