-/* $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
* 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: "
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 *
/* 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";
-/* $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
* 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: "
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 *
/* 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";