summaryrefslogtreecommitdiff
path: root/sys/arch/mvme88k
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-17 00:27:31 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-17 00:27:31 +0000
commit81f9f199b5e2a6741e5a9a68d39dd00dadaa4e18 (patch)
treeaa5797e58e49aa5ab1063818eacfa236c19c2adf /sys/arch/mvme88k
parent49e31b3e7fe854aae88f968da9911e2a4fd5d878 (diff)
significantly simplified disklabel infrastructure. MBR handling becomes MI
to support hotplug media on most architectures. disklabel setup and verification done using new helper functions. Disklabels must *always* have a correct checksum now. Same code paths are used to learn on-disk location disklabels, to avoid new errors sneaking in. Tested on almost all cases, testing help from todd, kettenis, krw, otto, dlg, robert, gwk, drahn
Diffstat (limited to 'sys/arch/mvme88k')
-rw-r--r--sys/arch/mvme88k/include/disklabel.h8
-rw-r--r--sys/arch/mvme88k/mvme88k/disksubr.c118
2 files changed, 49 insertions, 77 deletions
diff --git a/sys/arch/mvme88k/include/disklabel.h b/sys/arch/mvme88k/include/disklabel.h
index d7ae09fbec9..f70f7a3d739 100644
--- a/sys/arch/mvme88k/include/disklabel.h
+++ b/sys/arch/mvme88k/include/disklabel.h
@@ -1,4 +1,5 @@
-/* $OpenBSD: disklabel.h,v 1.11 2003/10/11 22:08:57 miod Exp $ */
+/* $OpenBSD: disklabel.h,v 1.12 2007/06/17 00:27:27 deraadt Exp $ */
+
/*
* Copyright (c) 1996 Nivas Madhur
* Copyright (c) 1995 Dale Rahn.
@@ -33,15 +34,16 @@
#define LABELSECTOR 0 /* sector containing label */
#define LABELOFFSET 0 /* offset of label in sector */
#define MAXPARTITIONS 16 /* number of partitions */
-#define RAW_PART 2 /* raw partition: xx?c */
/*
* Note: this structure is exactly 512 bytes in size. If you move fields
* around, make sure the various members are properly aligned and the
* compiler won't do any additional padding.
*/
-
struct cpu_disklabel {
+};
+
+struct mvmedisklabel {
/* VID */
u_char vid_id[4];
u_char vid_0[16];
diff --git a/sys/arch/mvme88k/mvme88k/disksubr.c b/sys/arch/mvme88k/mvme88k/disksubr.c
index 85dfa0783ac..9750a54032b 100644
--- a/sys/arch/mvme88k/mvme88k/disksubr.c
+++ b/sys/arch/mvme88k/mvme88k/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.53 2007/06/14 03:37:23 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.54 2007/06/17 00:27:29 deraadt Exp $ */
/*
* Copyright (c) 1998 Steve Murphree, Jr.
* Copyright (c) 1995 Dale Rahn.
@@ -34,8 +34,8 @@
#include <sys/disklabel.h>
#include <sys/disk.h>
-void bsdtocpulabel(struct disklabel *, struct cpu_disklabel *);
-void cputobsdlabel(struct disklabel *, struct cpu_disklabel *);
+void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
+void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
/*
* Attempt to read a disk label from a device
@@ -51,51 +51,43 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, struct cpu_disklabel *osdep, int spoofonly)
{
struct buf *bp = NULL;
- char *msg = NULL;
- int error, i;
-
- /* minimal requirements for archetypal disk label */
- if (lp->d_secsize < DEV_BSIZE)
- lp->d_secsize = DEV_BSIZE;
- 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++) {
- DL_SETPSIZE(&lp->d_partitions[i], 0);
- DL_SETPOFFSET(&lp->d_partitions[i], 0);
- }
- if (DL_GETPSIZE(&lp->d_partitions[RAW_PART]) == 0)
- DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
- DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
- lp->d_version = 1;
+ struct mvmedisklabel *mlp;
+ int error;
+ char *msg;
- /* don't read the on-disk label if we are in spoofed-only mode */
- if (spoofonly)
+ if ((msg = initdisklabel(lp)))
goto done;
/* get a buffer and initialize it */
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
+ /* don't read the on-disk label if we are in spoofed-only mode */
+ if (spoofonly)
+ goto done;
+
bp->b_blkno = LABELSECTOR;
bp->b_cylinder = 0; /* contained in block 0 */
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ;
(*strat)(bp);
-
error = biowait(bp);
- if (error == 0)
- bcopy(bp->b_data, osdep, sizeof (struct cpu_disklabel));
-
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";
+ goto done;
+ }
+
+ cputobsdlabel(lp, mlp);
+ if (dkcksum(lp) == 0)
+ goto done;
+ msg = "disk label corrupted";
+
#if defined(CD9660)
if (iso_disklabelspoof(dev, strat, lp) == 0) {
msg = NULL;
@@ -109,24 +101,11 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *),
}
#endif
- if (osdep->magic1 != DISKMAGIC || osdep->magic2 != DISKMAGIC) {
- msg = "no disk label";
- goto done;
- }
-
- cputobsdlabel(lp, osdep);
-
- if (dkcksum(lp) != 0) {
- msg = "disk label corrupted";
- goto done;
- }
-
done:
if (bp) {
bp->b_flags |= B_INVAL;
brelse(bp);
}
- disklabeltokernlabel(lp);
return (msg);
}
@@ -144,37 +123,20 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *),
bp = geteblk((int)lp->d_secsize);
bp->b_dev = dev;
+ /* Read it in, slap the new label in, and write it back out */
bp->b_blkno = LABELSECTOR;
+ bp->b_cylinder = 0;
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ;
- bp->b_cylinder = 0; /* contained in block 0 */
(*strat)(bp);
-
- if ((error = biowait(bp)) != 0) {
- /* nothing */
- } else {
- bcopy(bp->b_data, osdep, sizeof(struct cpu_disklabel));
- }
-
- if (error)
+ if ((error = biowait(bp)) != 0)
goto done;
- bsdtocpulabel(lp, osdep);
+ bsdtocpulabel(lp, (struct mvmedisklabel *)bp->b_data);
- if (lp->d_magic == DISKMAGIC && lp->d_magic2 == DISKMAGIC &&
- dkcksum(lp) == 0) {
- bcopy(osdep, bp->b_data, sizeof(struct cpu_disklabel));
-
- /* request no partition relocation by driver on I/O operations */
- bp->b_dev = dev;
- bp->b_blkno = 0; /* contained in block 0 */
- bp->b_bcount = lp->d_secsize;
- bp->b_flags = B_BUSY | B_WRITE;
- bp->b_cylinder = 0; /* contained in block 0 */
- (*strat)(bp);
-
- error = biowait(bp);
- }
+ bp->b_flags = B_BUSY | B_WRITE;
+ (*strat)(bp);
+ error = biowait(bp);
done:
if (bp) {
@@ -185,7 +147,7 @@ done:
}
void
-bsdtocpulabel(struct disklabel *lp, struct cpu_disklabel *clp)
+bsdtocpulabel(struct disklabel *lp, struct mvmedisklabel *clp)
{
char *tmot = "MOTOROLA", *id = "M88K", *mot;
int i;
@@ -250,7 +212,7 @@ bsdtocpulabel(struct disklabel *lp, struct cpu_disklabel *clp)
}
void
-cputobsdlabel(struct disklabel *lp, struct cpu_disklabel *clp)
+cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
{
int i;
@@ -301,7 +263,6 @@ cputobsdlabel(struct disklabel *lp, struct cpu_disklabel *clp)
lp->d_spare[i] = clp->spare[i];
lp->d_magic2 = clp->magic2;
- lp->d_checksum = 0;
lp->d_npartitions = clp->partitions;
lp->d_bbsize = clp->bbsize;
lp->d_sbsize = clp->sbsize;
@@ -309,10 +270,19 @@ cputobsdlabel(struct disklabel *lp, struct cpu_disklabel *clp)
bcopy(clp->vid_4, &lp->d_partitions[0], sizeof(struct partition) * 4);
bcopy(clp->cfg_4, &lp->d_partitions[4], sizeof(struct partition) * 12);
- if (clp->version == 2)
- lp->d_version = 1;
- else
- lp->d_version = 0;
+ if (clp->version < 2) {
+ struct __partitionv0 *v0pp = (struct __partitionv0 *)lp->d_partitions;
+ struct partition *pp = lp->d_partitions;
+
+ for (i = 0; i < lp->d_npartitions; i++, pp++, v0pp++) {
+ pp->p_fragblock = DISKLABELV1_FFS_FRAGBLOCK(v0pp->
+ p_fsize, v0pp->p_frag);
+ pp->p_offseth = 0;
+ pp->p_sizeh = 0;
+ }
+ }
+ lp->d_version = 1;
+ lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
}