summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2009-06-04 21:13:00 +0000
committerderaadt <deraadt@openbsd.org>2009-06-04 21:13:00 +0000
commit6534e983a084d72c31637f2b153022fcee93c492 (patch)
treedf9dcba3e6b8a3c72caa7d98a77622d1a81b6fee /sys/kern/subr_disk.c
parenttiny tiny space nit (diff)
downloadwireguard-openbsd-6534e983a084d72c31637f2b153022fcee93c492.tar.xz
wireguard-openbsd-6534e983a084d72c31637f2b153022fcee93c492.zip
Recycle four ancient fields in the disklabel structure, replacing them with
bounds information, ie. the zone of the disk that OpenBSD can use. Have each pre-disklabel parser (MBR, DPME, or per-arch MD disklabel parsers) figure out this area and pass it up to userland. Then, delete all the same disk parsing code from disklabel(8) since the kernel passes it up. Lots and lots of - signs in the disklabel(8) code. Tested on as many platforms as possible, the fallout will be repaired as time goes on. To test, use disklabel -d <drive> and validate that the bounds do not overlap any boot blocks. This same information is used by disklabel -A... OK for the concept from krw, miod, and drahn
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 81d7da5e4fe..435db496073 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.91 2009/06/03 22:09:30 thib Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.92 2009/06/04 21:13:02 deraadt Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -209,6 +209,8 @@ initdisklabel(struct disklabel *lp)
if (DL_GETPSIZE(&lp->d_partitions[RAW_PART]) == 0)
DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
+ DL_SETBSTART(lp, 0);
+ DL_SETBEND(lp, DL_GETDSIZE(lp));
lp->d_version = 1;
lp->d_bbsize = 8192;
lp->d_sbsize = 64*1024; /* XXX ? */
@@ -220,7 +222,8 @@ initdisklabel(struct disklabel *lp)
* a newer version if needed, etc etc.
*/
char *
-checkdisklabel(void *rlp, struct disklabel *lp)
+checkdisklabel(void *rlp, struct disklabel *lp,
+ u_int64_t boundstart, u_int64_t boundend)
{
struct disklabel *dlp = rlp;
struct __partitionv0 *v0pp;
@@ -281,10 +284,6 @@ checkdisklabel(void *rlp, struct disklabel *lp)
dlp->d_rpm = swap16(dlp->d_rpm);
dlp->d_interleave = swap16(dlp->d_interleave);
- dlp->d_trackskew = swap16(dlp->d_trackskew);
- dlp->d_cylskew = swap16(dlp->d_cylskew);
- dlp->d_headswitch = swap32(dlp->d_headswitch);
- dlp->d_trkseek = swap32(dlp->d_trkseek);
dlp->d_flags = swap32(dlp->d_flags);
for (i = 0; i < NDDATA; i++)
@@ -361,6 +360,8 @@ checkdisklabel(void *rlp, struct disklabel *lp)
DL_SETDSIZE(lp, disksize);
DL_SETPSIZE(&lp->d_partitions[RAW_PART], disksize);
DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
+ DL_SETBSTART(lp, boundstart);
+ DL_SETBEND(lp, boundend);
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
@@ -380,12 +381,11 @@ char *
readdoslabel(struct buf *bp, void (*strat)(struct buf *),
struct disklabel *lp, int *partoffp, int spoofonly)
{
+ u_int64_t dospartoff = 0, dospartend = DL_GETBEND(lp);
+ int i, ourpart = -1, wander = 1, n = 0, loop = 0, offset;
struct dos_partition dp[NDOSPART], *dp2;
- u_int32_t extoff = 0;
daddr64_t part_blkno = DOSBBSECTOR;
- int dospartoff = 0, i, ourpart = -1;
- int wander = 1, n = 0, loop = 0;
- int offset;
+ u_int32_t extoff = 0;
if (lp->d_secpercyl == 0)
return ("invalid label, d_secpercyl == 0");
@@ -444,6 +444,7 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *),
*/
dp2 = &dp[ourpart];
dospartoff = letoh32(dp2->dp_start) + part_blkno;
+ dospartend = dospartoff + letoh32(dp2->dp_size);
/* found our OpenBSD partition, finish up */
if (partoffp)
@@ -574,6 +575,8 @@ donot:
lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS;
}
notfat:
+ DL_SETBSTART(lp, dospartoff);
+ DL_SETBEND(lp, dospartend);
/* record the OpenBSD partition's placement for the caller */
if (partoffp)
@@ -593,7 +596,7 @@ notfat:
return ("disk label I/O error");
/* sub-MBR disklabels are always at a LABELOFFSET of 0 */
- return checkdisklabel(bp->b_data + offset, lp);
+ return checkdisklabel(bp->b_data + offset, lp, dospartoff, dospartend);
}
/*