diff options
22 files changed, 1484 insertions, 1561 deletions
diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index 7321adf2701..ebd2c79cbc6 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.57 2006/10/10 03:17:45 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.58 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -218,9 +218,12 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) int *cylp; int spoofonly; { - struct dos_partition *dp = osdep->u._i386.dosparts, *dp2; + struct dos_partition *dp, *dp2; + unsigned long extoff = 0; + daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL, *cp; int dospartoff, cyl, i, ourpart = -1; + int wander = 1, n = 0, loop = 0; if (lp->d_secpercyl == 0) { msg = "invalid label, d_secpercyl == 0"; @@ -234,138 +237,132 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) /* do dos partitions in the process of getting disklabel? */ dospartoff = 0; cyl = I386_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"; + if (partoffp) + *partoffp = -1; + return (msg); + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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"; - if (partoffp) - *partoffp = -1; - return (msg); - } - 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); + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; - /* 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; + 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 = n > 0 ? n + 8 : 3; } + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = n > 0 ? n + 8 : 3; /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/alpha/include/disklabel.h b/sys/arch/alpha/include/disklabel.h index a78d7d69cef..98d471dd846 100644 --- a/sys/arch/alpha/include/disklabel.h +++ b/sys/arch/alpha/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.16 2006/10/04 00:52:55 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.17 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.1 1995/02/13 23:07:34 cgd Exp $ */ /* @@ -88,13 +88,6 @@ struct dos_partition { struct cpu_disklabel { int labelsector; - union { - struct { - } _alpha; - struct { - struct dos_partition dosparts[NDOSPART]; - } _i386; - } u; }; #endif /* _MACHINE_DISKLABEL_H_ */ diff --git a/sys/arch/amd64/amd64/disksubr.c b/sys/arch/amd64/amd64/disksubr.c index a69436e2847..39774fc600c 100644 --- a/sys/arch/amd64/amd64/disksubr.c +++ b/sys/arch/amd64/amd64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.18 2006/10/12 00:25:19 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.19 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,11 +67,14 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct cpu_disklabel *osdep; int spoofonly; { - struct dos_partition *dp = osdep->dosparts, *dp2; - struct buf *bp = NULL; + struct dos_partition *dp, *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) @@ -96,133 +99,128 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) /* 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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) @@ -345,7 +343,7 @@ writedisklabel(dev, strat, lp, osdep) register struct disklabel *lp; struct cpu_disklabel *osdep; { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -358,35 +356,33 @@ writedisklabel(dev, strat, lp, osdep) /* 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); + + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ diff --git a/sys/arch/amd64/include/disklabel.h b/sys/arch/amd64/include/disklabel.h index a326912037d..0e8b46bb451 100644 --- a/sys/arch/amd64/include/disklabel.h +++ b/sys/arch/amd64/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.5 2006/10/04 00:52:55 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.6 2006/10/17 23:42:37 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. */ diff --git a/sys/arch/arm/arm/disksubr.c b/sys/arch/arm/arm/disksubr.c index db214fd2551..5d4329fff42 100644 --- a/sys/arch/arm/arm/disksubr.c +++ b/sys/arch/arm/arm/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.16 2006/10/12 00:25:19 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.17 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,11 +67,14 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct cpu_disklabel *osdep; int spoofonly; { - struct dos_partition *dp = osdep->dosparts, *dp2; - struct buf *bp = NULL; + struct dos_partition *dp, *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) @@ -96,132 +99,127 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) /* 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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: - 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: + 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) @@ -344,7 +342,7 @@ writedisklabel(dev, strat, lp, osdep) register struct disklabel *lp; struct cpu_disklabel *osdep; { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -357,35 +355,33 @@ writedisklabel(dev, strat, lp, osdep) /* 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); + + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ @@ -416,7 +412,6 @@ writedisklabel(dev, strat, lp, osdep) 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/arm/include/disklabel.h b/sys/arch/arm/include/disklabel.h index 661beeb89aa..bc31960687a 100644 --- a/sys/arch/arm/include/disklabel.h +++ b/sys/arch/arm/include/disklabel.h @@ -1,5 +1,5 @@ -/* $OpenBSD: disklabel.h,v 1.8 2006/10/04 03:30:48 krw Exp $ */ -/* $OpenBSD: disklabel.h,v 1.8 2006/10/04 03:30:48 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.9 2006/10/17 23:42:37 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.9 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.2 2001/11/25 19:02:03 thorpej Exp $ */ /* @@ -105,7 +105,6 @@ struct dos_partition { struct cpu_disklabel { - struct dos_partition dosparts[NDOSPART]; }; #endif /* _ARM_DISKLABEL_H_ */ diff --git a/sys/arch/aviion/aviion/disksubr.c b/sys/arch/aviion/aviion/disksubr.c index 2ee724cb487..201c58595bb 100644 --- a/sys/arch/aviion/aviion/disksubr.c +++ b/sys/arch/aviion/aviion/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.7 2006/10/04 03:23:01 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.8 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,11 +67,14 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct cpu_disklabel *osdep; int spoofonly; { - struct dos_partition *dp = osdep->dosparts, *dp2; - struct buf *bp = NULL; + struct dos_partition *dp, *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) @@ -96,132 +99,127 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) /* 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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: - 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: + 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) @@ -265,7 +263,6 @@ donot: if (msg && udf_disklabelspoof(dev, strat, lp) == 0) msg = NULL; #endif - goto done; } done: @@ -344,7 +341,7 @@ writedisklabel(dev, strat, lp, osdep) register struct disklabel *lp; struct cpu_disklabel *osdep; { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -357,35 +354,32 @@ writedisklabel(dev, strat, lp, osdep) /* 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); + /* 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; + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ @@ -416,7 +410,6 @@ writedisklabel(dev, strat, lp, osdep) 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/aviion/include/disklabel.h b/sys/arch/aviion/include/disklabel.h index 061b43f4543..56b20afa8fd 100644 --- a/sys/arch/aviion/include/disklabel.h +++ b/sys/arch/aviion/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.4 2006/10/03 01:37:22 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.5 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.2 2001/11/25 19:02:03 thorpej Exp $ */ /* @@ -96,7 +96,6 @@ struct dos_partition { #define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2)) struct cpu_disklabel { - struct dos_partition dosparts[NDOSPART]; }; #endif /* _AVIION_DISKLABEL_H_ */ diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index 912c18c733b..0e93c66d57c 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.37 2006/10/10 03:17:45 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.38 2006/10/17 23:42:37 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -221,9 +221,12 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) int *cylp; int spoofonly; { - struct dos_partition *dp = osdep->u._i386.dosparts, *dp2; + struct dos_partition *dp, *dp2; + unsigned long extoff = 0; + daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL, *cp; int dospartoff, cyl, i, ourpart = -1; + int wander = 1, n = 0, loop = 0; if (lp->d_secpercyl == 0) { msg = "invalid label, d_secpercyl == 0"; @@ -237,138 +240,132 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) /* do dos partitions in the process of getting disklabel? */ dospartoff = 0; cyl = I386_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"; + if (partoffp) + *partoffp = -1; + return (msg); + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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"; - if (partoffp) - *partoffp = -1; - return (msg); - } - 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); + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; - /* 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]; + case DOSPTYP_LINUX: + pp->p_fstype = FS_EXT2FS; + n++; + break; - 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; + 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 = n > 0 ? n + 8 : 3; } + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = n > 0 ? n + 8 : 3; /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/hppa/include/disklabel.h b/sys/arch/hppa/include/disklabel.h index c5652c1c816..d6df714beb0 100644 --- a/sys/arch/hppa/include/disklabel.h +++ b/sys/arch/hppa/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.13 2006/10/04 00:52:55 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.14 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.1 1995/02/13 23:07:34 cgd Exp $ */ /* @@ -179,9 +179,6 @@ struct cpu_disklabel { int labelsector; union { struct { - struct dos_partition dosparts[NDOSPART]; - } _i386; - struct { struct lifvol lifvol; struct lifdir lifdir[LIF_NUMDIR]; struct hpux_label hplabel; diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c index 95dbc857b35..ebcfbae1b20 100644 --- a/sys/arch/hppa64/hppa64/disksubr.c +++ b/sys/arch/hppa64/hppa64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.20 2006/10/10 03:17:45 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.21 2006/10/17 23:42:37 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -217,9 +217,12 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) int *cylp; int spoofonly; { - struct dos_partition *dp = osdep->u._i386.dosparts, *dp2; + struct dos_partition *dp, *dp2; + unsigned long extoff = 0; + daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL, *cp; int dospartoff, cyl, i, ourpart = -1; + int wander = 1, n = 0, loop = 0; if (lp->d_secpercyl == 0) { msg = "invalid label, d_secpercyl == 0"; @@ -233,138 +236,132 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) /* do dos partitions in the process of getting disklabel? */ dospartoff = 0; cyl = I386_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"; + if (partoffp) + *partoffp = -1; + return (msg); + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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"; - if (partoffp) - *partoffp = -1; - return (msg); - } - 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); + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; - /* 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]; + case DOSPTYP_LINUX: + pp->p_fstype = FS_EXT2FS; + n++; + break; - 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; + 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 = n > 0 ? n + 8 : 3; } + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = n > 0 ? n + 8 : 3; /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/hppa64/include/disklabel.h b/sys/arch/hppa64/include/disklabel.h index ef2437b2500..fa058bf0c5a 100644 --- a/sys/arch/hppa64/include/disklabel.h +++ b/sys/arch/hppa64/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.7 2006/10/03 01:37:22 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.8 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.1 1995/02/13 23:07:34 cgd Exp $ */ /* @@ -179,9 +179,6 @@ struct cpu_disklabel { int labelsector; union { struct { - struct dos_partition dosparts[NDOSPART]; - } _i386; - struct { struct lifvol lifvol; struct lifdir lifdir[LIF_NUMDIR]; struct hpux_label hplabel; diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c index a416edda3af..2a5be3212a4 100644 --- a/sys/arch/i386/i386/disksubr.c +++ b/sys/arch/i386/i386/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.60 2006/10/12 00:25:20 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.61 2006/10/17 23:42:37 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, *dp2; + unsigned long extoff = 0; struct disklabel *dlp; + 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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,7 +333,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *osdep) { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -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? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - 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 63f38be5bf6..699ca533fe6 100644 --- a/sys/arch/i386/include/disklabel.h +++ b/sys/arch/i386/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.29 2006/10/04 00:52:55 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.30 2006/10/17 23:42:37 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. */ diff --git a/sys/arch/landisk/landisk/disksubr.c b/sys/arch/landisk/landisk/disksubr.c index 6c21b778da0..e465f1b3311 100644 --- a/sys/arch/landisk/landisk/disksubr.c +++ b/sys/arch/landisk/landisk/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.4 2006/10/12 00:25:20 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.5 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,11 +67,14 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct cpu_disklabel *osdep; int spoofonly; { - struct dos_partition *dp = osdep->dosparts, *dp2; - struct buf *bp = NULL; + struct dos_partition *dp, *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) @@ -96,132 +99,127 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) /* 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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: - 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: + 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) @@ -344,7 +342,7 @@ writedisklabel(dev, strat, lp, osdep) register struct disklabel *lp; struct cpu_disklabel *osdep; { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -357,35 +355,33 @@ writedisklabel(dev, strat, lp, osdep) /* 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); + + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ @@ -416,7 +412,6 @@ writedisklabel(dev, strat, lp, osdep) 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/macppc/include/disklabel.h b/sys/arch/macppc/include/disklabel.h index eae1308c265..70bc81f47ae 100644 --- a/sys/arch/macppc/include/disklabel.h +++ b/sys/arch/macppc/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.8 2006/10/04 00:52:55 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.9 2006/10/17 23:42:37 krw Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -134,7 +134,6 @@ struct part_map_entry { struct cpu_disklabel { - struct dos_partition dosparts[NDOSPART]; /* only store first entry and openbsd partition */ struct part_map_entry macparts[2]; }; diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index 9448a263fb7..832e425bd21 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.26 2006/10/12 00:25:20 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.27 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -66,12 +66,15 @@ 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; + struct dos_partition *dp, *dp2; struct disklabel *dlp; + unsigned long extoff = 0; + struct buf *bp; + daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL, *cp; char *s; int dospartoff, cyl, i, ourpart = -1; + int wander = 1, loop = 0; /* HFS variables */ int part_cnt, n, hfspartoff; struct part_map_entry *part; @@ -178,137 +181,131 @@ hfs_done: /* 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, loop = 0; - n = 0; + n = 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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); + 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; - /* 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; + 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_FAT16L: - case DOSPTYP_FAT32: - 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_FAT16L: + case DOSPTYP_FAT32: + 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) @@ -427,7 +424,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct cpu_disklabel *osdep) { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -461,36 +458,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); + /* 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; + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == - DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ @@ -522,7 +516,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/mips64/include/disklabel.h b/sys/arch/mips64/include/disklabel.h index d847519c48c..16d1a1cdbba 100644 --- a/sys/arch/mips64/include/disklabel.h +++ b/sys/arch/mips64/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.9 2006/10/03 01:37:22 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.10 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.1 1995/02/13 23:07:34 cgd Exp $ */ /* @@ -149,11 +149,6 @@ struct sgilabel { struct cpu_disklabel { int labelsector; - union { - struct { - struct dos_partition dosparts[NDOSPART]; - } _i386; - } u; }; #endif /* _MACHINE_DISKLABEL_H_ */ diff --git a/sys/arch/mips64/mips64/disksubr.c b/sys/arch/mips64/mips64/disksubr.c index c7433bdb1f3..14217544ce9 100644 --- a/sys/arch/mips64/mips64/disksubr.c +++ b/sys/arch/mips64/mips64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.26 2006/10/10 03:17:45 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.27 2006/10/17 23:42:37 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -225,9 +225,12 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) int *cylp; int spoofonly; { - struct dos_partition *dp = osdep->u._i386.dosparts, *dp2; + struct dos_partition *dp, *dp2; + unsigned long extoff = 0; + daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL, *cp; int dospartoff, cyl, i, ourpart = -1; + int wander = 1, n = 0, loop = 0; if (lp->d_secpercyl == 0) { msg = "invalid label, d_secpercyl == 0"; @@ -241,138 +244,132 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) /* do dos partitions in the process of getting disklabel? */ dospartoff = 0; cyl = I386_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"; + if (partoffp) + *partoffp = -1; + return (msg); + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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"; - if (partoffp) - *partoffp = -1; - return (msg); - } - 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); + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; - /* 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; + 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 = n > 0 ? n + 8 : 3; } + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = n > 0 ? n + 8 : 3; /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/mvmeppc/include/disklabel.h b/sys/arch/mvmeppc/include/disklabel.h index f8ce2503b3a..d667d3c48dd 100644 --- a/sys/arch/mvmeppc/include/disklabel.h +++ b/sys/arch/mvmeppc/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.7 2006/10/03 01:37:22 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.8 2006/10/17 23:42:37 krw Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -79,7 +79,6 @@ struct dos_partition { #define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */ struct cpu_disklabel { - struct dos_partition dosparts[NDOSPART]; }; /* Isolate the relevant bits to get sector and cylinder. */ diff --git a/sys/arch/mvmeppc/mvmeppc/disksubr.c b/sys/arch/mvmeppc/mvmeppc/disksubr.c index c76072cd392..b6912d7eafb 100644 --- a/sys/arch/mvmeppc/mvmeppc/disksubr.c +++ b/sys/arch/mvmeppc/mvmeppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.22 2006/10/12 00:25:20 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.23 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -70,11 +70,14 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct cpu_disklabel *osdep; int spoofonly; { - struct dos_partition *dp = osdep->dosparts, *dp2; - struct buf *bp; + struct dos_partition *dp, *dp2; struct disklabel *dlp; + unsigned long extoff = 0; + struct buf *bp; + 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) @@ -99,132 +102,127 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) /* 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; + } + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); + + 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_FAT16L: - case DOSPTYP_FAT32: - 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_FAT16L: + case DOSPTYP_FAT32: + 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) @@ -345,7 +343,7 @@ writedisklabel(dev, strat, lp, osdep) register struct disklabel *lp; struct cpu_disklabel *osdep; { - struct dos_partition *dp = osdep->dosparts, *dp2; + struct dos_partition *dp, *dp2; struct buf *bp; struct disklabel *dlp; int error, dospartoff, cyl, i; @@ -358,35 +356,32 @@ writedisklabel(dev, strat, lp, osdep) /* 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); + /* 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; + if ((error = biowait(bp)) != 0) + goto done; - /* XXX how do we check veracity/bounds of this? */ - bcopy(bp->b_data + DOSPARTOFF, dp, - NDOSPART * sizeof(*dp)); + /* XXX how do we check veracity/bounds of this? */ + dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF); - for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) - if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) - ourpart = i; + 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) { - dp2 = &dp[ourpart]; + 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); - } + /* + * 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 */ @@ -417,7 +412,6 @@ writedisklabel(dev, strat, lp, osdep) 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/sh/include/disklabel.h b/sys/arch/sh/include/disklabel.h index 55167f8f181..0163179f532 100644 --- a/sys/arch/sh/include/disklabel.h +++ b/sys/arch/sh/include/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.2 2006/10/06 22:26:29 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.3 2006/10/17 23:42:37 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.2 2001/11/25 19:02:03 thorpej Exp $ */ /* @@ -104,7 +104,6 @@ struct dos_partition { struct cpu_disklabel { - struct dos_partition dosparts[NDOSPART]; }; #endif /* _ARM_DISKLABEL_H_ */ |