diff options
author | 2009-06-04 21:13:00 +0000 | |
---|---|---|
committer | 2009-06-04 21:13:00 +0000 | |
commit | 6534e983a084d72c31637f2b153022fcee93c492 (patch) | |
tree | df9dcba3e6b8a3c72caa7d98a77622d1a81b6fee | |
parent | tiny tiny space nit (diff) | |
download | wireguard-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
-rw-r--r-- | lib/libc/gen/disklabel.c | 4 | ||||
-rw-r--r-- | sbin/disklabel/Makefile | 8 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 295 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 65 | ||||
-rw-r--r-- | sbin/disklabel/extern.h | 10 | ||||
-rw-r--r-- | sys/arch/alpha/alpha/disksubr.c | 4 | ||||
-rw-r--r-- | sys/arch/hp300/hp300/disksubr.c | 4 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/disksubr.c | 8 | ||||
-rw-r--r-- | sys/arch/luna88k/luna88k/disksubr.c | 6 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 16 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/disksubr.c | 8 | ||||
-rw-r--r-- | sys/arch/socppc/socppc/disksubr.c | 16 | ||||
-rw-r--r-- | sys/arch/sparc/sparc/disksubr.c | 12 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/disksubr.c | 6 | ||||
-rw-r--r-- | sys/arch/vax/vax/disksubr.c | 6 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 25 | ||||
-rw-r--r-- | sys/sys/disklabel.h | 34 |
17 files changed, 116 insertions, 411 deletions
diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index 539e422ebd1..402665c8f70 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -97,10 +97,6 @@ getdiskbyname(const char *name) getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); getnumdflt(dp->d_rpm, "rm", 3600); getnumdflt(dp->d_interleave, "il", 1); - getnumdflt(dp->d_trackskew, "sk", 0); - getnumdflt(dp->d_cylskew, "cs", 0); - getnumdflt(dp->d_headswitch, "hs", 0); - getnumdflt(dp->d_trkseek, "ts", 0); getnumdflt(dp->d_bbsize, "bs", BBSIZE); getnumdflt(dp->d_sbsize, "sb", SBSIZE); strlcpy(psize, "px", sizeof psize); diff --git a/sbin/disklabel/Makefile b/sbin/disklabel/Makefile index a3c6796f805..ed86f845aa3 100644 --- a/sbin/disklabel/Makefile +++ b/sbin/disklabel/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.49 2009/01/11 19:44:57 miod Exp $ +# $OpenBSD: Makefile,v 1.50 2009/06/04 21:13:03 deraadt Exp $ PROG= disklabel SRCS= disklabel.c dkcksum.c editor.c manual.c @@ -28,12 +28,10 @@ CFLAGS+= -DSEEALSO="\"fdisk(8), installboot(8)\"" .endif .if (${MACHINE} == "amd64") || (${MACHINE} == "i386") -CFLAGS+= -DDOSLABEL CFLAGS+= -DSEEALSO="\"fdisk(8), installboot(8)\"" .endif .if (${MACHINE} == "armish") -CFLAGS+= -DDOSLABEL CFLAGS+= -DSEEALSO="\"fdisk(8)\"" .endif @@ -43,12 +41,11 @@ CFLAGS+= -DNUMBOOT=1 .endif .if (${MACHINE} == "landisk") -CFLAGS+= -DNUMBOOT=1 -DDOSLABEL +CFLAGS+= -DNUMBOOT=1 CFLAGS+= -DSEEALSO="\"fdisk(8)\"" .endif .if (${MACHINE} == "macppc" || ${MACHINE} == "socppc") -CFLAGS+= -DDOSLABEL -DDPMELABEL CFLAGS+= -DSEEALSO="\"fdisk(8), pdisk(8)\"" .endif @@ -62,7 +59,6 @@ CFLAGS+= -DSEEALSO="\"installboot(8)\"" -DSUN_CYLCHECK -DSUN_AAT0 .endif .if (${MACHINE} == "zaurus") -CFLAGS+= -DDOSLABEL CFLAGS+= -DSEEALSO="\"fdisk(8)\"" .endif diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index adef2b2cd97..1133519c7bb 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.157 2009/06/02 16:23:45 krw Exp $ */ +/* $OpenBSD: disklabel.c,v 1.158 2009/06/04 21:13:03 deraadt Exp $ */ /* * Copyright (c) 1987, 1993 @@ -39,7 +39,7 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint -static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.157 2009/06/02 16:23:45 krw Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.158 2009/06/04 21:13:03 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -112,18 +112,6 @@ int verbose; int donothing; char print_unit; -#ifdef DOSLABEL -struct dos_partition *dosdp; /* DOS partition, if found */ -struct dos_partition *findopenbsd(int, off_t, struct dos_partition **, int *); -struct dos_partition *readmbr(int); -#endif - -#ifdef DPMELABEL -int dpme_label = 0; -uint32_t dpme_obsd_start, dpme_obsd_size; -int check_dpme(int, uint32_t *, uint32_t *); -#endif - void makedisktab(FILE *, struct disklabel *); void makelabel(char *, char *, struct disklabel *); int writelabel(int, char *, struct disklabel *); @@ -258,26 +246,6 @@ main(int argc, char *argv[]) endfsent(); free(partname); -#ifdef DOSLABEL - /* - * Check for presence of DOS partition table in - * master boot record. Return pointer to OpenBSD - * partition, if present. If no valid partition table, - * return NULL. If valid partition table present, but no - * partition to use, return a pointer to a non-386bsd - * partition. - */ - dosdp = readmbr(f); -#endif - -#ifdef DPMELABEL - /* - * Check for a MacOS DPME partition table, and find out the - * area of the OpenBSD DPME partition, if any. - */ - dpme_label = check_dpme(f, &dpme_obsd_start, &dpme_obsd_size); -#endif - switch (op) { case EDIT: if (argc != 1) @@ -413,35 +381,6 @@ writelabel(int f, char *boot, struct disklabel *lp) lp->d_checksum = dkcksum(lp); #if NUMBOOT > 0 if (installboot) { -#ifdef DOSLABEL - struct partition *pp = &lp->d_partitions[2]; - - /* - * If OpenBSD DOS partition is missing, or if - * the label to be written is not within partition, - * prompt first. Need to allow this in case operator - * wants to convert the drive for dedicated use. - * In this case, partition 'a' had better start at 0, - * otherwise we reject the request as meaningless. -wfj - */ - if (dosdp && DL_GETPSIZE(pp) && (dosdp->dp_typ == DOSPTYP_OPENBSD)) { - sectoffset = (off_t)letoh32(dosdp->dp_start) * - lp->d_secsize; - } else { - if (dosdp) { - int first, ch; - - printf("Erase the previous contents of the disk? [n]: "); - fflush(stdout); - first = ch = getchar(); - while (ch != '\n' && ch != EOF) - ch = getchar(); - if (first != 'y' && first != 'Y') - exit(0); - } - sectoffset = 0; - } -#endif /* * First set the kernel disk label, * then write a label to the raw disk. @@ -544,163 +483,6 @@ l_perror(char *s) } } -#ifdef DOSLABEL -struct dos_partition * -findopenbsd(int f, off_t mbroff, struct dos_partition **first, int *n) -{ - static struct dos_partition res; - int mbr[DEV_BSIZE / sizeof(int)]; - struct dos_partition *dp, *p; - u_int16_t signature; - u_int32_t start = 0; - int part; - - /* Limit the number of recursions */ - if (!(*n)--) - return (NULL); - - /* - * This must be done this way due to alignment restrictions - * in for example mips processors. - */ - dp = (struct dos_partition *)mbr; - if (lseek(f, (off_t)mbroff * DEV_BSIZE, SEEK_SET) < 0 || - read(f, mbr, sizeof(mbr)) != sizeof(mbr)) - return (NULL); - signature = *((u_char *)mbr + DOSMBR_SIGNATURE_OFF) | - (*((u_char *)mbr + DOSMBR_SIGNATURE_OFF + 1) << 8); - bcopy((char *)mbr+DOSPARTOFF, (char *)mbr, sizeof(*dp) * NDOSPART); - - /* - * If there is no signature and no OpenBSD partition this is probably - * not an MBR. - */ - if (signature != DOSMBR_SIGNATURE) - return (NULL); - - /* - * Don't (yet) know disk geometry, use partition table to find OpenBSD - * partition, and obtain disklabel from there. - */ - /* Check if table is valid. */ - for (part = 0; part < NDOSPART; part++) { - if ((dp[part].dp_flag & ~0x80) != 0) - return (NULL); - } - /* Find OpenBSD partition. */ - for (part = 0; part < NDOSPART; part++) { - if (!letoh32(dp[part].dp_size)) - continue; - if (first && *first == NULL) { - bcopy(&dp[part], &res, sizeof(struct dos_partition)); - *first = &res; - } - switch (dp[part].dp_typ) { - case DOSPTYP_OPENBSD: - if (verbose) - fprintf(stderr, "# Inside MBR partition %d: " - "type %02X start %u size %u\n", part, - dp[part].dp_typ, letoh32(dp[part].dp_start), - letoh32(dp[part].dp_size)); - bcopy(&dp[part], &res, sizeof(struct dos_partition)); - res.dp_start = - htole32((off_t)letoh32(res.dp_start) + mbroff); - return (&res); - case DOSPTYP_EXTEND: - case DOSPTYP_EXTENDL: - fprintf(stderr, "# Extended partition %d: " - "type %02X start %u size %u\n", - part, dp[part].dp_typ, - letoh32(dp[part].dp_start), letoh32(dp[part].dp_size)); - start = letoh32(dp[part].dp_start) + mbroff; - p = findopenbsd(f, start, NULL, n); - if (p != NULL) - return (p); - break; - } - } - - return (NULL); -} - -/* - * Fetch DOS partition table from disk. - */ -struct dos_partition * -readmbr(int f) -{ - struct dos_partition *dp, *first = NULL; - int n = 8; - - dp = findopenbsd(f, DOSBBSECTOR, &first, &n); - if (dp != NULL) - return (dp); - - /* If no OpenBSD partition, find first used partition. */ - if (first != NULL) { - warnx("warning, DOS partition table with no valid OpenBSD partition"); - return (first); - } - - /* Table appears to be empty. */ - return (NULL); -} -#endif - -#ifdef DPMELABEL -int -check_dpme(int f, uint32_t *start, uint32_t *size) -{ - char sector[DEV_BSIZE]; - unsigned int partno, partcnt; - struct part_map_entry part; - - /* - * Read what would be the first DPME partition, and - * check for a valid signature. - */ - - if (lseek(f, (off_t)DEV_BSIZE, SEEK_SET) < 0 || - read(f, sector, sizeof(sector)) != sizeof(sector)) - return (0); - /* no direct derefence due to strict alignment */ - memcpy(&part, sector, sizeof part); - - if (part.pmSig != PART_ENTRY_MAGIC) - return (0); - - /* - * If the signature matches, perform a few more sanity checks, - * and then loop over the remaining partitions. We can safely - * rely on the first entry being of the partition map type, - * so it's ok to skip it. - */ - - partcnt = part.pmMapBlkCnt; - if (partcnt <= 1 || partcnt > 32) - return (0); - - for (partno = 2; partno <= partcnt; partno++) { - if (lseek(f, (off_t)partno * DEV_BSIZE, SEEK_SET) < 0 || - read(f, sector, sizeof(sector)) != sizeof(sector)) - return (0); - /* no direct derefence due to strict alignment */ - memcpy(&part, sector, sizeof part); - - if (part.pmSig != PART_ENTRY_MAGIC) - return (0); - - if (strcasecmp(part.pmPartType, PART_TYPE_OPENBSD) == 0) { - *start = part.pmPyPartStart; - *size = part.pmPartBlkCnt; - return (1); - } - } - - return (0); -} -#endif - /* * Fetch requested disklabel into 'lab' using ioctl. */ @@ -852,22 +634,10 @@ makedisktab(FILE *f, struct disklabel *lp) (void)fprintf(f, "%sil#%hu:", did, lp->d_interleave); did = ""; } - if (lp->d_trackskew != 0) { - (void)fprintf(f, "%ssk#%hu:", did, lp->d_trackskew); - did = ""; - } - if (lp->d_cylskew != 0) { - (void)fprintf(f, "%scs#%hu:", did, lp->d_cylskew); - did = ""; - } - if (lp->d_headswitch != 0) { - (void)fprintf(f, "%shs#%u:", did, lp->d_headswitch); - did = ""; - } - if (lp->d_trkseek != 0) { - (void)fprintf(f, "%sts#%u:", did, lp->d_trkseek); - did = ""; - } + /* + * XXX We do not print have disktab information yet for + * XXX DL_GETBSTART DL_GETBEND + */ for (i = 0; i < NDDATA; i++) if (lp->d_drivedata[i]) (void)fprintf(f, "d%d#%u", i, lp->d_drivedata[i]); @@ -1040,12 +810,8 @@ display(FILE *f, struct disklabel *lp, char unit, int all) fprintf(f, "rpm: %hu\n", lp->d_rpm); fprintf(f, "interleave: %hu\n", lp->d_interleave); - fprintf(f, "trackskew: %hu\n", lp->d_trackskew); - fprintf(f, "cylinderskew: %hu\n", lp->d_cylskew); - fprintf(f, "headswitch: %u\t\t# microseconds\n", - lp->d_headswitch); - fprintf(f, "track-to-track seek: %u\t# microseconds\n", - lp->d_trkseek); + fprintf(f, "boundstart: %llu\n", DL_GETBSTART(lp)); + fprintf(f, "boundend: %llu\n", DL_GETBEND(lp)); fprintf(f, "drivedata: "); for (i = NDDATA - 1; i >= 0; i--) if (lp->d_drivedata[i]) @@ -1396,39 +1162,27 @@ getasciilabel(FILE *f, struct disklabel *lp) continue; } if (!strcmp(cp, "trackskew")) { - v = GETNUM(lp->d_trackskew, tp, 0, &errstr); - if (errstr) { - warnx("line %d: bad %s: %s", lineno, cp, tp); - errors++; - } else - lp->d_trackskew = v; + /* ignore */ continue; } if (!strcmp(cp, "cylinderskew")) { - v = GETNUM(lp->d_cylskew, tp, 0, &errstr); - if (errstr) { - warnx("line %d: bad %s: %s", lineno, cp, tp); - errors++; - } else - lp->d_cylskew = v; + /* ignore */ continue; } if (!strcmp(cp, "headswitch")) { - v = GETNUM(lp->d_headswitch, tp, 0, &errstr); - if (errstr) { - warnx("line %d: bad %s: %s", lineno, cp, tp); - errors++; - } else - lp->d_headswitch = v; + /* ignore */ continue; } if (!strcmp(cp, "track-to-track seek")) { - v = GETNUM(lp->d_trkseek, tp, 0, &errstr); - if (errstr) { - warnx("line %d: bad %s: %s", lineno, cp, tp); - errors++; - } else - lp->d_trkseek = v; + /* ignore */ + continue; + } + if (!strcmp(cp, "boundstart")) { + /* ignore */ + continue; + } + if (!strcmp(cp, "boundend")) { + /* ignore */ continue; } if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') { @@ -1561,15 +1315,6 @@ checklabel(struct disklabel *lp) lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; if (DL_GETDSIZE(lp) == 0) DL_SETDSIZE(lp, (u_int64_t)lp->d_secpercyl * lp->d_ncylinders); -#ifdef i386__notyet - if (dosdp && dosdp->dp_size && - (dosdp->dp_typ == DOSPTYP_OPENBSD)) { - && DL_GETDSIZE(lp) > dosdp->dp_start + dosdp->dp_size) { - warnx("exceeds DOS partition size"); - errors++; - DL_SETDSIZE(lp, dosdp->dp_start + dosdp->dp_size); - } -#endif if (lp->d_bbsize == 0) { warnx("boot block size %d", lp->d_bbsize); errors++; diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 0464f9c3029..50a7d1b53d4 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.216 2009/06/02 21:38:36 chl Exp $ */ +/* $OpenBSD: editor.c,v 1.217 2009/06/04 21:13:03 deraadt Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.216 2009/06/02 21:38:36 chl Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.217 2009/06/04 21:13:03 deraadt Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -1457,7 +1457,6 @@ getdisktype(struct disklabel *lp, char *banner, char *dev) /* * Get beginning and ending sectors of the OpenBSD portion of the disk * from the user. - * XXX - should mention MBR values if DOSLABEL */ void set_bounds(struct disklabel *lp) @@ -1546,67 +1545,13 @@ free_chunks(struct disklabel *lp) return(chunks); } -/* - * What is the OpenBSD portion of the disk? Uses the MBR if applicable. - */ void find_bounds(struct disklabel *lp) { - int has_bounds = 0; - - /* Defaults */ - /* XXX - reserve a cylinder for hp300? */ - starting_sector = 0; - ending_sector = DL_GETDSIZE(lp); - -#ifdef DOSLABEL - /* - * If we have an MBR, use values from the OpenBSD partition. - */ - if (dosdp) { - if (dosdp->dp_typ == DOSPTYP_OPENBSD) { - struct partition *pp; - u_int64_t new_end; - int i; - - /* Set start and end based on fdisk partition bounds */ - starting_sector = letoh32(dosdp->dp_start); - ending_sector = starting_sector + letoh32(dosdp->dp_size); - - /* - * If there are any BSD or SWAP partitions beyond - * ending_sector we extend ending_sector to include - * them. This is done because the BIOS geometry is - * generally different from the disk geometry. - */ - for (i = new_end = 0; i < lp->d_npartitions; i++) { - pp = &lp->d_partitions[i]; - if ((pp->p_fstype == FS_BSDFFS || - pp->p_fstype == FS_SWAP) && - DL_GETPSIZE(pp) + DL_GETPOFFSET(pp) > - new_end) - new_end = DL_GETPSIZE(pp) + - DL_GETPOFFSET(pp); - } - if (new_end > ending_sector) - ending_sector = new_end; - } else { - /* Don't trounce the MBR */ - starting_sector = 63; - } - - has_bounds = 1; - } -#endif -#ifdef DPMELABEL - if (dpme_label) { - starting_sector = dpme_obsd_start; - ending_sector = dpme_obsd_start + dpme_obsd_size; - has_bounds = 1; - } -#endif + starting_sector = DL_GETBSTART(lp); + ending_sector = DL_GETBEND(lp); - if (has_bounds) { + if (ending_sector) { if (verbose) printf("Treating sectors %llu-%llu as the OpenBSD" " portion of the disk.\nYou can use the 'b'" diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h index ea86a4c0a39..75397700e38 100644 --- a/sbin/disklabel/extern.h +++ b/sbin/disklabel/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.16 2009/06/02 16:23:45 krw Exp $ */ +/* $OpenBSD: extern.h,v 1.17 2009/06/04 21:13:03 deraadt Exp $ */ /* * Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org> @@ -37,11 +37,3 @@ extern int aflag, dflag; extern int donothing; extern int verbose; extern char print_unit; - -#ifdef DOSLABEL -extern struct dos_partition *dosdp; /* DOS partition, if found */ -#endif -#ifdef DPMELABEL -extern int dpme_label; /* nonzero if DPME table */ -extern uint32_t dpme_obsd_start, dpme_obsd_size; /* OpenBSD DPME boundaries */ -#endif diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index 30fed88279c..9d35841482c 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.92 2008/06/12 06:58:31 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.93 2009/06/04 21:13:00 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -74,7 +74,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (msg == NULL) goto done; diff --git a/sys/arch/hp300/hp300/disksubr.c b/sys/arch/hp300/hp300/disksubr.c index 8b1df78cbeb..c7750499c1f 100644 --- a/sys/arch/hp300/hp300/disksubr.c +++ b/sys/arch/hp300/hp300/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.44 2008/06/12 06:58:33 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.45 2009/06/04 21:13:01 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.9 1997/04/01 03:12:13 scottr Exp $ */ /* @@ -75,7 +75,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (msg == NULL) goto done; diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index 8c46091d841..df0df856259 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.72 2008/06/12 06:58:34 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.73 2009/06/04 21:13:01 deraadt Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -213,6 +213,9 @@ finished: if (partoffp) *partoffp = fsoff; + DL_SETBSTART(lp, fsoff); + DL_SETBEND(lp, DL_GETDSIZE(lp)); /* XXX */ + if (spoofonly) goto done; @@ -227,7 +230,8 @@ finished: goto done; } - return checkdisklabel(bp->b_data + LABELOFFSET, lp); + return checkdisklabel(bp->b_data + LABELOFFSET, lp, fsoff, + DL_GETDSIZE(lp)); /* XXX */ done: if (dbp) { diff --git a/sys/arch/luna88k/luna88k/disksubr.c b/sys/arch/luna88k/luna88k/disksubr.c index f7b4647c345..a8a30325008 100644 --- a/sys/arch/luna88k/luna88k/disksubr.c +++ b/sys/arch/luna88k/luna88k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.40 2009/05/21 23:45:48 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.41 2009/06/04 21:13:01 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.12 2002/02/19 17:09:44 wiz Exp $ */ /* @@ -138,7 +138,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (msg == NULL) goto done; @@ -312,7 +312,7 @@ disklabel_om_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - return (checkdisklabel(lp, lp)); + return (checkdisklabel(lp, lp, 0, DL_GETDSIZE(lp))); } /* diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index c0b3769fa33..494ea445e79 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.61 2008/08/24 12:56:17 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.62 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -106,11 +106,9 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), struct disklabel *lp, int *partoffp, int spoofonly) { int i, part_cnt, n, hfspartoff = -1; + u_int hfspartlen; struct part_map_entry *part; - if (partoffp) - *partoffp = hfspartoff; - /* First check for a DPME (HFS) disklabel */ bp->b_blkno = 1; bp->b_bcount = lp->d_secsize; @@ -145,6 +143,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (strcmp(part->pmPartType, PART_TYPE_OPENBSD) == 0) { hfspartoff = part->pmPyPartStart - LABELSECTOR; + hfspartlen = part->pmPartBlkCnt; if (partoffp) { *partoffp = hfspartoff; return (NULL); @@ -163,12 +162,14 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), pp->p_fstype = FS_HFS; n++; } + + DL_SETBSTART(lp, hfspartoff); + DL_SETBEND(lp, hfspartoff + hfspartlen); } + if (hfspartoff == -1) return ("no OpenBSD partition inside DPME label"); - lp->d_npartitions = MAXPARTITIONS; - if (spoofonly) return (NULL); @@ -180,7 +181,8 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (biowait(bp)) return("disk label I/O error"); - return checkdisklabel(bp->b_data + LABELOFFSET, lp); + return checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff, + hfspartoff + hfspartlen); } /* diff --git a/sys/arch/sgi/sgi/disksubr.c b/sys/arch/sgi/sgi/disksubr.c index 7a0646fb8fe..4be24dee9c4 100644 --- a/sys/arch/sgi/sgi/disksubr.c +++ b/sys/arch/sgi/sgi/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.13 2009/05/28 17:05:50 miod Exp $ */ +/* $OpenBSD: disksubr.c,v 1.14 2009/06/04 21:13:02 deraadt Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -117,6 +117,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), char *msg = NULL; int i, *p, cs = 0; int fsoffs = 0; + u_int fslen; int offset; if (partoffp) @@ -142,6 +143,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), goto done; } fsoffs = dlp->partitions[0].first * (dlp->dp.dp_secbytes / DEV_BSIZE); + fslen = dlp->partitions[0].blocks * (dlp->dp.dp_secbytes / DEV_BSIZE); /* * If the disklabel is about to be written to disk, don't modify it! @@ -189,6 +191,8 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), } } + DL_GETBSTART(lp, fsoffs); + DL_GETBSIZE(lp, fsoffs + fslen); lp->d_version = 1; lp->d_flags = D_VENDOR; lp->d_checksum = 0; @@ -208,7 +212,7 @@ finished: goto done; } - return checkdisklabel(bp->b_data + offset, lp); + return checkdisklabel(bp->b_data + offset, lp, fsoffs, fsoffs + fslen); done: return (msg); diff --git a/sys/arch/socppc/socppc/disksubr.c b/sys/arch/socppc/socppc/disksubr.c index 7cba2a80a9a..4ecf30af00a 100644 --- a/sys/arch/socppc/socppc/disksubr.c +++ b/sys/arch/socppc/socppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.5 2008/08/24 12:56:17 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.6 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -106,11 +106,9 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), struct disklabel *lp, int *partoffp, int spoofonly) { int i, part_cnt, n, hfspartoff = -1; + u_int hfspartlen; struct part_map_entry *part; - if (partoffp) - *partoffp = hfspartoff; - /* First check for a DPME (HFS) disklabel */ bp->b_blkno = 1; bp->b_bcount = lp->d_secsize; @@ -145,6 +143,7 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (strcmp(part->pmPartType, PART_TYPE_OPENBSD) == 0) { hfspartoff = part->pmPyPartStart - LABELSECTOR; + hfspartlen = part->pmPartBlkCnt; if (partoffp) { *partoffp = hfspartoff; return (NULL); @@ -163,12 +162,14 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), pp->p_fstype = FS_HFS; n++; } + + DL_SETBSTART(lp, hfspartoff); + DL_SETBEND(lp, hfspartoff + hfspartlen); } + if (hfspartoff == -1) return ("no OpenBSD partition inside DPME label"); - lp->d_npartitions = MAXPARTITIONS; - if (spoofonly) return (NULL); @@ -180,7 +181,8 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (biowait(bp)) return("disk label I/O error"); - return checkdisklabel(bp->b_data + LABELOFFSET, lp); + return checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff, + hfspartoff + hfspartlen); } /* diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c index 2b89a538017..2e1ee4a9dd1 100644 --- a/sys/arch/sparc/sparc/disksubr.c +++ b/sys/arch/sparc/sparc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.80 2009/05/13 01:31:58 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.81 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.16 1996/04/28 20:25:59 thorpej Exp $ */ /* @@ -97,7 +97,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), } #endif /* NCD > 0 */ - /* get a buffer and initialize it */ + /* get buffer and initialize it */ bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; @@ -119,7 +119,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (msg == NULL) goto done; @@ -159,7 +159,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) struct buf *bp = NULL; int error; - /* get a buffer and initialize it */ + /* get buffer and initialize it */ bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; @@ -234,7 +234,7 @@ sun_extended_sum(struct sun_disklabel *sl, void *end) * * The BSD label is cleared out before this is called. */ -char * +static char * disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) { struct sun_preamble *preamble = (struct sun_preamble *)sl; @@ -385,7 +385,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - return (checkdisklabel(lp, lp)); + return (checkdisklabel(lp, lp, 0, DL_GETDSIZE(lp))); } /* diff --git a/sys/arch/sparc64/sparc64/disksubr.c b/sys/arch/sparc64/sparc64/disksubr.c index 2bb7ddc9d67..5c210d13284 100644 --- a/sys/arch/sparc64/sparc64/disksubr.c +++ b/sys/arch/sparc64/sparc64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.55 2009/05/13 01:31:58 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.56 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk Exp $ */ /* @@ -112,7 +112,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (msg == NULL) goto done; @@ -378,7 +378,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - return (checkdisklabel(lp, lp)); + return (checkdisklabel(lp, lp, 0, DL_GETDSIZE(lp))); } /* diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c index ab73c279126..03be0cb3357 100644 --- a/sys/arch/vax/vax/disksubr.c +++ b/sys/arch/vax/vax/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.58 2008/08/14 11:41:30 martin Exp $ */ +/* $OpenBSD: disksubr.c,v 1.59 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1999/06/30 18:48:06 ragge Exp $ */ /* @@ -71,6 +71,8 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; + DL_SETBSTART(lp, 16); + if (spoofonly) goto done; @@ -83,7 +85,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), goto done; } - msg = checkdisklabel(bp->b_data + LABELOFFSET, lp); + msg = checkdisklabel(bp->b_data + LABELOFFSET, lp, 16, DL_GETDSIZE(lp)); if (msg == NULL) goto done; 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); } /* diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index 7ce4fee97c6..67909e7840b 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.44 2008/08/10 15:52:50 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.45 2009/06/04 21:13:02 deraadt Exp $ */ /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ /* @@ -141,10 +141,10 @@ struct disklabel { */ u_int16_t d_rpm; /* rotational speed */ u_int16_t d_interleave; /* hardware sector interleave */ - u_int16_t d_trackskew; /* sector 0 skew, per track */ - u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ - u_int32_t d_headswitch; /* head switch time, usec */ - u_int32_t d_trkseek; /* track-to-track seek, usec */ + u_int16_t d_bstarth; /* start of useable region (high part) */ + u_int16_t d_bendh; /* size of useable region (high part) */ + u_int32_t d_bstart; /* start of useable region */ + u_int32_t d_bend; /* end of useable region */ u_int32_t d_flags; /* generic flags */ #define NDDATA 5 u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ @@ -207,25 +207,39 @@ struct __partitionv0 { /* the partition table */ (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i))) #define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size) -#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset) -#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \ - (d)->d_secperunit) - #define DL_SETPSIZE(p, n) do { \ daddr64_t x = (n); \ (p)->p_sizeh = x >> 32; \ (p)->p_size = x; \ } while (0) +#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset) #define DL_SETPOFFSET(p, n) do { \ daddr64_t x = (n); \ (p)->p_offseth = x >> 32; \ (p)->p_offset = x; \ } while (0) + +#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \ + (d)->d_secperunit) #define DL_SETDSIZE(d, n) do { \ daddr64_t x = (n); \ (d)->d_secperunith = x >> 32; \ (d)->d_secperunit = x; \ } while (0) +#define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \ + (d)->d_bstart) +#define DL_SETBSTART(d, n) do { \ + daddr64_t x = (n); \ + (d)->d_bstarth = x >> 32; \ + (d)->d_bstart = x; \ + } while (0) +#define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \ + (d)->d_bend) +#define DL_SETBEND(d, n) do { \ + daddr64_t x = (n); \ + (d)->d_bendh = x >> 32; \ + (d)->d_bend = x; \ + } while (0) #define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE) #define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d)) @@ -458,7 +472,7 @@ void diskerr(struct buf *, char *, char *, int, int, struct disklabel *); void disksort(struct buf *, struct buf *); u_int dkcksum(struct disklabel *); char *initdisklabel(struct disklabel *); -char *checkdisklabel(void *, struct disklabel *); +char *checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t); int setdisklabel(struct disklabel *, struct disklabel *, u_int); char *readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int); int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *); |