summaryrefslogtreecommitdiff
path: root/sys/arch/i386
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2006-10-20 23:47:44 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2006-10-20 23:47:44 +0000
commit35e93d666997c4a80c78d8a0545cefbaf5456d3c (patch)
tree2b7e91bd5ca551cb5c1d979862f0fa7a69e2eed8 /sys/arch/i386
parent8319e7ff3af89818c80d8c1ece069a0d01e1a25c (diff)
Try again with local variable to avoid alignment issues.
"The dosparts member of cpu_disklabel was not used for any persistant data. Eliminate it, and just use the data being read in while processing MBR and EBR records. Should be no functional change. ok weingart@ deraadt@"
Diffstat (limited to 'sys/arch/i386')
-rw-r--r--sys/arch/i386/i386/disksubr.c292
-rw-r--r--sys/arch/i386/include/disklabel.h3
2 files changed, 144 insertions, 151 deletions
diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c
index 17f8ba4c2d1..0cf29aaeefe 100644
--- a/sys/arch/i386/i386/disksubr.c
+++ b/sys/arch/i386/i386/disksubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disksubr.c,v 1.62 2006/10/18 20:09:38 deraadt Exp $ */
+/* $OpenBSD: disksubr.c,v 1.63 2006/10/20 23:47:42 krw Exp $ */
/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
/*
@@ -63,11 +63,14 @@ char *
readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
struct cpu_disklabel *osdep, int spoofonly)
{
- struct dos_partition *dp = osdep->dosparts, *dp2;
- struct buf *bp = NULL;
+ struct dos_partition dp[NDOSPART], *dp2;
struct disklabel *dlp;
+ unsigned long extoff = 0;
+ struct buf *bp = NULL;
+ daddr_t part_blkno = DOSBBSECTOR;
char *msg = NULL, *cp;
int dospartoff, cyl, i, ourpart = -1;
+ int wander = 1, n = 0, loop = 0;
/* minimal requirements for archetypal disk label */
if (lp->d_secsize < DEV_BSIZE)
@@ -92,133 +95,128 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
/* do dos partitions in the process of getting disklabel? */
dospartoff = 0;
cyl = LABELSECTOR / lp->d_secpercyl;
- if (dp) {
- daddr_t part_blkno = DOSBBSECTOR;
- unsigned long extoff = 0;
- int wander = 1, n = 0, loop = 0;
+ /*
+ * Read dos partition table, follow extended partitions.
+ * Map the partitions to disklabel entries i-p
+ */
+ while (wander && n < 8 && loop < 8) {
+ loop++;
+ wander = 0;
+ if (part_blkno < extoff)
+ part_blkno = extoff;
+
+ /* read boot record */
+ bp->b_blkno = part_blkno;
+ bp->b_bcount = lp->d_secsize;
+ bp->b_flags = B_BUSY | B_READ;
+ bp->b_cylinder = part_blkno / lp->d_secpercyl;
+ (*strat)(bp);
+
+ /* if successful, wander through dos partition table */
+ if (biowait(bp)) {
+ msg = "dos partition I/O error";
+ goto done;
+ }
+ bcopy(bp->b_data + DOSPARTOFF, dp, sizeof(dp));
+
+ if (ourpart == -1) {
+ /* Search for our MBR partition */
+ for (dp2=dp, i=0; i < NDOSPART && ourpart == -1;
+ i++, dp2++)
+ if (letoh32(dp2->dp_size) &&
+ dp2->dp_typ == DOSPTYP_OPENBSD)
+ ourpart = i;
+ if (ourpart == -1)
+ goto donot;
+ /*
+ * This is our MBR partition. need sector address
+ * for SCSI/IDE, cylinder for ESDI/ST506/RLL
+ */
+ dp2 = &dp[ourpart];
+ dospartoff = letoh32(dp2->dp_start) + part_blkno;
+ cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
+
+ /* XXX build a temporary disklabel */
+ lp->d_partitions[0].p_size = letoh32(dp2->dp_size);
+ lp->d_partitions[0].p_offset =
+ letoh32(dp2->dp_start) + part_blkno;
+ if (lp->d_ntracks == 0)
+ lp->d_ntracks = dp2->dp_ehd + 1;
+ if (lp->d_nsectors == 0)
+ lp->d_nsectors = DPSECT(dp2->dp_esect);
+ if (lp->d_secpercyl == 0)
+ lp->d_secpercyl = lp->d_ntracks *
+ lp->d_nsectors;
+ }
+donot:
/*
- * Read dos partition table, follow extended partitions.
- * Map the partitions to disklabel entries i-p
+ * In case the disklabel read below fails, we want to
+ * provide a fake label in i-p.
*/
- while (wander && n < 8 && loop < 8) {
- loop++;
- wander = 0;
- if (part_blkno < extoff)
- part_blkno = extoff;
-
- /* read boot record */
- bp->b_blkno = part_blkno;
- bp->b_bcount = lp->d_secsize;
- bp->b_flags = B_BUSY | B_READ;
- bp->b_cylinder = part_blkno / lp->d_secpercyl;
- (*strat)(bp);
-
- /* if successful, wander through dos partition table */
- if (biowait(bp)) {
- msg = "dos partition I/O error";
- goto done;
- }
- bcopy(bp->b_data + DOSPARTOFF, dp, NDOSPART * sizeof(*dp));
-
- if (ourpart == -1) {
- /* Search for our MBR partition */
- for (dp2=dp, i=0; i < NDOSPART && ourpart == -1;
- i++, dp2++)
- if (letoh32(dp2->dp_size) &&
- dp2->dp_typ == DOSPTYP_OPENBSD)
- ourpart = i;
- if (ourpart == -1)
- goto donot;
+ for (dp2=dp, i=0; i < NDOSPART && n < 8; i++, dp2++) {
+ struct partition *pp = &lp->d_partitions[8+n];
+
+ if (dp2->dp_typ == DOSPTYP_OPENBSD)
+ continue;
+ if (letoh32(dp2->dp_size) > lp->d_secperunit)
+ continue;
+ if (letoh32(dp2->dp_size))
+ pp->p_size = letoh32(dp2->dp_size);
+ if (letoh32(dp2->dp_start))
+ pp->p_offset =
+ letoh32(dp2->dp_start) + part_blkno;
+
+ switch (dp2->dp_typ) {
+ case DOSPTYP_UNUSED:
+ for (cp = (char *)dp2;
+ cp < (char *)(dp2 + 1); cp++)
+ if (*cp)
+ break;
/*
- * This is our MBR partition. need sector address
- * for SCSI/IDE, cylinder for ESDI/ST506/RLL
+ * Was it all zeroes? If so, it is
+ * an unused entry that we don't
+ * want to show.
*/
- dp2 = &dp[ourpart];
- dospartoff = letoh32(dp2->dp_start) + part_blkno;
- cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
-
- /* XXX build a temporary disklabel */
- lp->d_partitions[0].p_size = letoh32(dp2->dp_size);
- lp->d_partitions[0].p_offset =
- letoh32(dp2->dp_start) + part_blkno;
- if (lp->d_ntracks == 0)
- lp->d_ntracks = dp2->dp_ehd + 1;
- if (lp->d_nsectors == 0)
- lp->d_nsectors = DPSECT(dp2->dp_esect);
- if (lp->d_secpercyl == 0)
- lp->d_secpercyl = lp->d_ntracks *
- lp->d_nsectors;
- }
-donot:
- /*
- * In case the disklabel read below fails, we want to
- * provide a fake label in i-p.
- */
- for (dp2=dp, i=0; i < NDOSPART && n < 8; i++, dp2++) {
- struct partition *pp = &lp->d_partitions[8+n];
-
- if (dp2->dp_typ == DOSPTYP_OPENBSD)
- continue;
- if (letoh32(dp2->dp_size) > lp->d_secperunit)
- continue;
- if (letoh32(dp2->dp_size))
- pp->p_size = letoh32(dp2->dp_size);
- if (letoh32(dp2->dp_start))
- pp->p_offset =
- letoh32(dp2->dp_start) + part_blkno;
-
- switch (dp2->dp_typ) {
- case DOSPTYP_UNUSED:
- for (cp = (char *)dp2;
- cp < (char *)(dp2 + 1); cp++)
- if (*cp)
- break;
- /*
- * Was it all zeroes? If so, it is
- * an unused entry that we don't
- * want to show.
- */
- if (cp == (char *)(dp2 + 1))
- continue;
- lp->d_partitions[8 + n++].p_fstype =
- FS_UNUSED;
- break;
-
- case DOSPTYP_LINUX:
- pp->p_fstype = FS_EXT2FS;
- n++;
- break;
-
- case DOSPTYP_FAT12:
- case DOSPTYP_FAT16S:
- case DOSPTYP_FAT16B:
- case DOSPTYP_FAT32:
- case DOSPTYP_FAT32L:
- case DOSPTYP_FAT16L:
- pp->p_fstype = FS_MSDOS;
- n++;
- break;
- case DOSPTYP_EXTEND:
- case DOSPTYP_EXTENDL:
- part_blkno = letoh32(dp2->dp_start) + extoff;
- if (!extoff) {
- extoff = letoh32(dp2->dp_start);
- part_blkno = 0;
- }
- wander = 1;
- break;
- default:
- pp->p_fstype = FS_OTHER;
- n++;
- break;
+ if (cp == (char *)(dp2 + 1))
+ continue;
+ lp->d_partitions[8 + n++].p_fstype =
+ FS_UNUSED;
+ break;
+
+ case DOSPTYP_LINUX:
+ pp->p_fstype = FS_EXT2FS;
+ n++;
+ break;
+
+ case DOSPTYP_FAT12:
+ case DOSPTYP_FAT16S:
+ case DOSPTYP_FAT16B:
+ case DOSPTYP_FAT32:
+ case DOSPTYP_FAT32L:
+ case DOSPTYP_FAT16L:
+ pp->p_fstype = FS_MSDOS;
+ n++;
+ break;
+ case DOSPTYP_EXTEND:
+ case DOSPTYP_EXTENDL:
+ part_blkno = letoh32(dp2->dp_start) + extoff;
+ if (!extoff) {
+ extoff = letoh32(dp2->dp_start);
+ part_blkno = 0;
}
+ wander = 1;
+ break;
+ default:
+ pp->p_fstype = FS_OTHER;
+ n++;
+ break;
}
}
- lp->d_bbsize = 8192;
- lp->d_sbsize = 64*1024; /* XXX ? */
- lp->d_npartitions = MAXPARTITIONS;
}
+ lp->d_bbsize = 8192;
+ lp->d_sbsize = 64*1024; /* XXX ? */
+ lp->d_npartitions = MAXPARTITIONS;
/* don't read the on-disk label if we are in spoofed-only mode */
if (spoofonly)
@@ -262,7 +260,6 @@ donot:
if (msg && udf_disklabelspoof(dev, strat, lp) == 0)
msg = NULL;
#endif
- goto done;
}
done:
@@ -336,9 +333,9 @@ int
writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
struct cpu_disklabel *osdep)
{
- struct dos_partition *dp = osdep->dosparts, *dp2;
- struct buf *bp;
+ struct dos_partition dp[NDOSPART], *dp2;
struct disklabel *dlp;
+ struct buf *bp;
int error, dospartoff, cyl, i;
int ourpart = -1;
@@ -349,35 +346,33 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
/* do dos partitions in the process of getting disklabel? */
dospartoff = 0;
cyl = LABELSECTOR / lp->d_secpercyl;
- if (dp) {
- /* read master boot record */
- bp->b_blkno = DOSBBSECTOR;
- bp->b_bcount = lp->d_secsize;
- bp->b_flags = B_BUSY | B_READ;
- bp->b_cylinder = DOSBBSECTOR / lp->d_secpercyl;
- (*strat)(bp);
- if ((error = biowait(bp)) != 0)
- goto done;
+ /* read master boot record */
+ bp->b_blkno = DOSBBSECTOR;
+ bp->b_bcount = lp->d_secsize;
+ bp->b_flags = B_BUSY | B_READ;
+ bp->b_cylinder = DOSBBSECTOR / lp->d_secpercyl;
+ (*strat)(bp);
- /* XXX how do we check veracity/bounds of this? */
- bcopy(bp->b_data + DOSPARTOFF, dp,
- NDOSPART * sizeof(*dp));
+ if ((error = biowait(bp)) != 0)
+ goto done;
- for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++)
- if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD)
- ourpart = i;
+ /* XXX how do we check veracity/bounds of this? */
+ bcopy(bp->b_data + DOSPARTOFF, dp, sizeof(dp));
- if (ourpart != -1) {
- dp2 = &dp[ourpart];
+ for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++)
+ if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD)
+ ourpart = i;
- /*
- * need sector address for SCSI/IDE,
- * cylinder for ESDI/ST506/RLL
- */
- dospartoff = letoh32(dp2->dp_start);
- cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
- }
+ if (ourpart != -1) {
+ dp2 = &dp[ourpart];
+
+ /*
+ * need sector address for SCSI/IDE,
+ * cylinder for ESDI/ST506/RLL
+ */
+ dospartoff = letoh32(dp2->dp_start);
+ cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect);
}
/* next, dig out disk label */
@@ -408,7 +403,6 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp,
bp->b_flags = B_BUSY | B_WRITE;
(*strat)(bp);
error = biowait(bp);
- goto done;
done:
bp->b_flags |= B_INVAL;
diff --git a/sys/arch/i386/include/disklabel.h b/sys/arch/i386/include/disklabel.h
index 953a5d4c148..5a960c6dfb7 100644
--- a/sys/arch/i386/include/disklabel.h
+++ b/sys/arch/i386/include/disklabel.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.h,v 1.31 2006/10/18 20:09:38 deraadt Exp $ */
+/* $OpenBSD: disklabel.h,v 1.32 2006/10/20 23:47:42 krw Exp $ */
/* $NetBSD: disklabel.h,v 1.3 1996/03/09 20:52:54 ghudson Exp $ */
/*
@@ -85,7 +85,6 @@ struct dos_mbr {
#define DOSMBR_SIGNATURE_OFF (0x1fe)
struct cpu_disklabel {
- struct dos_partition dosparts[NDOSPART];
};
/* Isolate the relevant bits to get sector and cylinder. */