Module Name:    src
Committed By:   martin
Date:           Sat Jun 15 08:20:34 UTC 2019

Modified Files:
        src/usr.sbin/sysinst: bsddisklabel.c disks.c install.c mbr.c
            part_edit.c partitions.h target.c

Log Message:
When setting up a "use whole disk" single outer partition, force an
empty set of inner partitions immediately,

This avoids reading old (stale) partitions (e.g. disklabel that
survived cleaning and re-creating the MBR with the MBR NetBSD partition
starting at the same offset) later.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/sysinst/bsddisklabel.c
cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/sysinst/disks.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/sysinst/install.c
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/sysinst/mbr.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/part_edit.c \
    src/usr.sbin/sysinst/partitions.h
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/sysinst/target.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/bsddisklabel.c
diff -u src/usr.sbin/sysinst/bsddisklabel.c:1.11 src/usr.sbin/sysinst/bsddisklabel.c:1.12
--- src/usr.sbin/sysinst/bsddisklabel.c:1.11	Thu Jun 13 12:44:20 2019
+++ src/usr.sbin/sysinst/bsddisklabel.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bsddisklabel.c,v 1.11 2019/06/13 12:44:20 martin Exp $	*/
+/*	$NetBSD: bsddisklabel.c,v 1.12 2019/06/15 08:20:33 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1458,7 +1458,7 @@ make_bsd_partitions(struct install_parti
 	if (pscheme->secondary_partitions) {
 		struct disk_partitions *p;
 
-		p = pscheme->secondary_partitions(parts, pm->ptstart);
+		p = pscheme->secondary_partitions(parts, pm->ptstart, false);
 		if (p) {
 			parts = p;
 			pscheme = parts->pscheme;

Index: src/usr.sbin/sysinst/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.31 src/usr.sbin/sysinst/disks.c:1.32
--- src/usr.sbin/sysinst/disks.c:1.31	Thu Jun 13 19:13:05 2019
+++ src/usr.sbin/sysinst/disks.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.31 2019/06/13 19:13:05 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.32 2019/06/15 08:20:33 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -777,7 +777,7 @@ convert_copy(struct disk_partitions *old
 				struct disk_partitions *sec_part =
 					old_parts->pscheme->
 					    secondary_partitions(
-					    old_parts, oinfo.start);
+					    old_parts, oinfo.start, false);
 				if (sec_part)
 					convert_copy(sec_part, new_parts);
 			}
@@ -946,7 +946,7 @@ again:
 			if (pm->parts->pscheme->secondary_partitions) {
 				const struct disk_partitions *sparts =
 				    pm->parts->pscheme->secondary_partitions(
-				    pm->parts, pm->ptstart);
+				    pm->parts, pm->ptstart, false);
 				if (sparts != NULL)
 					dump_parts(sparts);
 			}

Index: src/usr.sbin/sysinst/install.c
diff -u src/usr.sbin/sysinst/install.c:1.6 src/usr.sbin/sysinst/install.c:1.7
--- src/usr.sbin/sysinst/install.c:1.6	Wed Jun 12 06:20:17 2019
+++ src/usr.sbin/sysinst/install.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: install.c,v 1.6 2019/06/12 06:20:17 martin Exp $	*/
+/*	$NetBSD: install.c,v 1.7 2019/06/15 08:20:33 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -185,7 +185,7 @@ do_install(void)
 			if (parts->pscheme->secondary_scheme != NULL &&
 			    parts->pscheme->secondary_partitions != NULL) {
 				parts = parts->pscheme->secondary_partitions(
-				    parts, pm->ptstart);
+				    parts, pm->ptstart, false);
 				if (parts == NULL)
 					parts = pm->parts;
 			}

Index: src/usr.sbin/sysinst/mbr.c
diff -u src/usr.sbin/sysinst/mbr.c:1.12 src/usr.sbin/sysinst/mbr.c:1.13
--- src/usr.sbin/sysinst/mbr.c:1.12	Sat Jun 15 07:57:38 2019
+++ src/usr.sbin/sysinst/mbr.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbr.c,v 1.12 2019/06/15 07:57:38 martin Exp $ */
+/*	$NetBSD: mbr.c,v 1.13 2019/06/15 08:20:33 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1603,12 +1603,15 @@ mbr_find_netbsd(const struct mbr_info_t 
 }
 
 static struct disk_partitions *
-mbr_read_disklabel(struct disk_partitions *arg, daddr_t start)
+mbr_read_disklabel(struct disk_partitions *arg, daddr_t start, bool force_empty)
 {
 	struct mbr_disk_partitions *myparts =
 	    (struct mbr_disk_partitions*)arg;
 	struct disk_part_info part;
 
+	if (force_empty && myparts->dlabel) 
+		myparts->dlabel->pscheme->delete_all_partitions(myparts->dlabel);
+
 	if (myparts->dlabel == NULL) {
 		/*
 		 * Find the NetBSD MBR partition
@@ -1616,8 +1619,9 @@ mbr_read_disklabel(struct disk_partition
 		if (!mbr_find_netbsd(&myparts->mbr, start, &part))
 			return NULL;
 
-		myparts->dlabel = disklabel_parts.read_from_disk(
-		    myparts->dp.disk, part.start, part.size);
+		if (!force_empty)
+			myparts->dlabel = disklabel_parts.read_from_disk(
+			    myparts->dp.disk, part.start, part.size);
 
 		if (myparts->dlabel == NULL && part.size > 0) {
 			/* we just created the outer partitions? */

Index: src/usr.sbin/sysinst/part_edit.c
diff -u src/usr.sbin/sysinst/part_edit.c:1.1 src/usr.sbin/sysinst/part_edit.c:1.2
--- src/usr.sbin/sysinst/part_edit.c:1.1	Wed Jun 12 06:20:18 2019
+++ src/usr.sbin/sysinst/part_edit.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: part_edit.c,v 1.1 2019/06/12 06:20:18 martin Exp $ */
+/*	$NetBSD: part_edit.c,v 1.2 2019/06/15 08:20:33 martin Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -871,6 +871,11 @@ parts_use_wholedisk(struct disk_partitio
 	if (!parts->pscheme->get_part_info(parts, nbsd, &info))
 		return false;
 
+	if (parts->pscheme->secondary_scheme != NULL) {
+		/* force empty secondary partitions */
+		parts->pscheme->secondary_partitions(parts, info.start, true);
+	}
+
 	pm->ptstart = info.start;
 	pm->ptsize = info.size;
 	return true;
Index: src/usr.sbin/sysinst/partitions.h
diff -u src/usr.sbin/sysinst/partitions.h:1.1 src/usr.sbin/sysinst/partitions.h:1.2
--- src/usr.sbin/sysinst/partitions.h:1.1	Wed Jun 12 06:20:18 2019
+++ src/usr.sbin/sysinst/partitions.h	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: partitions.h,v 1.1 2019/06/12 06:20:18 martin Exp $	*/
+/*	$NetBSD: partitions.h,v 1.2 2019/06/15 08:20:33 martin Exp $	*/
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -379,12 +379,18 @@ struct disk_partitioning_scheme {
 	 * Schemes that NEVER use a secondary scheme set this
 	 * function pointer to NULL.
 	 *
+	 * If force_empty = true, ignore all on-disk contents and just
+	 * create a new disk_partitons structure for the secondary scheme
+	 * (this is used after deleting all partitions and setting up
+	 * things for "use whole disk").
+	 *
 	 * The returned pointer is always owned by the primary partitions,
 	 * caller MUST never free it, but otherwise can manipulate it
 	 * arbitrarily.
 	 */
 	struct disk_partitions *
-	    (*secondary_partitions)(struct disk_partitions *, daddr_t start);
+	    (*secondary_partitions)(struct disk_partitions *, daddr_t start,
+	        bool force_empty);
 
 	/*
 	 * Write the whole set (in new_state) back to disk.

Index: src/usr.sbin/sysinst/target.c
diff -u src/usr.sbin/sysinst/target.c:1.5 src/usr.sbin/sysinst/target.c:1.6
--- src/usr.sbin/sysinst/target.c:1.5	Wed Jun 12 06:20:18 2019
+++ src/usr.sbin/sysinst/target.c	Sat Jun 15 08:20:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: target.c,v 1.5 2019/06/12 06:20:18 martin Exp $	*/
+/*	$NetBSD: target.c,v 1.6 2019/06/15 08:20:33 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.5 2019/06/12 06:20:18 martin Exp $");
+__RCSID("$NetBSD: target.c,v 1.6 2019/06/15 08:20:33 martin Exp $");
 #endif
 
 /*
@@ -173,7 +173,7 @@ target_already_root(void)
 	}
 	if (pm->parts->pscheme->secondary_partitions != NULL)
 		parts = pm->parts->pscheme->secondary_partitions(parts,
-		    pm->ptstart);
+		    pm->ptstart, false);
 
 	for (ptn = 0; ptn < parts->num_part; ptn++) {
 		if (!parts->pscheme->get_part_info(parts, ptn, &info))

Reply via email to