summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/stand/libsa
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-08-12 22:48:33 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-08-12 22:48:33 +0000
commita736b4e6e85b893396da7cd588d3af34c1053eec (patch)
treecf7c3aa9fc05f6f03f20fe94279fdb6dda204849 /sys/arch/amd64/stand/libsa
parenta8fc02827e8d7a2f0c6b2a94fbcec20152cfaf0e (diff)
Fix multiple addition error recently introduced for when extended partitions
are just before an OpenBSD partition in a MBR; done with kettenis & otto ok reyk
Diffstat (limited to 'sys/arch/amd64/stand/libsa')
-rw-r--r--sys/arch/amd64/stand/libsa/biosdev.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/sys/arch/amd64/stand/libsa/biosdev.c b/sys/arch/amd64/stand/libsa/biosdev.c
index ad5075e324f..ef679b5193f 100644
--- a/sys/arch/amd64/stand/libsa/biosdev.c
+++ b/sys/arch/amd64/stand/libsa/biosdev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: biosdev.c,v 1.7 2008/08/04 15:58:13 reyk Exp $ */
+/* $OpenBSD: biosdev.c,v 1.8 2008/08/12 22:48:32 deraadt Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -342,34 +342,37 @@ biosd_io(int rw, bios_diskinfo_t *bd, daddr_t off, int nsect, void *buf)
* Try to read the bsd label on the given BIOS device
*/
static daddr_t
-findopenbsd(bios_diskinfo_t *bd, daddr_t off, const char **err, int *n)
+findopenbsd(bios_diskinfo_t *bd, daddr_t mbroff, const char **err, int *n)
{
int error, i;
struct dos_mbr mbr;
struct dos_partition *dp;
+ daddr_t off;
/* Limit the number of recursions */
if (!(*n)--) {
*err = "too many extended partitions";
- return (0);
+ return (-1);
}
/* Read MBR */
- error = biosd_io(F_READ, bd, off, 1, &mbr);
+ error = biosd_io(F_READ, bd, mbroff, 1, &mbr);
if (error) {
*err = biosdisk_err(error);
- return (0);
+ return (-1);
}
/* check mbr signature */
if (mbr.dmbr_sign != DOSMBR_SIGNATURE) {
*err = "bad MBR signature\n";
- return (0);
+ return (-1);
}
/* Search for OpenBSD partition */
for (i = 0; i < NDOSPART; i++) {
dp = &mbr.dmbr_parts[i];
+ if (!dp->dp_size)
+ continue;
#ifdef BIOS_DEBUG
if (debug)
printf("found partition %u: "
@@ -379,28 +382,16 @@ findopenbsd(bios_diskinfo_t *bd, daddr_t off, const char **err, int *n)
dp->dp_start, dp->dp_start);
#endif
if (dp->dp_typ == DOSPTYP_OPENBSD) {
- off = dp->dp_start + off;
- break;
+ return (dp->dp_start + mbroff);
} else if (dp->dp_typ == DOSPTYP_EXTEND ||
dp->dp_typ == DOSPTYP_EXTENDL) {
- off = findopenbsd(bd, dp->dp_start + off, err, n);
- if (off != 0)
- break;
+ off = findopenbsd(bd, dp->dp_start + mbroff, err, n);
+ if (off != -1)
+ return (off);
}
}
-#ifdef BIOS_DEBUG
- if (debug)
- printf("using offset %u\n", off);
-#endif
-
- if (off == 0) {
- if (*err == NULL)
- *err = "no OpenBSD partition\n";
- return (0);
- }
-
- return (off);
+ return (-1);
}
const char *
@@ -420,7 +411,7 @@ bios_getdisklabel(bios_diskinfo_t *bd, struct disklabel *label)
/* MBR is a harddisk thing */
if (bd->bios_number & 0x80) {
off = findopenbsd(bd, DOSBBSECTOR, &err, &n);
- if (off == 0) {
+ if (off == -1) {
if (err != NULL)
return (err);
return "no OpenBSD partition\n";