summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/alpha/alpha/disksubr.c31
-rw-r--r--sys/arch/amd64/amd64/disksubr.c24
-rw-r--r--sys/arch/arm/arm/disksubr.c24
-rw-r--r--sys/arch/aviion/aviion/disksubr.c24
-rw-r--r--sys/arch/hp300/hp300/disksubr.c26
-rw-r--r--sys/arch/hppa/hppa/disksubr.c57
-rw-r--r--sys/arch/hppa64/hppa64/disksubr.c57
-rw-r--r--sys/arch/i386/i386/disksubr.c24
-rw-r--r--sys/arch/landisk/landisk/disksubr.c24
-rw-r--r--sys/arch/luna88k/luna88k/disksubr.c40
-rw-r--r--sys/arch/mac68k/mac68k/disksubr.c45
-rw-r--r--sys/arch/macppc/macppc/disksubr.c46
-rw-r--r--sys/arch/mvme68k/mvme68k/disksubr.c46
-rw-r--r--sys/arch/mvme88k/mvme88k/disksubr.c46
-rw-r--r--sys/arch/mvmeppc/mvmeppc/disksubr.c24
-rw-r--r--sys/arch/sgi/sgi/disksubr.c70
-rw-r--r--sys/arch/socppc/socppc/disksubr.c42
-rw-r--r--sys/arch/sparc/dev/fd.c13
-rw-r--r--sys/arch/sparc/dev/xd.c14
-rw-r--r--sys/arch/sparc/dev/xy.c16
-rw-r--r--sys/arch/sparc/sparc/disksubr.c43
-rw-r--r--sys/arch/sparc64/dev/fd.c13
-rw-r--r--sys/arch/sparc64/sparc64/disksubr.c38
-rw-r--r--sys/arch/vax/mscp/mscp_disk.c9
-rw-r--r--sys/arch/vax/vax/disksubr.c27
-rw-r--r--sys/arch/vax/vsa/hdc9224.c9
-rw-r--r--sys/dev/ata/wd.c20
-rw-r--r--sys/dev/ccd.c12
-rw-r--r--sys/dev/isa/fd.c13
-rw-r--r--sys/dev/vnd.c15
-rw-r--r--sys/kern/subr_disk.c52
-rw-r--r--sys/scsi/cd.c16
-rw-r--r--sys/scsi/sd.c18
-rw-r--r--sys/sys/disklabel.h10
34 files changed, 449 insertions, 539 deletions
diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c
index 9d35841482c..7bc00bdafa3 100644
--- a/sys/arch/alpha/alpha/disksubr.c
+++ b/sys/arch/alpha/alpha/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.93 2009/06/04 21:13:00 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.94 2009/08/13 15:23:08 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -48,14 +48,14 @@
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
@@ -70,30 +70,29 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label read error";
+ error = bp->b_error;
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0,
+ DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
doslabel:
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -101,7 +100,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/amd64/amd64/disksubr.c b/sys/arch/amd64/amd64/disksubr.c
index 4315574787f..43cefac1dd2 100644
--- a/sys/arch/amd64/amd64/disksubr.c
+++ b/sys/arch/amd64/amd64/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.56 2008/06/12 06:58:33 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.57 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -61,16 +61,16 @@
*/
bios_diskinfo_t *bios_getdiskinfo(dev_t dev);
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
bios_diskinfo_t *pdi;
struct buf *bp = NULL;
dev_t devno;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* Look for any BIOS geometry information we should honour. */
@@ -96,21 +96,19 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == NULL)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -118,7 +116,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/arm/arm/disksubr.c b/sys/arch/arm/arm/disksubr.c
index a8750d9646a..e31ca5cc581 100644
--- a/sys/arch/arm/arm/disksubr.c
+++ b/sys/arch/arm/arm/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.51 2008/06/12 06:58:33 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.52 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -55,35 +55,33 @@
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,7 +89,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/aviion/aviion/disksubr.c b/sys/arch/aviion/aviion/disksubr.c
index e9cc38389f5..bed2d9aa78d 100644
--- a/sys/arch/aviion/aviion/disksubr.c
+++ b/sys/arch/aviion/aviion/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.44 2008/07/23 16:24:42 beck Exp $ */
+/* $OpenBSD: disksubr.c,v 1.45 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -55,35 +55,33 @@
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,7 +89,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/hp300/hp300/disksubr.c b/sys/arch/hp300/hp300/disksubr.c
index 78f47c9fbd9..bee4527ab72 100644
--- a/sys/arch/hp300/hp300/disksubr.c
+++ b/sys/arch/hp300/hp300/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.46 2009/07/05 19:18:22 miod Exp $ */
+/* $OpenBSD: disksubr.c,v 1.47 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.9 1997/04/01 03:12:13 scottr Exp $ */
/*
@@ -49,14 +49,14 @@
* filled in before calling us. Returns null on success and an error
* string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
bp = geteblk((int)lp->d_secsize);
@@ -73,26 +73,24 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label I/O error";
+ error = bp->b_error;
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp,
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp,
DL_GETBSTART(lp), DL_GETDSIZE(lp));
- if (msg == NULL)
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -100,7 +98,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c
index 93ef104997e..1ccee03c232 100644
--- a/sys/arch/hppa/hppa/disksubr.c
+++ b/sys/arch/hppa/hppa/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.75 2009/06/17 07:00:43 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.76 2009/08/13 15:23:10 deraadt Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -38,8 +38,8 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-char *readliflabel(struct buf *, void (*)(struct buf *),
- struct disklabel *, int *, int);
+int readliflabel(struct buf *, void (*)(struct buf *),
+ struct disklabel *, int *, int);
/*
* Attempt to read a disk label from a device
@@ -51,39 +51,37 @@ char *readliflabel(struct buf *, void (*)(struct buf *),
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readliflabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readliflabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,17 +89,17 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
-char *
+int
readliflabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
struct buf *dbp = NULL;
struct lifdir *p;
struct lifvol *lvp;
- char *msg = NULL;
+ int error = 0;
int fsoff = 0, openbsdstart = MAXLIFSPACE, i;
/* read LIF volume header */
@@ -110,11 +108,13 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return "LIF volume header I/O error";
+ return bp->b_error;
lvp = (struct lifvol *)bp->b_data;
- if (lvp->vol_id != LIF_VOL_ID)
- return "no LIF volume header";
+ if (lvp->vol_id != LIF_VOL_ID) {
+ error = EINVAL; /* no LIF volume header */
+ goto done;
+ }
dbp = geteblk(LIF_DIRSIZE);
dbp->b_dev = bp->b_dev;
@@ -124,9 +124,8 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
dbp->b_bcount = lp->d_secsize;
dbp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(dbp);
-
if (biowait(dbp)) {
- msg = "LIF directory I/O error";
+ error = dbp->b_error;
goto done;
}
@@ -159,14 +158,14 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
(*strat)(dbp);
if (biowait(dbp)) {
- msg = "HPUX label I/O error";
+ error = dbp->b_error;
goto done;
}
hl = (struct hpux_label *)dbp->b_data;
if (hl->hl_magic1 != hl->hl_magic2 ||
hl->hl_magic != HPUX_MAGIC || hl->hl_version != 1) {
- msg = "HPUX label magic mismatch";
+ error = EINVAL; /* HPUX label magic mismatch */
goto done;
}
@@ -228,11 +227,11 @@ finished:
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label I/O error";
+ error = bp->b_error;
goto done;
}
- return checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart,
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart,
DL_GETDSIZE(lp)); /* XXX */
done:
@@ -240,7 +239,7 @@ done:
dbp->b_flags |= B_INVAL;
brelse(dbp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c
index 74c4f77be09..8da4e7ae0a5 100644
--- a/sys/arch/hppa64/hppa64/disksubr.c
+++ b/sys/arch/hppa64/hppa64/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.59 2009/06/17 07:00:45 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.60 2009/08/13 15:23:10 deraadt Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -38,8 +38,8 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-char *readliflabel(struct buf *, void (*)(struct buf *),
- struct disklabel *, int *, int);
+int readliflabel(struct buf *, void (*)(struct buf *),
+ struct disklabel *, int *, int);
/*
* Attempt to read a disk label from a device
@@ -51,39 +51,37 @@ char *readliflabel(struct buf *, void (*)(struct buf *),
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readliflabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readliflabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,17 +89,17 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
-char *
+int
readliflabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
struct buf *dbp = NULL;
struct lifdir *p;
struct lifvol *lvp;
- char *msg = NULL;
+ int error = 0;
int fsoff = 0, openbsdstart = MAXLIFSPACE, i;
/* read LIF volume header */
@@ -110,11 +108,13 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return "LIF volume header I/O error";
+ return (bp->b_error);
lvp = (struct lifvol *)bp->b_data;
- if (lvp->vol_id != LIF_VOL_ID)
- return "no LIF volume header";
+ if (lvp->vol_id != LIF_VOL_ID) {
+ error = EINVAL; /* no LIF volume header */
+ goto done;
+ }
dbp = geteblk(LIF_DIRSIZE);
dbp->b_dev = bp->b_dev;
@@ -124,9 +124,8 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
dbp->b_bcount = lp->d_secsize;
dbp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(dbp);
-
if (biowait(dbp)) {
- msg = "LIF directory I/O error";
+ error = dbp->b_error;
goto done;
}
@@ -159,14 +158,14 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *),
(*strat)(dbp);
if (biowait(dbp)) {
- msg = "HPUX label I/O error";
+ error = dbp->b_error;
goto done;
}
hl = (struct hpux_label *)dbp->b_data;
if (hl->hl_magic1 != hl->hl_magic2 ||
hl->hl_magic != HPUX_MAGIC || hl->hl_version != 1) {
- msg = "HPUX label magic mismatch";
+ error = EINVAL; /* HPUX label magic mismatch */
goto done;
}
@@ -228,11 +227,11 @@ finished:
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label I/O error";
+ error = bp->b_error;
goto done;
}
- return checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart,
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, openbsdstart,
DL_GETDSIZE(lp)); /* XXX */
done:
@@ -240,7 +239,7 @@ done:
dbp->b_flags |= B_INVAL;
brelse(dbp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c
index ea875b7f36b..ff84bdcf42e 100644
--- a/sys/arch/i386/i386/disksubr.c
+++ b/sys/arch/i386/i386/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.98 2008/08/08 23:49:53 krw Exp $ */
+/* $OpenBSD: disksubr.c,v 1.99 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -61,16 +61,16 @@
*/
bios_diskinfo_t *bios_getdiskinfo(dev_t dev);
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
bios_diskinfo_t *pdi;
struct buf *bp = NULL;
dev_t devno;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* Look for any BIOS geometry information we should honour. */
@@ -96,21 +96,19 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -118,7 +116,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/landisk/landisk/disksubr.c b/sys/arch/landisk/landisk/disksubr.c
index f32086e2306..42a6a10c307 100644
--- a/sys/arch/landisk/landisk/disksubr.c
+++ b/sys/arch/landisk/landisk/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.39 2008/06/12 06:58:35 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.40 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -55,35 +55,33 @@
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,7 +89,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/luna88k/luna88k/disksubr.c b/sys/arch/luna88k/luna88k/disksubr.c
index a8a30325008..d5d96e7f50f 100644
--- a/sys/arch/luna88k/luna88k/disksubr.c
+++ b/sys/arch/luna88k/luna88k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.41 2009/06/04 21:13:01 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.42 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.12 2002/02/19 17:09:44 wiz Exp $ */
/*
@@ -103,15 +103,15 @@ int disklabel_bsd_to_om(struct disklabel *, struct sun_disklabel *);
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct sun_disklabel *slp;
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
lp->d_flags |= D_VENDOR;
@@ -128,31 +128,28 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label read error";
+ error = bp->b_error;
goto done;
}
- slp = (struct sun_disklabel *)bp->b_data;
- if (slp->sl_magic == SUN_DKMAGIC) {
- msg = disklabel_om_to_bsd(slp, lp);
+ error = disklabel_om_to_bsd((struct sun_disklabel *)bp->b_data, lp);
+ if (error == 0)
goto done;
- }
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0,
+ DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -160,7 +157,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
@@ -230,7 +227,7 @@ sun_fstypes[8] = {
*
* The BSD label is cleared out before this is called.
*/
-char *
+int
disklabel_om_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
{
struct partition *npp;
@@ -238,13 +235,16 @@ disklabel_om_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
int i, secpercyl;
u_short cksum = 0, *sp1, *sp2;
+ if (sl->sl_magic != SUN_DKMAGIC)
+ return (EINVAL);
+
/* Verify the XOR check. */
sp1 = (u_short *)sl;
sp2 = (u_short *)(sl + 1);
while (sp1 < sp2)
cksum ^= *sp1++;
if (cksum != 0)
- return ("UniOS disk label, bad checksum");
+ return (EINVAL); /* UniOS disk label, bad checksum */
memset((caddr_t)lp, 0, sizeof(struct disklabel));
/* Format conversion. */
diff --git a/sys/arch/mac68k/mac68k/disksubr.c b/sys/arch/mac68k/mac68k/disksubr.c
index 830fa54a495..021a4fa956b 100644
--- a/sys/arch/mac68k/mac68k/disksubr.c
+++ b/sys/arch/mac68k/mac68k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.58 2009/06/24 20:52:41 miod Exp $ */
+/* $OpenBSD: disksubr.c,v 1.59 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.22 1997/11/26 04:18:20 briggs Exp $ */
/*
@@ -98,7 +98,7 @@ int whichType(struct partmapentry *);
int fixPartTable(struct partmapentry *, long, char *);
void setPart(struct partmapentry *, struct disklabel *, int, int);
int getNamedType(struct partmapentry *, int8_t *, int, int, int);
-char *read_mac_label(char *, struct disklabel *, int);
+int read_mac_label(char *, struct disklabel *, int);
/*
* Find an entry in the disk label that is unused and return it
@@ -244,7 +244,7 @@ getNamedType(struct partmapentry *part, int8_t *parttypes, int num_parts,
* NetBSD to live on cluster 0--regardless of the actual order on the
* disk. This whole algorithm should probably be changed in the future.
*/
-char *
+int
read_mac_label(char *dlbuf, struct disklabel *lp, int spoofonly)
{
int i, num_parts;
@@ -256,7 +256,7 @@ read_mac_label(char *dlbuf, struct disklabel *lp, int spoofonly)
pmap = (struct partmapentry *)malloc(NUM_PARTS_PROBED *
sizeof(struct partmapentry), M_DEVBUF, M_NOWAIT);
if (pmap == NULL)
- return ("out of memory");
+ return (ENOMEM);
bsdend = 0;
bsdstart = DL_GETDSIZE(lp);
@@ -376,7 +376,7 @@ read_mac_label(char *dlbuf, struct disklabel *lp, int spoofonly)
}
}
- return (NULL);
+ return (0);
}
lp->d_npartitions = MAXPARTITIONS;
@@ -393,16 +393,16 @@ read_mac_label(char *dlbuf, struct disklabel *lp, int spoofonly)
* filled in before calling us. Returns null on success and an error
* string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
u_int16_t *sbSigp;
int size;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
size = roundup((NUM_PARTS_PROBED + 1) << DEV_BSHIFT, lp->d_secsize);
@@ -414,14 +414,14 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label I/O error";
+ error = bp->b_error;
goto done;
}
sbSigp = (u_int16_t *)bp->b_data;
if (*sbSigp == 0x4552) {
- msg = read_mac_label(bp->b_data, lp, spoofonly);
- if (msg == NULL)
+ error = read_mac_label(bp->b_data, lp, spoofonly);
+ if (error == 0)
goto done;
}
@@ -434,30 +434,29 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label I/O error";
+ error = bp->b_error;
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0,
+ DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
doslabel:
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -465,7 +464,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c
index 7e04b037c19..7988eae966d 100644
--- a/sys/arch/macppc/macppc/disksubr.c
+++ b/sys/arch/macppc/macppc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.66 2009/06/19 11:47:09 krw Exp $ */
+/* $OpenBSD: disksubr.c,v 1.67 2009/08/13 15:23:10 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -37,7 +37,7 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-char *readdpmelabel(struct buf *, void (*)(struct buf *),
+int readdpmelabel(struct buf *, void (*)(struct buf *),
struct disklabel *, int *, int);
/*
@@ -58,39 +58,37 @@ char *readdpmelabel(struct buf *, void (*)(struct buf *),
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdpmelabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdpmelabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -98,10 +96,10 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
-char *
+int
readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
@@ -115,13 +113,13 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return ("DPME partition I/O error");
+ return (bp->b_error);
/* if successful, wander through DPME partition table */
part = (struct part_map_entry *)bp->b_data;
/* if first partition is not valid, assume not HFS/DPME partitioned */
if (part->pmSig != PART_ENTRY_MAGIC)
- return ("not a DPME partition");
+ return (EINVAL); /* not a DPME partition */
part_cnt = part->pmMapBlkCnt;
n = 8;
for (i = 0; i < part_cnt; i++) {
@@ -133,7 +131,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return ("DPME partition I/O error");
+ return (bp->b_error);
part = (struct part_map_entry *)bp->b_data;
/* toupper the string, in case caps are different... */
@@ -146,7 +144,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
hfspartend = hfspartoff + part->pmPartBlkCnt;
if (partoffp) {
*partoffp = hfspartoff;
- return (NULL);
+ return (0);
} else {
DL_SETBSTART(lp, hfspartoff);
DL_SETBEND(lp,
@@ -171,10 +169,10 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
}
if (hfspartoff == -1)
- return ("no OpenBSD partition inside DPME label");
+ return (EINVAL); /* no OpenBSD partition inside DPME label */
if (spoofonly)
- return (NULL);
+ return (0);
/* next, dig out disk label */
bp->b_blkno = hfspartoff + LABELSECTOR;
@@ -182,7 +180,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return("disk label I/O error");
+ return(bp->b_error);
if (hfspartoff == -1)
hfspartoff = 0;
diff --git a/sys/arch/mvme68k/mvme68k/disksubr.c b/sys/arch/mvme68k/mvme68k/disksubr.c
index bb66ddd730e..12e444a4059 100644
--- a/sys/arch/mvme68k/mvme68k/disksubr.c
+++ b/sys/arch/mvme68k/mvme68k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.64 2009/06/04 21:57:56 miod Exp $ */
+/* $OpenBSD: disksubr.c,v 1.65 2009/08/13 15:23:10 deraadt Exp $ */
/*
* Copyright (c) 1998 Steve Murphree, Jr.
* Copyright (c) 1995 Dale Rahn.
@@ -33,8 +33,8 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
-void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
+void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
+int cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
/*
* Attempt to read a disk label from a device
@@ -45,16 +45,14 @@ void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
* Returns NULL on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- struct mvmedisklabel *mlp;
int error;
- char *msg;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
@@ -69,34 +67,24 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
- error = biowait(bp);
- if (error) {
- msg = "disk label read error";
- goto done;
- }
-
- mlp = (struct mvmedisklabel *)bp->b_data;
- if (mlp->magic1 != DISKMAGIC || mlp->magic2 != DISKMAGIC) {
- msg = "no disk label";
+ if (biowait(bp)) {
+ error = bp->b_error;
goto done;
}
- cputobsdlabel(lp, mlp);
- if (dkcksum(lp) == 0)
+ error = cputobsdlabel(lp, (struct mvmedisklabel *)bp->b_data);
+ if (error == 0)
goto done;
- msg = "disk label corrupted";
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -104,7 +92,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
@@ -194,11 +182,14 @@ bsdtocpulabel(struct disklabel *lp, struct mvmedisklabel *clp)
*mot++ = *id++;
}
-void
+int
cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
{
int i;
+ if (clp->magic1 != DISKMAGIC || clp->magic2 != DISKMAGIC)
+ return (EINVAL); /* no disk label */
+
lp->d_magic = clp->magic1;
lp->d_type = clp->type;
lp->d_subtype = clp->subtype;
@@ -246,4 +237,5 @@ cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
lp->d_version = 1;
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
+ return (0);
}
diff --git a/sys/arch/mvme88k/mvme88k/disksubr.c b/sys/arch/mvme88k/mvme88k/disksubr.c
index 3f11a1f918b..7e2bf40999b 100644
--- a/sys/arch/mvme88k/mvme88k/disksubr.c
+++ b/sys/arch/mvme88k/mvme88k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.60 2009/06/04 21:57:56 miod Exp $ */
+/* $OpenBSD: disksubr.c,v 1.61 2009/08/13 15:23:10 deraadt Exp $ */
/*
* Copyright (c) 1998 Steve Murphree, Jr.
* Copyright (c) 1995 Dale Rahn.
@@ -33,8 +33,8 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
-void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
+void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
+int cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
/*
* Attempt to read a disk label from a device
@@ -45,16 +45,14 @@ void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
* Returns NULL on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- struct mvmedisklabel *mlp;
int error;
- char *msg;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
@@ -69,34 +67,24 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
- error = biowait(bp);
- if (error) {
- msg = "disk label read error";
- goto done;
- }
-
- mlp = (struct mvmedisklabel *)bp->b_data;
- if (mlp->magic1 != DISKMAGIC || mlp->magic2 != DISKMAGIC) {
- msg = "no disk label";
+ if (biowait(bp)) {
+ error = bp->b_error;
goto done;
}
- cputobsdlabel(lp, mlp);
- if (dkcksum(lp) == 0)
+ error = cputobsdlabel(lp, (struct mvmedisklabel *)bp->b_data);
+ if (error == 0)
goto done;
- msg = "disk label corrupted";
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -104,7 +92,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
@@ -195,11 +183,14 @@ bsdtocpulabel(struct disklabel *lp, struct mvmedisklabel *clp)
*mot++ = *id++;
}
-void
+int
cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
{
int i;
+ if (clp->magic1 != DISKMAGIC || clp->magic2 != DISKMAGIC)
+ return (EINVAL); /* no disk label */
+
lp->d_magic = clp->magic1;
lp->d_type = clp->type;
lp->d_subtype = clp->subtype;
@@ -247,4 +238,5 @@ cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
lp->d_version = 1;
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
+ return (0);
}
diff --git a/sys/arch/mvmeppc/mvmeppc/disksubr.c b/sys/arch/mvmeppc/mvmeppc/disksubr.c
index 6db60e52d88..a35f34cf7d3 100644
--- a/sys/arch/mvmeppc/mvmeppc/disksubr.c
+++ b/sys/arch/mvmeppc/mvmeppc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.57 2008/06/12 06:58:36 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.58 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -55,35 +55,33 @@
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -91,7 +89,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/sgi/sgi/disksubr.c b/sys/arch/sgi/sgi/disksubr.c
index 534a579fced..d0571d2176b 100644
--- a/sys/arch/sgi/sgi/disksubr.c
+++ b/sys/arch/sgi/sgi/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.16 2009/06/14 00:09:39 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.17 2009/08/13 15:23:11 deraadt Exp $ */
/*
* Copyright (c) 1999 Michael Shalayeff
@@ -40,8 +40,8 @@
#include <sys/syslog.h>
#include <sys/disk.h>
-char *readsgilabel(struct buf *, void (*)(struct buf *),
- struct disklabel *, int *, int);
+int readsgilabel(struct buf *, void (*)(struct buf *),
+ struct disklabel *, int *, int);
/*
* Attempt to read a disk label from a device
@@ -53,14 +53,14 @@ char *readsgilabel(struct buf *, void (*)(struct buf *),
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
lp->d_flags |= D_VENDOR;
@@ -68,25 +68,23 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readsgilabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readsgilabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -94,7 +92,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
static struct {
@@ -109,12 +107,11 @@ static struct {
{ 8, FS_BSDFFS}
};
-char *
+int
readsgilabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
struct sgilabel *dlp;
- char *msg = NULL;
int i, *p, cs = 0;
int fsoffs = 0;
u_int fsend;
@@ -126,21 +123,18 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *),
(*strat)(bp);
/* if successful, locate disk label within block and validate */
- if (biowait(bp)) {
- msg = "disk label I/O error";
- goto done;
- }
+ if (biowait(bp))
+ return (bp->b_error);
dlp = (struct sgilabel *)(bp->b_data + LABELOFFSET);
if (dlp->magic != htobe32(SGILABEL_MAGIC))
goto finished;
- if (dlp->partitions[0].blocks == 0) {
- msg = "no BSD partition";
- goto done;
- }
+ if (dlp->partitions[0].blocks == 0)
+ return (EINVAL);
fsoffs = dlp->partitions[0].first * (dlp->dp.dp_secbytes / DEV_BSIZE);
- fsend = fsoffs + dlp->partitions[0].blocks * (dlp->dp.dp_secbytes / DEV_BSIZE);
+ fsend = fsoffs + dlp->partitions[0].blocks *
+ (dlp->dp.dp_secbytes / DEV_BSIZE);
/* Only came here to find the offset... */
if (partoffp) {
@@ -152,10 +146,8 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *),
i = sizeof(struct sgilabel) / sizeof(int);
while (i--)
cs += *p++;
- if (cs != 0) {
- msg = "sgilabel checksum error";
- goto done;
- }
+ if (cs != 0)
+ return (EINVAL); /* sgilabel checksum error */
/* Spoof info from sgi label, in case there is no OpenBSD label. */
DL_SETDSIZE(lp, (DL_GETDSIZE(lp)*lp->d_secsize) / dlp->dp.dp_secbytes);
@@ -203,22 +195,18 @@ finished:
/* don't read the on-disk label if we are in spoofed-only mode */
if (spoofonly)
- goto done;
+ return (0);
- bp->b_blkno = DL_BLKTOSEC(lp, fsoffs + LABELSECTOR) * DL_BLKSPERSEC(lp);
+ bp->b_blkno = DL_BLKTOSEC(lp, fsoffs + LABELSECTOR) *
+ DL_BLKSPERSEC(lp);
offset = DL_BLKOFFSET(lp, fsoffs + LABELSECTOR) + LABELOFFSET;
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
- if (biowait(bp)) {
- msg = "disk label I/O error";
- goto done;
- }
+ if (biowait(bp))
+ return (bp->b_error);
return checkdisklabel(bp->b_data + offset, lp, fsoffs, fsend);
-
-done:
- return (msg);
}
/*
diff --git a/sys/arch/socppc/socppc/disksubr.c b/sys/arch/socppc/socppc/disksubr.c
index 6ef5b537cd4..8bfa40dbaa4 100644
--- a/sys/arch/socppc/socppc/disksubr.c
+++ b/sys/arch/socppc/socppc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.9 2009/06/19 11:47:09 krw Exp $ */
+/* $OpenBSD: disksubr.c,v 1.10 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -58,39 +58,37 @@ char *readdpmelabel(struct buf *, void (*)(struct buf *),
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
- msg = readdpmelabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdpmelabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -98,10 +96,10 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
-char *
+int
readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
@@ -115,7 +113,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return ("DPME partition I/O error");
+ return (bp->b_error);
/* if successful, wander through DPME partition table */
part = (struct part_map_entry *)bp->b_data;
@@ -133,7 +131,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return ("DPME partition I/O error");
+ return (bp->b_error);
part = (struct part_map_entry *)bp->b_data;
/* toupper the string, in case caps are different... */
@@ -146,7 +144,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
hfspartend = hfspartoff + part->pmPartBlkCnt;
if (partoffp) {
*partoffp = hfspartoff;
- return (NULL);
+ return (0);
} else {
DL_SETBSTART(lp, hfspartoff);
DL_SETBEND(lp,
@@ -170,10 +168,10 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
}
if (hfspartoff == -1)
- return ("no OpenBSD partition inside DPME label");
+ return (EINVAL);
if (spoofonly)
- return (NULL);
+ return (0);
/* next, dig out disk label */
bp->b_blkno = hfspartoff + LABELSECTOR;
@@ -181,7 +179,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return("disk label I/O error");
+ return (bp->b_error);
return checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff,
hfspartend);
diff --git a/sys/arch/sparc/dev/fd.c b/sys/arch/sparc/dev/fd.c
index 9c99fad9d59..070f4c029e1 100644
--- a/sys/arch/sparc/dev/fd.c
+++ b/sys/arch/sparc/dev/fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fd.c,v 1.65 2009/07/24 08:07:39 blambert Exp $ */
+/* $OpenBSD: fd.c,v 1.66 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: fd.c,v 1.51 1997/05/24 20:16:19 pk Exp $ */
/*-
@@ -237,7 +237,7 @@ struct cfdriver fd_cd = {
NULL, "fd", DV_DISK
};
-void fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
+int fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
int fd_get_parms(struct fd_softc *);
void fdstrategy(struct buf *);
void fdstart(struct fd_softc *);
@@ -1931,12 +1931,10 @@ fdformat(dev, finfo, p)
return (rv);
}
-void
+int
fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
int spoofonly)
{
- char *errstring;
-
bzero(lp, sizeof(struct disklabel));
lp->d_type = DTYPE_FLOPPY;
@@ -1960,10 +1958,7 @@ fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
/*
* Call the generic disklabel extraction routine.
*/
- errstring = readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
- if (errstring) {
- /*printf("%s: %s\n", fd->sc_dv.dv_xname, errstring);*/
- }
+ return readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
}
void
diff --git a/sys/arch/sparc/dev/xd.c b/sys/arch/sparc/dev/xd.c
index 096e3e758d7..dbdb87adbaf 100644
--- a/sys/arch/sparc/dev/xd.c
+++ b/sys/arch/sparc/dev/xd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xd.c,v 1.44 2009/01/04 16:51:05 miod Exp $ */
+/* $OpenBSD: xd.c,v 1.45 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: xd.c,v 1.37 1997/07/29 09:58:16 fair Exp $ */
/*
@@ -296,7 +296,7 @@ xdgetdisklabel(xd, b)
{
struct disklabel *lp = xd->sc_dk.dk_label;
struct sun_disklabel *sl = b;
- char *err;
+ int error;
bzero(lp, sizeof(struct disklabel));
/* Required parameters for readdisklabel() */
@@ -311,12 +311,10 @@ xdgetdisklabel(xd, b)
/* We already have the label data in `b'; setup for dummy strategy */
xd_labeldata = b;
- err = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART),
+ error = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART),
xddummystrat, lp, 0);
- if (err) {
- /*printf("%s: %s\n", xd->sc_dev.dv_xname, err);*/
- return (XD_ERR_FAIL);
- }
+ if (error)
+ return (error);
/* Ok, we have the label; fill in `pcyl' if there's SunOS magic */
sl = b;
@@ -336,7 +334,7 @@ xdgetdisklabel(xd, b)
xd->nhead = lp->d_ntracks;
xd->nsect = lp->d_nsectors;
xd->sectpercyl = lp->d_secpercyl;
- return (XD_ERR_AOK);
+ return (0);
}
/*
diff --git a/sys/arch/sparc/dev/xy.c b/sys/arch/sparc/dev/xy.c
index 4a10df3ca32..a4684a70c42 100644
--- a/sys/arch/sparc/dev/xy.c
+++ b/sys/arch/sparc/dev/xy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xy.c,v 1.41 2009/01/04 16:51:05 miod Exp $ */
+/* $OpenBSD: xy.c,v 1.42 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: xy.c,v 1.26 1997/07/19 21:43:56 pk Exp $ */
/*
@@ -236,7 +236,7 @@ xygetdisklabel(xy, b)
{
struct disklabel *lp = xy->sc_dk.dk_label;
struct sun_disklabel *sl = b;
- char *err;
+ int error;
bzero(lp, sizeof(struct disklabel));
/* Required parameters for readdisklabel() */
@@ -251,12 +251,10 @@ xygetdisklabel(xy, b)
/* We already have the label data in `b'; setup for dummy strategy */
xy_labeldata = b;
- err = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART),
+ error = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART),
xydummystrat, lp, 0);
- if (err) {
- /*printf("%s: %s\n", xy->sc_dev.dv_xname, err);*/
- return (XY_ERR_FAIL);
- }
+ if (error)
+ return (error);
/* Ok, we have the label; fill in `pcyl' if there's SunOS magic */
sl = b;
@@ -276,7 +274,7 @@ xygetdisklabel(xy, b)
xy->nhead = lp->d_ntracks;
xy->nsect = lp->d_nsectors;
xy->sectpercyl = lp->d_secpercyl;
- return (XY_ERR_AOK);
+ return (error);
}
/*
@@ -596,7 +594,7 @@ xyattach(parent, self, aux)
/* Attach the disk: must be before getdisklabel to malloc label */
disk_attach(&xy->sc_dk);
- if (xygetdisklabel(xy, xa->buf) != XY_ERR_AOK)
+ if (xygetdisklabel(xy, xa->buf) != 0)
goto done;
/* inform the user of what is up */
diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c
index 2e1ee4a9dd1..94aa419edf0 100644
--- a/sys/arch/sparc/sparc/disksubr.c
+++ b/sys/arch/sparc/sparc/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.81 2009/06/04 21:13:02 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.82 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.16 1996/04/28 20:25:59 thorpej Exp $ */
/*
@@ -46,7 +46,7 @@
#include "cd.h"
-static char *disklabel_sun_to_bsd(struct sun_disklabel *, struct disklabel *);
+static int disklabel_sun_to_bsd(struct sun_disklabel *, struct disklabel *);
static int disklabel_bsd_to_sun(struct disklabel *, struct sun_disklabel *);
static __inline u_int sun_extended_sum(struct sun_disklabel *, void *);
@@ -66,15 +66,15 @@ extern void cdstrategy(struct buf *);
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct sun_disklabel *slp;
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
lp->d_flags |= D_VENDOR;
@@ -87,11 +87,11 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
#if NCD > 0
if (strat == cdstrategy) {
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0)
+ if ((error = iso_disklabelspoof(dev, strat, lp)) == 0)
goto done;
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0)
+ if ((error = udf_disklabelspoof(dev, strat, lp)) == 0)
goto done;
#endif
}
@@ -109,37 +109,35 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label read error";
+ error = bp->b_error;
goto done;
}
slp = (struct sun_disklabel *)bp->b_data;
if (slp->sl_magic == SUN_DKMAGIC) {
- msg = disklabel_sun_to_bsd(slp, lp);
+ error = disklabel_sun_to_bsd(slp, lp);
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
doslabel:
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
/* A CD9660/UDF label may be on a non-CD drive, so recheck */
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -147,7 +145,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
@@ -234,7 +232,7 @@ sun_extended_sum(struct sun_disklabel *sl, void *end)
*
* The BSD label is cleared out before this is called.
*/
-static char *
+static int
disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
{
struct sun_preamble *preamble = (struct sun_preamble *)sl;
@@ -250,7 +248,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
while (sp1 < sp2)
cksum ^= *sp1++;
if (cksum != 0)
- return ("SunOS disk label, bad checksum");
+ return (EINVAL); /* SunOS disk label, bad checksum */
/* Format conversion. */
lp->d_magic = DISKMAGIC;
@@ -461,7 +459,6 @@ disklabel_bsd_to_sun(struct disklabel *lp, struct sun_disklabel *sl)
while (sp1 < sp2)
cksum ^= *sp1++;
sl->sl_cksum = cksum;
-
return (0);
}
diff --git a/sys/arch/sparc64/dev/fd.c b/sys/arch/sparc64/dev/fd.c
index f7ea60ad2e9..d326a7bfcd2 100644
--- a/sys/arch/sparc64/dev/fd.c
+++ b/sys/arch/sparc64/dev/fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fd.c,v 1.27 2009/07/24 08:07:39 blambert Exp $ */
+/* $OpenBSD: fd.c,v 1.28 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: fd.c,v 1.112 2003/08/07 16:29:35 agc Exp $ */
/*-
@@ -283,7 +283,7 @@ struct cfdriver fd_cd = {
NULL, "fd", DV_DISK
};
-void fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
+int fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
int fd_get_parms(struct fd_softc *);
void fdstrategy(struct buf *);
void fdstart(struct fd_softc *);
@@ -2007,12 +2007,10 @@ fdformat(dev, finfo, p)
return (rv);
}
-void
+int
fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
int spoofonly)
{
- char *errstring;
-
bzero(lp, sizeof(struct disklabel));
lp->d_type = DTYPE_FLOPPY;
@@ -2037,10 +2035,7 @@ fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
* Call the generic disklabel extraction routine. If there's
* not a label there, fake it.
*/
- errstring = readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
- if (errstring) {
- /*printf("%s: %s\n", fd->sc_dv.dv_xname, errstring);*/
- }
+ return readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
}
void
diff --git a/sys/arch/sparc64/sparc64/disksubr.c b/sys/arch/sparc64/sparc64/disksubr.c
index 5c210d13284..50b1d0508f0 100644
--- a/sys/arch/sparc64/sparc64/disksubr.c
+++ b/sys/arch/sparc64/sparc64/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.56 2009/06/04 21:13:02 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.57 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk Exp $ */
/*
@@ -39,7 +39,7 @@
#include "cd.h"
-static char *disklabel_sun_to_bsd(struct sun_disklabel *, struct disklabel *);
+static int disklabel_sun_to_bsd(struct sun_disklabel *, struct disklabel *);
static int disklabel_bsd_to_sun(struct disklabel *, struct sun_disklabel *);
static __inline u_int sun_extended_sum(struct sun_disklabel *, void *);
@@ -59,15 +59,15 @@ extern void cdstrategy(struct buf *);
*
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct sun_disklabel *slp;
struct buf *bp = NULL;
- char *msg;
+ int error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
lp->d_flags |= D_VENDOR;
@@ -102,37 +102,35 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "disk label read error";
+ error = bp->b_error;
goto done;
}
slp = (struct sun_disklabel *)bp->b_data;
if (slp->sl_magic == SUN_DKMAGIC) {
- msg = disklabel_sun_to_bsd(slp, lp);
+ error = disklabel_sun_to_bsd(slp, lp);
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
doslabel:
- msg = readdoslabel(bp, strat, lp, NULL, spoofonly);
- if (msg == NULL)
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
goto done;
/* A CD9660/UDF label may be on a non-CD drive, so recheck */
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -140,7 +138,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
@@ -227,7 +225,7 @@ sun_extended_sum(struct sun_disklabel *sl, void *end)
*
* The BSD label is cleared out before this is called.
*/
-static char *
+static int
disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
{
struct sun_preamble *preamble = (struct sun_preamble *)sl;
@@ -243,7 +241,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp)
while (sp1 < sp2)
cksum ^= *sp1++;
if (cksum != 0)
- return ("SunOS disk label, bad checksum");
+ return (EINVAL); /* SunOS disk label, bad checksum */
/* Format conversion. */
lp->d_magic = DISKMAGIC;
diff --git a/sys/arch/vax/mscp/mscp_disk.c b/sys/arch/vax/mscp/mscp_disk.c
index 257cb20e6d2..4ea13d908b5 100644
--- a/sys/arch/vax/mscp/mscp_disk.c
+++ b/sys/arch/vax/mscp/mscp_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mscp_disk.c,v 1.25 2009/06/04 21:38:10 miod Exp $ */
+/* $OpenBSD: mscp_disk.c,v 1.26 2009/08/13 15:23:13 deraadt Exp $ */
/* $NetBSD: mscp_disk.c,v 1.30 2001/11/13 07:38:28 lukem Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
@@ -153,7 +153,6 @@ ra_putonline(ra)
struct ra_softc *ra;
{
struct disklabel *dl;
- char *msg;
if (rx_putonline(ra) != MSCP_DONE)
return MSCP_FAILED;
@@ -162,9 +161,9 @@ ra_putonline(ra)
ra->ra_state = DK_RDLABEL;
printf("%s", ra->ra_dev.dv_xname);
- if ((msg = readdisklabel(MAKEDISKDEV(RAMAJOR, ra->ra_dev.dv_unit,
- RAW_PART), rastrategy, dl, 0)) != NULL) {
- /*printf(": %s", msg);*/
+ if ((readdisklabel(MAKEDISKDEV(RAMAJOR, ra->ra_dev.dv_unit,
+ RAW_PART), rastrategy, dl, 0)) != 0) {
+ /* EIO and others */
} else {
ra->ra_havelabel = 1;
ra->ra_state = DK_OPEN;
diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c
index 03be0cb3357..d8b174f6da9 100644
--- a/sys/arch/vax/vax/disksubr.c
+++ b/sys/arch/vax/vax/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.59 2009/06/04 21:13:02 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.60 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1999/06/30 18:48:06 ragge Exp $ */
/*
@@ -58,14 +58,14 @@
* (e.g., sector size) must be filled in before calling us.
* Returns null on success and an error string on failure.
*/
-char *
+int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly)
{
struct buf *bp = NULL;
- char *msg;
+ char error;
- if ((msg = initdisklabel(lp)))
+ if ((error = initdisklabel(lp)))
goto done;
bp = geteblk((int)lp->d_secsize);
@@ -81,25 +81,24 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp)) {
- msg = "I/O error";
+ error = bp->b_error;
goto done;
}
- msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 16, DL_GETDSIZE(lp));
- if (msg == NULL)
+ error = checkdisklabel(bp->b_data + LABELOFFSET, lp,
+ 16, DL_GETDSIZE(lp));
+ if (error == 0)
goto done;
#if defined(CD9660)
- if (iso_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
#if defined(UDF)
- if (udf_disklabelspoof(dev, strat, lp) == 0) {
- msg = NULL;
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
goto done;
- }
#endif
done:
@@ -107,7 +106,7 @@ done:
bp->b_flags |= B_INVAL;
brelse(bp);
}
- return (msg);
+ return (error);
}
/*
diff --git a/sys/arch/vax/vsa/hdc9224.c b/sys/arch/vax/vsa/hdc9224.c
index edf8a9078b2..10151a5eae3 100644
--- a/sys/arch/vax/vsa/hdc9224.c
+++ b/sys/arch/vax/vsa/hdc9224.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hdc9224.c,v 1.23 2009/06/04 21:38:10 miod Exp $ */
+/* $OpenBSD: hdc9224.c,v 1.24 2009/08/13 15:23:13 deraadt Exp $ */
/* $NetBSD: hdc9224.c,v 1.16 2001/07/26 15:05:09 wiz Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
@@ -345,7 +345,7 @@ hdattach(struct device *parent, struct device *self, void *aux)
struct hdsoftc *hd = (void*)self;
struct hdc_attach_args *ha = aux;
struct disklabel *dl;
- char *msg;
+ int error;
hd->sc_drive = ha->ha_drive;
/*
@@ -362,14 +362,11 @@ hdattach(struct device *parent, struct device *self, void *aux)
disk_printtype(hd->sc_drive, hd->sc_xbn.media_id);
dl = hd->sc_disk.dk_label;
hdmakelabel(dl, &hd->sc_xbn);
- msg = readdisklabel(MAKEDISKDEV(HDMAJOR, hd->sc_dev.dv_unit, RAW_PART),
+ error = readdisklabel(MAKEDISKDEV(HDMAJOR, hd->sc_dev.dv_unit, RAW_PART),
hdstrategy, dl, 0);
printf("%s: %luMB, %lu sectors\n",
hd->sc_dev.dv_xname, DL_GETDSIZE(dl) / (1048576 / DEV_BSIZE),
DL_GETDSIZE(dl));
- if (msg) {
- /*printf("%s: %s\n", hd->sc_dev.dv_xname, msg);*/
- }
#ifdef HDDEBUG
hdc_printgeom(&hd->sc_xbn);
#endif
diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c
index b70a68ba61e..40558d85d74 100644
--- a/sys/dev/ata/wd.c
+++ b/sys/dev/ata/wd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wd.c,v 1.75 2009/06/17 01:30:30 thib Exp $ */
+/* $OpenBSD: wd.c,v 1.76 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */
/*
@@ -169,7 +169,7 @@ struct cfdriver wd_cd = {
};
void wdgetdefaultlabel(struct wd_softc *, struct disklabel *);
-void wdgetdisklabel(dev_t dev, struct wd_softc *, struct disklabel *, int);
+int wdgetdisklabel(dev_t dev, struct wd_softc *, struct disklabel *, int);
void wdstrategy(struct buf *);
void wdstart(void *);
void __wdstart(struct wd_softc*, struct buf *);
@@ -703,7 +703,11 @@ wdopen(dev_t dev, int flag, int fmt, struct proc *p)
wd_get_params(wd, AT_WAIT, &wd->sc_params);
/* Load the partition info if not already loaded. */
- wdgetdisklabel(dev, wd, wd->sc_dk.dk_label, 0);
+ if (wdgetdisklabel(dev, wd,
+ wd->sc_dk.dk_label, 0) == EIO) {
+ error = EIO;
+ goto bad;
+ }
}
}
@@ -816,11 +820,11 @@ wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp)
/*
* Fabricate a default disk label, and try to read the correct one.
*/
-void
+int
wdgetdisklabel(dev_t dev, struct wd_softc *wd, struct disklabel *lp,
int spoofonly)
{
- char *errstring;
+ int error;
WDCDEBUG_PRINT(("wdgetdisklabel\n"), DEBUG_FUNCS);
@@ -828,13 +832,11 @@ wdgetdisklabel(dev_t dev, struct wd_softc *wd, struct disklabel *lp,
if (wd->drvp->state > RECAL)
wd->drvp->drive_flags |= DRIVE_RESET;
- errstring = readdisklabel(DISKLABELDEV(dev), wdstrategy, lp,
+ error = readdisklabel(DISKLABELDEV(dev), wdstrategy, lp,
spoofonly);
if (wd->drvp->state > RECAL)
wd->drvp->drive_flags |= DRIVE_RESET;
- if (errstring) {
- /*printf("%s: %s\n", wd->sc_dev.dv_xname, errstring);*/
- }
+ return (error);
}
int
diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c
index 18169e5efd2..d6c13072962 100644
--- a/sys/dev/ccd.c
+++ b/sys/dev/ccd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ccd.c,v 1.86 2009/06/04 05:57:27 krw Exp $ */
+/* $OpenBSD: ccd.c,v 1.87 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: ccd.c,v 1.33 1996/05/05 04:21:14 thorpej Exp $ */
/*-
@@ -175,7 +175,7 @@ int ccdinit(struct ccddevice *, char **, struct proc *);
int ccdlookup(char *, struct proc *p, struct vnode **);
long ccdbuffer(struct ccd_softc *, struct buf *, daddr64_t, caddr_t,
long, struct ccdbuf **);
-void ccdgetdisklabel(dev_t, struct ccd_softc *, struct disklabel *, int);
+int ccdgetdisklabel(dev_t, struct ccd_softc *, struct disklabel *, int);
INLINE struct ccdbuf *getccdbuf(void);
INLINE void putccdbuf(struct ccdbuf *);
@@ -1353,12 +1353,11 @@ ccdlookup(char *path, struct proc *p, struct vnode **vpp)
* Read the disklabel from the ccd. If one is not present, fake one
* up.
*/
-void
+int
ccdgetdisklabel(dev_t dev, struct ccd_softc *cs, struct disklabel *lp,
int spoofonly)
{
struct ccdgeom *ccg = &cs->sc_geom;
- char *errstring;
bzero(lp, sizeof(*lp));
@@ -1384,11 +1383,8 @@ ccdgetdisklabel(dev_t dev, struct ccd_softc *cs, struct disklabel *lp,
/*
* Call the generic disklabel extraction routine.
*/
- errstring = readdisklabel(DISKLABELDEV(dev), ccdstrategy,
+ return readdisklabel(DISKLABELDEV(dev), ccdstrategy,
cs->sc_dkdev.dk_label, spoofonly);
- /* It's actually extremely common to have unlabeled ccds. */
- if (errstring != NULL)
- CCD_DPRINTF(CCDB_LABEL, ("%s: %s\n", cs->sc_xname, errstring));
}
#ifdef CCDDEBUG
diff --git a/sys/dev/isa/fd.c b/sys/dev/isa/fd.c
index 893b73d7e5d..8c51510a216 100644
--- a/sys/dev/isa/fd.c
+++ b/sys/dev/isa/fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fd.c,v 1.77 2009/08/05 13:45:29 blambert Exp $ */
+/* $OpenBSD: fd.c,v 1.78 2009/08/13 15:23:12 deraadt Exp $ */
/* $NetBSD: fd.c,v 1.90 1996/05/12 23:12:03 mycroft Exp $ */
/*-
@@ -139,7 +139,7 @@ struct cfdriver fd_cd = {
NULL, "fd", DV_DISK
};
-void fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
+int fdgetdisklabel(dev_t, struct fd_softc *, struct disklabel *, int);
int fd_get_parms(struct fd_softc *);
void fdstrategy(struct buf *);
void fdstart(struct fd_softc *);
@@ -156,12 +156,10 @@ static __inline struct fd_type *fd_dev_to_type(struct fd_softc *, dev_t);
void fdretry(struct fd_softc *);
void fdtimeout(void *);
-void
+int
fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
int spoofonly)
{
- char *errstring;
-
bzero(lp, sizeof(struct disklabel));
lp->d_type = DTYPE_FLOPPY;
@@ -186,10 +184,7 @@ fdgetdisklabel(dev_t dev, struct fd_softc *fd, struct disklabel *lp,
* Call the generic disklabel extraction routine. If there's
* not a label there, fake it.
*/
- errstring = readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
- if (errstring) {
- /*printf("%s: %s\n", fd->sc_dev.dv_xname, errstring);*/
- }
+ return readdisklabel(DISKLABELDEV(dev), fdstrategy, lp, spoofonly);
}
int
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c
index 43c78122563..14e94094cf5 100644
--- a/sys/dev/vnd.c
+++ b/sys/dev/vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vnd.c,v 1.93 2009/06/17 01:30:30 thib Exp $ */
+/* $OpenBSD: vnd.c,v 1.94 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */
/*
@@ -163,7 +163,7 @@ void vndstart(struct vnd_softc *);
int vndsetcred(struct vnd_softc *, struct ucred *);
void vndiodone(struct buf *);
void vndshutdown(void);
-void vndgetdisklabel(dev_t, struct vnd_softc *, struct disklabel *, int);
+int vndgetdisklabel(dev_t, struct vnd_softc *, struct disklabel *, int);
void vndencrypt(struct vnd_softc *, caddr_t, size_t, daddr64_t, int);
size_t vndbdevsize(struct vnode *, struct proc *);
@@ -300,12 +300,10 @@ bad:
/*
* Load the label information on the named device
*/
-void
+int
vndgetdisklabel(dev_t dev, struct vnd_softc *sc, struct disklabel *lp,
int spoofonly)
{
- char *errstring = NULL;
-
bzero(lp, sizeof(struct disklabel));
lp->d_secsize = sc->sc_secsize;
@@ -328,12 +326,7 @@ vndgetdisklabel(dev_t dev, struct vnd_softc *sc, struct disklabel *lp,
lp->d_checksum = dkcksum(lp);
/* Call the generic disklabel extraction routine */
- errstring = readdisklabel(VNDLABELDEV(dev), vndstrategy, lp, spoofonly);
- if (errstring) {
- DNPRINTF(VDB_IO, "%s: %s\n", sc->sc_dev.dv_xname,
- errstring);
- return;
- }
+ return readdisklabel(VNDLABELDEV(dev), vndstrategy, lp, spoofonly);
}
int
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 089167d1f8c..077b0874e77 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.96 2009/08/09 14:06:52 marco Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.97 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -190,7 +190,7 @@ dkcksum(struct disklabel *lp)
return (sum);
}
-char *
+int
initdisklabel(struct disklabel *lp)
{
int i;
@@ -201,7 +201,7 @@ initdisklabel(struct disklabel *lp)
if (DL_GETDSIZE(lp) == 0)
DL_SETDSIZE(lp, MAXDISKSIZE);
if (lp->d_secpercyl == 0)
- return ("invalid geometry");
+ return (ERANGE);
lp->d_npartitions = MAXPARTITIONS;
for (i = 0; i < RAW_PART; i++) {
DL_SETPSIZE(&lp->d_partitions[i], 0);
@@ -215,14 +215,14 @@ initdisklabel(struct disklabel *lp)
lp->d_version = 1;
lp->d_bbsize = 8192;
lp->d_sbsize = 64*1024; /* XXX ? */
- return (NULL);
+ return (0);
}
/*
* Check an incoming block to make sure it is a disklabel, convert it to
* a newer version if needed, etc etc.
*/
-char *
+int
checkdisklabel(void *rlp, struct disklabel *lp,
u_int64_t boundstart, u_int64_t boundend)
{
@@ -230,28 +230,28 @@ checkdisklabel(void *rlp, struct disklabel *lp,
struct __partitionv0 *v0pp;
struct partition *pp;
daddr64_t disksize;
- char *msg = NULL;
+ int error = 0;
int i;
if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC)
- msg = "no disk label";
+ error = ENOENT; /* no disk label */
else if (dlp->d_npartitions > MAXPARTITIONS)
- msg = "invalid label, partition count > MAXPARTITIONS";
+ error = E2BIG; /* too many partitions */
else if (dlp->d_secpercyl == 0)
- msg = "invalid label, d_secpercyl == 0";
+ error = EINVAL; /* invalid label */
else if (dlp->d_secsize == 0)
- msg = "invalid label, d_secsize == 0";
+ error = ENOSPC; /* disk too small */
else if (dkcksum(dlp) != 0)
- msg = "invalid label, incorrect checksum";
+ error = EINVAL; /* incorrect checksum */
- if (msg) {
+ if (error) {
u_int16_t *start, *end, sum = 0;
/* If it is byte-swapped, attempt to convert it */
if (swap32(dlp->d_magic) != DISKMAGIC ||
swap32(dlp->d_magic2) != DISKMAGIC ||
swap16(dlp->d_npartitions) > MAXPARTITIONS)
- return (msg);
+ return (error);
/*
* Need a byte-swap aware dkcksum varient
@@ -263,7 +263,7 @@ checkdisklabel(void *rlp, struct disklabel *lp,
while (start < end)
sum ^= *start++;
if (sum != 0)
- return (msg);
+ return (error);
dlp->d_magic = swap32(dlp->d_magic);
dlp->d_type = swap16(dlp->d_type);
@@ -319,13 +319,13 @@ checkdisklabel(void *rlp, struct disklabel *lp,
dlp->d_checksum = 0;
dlp->d_checksum = dkcksum(dlp);
- msg = NULL;
+ error = 0;
}
/* XXX should verify lots of other fields and whine a lot */
- if (msg)
- return (msg);
+ if (error)
+ return (error);
/* Initial passed in lp contains the real disk size. */
disksize = DL_GETDSIZE(lp);
@@ -366,7 +366,7 @@ checkdisklabel(void *rlp, struct disklabel *lp,
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
- return (msg);
+ return (0);
}
/*
@@ -378,7 +378,7 @@ checkdisklabel(void *rlp, struct disklabel *lp,
* we cannot because it doesn't always exist. So.. we assume the
* MBR is valid.
*/
-char *
+int
readdoslabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
@@ -387,11 +387,12 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *),
struct dos_partition dp[NDOSPART], *dp2;
daddr64_t part_blkno = DOSBBSECTOR;
u_int32_t extoff = 0;
+ int error;
if (lp->d_secpercyl == 0)
- return ("invalid label, d_secpercyl == 0");
+ return (EINVAL); /* invalid label */
if (lp->d_secsize == 0)
- return ("invalid label, d_secsize == 0");
+ return (ENOSPC); /* disk too small */
/* do DOS partitions in the process of getting disklabel? */
@@ -411,10 +412,11 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *),
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
- if (biowait(bp)) {
+ error = biowait(bp);
+ if (error) {
/*wrong*/ if (partoffp)
/*wrong*/ *partoffp = -1;
- return ("dos partition I/O error");
+ return (error);
}
bcopy(bp->b_data + offset, dp, sizeof(dp));
@@ -587,7 +589,7 @@ notfat:
/* don't read the on-disk label if we are in spoofed-only mode */
if (spoofonly)
- return (NULL); /* jump to the checkdisklabel below?? */
+ return (0);
bp->b_blkno = DL_BLKTOSEC(lp, dospartoff + DOS_LABELSECTOR) *
DL_BLKSPERSEC(lp);
@@ -596,7 +598,7 @@ notfat:
bp->b_flags = B_BUSY | B_READ | B_RAW;
(*strat)(bp);
if (biowait(bp))
- return ("disk label I/O error");
+ return (bp->b_error);
/* sub-MBR disklabels are always at a LABELOFFSET of 0 */
return checkdisklabel(bp->b_data + offset, lp, dospartoff, dospartend);
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c
index 64b8e7adc8a..01feb0726b2 100644
--- a/sys/scsi/cd.c
+++ b/sys/scsi/cd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd.c,v 1.148 2009/06/17 01:30:30 thib Exp $ */
+/* $OpenBSD: cd.c,v 1.149 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */
/*
@@ -96,7 +96,7 @@ int cddetach(struct device *, int);
void cdstart(void *);
void cdrestart(void *);
void cdminphys(struct buf *);
-void cdgetdisklabel(dev_t, struct cd_softc *, struct disklabel *, int);
+int cdgetdisklabel(dev_t, struct cd_softc *, struct disklabel *, int);
void cddone(struct scsi_xfer *);
void cd_kill_buffers(struct cd_softc *);
int cd_setchan(struct cd_softc *, int, int, int, int, int);
@@ -1118,12 +1118,11 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
* EVENTUALLY take information about different
* data tracks from the TOC and put it in the disklabel
*/
-void
+int
cdgetdisklabel(dev_t dev, struct cd_softc *cd, struct disklabel *lp,
int spoofonly)
{
struct cd_toc *toc;
- char *errstring;
int tocidx, n, audioonly = 1;
bzero(lp, sizeof(struct disklabel));
@@ -1173,12 +1172,9 @@ cdgetdisklabel(dev_t dev, struct cd_softc *cd, struct disklabel *lp,
done:
free(toc, M_TEMP);
- if (!audioonly) {
- errstring = readdisklabel(DISKLABELDEV(dev), cdstrategy, lp,
- spoofonly);
- /*if (errstring)
- printf("%s: %s\n", cd->sc_dev.dv_xname, errstring);*/
- }
+ if (audioonly)
+ return (0);
+ return readdisklabel(DISKLABELDEV(dev), cdstrategy, lp, spoofonly);
}
int
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c
index 8f9d44c4e6d..e74777e44f9 100644
--- a/sys/scsi/sd.c
+++ b/sys/scsi/sd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sd.c,v 1.156 2009/06/17 01:30:30 thib Exp $ */
+/* $OpenBSD: sd.c,v 1.157 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */
/*-
@@ -81,7 +81,7 @@ int sdactivate(struct device *, enum devact);
int sddetach(struct device *, int);
void sdminphys(struct buf *);
-void sdgetdisklabel(dev_t, struct sd_softc *, struct disklabel *, int);
+int sdgetdisklabel(dev_t, struct sd_softc *, struct disklabel *, int);
void sdstart(void *);
void sdrestart(void *);
void sddone(struct scsi_xfer *);
@@ -398,7 +398,10 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
SC_DEBUG(sc_link, SDEV_DB3, ("Params loaded\n"));
/* Load the partition info if not already loaded. */
- sdgetdisklabel(dev, sd, sd->sc_dk.dk_label, 0);
+ if (sdgetdisklabel(dev, sd, sd->sc_dk.dk_label, 0) == EIO) {
+ error = EIO;
+ goto bad;
+ }
SC_DEBUG(sc_link, SDEV_DB3, ("Disklabel loaded\n"));
}
@@ -992,12 +995,12 @@ sd_ioctl_inquiry(struct sd_softc *sd, struct dk_inquiry *di)
/*
* Load the label information on the named device
*/
-void
+int
sdgetdisklabel(dev_t dev, struct sd_softc *sd, struct disklabel *lp,
int spoofonly)
{
size_t len;
- char *errstring, packname[sizeof(lp->d_packname) + 1];
+ char packname[sizeof(lp->d_packname) + 1];
char product[17], vendor[9];
bzero(lp, sizeof(struct disklabel));
@@ -1057,10 +1060,7 @@ sdgetdisklabel(dev_t dev, struct sd_softc *sd, struct disklabel *lp,
/*
* Call the generic disklabel extraction routine
*/
- errstring = readdisklabel(DISKLABELDEV(dev), sdstrategy, lp, spoofonly);
- if (errstring) {
- /*printf("%s: %s\n", sd->sc_dev.dv_xname, errstring);*/
- }
+ return readdisklabel(DISKLABELDEV(dev), sdstrategy, lp, spoofonly);
}
diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h
index 67909e7840b..40ca7c4ff93 100644
--- a/sys/sys/disklabel.h
+++ b/sys/sys/disklabel.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.h,v 1.45 2009/06/04 21:13:02 deraadt Exp $ */
+/* $OpenBSD: disklabel.h,v 1.46 2009/08/13 15:23:11 deraadt Exp $ */
/* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */
/*
@@ -471,13 +471,13 @@ struct dos_mbr {
void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
void disksort(struct buf *, struct buf *);
u_int dkcksum(struct disklabel *);
-char *initdisklabel(struct disklabel *);
-char *checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t);
+int initdisklabel(struct disklabel *);
+int checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t);
int setdisklabel(struct disklabel *, struct disklabel *, u_int);
-char *readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
+int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
int bounds_check_with_label(struct buf *, struct disklabel *, int);
-char *readdoslabel(struct buf *, void (*)(struct buf *),
+int readdoslabel(struct buf *, void (*)(struct buf *),
struct disklabel *, int *, int);
#ifdef CD9660
int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),