summaryrefslogtreecommitdiff
path: root/sys/arch/mvme88k
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-05 00:38:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-05 00:38:25 +0000
commit27424f98f99646fb8b3e4ef11652da62014a7ceb (patch)
tree47b5f078f236f633651ce1bad4b1228fac2f6d7d /sys/arch/mvme88k
parent91862e2af60dd7be0a8d86f5f3fe187dbb400d7f (diff)
use six new macros to access & store the 48-bit disklabel fields related
to size. tested on almost all machines, double checked by miod and krw next comes the type handling surrounding these values
Diffstat (limited to 'sys/arch/mvme88k')
-rw-r--r--sys/arch/mvme88k/mvme88k/disksubr.c158
1 files changed, 19 insertions, 139 deletions
diff --git a/sys/arch/mvme88k/mvme88k/disksubr.c b/sys/arch/mvme88k/mvme88k/disksubr.c
index 34169dfd5cc..21cebb280b7 100644
--- a/sys/arch/mvme88k/mvme88k/disksubr.c
+++ b/sys/arch/mvme88k/mvme88k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.38 2007/06/02 02:35:27 krw Exp $ */
+/* $OpenBSD: disksubr.c,v 1.39 2007/06/05 00:38:17 deraadt Exp $ */
/*
* Copyright (c) 1998 Steve Murphree, Jr.
* Copyright (c) 1995 Dale Rahn.
@@ -34,18 +34,9 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-#ifdef DEBUG
-int disksubr_debug;
-#endif
-
void bsdtocpulabel(struct disklabel *, struct cpu_disklabel *);
void cputobsdlabel(struct disklabel *, struct cpu_disklabel *);
-#ifdef DEBUG
-void printlp(struct disklabel *, char *);
-void printclp(struct cpu_disklabel *, char *);
-#endif
-
/*
* Attempt to read a disk label from a device
* using the indicated strategy routine.
@@ -70,20 +61,20 @@ readdisklabel(dev, strat, lp, clp, spoofonly)
/* minimal requirements for archetypal disk label */
if (lp->d_secsize < DEV_BSIZE)
lp->d_secsize = DEV_BSIZE;
- if (lp->d_secperunit == 0)
- lp->d_secperunit = 0x1fffffff;
+ if (DL_GETDSIZE(lp) == 0)
+ DL_SETDSIZE(lp, MAXDISKSIZE);
if (lp->d_secpercyl == 0) {
msg = "invalid geometry";
goto done;
}
lp->d_npartitions = RAW_PART + 1;
for (i = 0; i < RAW_PART; i++) {
- lp->d_partitions[i].p_size = 0;
- lp->d_partitions[i].p_offset = 0;
+ DL_SETPSIZE(&lp->d_partitions[i], 0);
+ DL_SETPOFFSET(&lp->d_partitions[i], 0);
}
- if (lp->d_partitions[i].p_size == 0)
- lp->d_partitions[i].p_size = lp->d_secperunit;
- lp->d_partitions[i].p_offset = 0;
+ if (DL_GETPSIZE(&lp->d_partitions[i]) == 0)
+ DL_SETPSIZE(&lp->d_partitions[i], DL_GETDSIZE(lp));
+ DL_SETPOFFSET(&lp->d_partitions[i], 0);
/* don't read the on-disk label if we are in spoofed-only mode */
if (spoofonly)
@@ -133,12 +124,6 @@ readdisklabel(dev, strat, lp, clp, spoofonly)
goto done;
}
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printlp(lp, "readdisklabel:bsd label");
- printclp(clp, "readdisklabel:cpu label");
- }
-#endif
done:
if (bp) {
bp->b_flags = B_INVAL | B_AGE | B_READ;
@@ -161,15 +146,6 @@ setdisklabel(olp, nlp, openmask, clp)
int i;
struct partition *opp, *npp;
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printlp(nlp, "setdisklabel:new disklabel");
- printlp(olp, "setdisklabel:old disklabel");
- printclp(clp, "setdisklabel:cpu disklabel");
- }
-#endif
-
-
/* sanity clause */
if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 ||
(nlp->d_secsize % DEV_BSIZE) != 0)
@@ -192,7 +168,8 @@ setdisklabel(olp, nlp, openmask, clp)
return (EBUSY);
opp = &olp->d_partitions[i];
npp = &nlp->d_partitions[i];
- if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
+ if (DL_GETPOFFSET(npp) != DL_GETPOFFSET(opp) ||
+ DL_GETPSIZE(npp) < DL_GETPSIZE(opp))
return (EBUSY);
/*
* Copy internally-set partition information
@@ -208,11 +185,6 @@ setdisklabel(olp, nlp, openmask, clp)
nlp->d_checksum = 0;
nlp->d_checksum = dkcksum(nlp);
*olp = *nlp;
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printlp(olp, "setdisklabel:old->new disklabel");
- }
-#endif
return (0);
}
@@ -229,12 +201,6 @@ writedisklabel(dev, strat, lp, clp)
struct buf *bp;
int error;
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printlp(lp, "writedisklabel: bsd label");
- }
-#endif
-
/* obtain buffer to read initial cpu_disklabel, for bootloader size :-) */
bp = geteblk((int)lp->d_secsize);
@@ -261,12 +227,6 @@ writedisklabel(dev, strat, lp, clp)
bsdtocpulabel(lp, clp);
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printclp(clp, "writedisklabel: cpu label");
- }
-#endif
-
if (lp->d_magic == DISKMAGIC && lp->d_magic2 == DISKMAGIC &&
dkcksum(lp) == 0) {
/* obtain buffer to scrozz drive with */
@@ -297,7 +257,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
{
#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE))
struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
- int labelsector = blockpersec(lp->d_partitions[0].p_offset, lp) +
+ int labelsector = blockpersec(DL_GETPOFFSET(&lp->d_partitions[0]), lp) +
LABELSECTOR;
int sz = howmany(bp->b_bcount, DEV_BSIZE);
@@ -309,9 +269,9 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
/* overwriting disk label ? */
/* XXX should also protect bootstrap in first 8K */
- if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsector &&
+ if (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) <= labelsector &&
#if LABELSECTOR != 0
- bp->b_blkno + blockpersec(p->p_offset, lp) + sz > labelsector &&
+ bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp) + sz > labelsector &&
#endif
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
bp->b_error = EROFS;
@@ -319,8 +279,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
}
/* beyond partition? */
- if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) {
- sz = blockpersec(p->p_size, lp) - bp->b_blkno;
+ if (bp->b_blkno + sz > blockpersec(DL_GETPSIZE(p), lp)) {
+ sz = blockpersec(DL_GETPSIZE(p), lp) - bp->b_blkno;
if (sz == 0) {
/* If exactly at end of disk, return EOF. */
bp->b_resid = bp->b_bcount;
@@ -336,7 +296,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
}
/* calculate cylinder for disksort to order transfers with */
- bp->b_cylinder = (bp->b_blkno + blockpersec(p->p_offset, lp)) /
+ bp->b_cylinder = (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp)) /
lp->d_secpercyl;
return (1);
@@ -367,7 +327,7 @@ bsdtocpulabel(lp, clp)
clp->cfg_hds = lp->d_ntracks;
clp->secpercyl = lp->d_secpercyl;
- clp->secperunit = lp->d_secperunit;
+ clp->secperunit = DL_GETDSIZE(lp);
clp->sparespertrack = lp->d_sparespertrack;
clp->sparespercyl = lp->d_sparespercyl;
clp->acylinders = lp->d_acylinders;
@@ -427,11 +387,6 @@ cputobsdlabel(lp, clp)
int i;
if (clp->version == 0) {
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printf("Reading old disklabel\n");
- }
-#endif
lp->d_magic = clp->magic1;
lp->d_type = clp->type;
lp->d_subtype = clp->subtype;
@@ -443,9 +398,7 @@ cputobsdlabel(lp, clp)
lp->d_ntracks = clp->cfg_hds;
lp->d_secpercyl = clp->secpercyl;
- lp->d_secperunit = clp->secperunit;
- lp->d_secpercyl = clp->secpercyl;
- lp->d_secperunit = clp->secperunit;
+ DL_SETDSIZE(lp, clp->secperunit);
lp->d_sparespertrack = clp->sparespertrack;
lp->d_sparespercyl = clp->sparespercyl;
lp->d_acylinders = clp->acylinders;
@@ -491,11 +444,6 @@ cputobsdlabel(lp, clp)
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
} else {
-#ifdef DEBUG
- if (disksubr_debug != 0) {
- printf("Reading new disklabel\n");
- }
-#endif
lp->d_magic = clp->magic1;
lp->d_type = clp->type;
lp->d_subtype = clp->subtype;
@@ -507,9 +455,7 @@ cputobsdlabel(lp, clp)
lp->d_ntracks = clp->cfg_hds;
lp->d_secpercyl = clp->secpercyl;
- lp->d_secperunit = clp->secperunit;
- lp->d_secpercyl = clp->secpercyl;
- lp->d_secperunit = clp->secperunit;
+ DL_SETDSIZE(lp, clp->secperunit);
lp->d_sparespertrack = clp->sparespertrack;
lp->d_sparespercyl = clp->sparespercyl;
lp->d_acylinders = clp->acylinders;
@@ -555,70 +501,4 @@ cputobsdlabel(lp, clp)
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
}
-#if defined(DEBUG)
- if (disksubr_debug != 0) {
- printlp(lp, "translated label read from disk\n");
- }
-#endif
-}
-
-#ifdef DEBUG
-void
-printlp(lp, str)
- struct disklabel *lp;
- char *str;
-{
- int i;
-
- printf("%s\n", str);
- printf("magic1 %x\n", lp->d_magic);
- printf("magic2 %x\n", lp->d_magic2);
- printf("typename %.*s\n", (int)sizeof(lp->d_typename), lp->d_typename);
- printf("secsize %x nsect %x ntrack %x ncylinders %x\n",
- lp->d_secsize, lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders);
- printf("Num partitions %x\n", lp->d_npartitions);
- for (i = 0; i < lp->d_npartitions; i++) {
- struct partition *part = &lp->d_partitions[i];
- char *fstyp = fstypenames[part->p_fstype];
-
- printf("%c: size %10x offset %10x type %7s frag %5x cpg %3x\n",
- 'a' + i, part->p_size, part->p_offset, fstyp,
- part->p_frag, part->p_cpg);
- }
}
-
-void
-printclp(clp, str)
- struct cpu_disklabel *clp;
- char *str;
-{
- int max, i;
-
- printf("%s\n", str);
- printf("magic1 %x\n", clp->magic1);
- printf("magic2 %x\n", clp->magic2);
- printf("typename %s\n", clp->vid_vd);
- printf("secsize %x nsect %x ntrack %x ncylinders %x\n",
- clp->cfg_psm, clp->cfg_spt, clp->cfg_hds, clp->cfg_trk);
- printf("Num partitions %x\n", clp->partitions);
- max = clp->partitions < 16 ? clp->partitions : 16;
- for (i = 0; i < max; i++) {
- struct partition *part;
- char *fstyp;
-
- if (i < 4) {
- part = (void *)&clp->vid_4[0];
- part = &part[i];
- } else {
- part = (void *)&clp->cfg_4[0];
- part = &part[i-4];
- }
-
- fstyp = fstypenames[part->p_fstype];
-
- printf("%c: size %10x offset %10x type %7s frag %5x cpg %3x\n",
- 'a' + i, part->p_size, part->p_offset, fstyp,
- part->p_frag, part->p_cpg);
- }
-}
-#endif