diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-23 05:18:51 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-23 05:18:51 +0000 |
commit | ec6051c247e24d52914e4f44a2bffa84baf87b7a (patch) | |
tree | ff6471841f3a77184c6decfeeca7d55963f76161 | |
parent | 272deaa2fdba4ffcc720cbae59800fa2b6880a7a (diff) |
Rename -F option to -f and add a new -F (full disk) option to use in -E mode.
When checking for an MBR, only say we have an mbr if there is a signature *or*
there is an fdisk partition with an {Open,Free,Net}BSD ID.
When setting the bounds in -E mode add hueristics to deal with disks
bigger than the BIOS geometry would indicate.
-rw-r--r-- | sbin/disklabel/disklabel.8 | 35 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 33 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 107 |
3 files changed, 121 insertions, 54 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 59c2b4f3698..38dceecbed2 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.26 1999/03/16 04:47:15 millert Exp $ +.\" $OpenBSD: disklabel.8,v 1.27 1999/03/23 05:18:49 millert Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -65,7 +65,8 @@ .Ar disk .Nm disklabel .Fl E -.Op Fl F Ar tempfile +.Op Fl f Ar tempfile +.Op Fl F .Op Fl n .Op Fl d Li \&| Fl r .Op Fl v @@ -343,6 +344,17 @@ to delete all partitions). If no partition is specified, the user will be prompted for one. You may not delete the .Dq c partition. +.It g Op d|b|u +Set disk geometry based on what the +.Em disk , +.Em BIOS , +or +.Em user +thinks (the +.Em user +geometry is simply what the label said before +.Nm +made any changes). .It m Op part Modify parameters for an existing partition. If no partition is specified, the user will be prompted for one. This option allows @@ -356,7 +368,7 @@ specified, the user will be prompted for one. This option is only valid if .Nm was invoked with the -.Fl F +.Fl f flag. .It s Op path Save the label to a file in ASCII format (suitable for loading via @@ -375,19 +387,26 @@ Exit the editor without saving any changes to the label. .El .Pp The -.Fl F Ar tempfile -flag to +.Fl F +and +.Fl f Ar tempfile +flags to .Nm -is only valid in conjunction with the +are only valid when used in conjunction with the .Fl E -flag. When specified, +flag. When the +.Fl f +flag is specified, .Nm will write entries to .Ar tempfile in .Xr fstab 5 format for any partitions for which mount point information has been -specified. +specified. The +.Fl F +flag indicates that the entire disk is to be used for +.Ox . .Pp The final three forms of .Nm diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 6e12096e34d..b2b00010dc4 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.61 1999/03/16 04:47:16 millert Exp $ */ +/* $OpenBSD: disklabel.c,v 1.62 1999/03/23 05:18:49 millert Exp $ */ /* $NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char rcsid[] = "$OpenBSD: disklabel.c,v 1.61 1999/03/16 04:47:16 millert Exp $"; +static char rcsid[] = "$OpenBSD: disklabel.c,v 1.62 1999/03/23 05:18:49 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -128,7 +128,7 @@ struct disklabel *makebootarea __P((char *, struct disklabel *, int)); void display __P((FILE *, struct disklabel *)); void display_partition __P((FILE *, struct disklabel *, char **, int, char, int)); int width_partition __P((struct disklabel *, int)); -int editor __P((struct disklabel *, int, char *, char *)); +int editor __P((struct disklabel *, int, char *, char *, int)); int edit __P((struct disklabel *, int)); int editit __P((void)); char *skip __P((char *)); @@ -146,11 +146,12 @@ main(argc, argv) char *argv[]; { int ch, f, writeable, error = 0; + int whole_mode = 0; char *fstabfile = NULL; struct disklabel *lp; FILE *t; - while ((ch = getopt(argc, argv, "BEF:NRWb:denrs:tvw")) != -1) + while ((ch = getopt(argc, argv, "BEFf:NRWb:denrs:tvw")) != -1) switch (ch) { #if NUMBOOT > 0 case 'B': @@ -196,6 +197,9 @@ main(argc, argv) op = EDITOR; break; case 'F': + whole_mode = 1; + break; + case 'f': fstabfile = optarg; break; case 'r': @@ -270,7 +274,7 @@ main(argc, argv) usage(); if ((lp = readlabel(f)) == NULL) exit(1); - error = editor(lp, f, specname, fstabfile); + error = editor(lp, f, specname, fstabfile, whole_mode); break; case READ: if (argc != 1) @@ -591,6 +595,7 @@ readmbr(f) { static int mbr[DEV_BSIZE / sizeof(int)]; struct dos_partition *dp; + u_int16_t signature; int part; /* @@ -601,7 +606,8 @@ readmbr(f) if (lseek(f, (off_t)DOSBBSECTOR * DEV_BSIZE, SEEK_SET) < 0 || read(f, mbr, sizeof(mbr)) < sizeof(mbr)) err(4, "can't read master boot record"); - + signature = *((u_char *)mbr + DOSMBR_SIGNATURE_OFF) | + (*((u_char *)mbr + DOSMBR_SIGNATURE_OFF + 1) << 8); bcopy((char *)mbr+DOSPARTOFF, (char *)mbr, sizeof(*dp) * NDOSPART); /* @@ -646,6 +652,13 @@ readmbr(f) } } + /* + * If there is no signature and no OpenBSD partition this is probably + * not an MBR. + */ + if (signature != DOSMBR_SIGNATURE) + return (NULL); + /* If no OpenBSD partition, find first used partition. */ for (part = 0; part < NDOSPART; part++) { if (get_le(&dp[part].dp_size)) { @@ -654,7 +667,7 @@ readmbr(f) } } /* Table appears to be empty. */ - return (0); + return (NULL); } #endif @@ -874,7 +887,7 @@ makedisktab(f, lp) FILE *f; struct disklabel *lp; { - int i, j; + int i; char *did = "\\\n\t:"; struct partition *pp; @@ -1738,8 +1751,8 @@ usage() " disklabel [-nv] [-r|-d] -e disk%s (edit)\n", blank); fprintf(stderr, - " disklabel [-nv] [-r|-d] [-F temp] -E disk%s(simple editor)\n", - blank); + " disklabel [-nv] [-r|-d] [-F] [-f temp] -E disk%.*s (simple editor)\n", + strlen(blank) - 9, blank); fprintf(stderr, " disklabel [-nv] [-r]%s -R disk proto (restore)\n", boot); diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 0bd6450dabc..e2e9fafe823 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.56 1999/03/21 22:11:42 millert Exp $ */ +/* $OpenBSD: editor.c,v 1.57 1999/03/23 05:18:50 millert Exp $ */ /* * Copyright (c) 1997-1999 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.56 1999/03/21 22:11:42 millert Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.57 1999/03/23 05:18:50 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -78,7 +78,7 @@ struct mountinfo { }; void edit_parms __P((struct disklabel *, u_int32_t *)); -int editor __P((struct disklabel *, int, char *, char *)); +int editor __P((struct disklabel *, int, char *, char *, int)); void editor_add __P((struct disklabel *, char **, u_int32_t *, char *)); void editor_change __P((struct disklabel *, u_int32_t *, char *)); void editor_countfree __P((struct disklabel *, u_int32_t *)); @@ -95,7 +95,7 @@ u_int32_t next_offset __P((struct disklabel *, struct partition *)); int partition_cmp __P((const void *, const void *)); struct partition **sort_partitions __P((struct disklabel *, u_int16_t *)); void getdisktype __P((struct disklabel *, char *, char *)); -void find_bounds __P((struct disklabel *)); +void find_bounds __P((struct disklabel *, struct disklabel *, int)); void set_bounds __P((struct disklabel *, u_int32_t *)); struct diskchunk *free_chunks __P((struct disklabel *)); char ** mpcopy __P((char **, char **)); @@ -134,7 +134,7 @@ extern struct dos_partition *dosdp; /* DOS partition, if found */ * Simple partition editor. Primarily intended for new labels. */ int -editor(lp, f, dev, fstabfile) +editor(lp, f, dev, fstabfile, whole_mode) struct disklabel *lp; int f; char *dev; @@ -159,12 +159,12 @@ editor(lp, f, dev, fstabfile) /* Don't allow disk type of "unknown" */ getdisktype(&label, "You need to specify a type for this disk.", dev); - /* How big is the OpenBSD portion of the disk? */ - find_bounds(&label); - /* Get the on-disk and BIOS geometries if possible */ get_geometry(f, &disk_geop, &bios_geop); + /* How big is the OpenBSD portion of the disk? */ + find_bounds(&label, bios_geop, whole_mode); + /* Set freesectors based on bounds and initial label */ editor_countfree(&label, &freesectors); @@ -173,7 +173,7 @@ editor(lp, f, dev, fstabfile) errx(1, "can't run when there is partition overlap."); /* If we don't have a 'c' partition, create one. */ - pp = &label.d_partitions[2]; + pp = &label.d_partitions[RAW_PART]; if (label.d_npartitions < 3 || pp->p_size == 0) { puts("No 'c' partition found, adding one that spans the disk."); if (label.d_npartitions < 3) @@ -1692,10 +1692,12 @@ free_chunks(lp) * What is the OpenBSD portion of the disk? Uses the MBR if applicable. */ void -find_bounds(lp) +find_bounds(lp, bios_lp, whole_mode) struct disklabel *lp; + struct disklabel *bios_lp; + int whole_mode; { - struct partition *pp = &lp->d_partitions[2]; + struct partition *pp = &lp->d_partitions[RAW_PART]; /* Defaults */ /* XXX - reserve a cylinder for hp300? */ @@ -1704,33 +1706,66 @@ find_bounds(lp) #ifdef DOSLABEL /* - * If we have an MBR, use values from the {Open,Free,Net}BSD partition. + * If we have an MBR, use values from the {Open,Free,Net}BSD partition + * unless we are in whole disk mode (in which case we ignore the MBR). */ - if (dosdp && pp->p_size && - (dosdp->dp_typ == DOSPTYP_OPENBSD || - dosdp->dp_typ == DOSPTYP_FREEBSD || - dosdp->dp_typ == DOSPTYP_NETBSD)) { - u_int32_t i, new_end; - - /* Set start and end based on the fdisk partition bounds */ - starting_sector = get_le(&dosdp->dp_start); - ending_sector = starting_sector + get_le(&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) && - pp->p_size + pp->p_offset > new_end) - new_end = pp->p_size + pp->p_offset; + if (dosdp) { + if (!whole_mode && (dosdp->dp_typ == DOSPTYP_OPENBSD || + dosdp->dp_typ == DOSPTYP_FREEBSD || + dosdp->dp_typ == DOSPTYP_NETBSD)) { + u_int32_t i, new_end; + + /* Set start and end based on fdisk partition bounds */ + starting_sector = get_le(&dosdp->dp_start); + ending_sector = starting_sector + get_le(&dosdp->dp_size); + + /* + * If the ending sector of the BSD fdisk partition + * is equal to the ending sector of the BIOS geometry + * but the real sector count > BIOS sector count, + * adjust the bounds accordingly. We do this because + * the BIOS geometry is limited to disks of ~4gig. + */ + if (bios_lp && ending_sector == bios_lp->d_secperunit && + lp->d_secperunit > bios_lp->d_secperunit) + ending_sector = lp->d_secperunit; + + /* + * 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) && + pp->p_size + pp->p_offset > new_end) + new_end = pp->p_size + pp->p_offset; + } + if (new_end > ending_sector) + ending_sector = new_end; + + /* + * If we are honoring the fdisk partitions, we should + * use the BIOS geometry unless ending_sector is beyond + * the end of the BIOS geometry, in which case we know + * the BIOS geometry is bogus. + */ + if (bios_lp != NULL && ending_sector <= bios_lp->d_secperunit) { + lp->d_secsize = bios_lp->d_secsize; + lp->d_nsectors = bios_lp->d_nsectors; + lp->d_ntracks = bios_lp->d_ntracks; + lp->d_ncylinders = bios_lp->d_ncylinders; + lp->d_secpercyl = bios_lp->d_secpercyl; + lp->d_secperunit = bios_lp->d_secperunit; + puts("Using BIOS geometry...\nYou can use the " + "'g' command to change this."); + } + } else { + /* Don't trounce the MBR */ + starting_sector = 32; } - if (new_end > ending_sector) - ending_sector = new_end; printf("\nTreating sectors %u-%u as the OpenBSD portion of the " "disk.\nYou can use the 'b' command to change this.\n", |