Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst PR 55384: detangle pm->ptstart from the "in...



details:   https://anonhg.NetBSD.org/src/rev/8db6311bff81
branches:  trunk
changeset: 955555:8db6311bff81
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Oct 03 18:54:18 2020 +0000

description:
PR 55384: detangle pm->ptstart from the "install" flag (selecting a
target partition). Instead introduce a new PTI_INSTALL_TARGET per partition
flag and deal with it in the partitioning backends.

Honour pm->ptstart when allocating new partitions - it is supposed to be
the first sector usable by NetBSD.

diffstat:

 usr.sbin/sysinst/bsddisklabel.c |   4 ++--
 usr.sbin/sysinst/disklabel.c    |  26 +++++++++++++++++++++++---
 usr.sbin/sysinst/gpt.c          |  27 +++++++++++++++++++++++++--
 usr.sbin/sysinst/label.c        |  24 +++++++++++-------------
 usr.sbin/sysinst/mbr.c          |  34 +++++++++++++++++++++++++++-------
 usr.sbin/sysinst/part_edit.c    |  40 ++++++++++++++++------------------------
 usr.sbin/sysinst/partitions.h   |   8 +++++++-
 7 files changed, 111 insertions(+), 52 deletions(-)

diffs (truncated from 564 to 300 lines):

diff -r 21f6e4a4161e -r 8db6311bff81 usr.sbin/sysinst/bsddisklabel.c
--- a/usr.sbin/sysinst/bsddisklabel.c   Sat Oct 03 18:42:20 2020 +0000
+++ b/usr.sbin/sysinst/bsddisklabel.c   Sat Oct 03 18:54:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bsddisklabel.c,v 1.45 2020/09/29 15:29:17 martin Exp $ */
+/*     $NetBSD: bsddisklabel.c,v 1.46 2020/10/03 18:54:18 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1431,7 +1431,7 @@
                }
        }
 
-       from = -1;
+       from = p->ptstart > 0 ? pm->ptstart : -1;
        /*
         * First add all outer partitions - we need to align those exactly
         * with the inner counterpart later.
diff -r 21f6e4a4161e -r 8db6311bff81 usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Sat Oct 03 18:42:20 2020 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Sat Oct 03 18:54:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.39 2020/09/29 15:29:17 martin Exp $    */
+/*     $NetBSD: disklabel.c,v 1.40 2020/10/03 18:54:18 martin Exp $    */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
 struct disklabel_disk_partitions {
        struct disk_partitions dp;
        struct disklabel l;
-       daddr_t ptn_alignment;
+       daddr_t ptn_alignment, install_target;
        char last_mounted[MAXPARTITIONS][MOUNTLEN];
        uint fs_sub_type[MAXPARTITIONS];
 };
@@ -150,6 +150,7 @@
        if (parts == NULL)
                return NULL;
 
+       parts->install_target = -1;
        total_size = geo.dg_secperunit;
        if (len*(geo.dg_secsize/512) > disklabel_parts.size_limit)
                len = disklabel_parts.size_limit/(geo.dg_secsize/512);
@@ -213,6 +214,7 @@
        struct disklabel_disk_partitions *parts = calloc(1, sizeof(*parts));
        if (parts == NULL)
                return NULL;
+       parts->install_target = -1;
 
        fd = opendisk(disk, O_RDONLY, diskpath, sizeof(diskpath), 0);
        if (fd == -1) {
@@ -272,8 +274,12 @@
                flags = 0;
                if (parts->l.d_partitions[part].p_fstype == FS_MSDOS)
                        flags = GLM_MAYBE_FAT32;
-               else if (parts->l.d_partitions[part].p_fstype == FS_BSDFFS)
+               else if (parts->l.d_partitions[part].p_fstype == FS_BSDFFS) {
                        flags = GLM_LIKELY_FFS;
+                       if (parts->install_target < 0)
+                               parts->install_target =
+                                   parts->l.d_partitions[part].p_offset;
+               }
                if (flags != 0) {
                        uint fs_type, fs_sub_type;
                        const char *lm = get_last_mounted(fd,
@@ -511,6 +517,9 @@
                                            MSG_part_not_deletable);
                                return false;
                        }
+                       if (parts->install_target ==
+                           parts->l.d_partitions[part].p_offset)
+                               parts->install_target = -1;
                        parts->l.d_partitions[part].p_size = 0;
                        parts->l.d_partitions[part].p_offset = 0;
                        parts->l.d_partitions[part].p_fstype = FS_UNUSED;
@@ -552,6 +561,8 @@
 
                if ((start >= r_start && start <= r_start+r_size) ||
                    (end >= r_start && end <= r_start+r_size)) {
+                       if (start == parts->install_target)
+                               parts->install_target  = -1;
                        if (parts->dp.num_part > 1)
                                parts->dp.num_part--;
                        parts->dp.free_space +=
@@ -765,6 +776,8 @@
                            parts->l.d_partitions[part].p_fstype == FS_UNUSED)
                                info->flags |=
                                    PTI_PSCHEME_INTERNAL|PTI_RAW_PART;
+                       if (info->start == parts->install_target)
+                               info->flags |= PTI_INSTALL_TARGET;
 #if RAW_PART == 3
                        if (part == (RAW_PART-1) && parts->dp.parent != NULL &&
                            parts->l.d_partitions[part].p_fstype == FS_UNUSED)
@@ -789,6 +802,7 @@
        struct disklabel_disk_partitions *parts =
            (struct disklabel_disk_partitions*)arg;
        part_id ndx;
+       bool was_inst_target;
 
        if (dl_types[0].description == NULL)
                dl_init_types();
@@ -800,6 +814,8 @@
                        continue;
 
                if (ndx == id) {
+                       was_inst_target = parts->l.d_partitions[part].p_offset
+                           == parts->install_target;
                        parts->l.d_partitions[part].p_offset = info->start;
                        parts->l.d_partitions[part].p_size = info->size;
                        parts->l.d_partitions[part].p_fstype =
@@ -809,6 +825,10 @@
                                strlcpy(parts->last_mounted[part],
                                    info->last_mounted,
                                    sizeof(parts->last_mounted[part]));
+                       if (info->flags & PTI_INSTALL_TARGET)
+                               parts->install_target = info->start;
+                       else if (was_inst_target)
+                               parts->install_target = -1;
                        assert(info->fs_type == 0 || info->fs_type ==
                            parts->l.d_partitions[part].p_fstype);
                        if (info->fs_sub_type != 0)
diff -r 21f6e4a4161e -r 8db6311bff81 usr.sbin/sysinst/gpt.c
--- a/usr.sbin/sysinst/gpt.c    Sat Oct 03 18:42:20 2020 +0000
+++ b/usr.sbin/sysinst/gpt.c    Sat Oct 03 18:54:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gpt.c,v 1.18 2020/03/30 12:19:28 martin Exp $  */
+/*     $NetBSD: gpt.c,v 1.19 2020/10/03 18:54:18 martin Exp $  */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -137,6 +137,7 @@
 #define        GPEF_MODIFIED   2               /* this entry has been changed */
 #define        GPEF_WEDGE      4               /* wedge for this exists */
 #define        GPEF_RESIZED    8               /* size has changed */
+#define        GPEF_TARGET     16              /* marked install target */
        struct gpt_part_entry *gp_next;
 };
 
@@ -281,6 +282,9 @@
        static const char regpart_prefix[] = "GPT part - ";
        struct gpt_disk_partitions *parts;
        struct gpt_part_entry *last = NULL, *add_to = NULL;
+       const struct gpt_ptype_desc *native_root
+            = gpt_find_native_type(gpt_native_root);
+       bool have_target = false;
 
        if (collect(T_OUTPUT, &textbuf, "gpt -r show -a %s 2>/dev/null", dev)
            < 1)
@@ -352,6 +356,11 @@
                        np->gp_start = p_start;
                        np->gp_size = p_size;
                        np->gp_flags |= GPEF_ON_DISK;
+                       if (!have_target && native_root != NULL &&
+                           strcmp(np->gp_id, native_root->tid) == 0) {
+                               have_target = true;
+                               np->gp_flags |= GPEF_TARGET;
+                       }
 
                        if (last == NULL)
                                parts->partitions = np;
@@ -509,6 +518,8 @@
        info->last_mounted = p->last_mounted;
        info->fs_type = p->fs_type;
        info->fs_sub_type = p->fs_sub_type;
+       if (p->gp_flags & GPEF_TARGET)
+               info->flags |= PTI_INSTALL_TARGET;
 
        return true;
 }
@@ -604,6 +615,7 @@
        struct gpt_part_entry *p = parts->partitions, *n;
        part_id no;
        daddr_t lendiff;
+       bool was_target;
 
        for (no = 0; p != NULL && no < id; no++)
                p = p->gp_next;
@@ -611,6 +623,17 @@
        if (no != id || p == NULL)
                return false;
 
+       /* update target mark - we can only have one */
+       was_target = (p->gp_flags & GPEF_TARGET) != 0;
+       if (info->flags & PTI_INSTALL_TARGET)
+               p->gp_flags |= GPEF_TARGET;
+       else
+               p->gp_flags &= ~GPEF_TARGET;
+       if (was_target)
+               for (n = parts->partitions; n != NULL; n = n->gp_next)
+                       if (n != p)
+                               n->gp_flags &= ~GPEF_TARGET;
+
        if ((p->gp_flags & GPEF_ON_DISK)) {
                if (info->start != p->gp_start) {
                        /* partition moved, we need to delete and re-add */
@@ -1444,7 +1467,7 @@
                p->gp_flags &= ~GPEF_WEDGE;
                if (root_id == NO_PART && p->gp_type != NULL) {
                        if (p->gp_type->gent.generic_ptype == PT_root &&
-                           p->gp_start == pm->ptstart) {
+                           (p->gp_flags & GPEF_TARGET)) {
                                root_id = pno;
                                root_is_new = !(p->gp_flags & GPEF_ON_DISK);
                        } else if (efi_id == NO_PART &&
diff -r 21f6e4a4161e -r 8db6311bff81 usr.sbin/sysinst/label.c
--- a/usr.sbin/sysinst/label.c  Sat Oct 03 18:42:20 2020 +0000
+++ b/usr.sbin/sysinst/label.c  Sat Oct 03 18:54:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.25 2020/09/29 14:29:56 martin Exp $        */
+/*     $NetBSD: label.c,v 1.26 2020/10/03 18:54:18 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.25 2020/09/29 14:29:56 martin Exp $");
+__RCSID("$NetBSD: label.c,v 1.26 2020/10/03 18:54:18 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -190,8 +190,8 @@
        daddr_t first_bsdstart, first_bsdsize, inst_start, inst_size;
        int rv;
 
-       first_bsdstart = first_bsdsize = 0;
-       inst_start = inst_size = 0;
+       first_bsdstart = inst_start = -1;
+       first_bsdsize = inst_size = 0;
        num_root = 0;
        parts = pset->parts;
        for (i = 0; i < pset->num; i++) {
@@ -207,18 +207,19 @@
                        continue;
                num_root++;
  
-               if (first_bsdstart == 0) {
+               if (first_bsdstart <= 0) {
                        first_bsdstart = wanted->cur_start;
                        first_bsdsize = wanted->size;
                }
-               if (inst_start == 0 && wanted->cur_start == pm->ptstart) {
+               if (inst_start < 0 &&
+                   (wanted->cur_flags & PTI_INSTALL_TARGET)) {
                        inst_start = wanted->cur_start;
                        inst_size = wanted->size;
                }
        }
 
        if ((num_root == 0 && install) ||
-           (num_root > 1 && inst_start == 0)) {
+           (num_root > 1 && inst_start < 0)) {
                if (num_root == 0 && install)
                        msg_display_subst(MSG_must_be_one_root, 2,
                            msg_string(parts->pscheme->name),
@@ -322,10 +323,7 @@
 {
        struct single_part_fs_edit *edit = arg;
 
-       if (edit->info.start == pm->ptstart)
-               pm->ptstart = 0;
-       else
-               pm->ptstart = edit->info.start;
+       edit->info.flags ^= PTI_INSTALL_TARGET;
        return 0;
 }
 
@@ -1064,7 +1062,7 @@
        }
        if (m->opts[opt].opt_action == edit_install) {
                wprintw(m->mw, "%*s : %s", col_width, ptn_install,
-                       msg_string(edit->info.start == pm->ptstart
+                       msg_string((edit->info.flags & PTI_INSTALL_TARGET)
                            ? MSG_Yes : MSG_No));
                return;
        }
@@ -1318,7 +1316,7 @@
 
        fp = flag_str;
        inst_flags = pset->infos[ptn].instflags;
-       if (with_inst_flag && info.start == pm->ptstart &&
+       if (with_inst_flag && (info.flags & PTI_INSTALL_TARGET) &&
            info.nat_type->generic_ptype == PT_root) {
                static char inst_flag;
 
diff -r 21f6e4a4161e -r 8db6311bff81 usr.sbin/sysinst/mbr.c
--- a/usr.sbin/sysinst/mbr.c    Sat Oct 03 18:42:20 2020 +0000
+++ b/usr.sbin/sysinst/mbr.c    Sat Oct 03 18:54:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.33 2020/09/29 15:29:17 martin Exp $ */
+/*     $NetBSD: mbr.c,v 1.34 2020/10/03 18:54:18 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -133,7 +133,7 @@
        struct disk_partitions dp, *dlabel;
        mbr_info_t mbr;
        uint ptn_alignment, ptn_0_offset, ext_ptn_alignment,



Home | Main Index | Thread Index | Old Index