Module Name:    src
Committed By:   martin
Date:           Thu Feb 10 16:11:42 UTC 2022

Modified Files:
        src/usr.sbin/sysinst: defs.h target.c
        src/usr.sbin/sysinst/arch/i386: md.c

Log Message:
x86: fix previous: in the UEFI case copy the bootloaders from install
media during initial installation, but use the (by then: updated)
files from the target disk for system upgrades.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.sbin/sysinst/defs.h
cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/sysinst/target.c
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/sysinst/arch/i386/md.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/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.79 src/usr.sbin/sysinst/defs.h:1.80
--- src/usr.sbin/sysinst/defs.h:1.79	Sun Jan 30 11:58:29 2022
+++ src/usr.sbin/sysinst/defs.h	Thu Feb 10 16:11:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.79 2022/01/30 11:58:29 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.80 2022/02/10 16:11:41 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -922,6 +922,7 @@ void	dup_file_into_target(const char *);
 void	mv_within_target_or_die(const char *, const char *);
 int	cp_within_target(const char *, const char *, int);
 int	target_mount(const char *, const char *, const char *);
+int	target_unmount(const char *);
 int	target_mount_do(const char *, const char *, const char *);
 int	target_test(unsigned int, const char *);
 int	target_dir_exists_p(const char *);

Index: src/usr.sbin/sysinst/target.c
diff -u src/usr.sbin/sysinst/target.c:1.17 src/usr.sbin/sysinst/target.c:1.18
--- src/usr.sbin/sysinst/target.c:1.17	Sun Jan 30 11:58:29 2022
+++ src/usr.sbin/sysinst/target.c	Thu Feb 10 16:11:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: target.c,v 1.17 2022/01/30 11:58:29 martin Exp $	*/
+/*	$NetBSD: target.c,v 1.18 2022/02/10 16:11:41 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.17 2022/01/30 11:58:29 martin Exp $");
+__RCSID("$NetBSD: target.c,v 1.18 2022/02/10 16:11:41 martin Exp $");
 #endif
 
 /*
@@ -527,6 +527,33 @@ target_mount(const char *opts, const cha
 	return target_mount_do(opts, from, on);
 }
 
+int
+target_unmount(const char *mount_point)
+{
+	struct unwind_mount *m, *prev = NULL;
+	int error;
+
+	for (m = unwind_mountlist; m != NULL; prev = m, m = m->um_prev)
+		if (strcmp(m->um_mountpoint, mount_point) == 0)
+			break;
+
+	if (m == NULL)
+		return ENOTDIR;
+
+	error = run_program(0, "/sbin/umount %s%s",
+		    target_prefix(), m->um_mountpoint);
+	if (error)
+		return error;
+
+	if (m == unwind_mountlist)
+		unwind_mountlist = m->um_prev;
+	else
+		prev->um_prev = m->um_prev;
+	free(m);
+
+	return 0;
+}
+
 static bool
 delete_wedge(const char *disk, const char *wedge)
 {

Index: src/usr.sbin/sysinst/arch/i386/md.c
diff -u src/usr.sbin/sysinst/arch/i386/md.c:1.34 src/usr.sbin/sysinst/arch/i386/md.c:1.35
--- src/usr.sbin/sysinst/arch/i386/md.c:1.34	Sat Jan 29 16:01:18 2022
+++ src/usr.sbin/sysinst/arch/i386/md.c	Thu Feb 10 16:11:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.c,v 1.34 2022/01/29 16:01:18 martin Exp $ */
+/*	$NetBSD: md.c,v 1.35 2022/02/10 16:11:42 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -334,9 +334,10 @@ md_post_newfs_bios(struct install_partit
  * boot partition (or update them).
  */
 static int
-copy_uefi_boot(const struct part_usage_info *boot)
+copy_uefi_boot(const struct part_usage_info *boot, bool target_is_populated)
 {
 	char dev[MAXPATHLEN], path[MAXPATHLEN], src[MAXPATHLEN];
+	const char *s;
 	size_t i;
 	int err;
 
@@ -364,13 +365,18 @@ copy_uefi_boot(const struct part_usage_i
 	make_target_dir(path);
 
 	for (i = 0; i < __arraycount(uefi_bootloaders); i++) {
-		strcpy(src, target_expand(uefi_bootloaders[i]));
+		s = uefi_bootloaders[i];
+		strcpy(src, target_is_populated ? target_expand(s) : s);
 		if (access(src, R_OK) != 0)
 			continue;
-		err = cp_within_target(uefi_bootloaders[i], path, 0);
+		err = target_is_populated ?
+		    cp_within_target(s, path, 0) :
+		    cp_to_target(s, path);
 		if (err)
 			return err;
 	}
+	if (boot->mount[0] == 0)
+		target_unmount("/mnt");
 
 	return 0;
 }
@@ -379,7 +385,8 @@ copy_uefi_boot(const struct part_usage_i
  * Find (U)EFI boot partition and install/update bootloaders
  */
 static int
-update_uefi_boot_code(struct install_partition_desc *install)
+update_uefi_boot_code(struct install_partition_desc *install,
+    bool target_is_populated)
 {
 	size_t i, boot_part;
 
@@ -405,7 +412,8 @@ update_uefi_boot_code(struct install_par
 	}
 
 	if (boot_part < install->num)
-		return copy_uefi_boot(&install->infos[boot_part]);
+		return copy_uefi_boot(&install->infos[boot_part],
+		    target_is_populated);
 
 	return -1;	/* no EFI boot partition found */
 }
@@ -420,17 +428,18 @@ update_bios_boot_code(struct install_par
 }
 
 static int
-update_boot_code(struct install_partition_desc *install)
+update_boot_code(struct install_partition_desc *install,
+    bool target_is_populated)
 {
 	return uefi_boot ?
-	    update_uefi_boot_code(install)
+	    update_uefi_boot_code(install, target_is_populated)
 	    : update_bios_boot_code(install);
 }
 
 static int
 md_post_newfs_uefi(struct install_partition_desc *install)
 {
-	return update_uefi_boot_code(install);
+	return update_uefi_boot_code(install, false);
 }
 
 /*
@@ -450,7 +459,7 @@ int
 md_post_extract(struct install_partition_desc *install, bool upgrade)
 {
 	if (upgrade)
-		update_boot_code(install);
+		update_boot_code(install, true);
 
 #if defined(__amd64__)
 	if (get_kernel_set() == SET_KERNEL_2) {

Reply via email to