diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-04 21:13:04 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2009-06-04 21:13:04 +0000 |
commit | 493210897221d7a7520ed88494339623a8d0cbb9 (patch) | |
tree | 437b23c9f66b7621e795b1a7278f3e5786b0ff8a /sbin | |
parent | feadbccc8166eb1acafe6168fece9b1756dfb533 (diff) |
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 'sbin')
-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 |
4 files changed, 28 insertions, 350 deletions
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 |