Remove more pm->ptstart abuse - calculate values localy where needed

instead.
This commit is contained in:
martin 2020-10-10 19:42:19 +00:00
parent 876682479f
commit 6ddad1490c
3 changed files with 26 additions and 55 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: md.c,v 1.30 2020/02/06 10:47:33 martin Exp $ */ /* $NetBSD: md.c,v 1.31 2020/10/10 19:42:19 martin Exp $ */
/* /*
* Copyright 1997 Piermont Information Systems Inc. * Copyright 1997 Piermont Information Systems Inc.
@ -65,7 +65,7 @@ static bool uefi_boot;
/* prototypes */ /* prototypes */
static bool get_bios_info(const char*, struct disk_partitions*, int*, int*, int*); static bool get_bios_info(const char*, struct disk_partitions*, int*, int*, int*);
static int mbr_root_above_chs(void); static int mbr_root_above_chs(daddr_t);
static int md_read_bootcode(const char *, struct mbr_sector *); static int md_read_bootcode(const char *, struct mbr_sector *);
static unsigned int get_bootmodel(void); static unsigned int get_bootmodel(void);
@ -462,6 +462,7 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
mbr_info_t *ext; mbr_info_t *ext;
struct mbr_partition *p; struct mbr_partition *p;
const char *bootcode; const char *bootcode;
daddr_t inst_start, inst_size;
int i, names, fl, ofl; int i, names, fl, ofl;
#define ACTIVE_FOUND 0x0100 #define ACTIVE_FOUND 0x0100
#define NETBSD_ACTIVE 0x0200 #define NETBSD_ACTIVE 0x0200
@ -469,8 +470,15 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
#define ACTIVE_NAMED 0x0800 #define ACTIVE_NAMED 0x0800
root_limit = 0; root_limit = 0;
if (parts->pscheme->guess_install_target == NULL ||
!parts->pscheme->guess_install_target(parts, &inst_start,
&inst_size)) {
inst_start = parts->disk_start;
inst_size = parts->disk_size;
}
if (biosdisk != NULL && (biosdisk->bi_flags & BIFLAG_EXTINT13) == 0) { if (biosdisk != NULL && (biosdisk->bi_flags & BIFLAG_EXTINT13) == 0) {
if (mbr_root_above_chs()) { if (mbr_root_above_chs(inst_start)) {
if (quiet) if (quiet)
return 0; return 0;
msg_display(MSG_partabovechs); msg_display(MSG_partabovechs);
@ -487,7 +495,7 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
} }
/* /*
* Ensure the install partition (at sector pm->ptstart) and the active * Ensure the install partition (at sector inst_start) and the active
* partition are bootable. * partition are bootable.
* Determine whether the bootselect code is needed. * Determine whether the bootselect code is needed.
* Note that MBR_BS_NEWMBR is always set, so we ignore it! * Note that MBR_BS_NEWMBR is always set, so we ignore it!
@ -499,14 +507,14 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
for (i = 0; i < MBR_PART_COUNT; p++, i++) { for (i = 0; i < MBR_PART_COUNT; p++, i++) {
if (p->mbrp_flag == MBR_PFLAG_ACTIVE) { if (p->mbrp_flag == MBR_PFLAG_ACTIVE) {
fl |= ACTIVE_FOUND; fl |= ACTIVE_FOUND;
if (ext->sector + p->mbrp_start == pm->ptstart) if (ext->sector + p->mbrp_start == inst_start)
fl |= NETBSD_ACTIVE; fl |= NETBSD_ACTIVE;
} }
if (ext->mbrb.mbrbs_nametab[i][0] == 0) { if (ext->mbrb.mbrbs_nametab[i][0] == 0) {
/* No bootmenu label... */ /* No bootmenu label... */
if (ext->sector == 0) if (ext->sector == 0)
continue; continue;
if (ext->sector + p->mbrp_start == pm->ptstart) if (ext->sector + p->mbrp_start == inst_start)
/* /*
* Have installed into an extended ptn * Have installed into an extended ptn
* force name & bootsel... * force name & bootsel...
@ -517,7 +525,7 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
/* Partition has a bootmenu label... */ /* Partition has a bootmenu label... */
if (ext->sector != 0) if (ext->sector != 0)
fl |= MBR_BS_EXTLBA; fl |= MBR_BS_EXTLBA;
if (ext->sector + p->mbrp_start == pm->ptstart) if (ext->sector + p->mbrp_start == inst_start)
fl |= NETBSD_NAMED; fl |= NETBSD_NAMED;
else if (p->mbrp_flag == MBR_PFLAG_ACTIVE) else if (p->mbrp_flag == MBR_PFLAG_ACTIVE)
fl |= ACTIVE_NAMED; fl |= ACTIVE_NAMED;
@ -571,7 +579,7 @@ md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
/* Check there is some bootcode at all... */ /* Check there is some bootcode at all... */
if (mbri->mbr.mbr_magic != htole16(MBR_MAGIC) || if (mbri->mbr.mbr_magic != htole16(MBR_MAGIC) ||
mbri->mbr.mbr_jmpboot[0] == 0 || mbri->mbr.mbr_jmpboot[0] == 0 ||
mbr_root_above_chs()) mbr_root_above_chs(inst_start))
/* Existing won't do, force update */ /* Existing won't do, force update */
fl |= MBR_BS_NEWMBR; fl |= MBR_BS_NEWMBR;
} }
@ -709,9 +717,9 @@ nogeom:
} }
static int static int
mbr_root_above_chs(void) mbr_root_above_chs(daddr_t ptstart)
{ {
return pm->ptstart + (daddr_t)DEFROOTSIZE * (daddr_t)(MEG / 512) return ptstart + (daddr_t)DEFROOTSIZE * (daddr_t)(MEG / 512)
>= pm->max_chs; >= pm->max_chs;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: label.c,v 1.27 2020/10/09 18:33:00 martin Exp $ */ /* $NetBSD: label.c,v 1.28 2020/10/10 19:42:19 martin Exp $ */
/* /*
* Copyright 1997 Jonathan Stone * Copyright 1997 Jonathan Stone
@ -36,7 +36,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: label.c,v 1.27 2020/10/09 18:33:00 martin Exp $"); __RCSID("$NetBSD: label.c,v 1.28 2020/10/10 19:42:19 martin Exp $");
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -187,11 +187,10 @@ verify_parts(struct partition_usage_set *pset, bool install)
struct part_usage_info *wanted; struct part_usage_info *wanted;
struct disk_partitions *parts; struct disk_partitions *parts;
size_t i, num_root; size_t i, num_root;
daddr_t first_bsdstart, first_bsdsize, inst_start, inst_size; daddr_t first_bsdstart, inst_start;
int rv; int rv;
first_bsdstart = inst_start = -1; first_bsdstart = inst_start = -1;
first_bsdsize = inst_size = 0;
num_root = 0; num_root = 0;
parts = pset->parts; parts = pset->parts;
for (i = 0; i < pset->num; i++) { for (i = 0; i < pset->num; i++) {
@ -209,12 +208,10 @@ verify_parts(struct partition_usage_set *pset, bool install)
if (first_bsdstart <= 0) { if (first_bsdstart <= 0) {
first_bsdstart = wanted->cur_start; first_bsdstart = wanted->cur_start;
first_bsdsize = wanted->size;
} }
if (inst_start < 0 && if (inst_start < 0 &&
(wanted->cur_flags & PTI_INSTALL_TARGET)) { (wanted->cur_flags & PTI_INSTALL_TARGET)) {
inst_start = wanted->cur_start; inst_start = wanted->cur_start;
inst_size = wanted->size;
} }
} }
@ -233,21 +230,6 @@ verify_parts(struct partition_usage_set *pset, bool install)
return rv; return rv;
} }
if (pm->ptstart == 0) {
if (inst_start > 0) {
pm->ptstart = inst_start;
pm->ptsize = inst_size;
} else if (first_bsdstart > 0) {
pm->ptstart = first_bsdstart;
pm->ptsize = first_bsdsize;
} else if (parts->pscheme->guess_install_target &&
parts->pscheme->guess_install_target(
parts, &inst_start, &inst_size)) {
pm->ptstart = inst_start;
pm->ptsize = inst_size;
}
}
/* Check for overlaps */ /* Check for overlaps */
if (checkoverlap(parts) != 0) { if (checkoverlap(parts) != 0) {
rv = ask_reedit(parts); rv = ask_reedit(parts);

View File

@ -1,4 +1,4 @@
/* $NetBSD: part_edit.c,v 1.20 2020/10/10 18:48:32 martin Exp $ */ /* $NetBSD: part_edit.c,v 1.21 2020/10/10 19:42:19 martin Exp $ */
/* /*
* Copyright (c) 2019 The NetBSD Foundation, Inc. * Copyright (c) 2019 The NetBSD Foundation, Inc.
@ -1093,10 +1093,10 @@ verify_outer_parts(struct disk_partitions *parts, bool quiet)
{ {
part_id i; part_id i;
int num_bsdparts; int num_bsdparts;
daddr_t first_bsdstart, first_bsdsize, inst_start, inst_size; daddr_t first_bsdstart, inst_start, inst_size;
first_bsdstart = inst_start = -1; first_bsdstart = inst_start = -1;
first_bsdsize = inst_size = 0; inst_size = 0;
num_bsdparts = 0; num_bsdparts = 0;
for (i = 0; i < parts->num_part; i++) { for (i = 0; i < parts->num_part; i++) {
struct disk_part_info info; struct disk_part_info info;
@ -1110,7 +1110,6 @@ verify_outer_parts(struct disk_partitions *parts, bool quiet)
if (first_bsdstart < 0) { if (first_bsdstart < 0) {
first_bsdstart = info.start; first_bsdstart = info.start;
first_bsdsize = info.size;
} }
if (inst_start< 0 && (info.flags & PTI_INSTALL_TARGET)) { if (inst_start< 0 && (info.flags & PTI_INSTALL_TARGET)) {
inst_start = info.start; inst_start = info.start;
@ -1122,12 +1121,9 @@ verify_outer_parts(struct disk_partitions *parts, bool quiet)
(num_bsdparts > 1 && inst_start < 0)) { (num_bsdparts > 1 && inst_start < 0)) {
if (quiet && num_bsdparts == 0) if (quiet && num_bsdparts == 0)
return 0; return 0;
if (quiet && parts->pscheme->guess_install_target && if (!quiet || parts->pscheme->guess_install_target == NULL ||
parts->pscheme->guess_install_target(parts, !parts->pscheme->guess_install_target(parts,
&inst_start, &inst_size)) { &inst_start, &inst_size)) {
pm->ptstart = inst_start;
pm->ptsize = inst_size;
} else {
if (num_bsdparts == 0) if (num_bsdparts == 0)
msg_display_subst(MSG_nobsdpart, 2, msg_display_subst(MSG_nobsdpart, 2,
msg_string(parts->pscheme->name), msg_string(parts->pscheme->name),
@ -1141,21 +1137,6 @@ verify_outer_parts(struct disk_partitions *parts, bool quiet)
} }
} }
if (pm->ptstart == 0) {
if (inst_start > 0) {
pm->ptstart = inst_start;
pm->ptsize = inst_size;
} else if (first_bsdstart > 0) {
pm->ptstart = first_bsdstart;
pm->ptsize = first_bsdsize;
} else if (parts->pscheme->guess_install_target &&
parts->pscheme->guess_install_target(
parts, &inst_start, &inst_size)) {
pm->ptstart = inst_start;
pm->ptsize = inst_size;
}
}
/* /*
* post_edit_verify returns: * post_edit_verify returns:
* 0 -> abort * 0 -> abort