diff options
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r-- | sys/kern/subr_disk.c | 52 |
1 files changed, 27 insertions, 25 deletions
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); |