Module Name:    src
Committed By:   martin
Date:           Sat Feb 13 15:31:36 UTC 2021

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

Log Message:
PR 55991: when extending the marked partition (typically: the NetBSD root
partition) round the new size up to current alignment.

This may lead to a slightly smaller than initialy planned last partition
(depending on order added) if the disk size is odd or the partitioning
scheme needs some internal space (like GPT) - but it avoids gaps elsewhere
due to alignement.

Ideally we would pin all other partitions in a first pass and then let
the partitioning backend pick the full available size for the extended
partition, but this should be good enough.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.sbin/sysinst/bsddisklabel.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.57 src/usr.sbin/sysinst/bsddisklabel.c:1.58
--- src/usr.sbin/sysinst/bsddisklabel.c:1.57	Sun Jan 31 22:45:46 2021
+++ src/usr.sbin/sysinst/bsddisklabel.c	Sat Feb 13 15:31:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bsddisklabel.c,v 1.57 2021/01/31 22:45:46 rillig Exp $	*/
+/*	$NetBSD: bsddisklabel.c,v 1.58 2021/02/13 15:31:35 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1387,6 +1387,8 @@ apply_settings_to_partitions(struct disk
 	 * Pass one: calculate space available for expanding
 	 * the marked partition.
 	 */
+	if (parts->free_space != parts->disk_size)
+		planned_space = align;	/* align first part */
 	for (i = 0; i < wanted->num; i++) {
 		if ((wanted->infos[i].flags & PUIFLAG_EXTEND) &&
 		    exp_ndx == ~0U)
@@ -1403,8 +1405,9 @@ apply_settings_to_partitions(struct disk
 			if (!(wanted->infos[i].flags & PUIFLG_IS_OUTER))
 				nsp -= infos[i].size;
 		}
-		if (nsp > 0)
-			planned_space += roundup(nsp, align);
+		if (nsp <= 0)
+			continue;
+		planned_space += roundup(nsp, align);
 	}
 
 	/*
@@ -1412,12 +1415,10 @@ apply_settings_to_partitions(struct disk
 	 * but check size limits.
 	 */
 	if (exp_ndx < wanted->num) {
-		daddr_t free_space =
-		    parts->free_space - roundup(wanted->reserved_space, align);
-		free_space -= planned_space;
+		daddr_t free_space = parts->free_space - planned_space;
 		daddr_t new_size = wanted->infos[exp_ndx].size;
 		if (free_space > 0)
-			new_size += free_space;
+			new_size += roundup(free_space,align);
 
 		if (wanted->infos[exp_ndx].limit > 0 &&
 		    (new_size + wanted->infos[exp_ndx].cur_start)

Reply via email to