Module Name:    src
Committed By:   martin
Date:           Tue Aug 20 06:38:18 UTC 2019

Modified Files:
        src/usr.sbin/sysinst: disks.c

Log Message:
PR install/54480: when upgrading a system and re-mounting the target /
with proper options, and the installed system does not use NAME= syntax
in fstab(5), use the device name we used to get here, instead of the
name from fstab, it might be different to what the real system calls the
device (compact flash root showing up as wd0 native, but sd? on the
card reader used for updating it right now).

This is an abuse of the upgrade functionality and in general pretty dangerous
when multiple devices are used in the upgraded fstab (e.g. separate /usr),
and it used to work more by accident with the old code.

However, it is a quite usefull way to upgrade tiny systems with compact flash
root, and it used to work - so support it properly (as far as we can).


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.sbin/sysinst/disks.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/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.50 src/usr.sbin/sysinst/disks.c:1.51
--- src/usr.sbin/sysinst/disks.c:1.50	Thu Aug  8 13:45:19 2019
+++ src/usr.sbin/sysinst/disks.c	Tue Aug 20 06:38:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.50 2019/08/08 13:45:19 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.51 2019/08/20 06:38:17 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1484,12 +1484,14 @@ process_found_fs(struct data *list, size
 	const char *fsname = (const char*)item->var;
 	part_id pno;
 	struct disk_partitions *parts;
-	bool first;
+	size_t len;
+	bool first, is_root;
 
 	if (num < 2 || strstr(list[2].u.s_val, "noauto") != NULL)
 		return 0;
 
-	if ((strcmp(list[1].u.s_val, "/") == 0) && target_mounted())
+	is_root = strcmp(list[1].u.s_val, "/") == 0;
+	if (is_root && target_mounted())
 		return 0;
 
 	if (strcmp(item->head, name_prefix) == 0) {
@@ -1502,11 +1504,36 @@ process_found_fs(struct data *list, size
 		parts->pscheme->get_part_device(parts, pno,
 		    rdev, sizeof(rdev), NULL, raw_dev_name, true);
 	} else {
-		/* plain device name */
-		strcpy(rdev, "/dev/r");
-		strlcat(rdev, list[0].u.s_val, sizeof(rdev));
-		strcpy(dev, "/dev/");
-		strlcat(dev, list[0].u.s_val, sizeof(dev));
+		/* this fstab entry uses the plain device name */
+		if (is_root) {
+			/*
+			 * PR 54480: we can not use the current device name
+			 * as it might be different from the real environment.
+			 * This is an abuse of the functionality, but it used
+			 * to work before (and still does work if only a single
+			 * target disk is involved).
+			 * Use the device name from the current "pm" instead.
+			 */
+			strcpy(rdev, "/dev/r");
+			strlcat(rdev, pm->diskdev, sizeof(rdev));
+			strcpy(dev, "/dev/");
+			strlcat(dev, pm->diskdev, sizeof(dev));
+			/* copy over the partition letter, if any */
+			len = strlen(list[0].u.s_val);
+			if (list[0].u.s_val[len-1] >= 'a' &&
+			    list[0].u.s_val[len-1] <=
+			    ('a' + getmaxpartitions())) {
+				strlcat(rdev, &list[0].u.s_val[len-1],
+				    sizeof(rdev));
+				strlcat(dev, &list[0].u.s_val[len-1],
+				    sizeof(dev));
+			}
+		} else {
+			strcpy(rdev, "/dev/r");
+			strlcat(rdev, list[0].u.s_val, sizeof(rdev));
+			strcpy(dev, "/dev/");
+			strlcat(dev, list[0].u.s_val, sizeof(dev));
+		}
 	}
 
 	if (with_fsck) {

Reply via email to