From ed32349f00a52e01c23ca4a162e3feb24484ce5a Mon Sep 17 00:00:00 2001 From: Xin LI Date: Wed, 15 Sep 2004 08:19:03 +0000 Subject: [PATCH] Clear all "active partition" bits before we set a new one. This adds a safebelt that prevents users to mark more than one "active" partitions, which will lead to a unbootable machine, especially in multi-boot configurations. PR: bin/71404 MFC After: 3 days Approved by: murray (mentor) --- usr.sbin/sade/disks.c | 8 +++++++- usr.sbin/sysinstall/disks.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/usr.sbin/sade/disks.c b/usr.sbin/sade/disks.c index 234c59c5f13..1e35c7b3a11 100644 --- a/usr.sbin/sade/disks.c +++ b/usr.sbin/sade/disks.c @@ -74,7 +74,8 @@ enum size_units_t { UNIT_BLOCKS, UNIT_KILO, UNIT_MEG, UNIT_GIG, UNIT_SIZE }; #define CHUNK_START_ROW 5 /* Where we keep track of MBR chunks */ -static struct chunk *chunk_info[16]; +#define CHUNK_INFO_ENTRIES 16 +static struct chunk *chunk_info[CHUNK_INFO_ENTRIES]; static int current_chunk; static void diskPartitionNonInteractive(Device *dev); @@ -312,6 +313,7 @@ diskPartition(Device *dev) { char *cp, *p; int rv, key = 0; + int i; Boolean chunking; char *msg = NULL; #ifdef PC98 @@ -535,6 +537,10 @@ diskPartition(Device *dev) break; case 'S': + /* Clear active states so we won't have two */ + for (i = 0; (chunk_info[i] != NULL) && (i < CHUNK_INFO_ENTRIES); i++) + chunk_info[i]->flags &= !CHUNK_ACTIVE; + /* Set Bootable */ chunk_info[current_chunk]->flags |= CHUNK_ACTIVE; break; diff --git a/usr.sbin/sysinstall/disks.c b/usr.sbin/sysinstall/disks.c index 234c59c5f13..1e35c7b3a11 100644 --- a/usr.sbin/sysinstall/disks.c +++ b/usr.sbin/sysinstall/disks.c @@ -74,7 +74,8 @@ enum size_units_t { UNIT_BLOCKS, UNIT_KILO, UNIT_MEG, UNIT_GIG, UNIT_SIZE }; #define CHUNK_START_ROW 5 /* Where we keep track of MBR chunks */ -static struct chunk *chunk_info[16]; +#define CHUNK_INFO_ENTRIES 16 +static struct chunk *chunk_info[CHUNK_INFO_ENTRIES]; static int current_chunk; static void diskPartitionNonInteractive(Device *dev); @@ -312,6 +313,7 @@ diskPartition(Device *dev) { char *cp, *p; int rv, key = 0; + int i; Boolean chunking; char *msg = NULL; #ifdef PC98 @@ -535,6 +537,10 @@ diskPartition(Device *dev) break; case 'S': + /* Clear active states so we won't have two */ + for (i = 0; (chunk_info[i] != NULL) && (i < CHUNK_INFO_ENTRIES); i++) + chunk_info[i]->flags &= !CHUNK_ACTIVE; + /* Set Bootable */ chunk_info[current_chunk]->flags |= CHUNK_ACTIVE; break;