From: deraadt Date: Tue, 12 Aug 2008 22:48:31 +0000 (+0000) Subject: Fix multiple addition error recently introduced for when extended partitions X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=df8d875b0b6d0a8bec74a5a8bd8a2589b7e24a24;p=openbsd 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 --- 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"; diff --git a/sys/arch/i386/stand/libsa/biosdev.c b/sys/arch/i386/stand/libsa/biosdev.c index 3ccc01258cd..01a0ca7e72a 100644 --- a/sys/arch/i386/stand/libsa/biosdev.c +++ b/sys/arch/i386/stand/libsa/biosdev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: biosdev.c,v 1.75 2008/08/04 15:58:13 reyk Exp $ */ +/* $OpenBSD: biosdev.c,v 1.76 2008/08/12 22:48:31 deraadt Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -345,34 +345,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: " @@ -382,28 +385,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 * @@ -423,7 +414,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";