Source-Changes-HG archive

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

[src/netbsd-9]: src/usr.sbin/sysinst Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/c34e587ca779
branches:  netbsd-9
changeset: 462704:c34e587ca779
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Oct 23 06:30:16 2019 +0000

description:
Pull up following revision(s) (requested by martin in ticket #369):
        usr.sbin/sysinst/disks.c: revision 1.51
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).

diffstat:

 usr.sbin/sysinst/disks.c |  43 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 35 insertions(+), 8 deletions(-)

diffs (68 lines):

diff -r fb101af35cc7 -r c34e587ca779 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c  Wed Oct 23 06:04:44 2019 +0000
+++ b/usr.sbin/sysinst/disks.c  Wed Oct 23 06:30:16 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.44.2.8 2019/10/23 06:04:44 msaitoh Exp $ */
+/*     $NetBSD: disks.c,v 1.44.2.9 2019/10/23 06:30:16 msaitoh Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1487,12 +1487,14 @@
        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) {
@@ -1505,11 +1507,36 @@
                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) {



Home | Main Index | Thread Index | Old Index