Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Keep a list of all partition tables from wh...



details:   https://anonhg.NetBSD.org/src/rev/a1f5acdb6080
branches:  trunk
changeset: 944182:a1f5acdb6080
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Sep 22 16:18:54 2020 +0000

description:
Keep a list of all partition tables from which we have deleted partitions
and make sure we update those partition tables when writing partitions,
even if no install related partition remains on them.

diffstat:

 usr.sbin/sysinst/bsddisklabel.c |   5 ++++-
 usr.sbin/sysinst/defs.h         |  18 +++++++++++++++---
 usr.sbin/sysinst/install.c      |  20 ++++++++++++++++++--
 usr.sbin/sysinst/label.c        |  29 +++++++++++++++++++++++++++--
 usr.sbin/sysinst/util.c         |   4 +++-
 5 files changed, 67 insertions(+), 9 deletions(-)

diffs (187 lines):

diff -r 9df151caa794 -r a1f5acdb6080 usr.sbin/sysinst/bsddisklabel.c
--- a/usr.sbin/sysinst/bsddisklabel.c   Tue Sep 22 15:24:01 2020 +0000
+++ b/usr.sbin/sysinst/bsddisklabel.c   Tue Sep 22 16:18:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bsddisklabel.c,v 1.42 2020/05/12 06:23:07 martin Exp $ */
+/*     $NetBSD: bsddisklabel.c,v 1.43 2020/09/22 16:18:54 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1774,6 +1774,8 @@
                /* update install infos */
                install->num = wanted.num;
                install->infos = wanted.infos;
+               install->write_back = wanted.write_back;
+               install->num_write_back = wanted.num_write_back;
                /* and check them */
                if (check_partitions(install))
                        break;
@@ -1781,6 +1783,7 @@
 
        /* we moved infos from wanted to install target */
        wanted.infos = NULL;
+       wanted.write_back = NULL;
        free_usage_set(&wanted);
 
        /* Everything looks OK. */
diff -r 9df151caa794 -r a1f5acdb6080 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Tue Sep 22 15:24:01 2020 +0000
+++ b/usr.sbin/sysinst/defs.h   Tue Sep 22 16:18:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.62 2020/05/18 21:19:36 jmcneill Exp $       */
+/*     $NetBSD: defs.h,v 1.63 2020/09/22 16:18:54 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -322,9 +322,15 @@
  * A list of partition suggestions, bundled for editing
  */
 struct partition_usage_set {
-       struct disk_partitions *parts;
-       size_t num;
+       struct disk_partitions *parts;  /* main partition table */
+       size_t num;                     /* number of infos */
        struct part_usage_info *infos;  /* 0 .. num-1 */
+       struct disk_partitions **write_back;
+                                       /* partition tables from which we
+                                        * did delete some partitions and
+                                        * that need updating, even if
+                                        * no active partition remains. */
+       size_t num_write_back;          /* number of write_back */
        daddr_t cur_free_space;         /* estimate of free sectors */
        menu_ent *menu_opts;            /* 0 .. num+N */
        int menu;                       /* the menu to edit this */
@@ -360,6 +366,12 @@
 struct install_partition_desc {
        size_t num;                             /* how many entries in infos */
        struct part_usage_info *infos;          /* individual partitions */
+       struct disk_partitions **write_back;    /* partition tables from 
+                                                * which we did delete some
+                                                * partitions and that need
+                                                * updating, even if no
+                                                * active partition remains. */
+       size_t num_write_back;                  /* number of write_back */
        bool cur_system;                        /* target is the life system */
 };
 
diff -r 9df151caa794 -r a1f5acdb6080 usr.sbin/sysinst/install.c
--- a/usr.sbin/sysinst/install.c        Tue Sep 22 15:24:01 2020 +0000
+++ b/usr.sbin/sysinst/install.c        Tue Sep 22 16:18:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: install.c,v 1.16 2020/05/12 17:04:00 martin Exp $      */
+/*     $NetBSD: install.c,v 1.17 2020/09/22 16:18:54 martin Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -57,12 +57,28 @@
        bool found, res;
 
        /* pessimistic assumption: all partitions on different devices */
-       allparts = calloc(install->num, sizeof(*allparts));
+       allparts = calloc(install->num + install->num_write_back,
+           sizeof(*allparts));
        if (allparts == NULL)
                return false;
 
        /* collect all different partition sets */
        num_parts = 0;
+       for (i = 0; i < install->num_write_back; i++) {
+               parts = install->write_back[i];
+               if (parts == NULL)
+                       continue;
+               found = false;
+               for (j = 0; j < num_parts; j++) {
+                       if (allparts[j] == parts) {
+                               found = true;
+                               break;
+                       }
+               }
+               if (found)
+                       continue;
+               allparts[num_parts++] = parts;
+       }
        for (i = 0; i < install->num; i++) {
                parts = install->infos[i].parts;
                if (parts == NULL)
diff -r 9df151caa794 -r a1f5acdb6080 usr.sbin/sysinst/label.c
--- a/usr.sbin/sysinst/label.c  Tue Sep 22 15:24:01 2020 +0000
+++ b/usr.sbin/sysinst/label.c  Tue Sep 22 16:18:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.23 2020/09/22 12:21:11 martin Exp $        */
+/*     $NetBSD: label.c,v 1.24 2020/09/22 16:18:54 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.23 2020/09/22 12:21:11 martin Exp $");
+__RCSID("$NetBSD: label.c,v 1.24 2020/09/22 16:18:54 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -710,6 +710,29 @@
 static void draw_edit_ptn_line(menudesc *m, int opt, void *arg);
 static int edit_ptn_custom_type(menudesc *m, void *arg);
 
+static void
+remember_deleted(struct partition_usage_set *pset,
+    struct disk_partitions *parts)
+{
+       size_t i, num;
+       struct disk_partitions **tab;
+
+       /* do we have parts on record already? */
+       for (i = 0; i < pset->num_write_back; i++)
+               if (pset->write_back[i] == parts)
+                       return;
+       /*
+        * Need to record this partition table for write back
+        */
+       num = pset->num_write_back + 1;
+       tab = realloc(pset->write_back, num*sizeof(*pset->write_back));
+       if (!tab)
+               return;
+       tab[pset->num_write_back] = parts;
+       pset->write_back = tab;
+       pset->num_write_back = num;
+}
+
 int
 edit_ptn(menudesc *menu, void *arg)
 {
@@ -884,6 +907,8 @@
                        err_msg_win(err);
                        return 0;
                }
+               remember_deleted(pset,
+                   pset->infos[edit.index].parts);
                memmove(pset->infos+edit.index,
                    pset->infos+edit.index+1,
                    sizeof(*pset->infos)*(pset->num-edit.index));
diff -r 9df151caa794 -r a1f5acdb6080 usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c   Tue Sep 22 15:24:01 2020 +0000
+++ b/usr.sbin/sysinst/util.c   Tue Sep 22 16:18:54 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.45 2020/05/18 21:19:36 jmcneill Exp $       */
+/*     $NetBSD: util.c,v 1.46 2020/09/22 16:18:54 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -2181,6 +2181,7 @@
 free_usage_set(struct partition_usage_set *wanted)
 {
        /* XXX - free parts? free clone src? */
+       free(wanted->write_back);
        free(wanted->menu_opts);
        free(wanted->infos);
 }
@@ -2202,6 +2203,7 @@
                                install->infos[j].clone_src = NULL; 
        }
 #endif
+       free(install->write_back);
        free(install->infos);
 }
 



Home | Main Index | Thread Index | Old Index