diff options
author | 2016-01-09 18:10:56 +0000 | |
---|---|---|
committer | 2016-01-09 18:10:56 +0000 | |
commit | 77db81de27cd5d3171d0adc7c2cb1637205cf3db (patch) | |
tree | 9b48d46bcf2e8fa77fda6559863998dd03597f7f | |
parent | Remove superfluous and barely used macro aliases for wctype.h functions. (diff) | |
download | wireguard-openbsd-77db81de27cd5d3171d0adc7c2cb1637205cf3db.tar.xz wireguard-openbsd-77db81de27cd5d3171d0adc7c2cb1637205cf3db.zip |
Revamp the display of GPT information, hiding less important
information under the '-v' flag. This brings the GPT display more
into line with the MBR display and simplifies and hardens the parsing
of the partition info in the install scripts.
Original problem with install scripts parsing hand edited GPT
information reported by Valere Monseur via bugs@.
Man page fixes and tweaks from jmc@.
Install script changes tested & ok rpe@.
-rw-r--r-- | distrib/miniroot/install.sub | 8 | ||||
-rw-r--r-- | sbin/fdisk/cmd.c | 10 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.8 | 48 | ||||
-rw-r--r-- | sbin/fdisk/gpt.c | 84 | ||||
-rw-r--r-- | sbin/fdisk/gpt.h | 8 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 6 |
6 files changed, 81 insertions, 83 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 67e9d92ad0b..435cfa63320 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.867 2015/12/27 18:42:11 rpe Exp $ +# $OpenBSD: install.sub,v 1.868 2016/01/09 18:10:57 krw Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org> @@ -289,9 +289,9 @@ disk_has() { local _c_sr="bioctl -q $_disk" # Patterns for partition-table-types and partition-types. - local _p_gpt='First usable LBA:' - local _p_gpt_openbsd='^[ ]+OpenBSD[ ]+OpenBSD Area' - local _p_gpt_efisys='^[ ]+EFI Sys[ ]+EFI System Area' + local _p_gpt='Usable LBA:' + local _p_gpt_openbsd='^[ *]...: OpenBSD ' + local _p_gpt_efisys='^[ *]...: EFI Sys ' local _p_hfs='^Partition map ' local _p_hfs_openbsd=' OpenBSD OpenBSD ' local _p_mbr='Signature: 0xAA55' diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 07c47327266..b2197200aad 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.92 2015/11/26 08:15:07 tim Exp $ */ +/* $OpenBSD: cmd.c,v 1.93 2016/01/09 18:10:56 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -65,7 +65,7 @@ Xreinit(char *args, struct mbr *mbr) if (dogpt) { MBR_init_GPT(mbr); GPT_init(); - GPT_print("s"); + GPT_print("s", 0); } else { MBR_init(mbr); MBR_print(mbr, "s"); @@ -299,8 +299,8 @@ Xgsetpid(char *args) gg = &gp[pn]; /* Print out current table entry */ - GPT_print_parthdr(); - GPT_print_part(pn, "s"); + GPT_print_parthdr(0); + GPT_print_part(pn, "s", 0); /* Ask for partition type or GUID. */ uuid_dec_le(&gg->gp_type, &guid); @@ -397,7 +397,7 @@ Xprint(char *args, struct mbr *mbr) { if (MBR_protective_mbr(mbr) == 0 && letoh64(gh.gh_sig) == GPTSIGNATURE) - GPT_print(args); + GPT_print(args, 1); else MBR_print(mbr, args); diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8 index b36b4558470..69c1ba14c9f 100644 --- a/sbin/fdisk/fdisk.8 +++ b/sbin/fdisk/fdisk.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fdisk.8,v 1.90 2015/12/11 23:30:23 jmc Exp $ +.\" $OpenBSD: fdisk.8,v 1.91 2016/01/09 18:10:56 krw Exp $ .\" .\" .\" Copyright (c) 1997 Tobias Weingartner @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 11 2015 $ +.Dd $Mdocdate: January 9 2016 $ .Dt FDISK 8 .Os .Sh NAME @@ -158,6 +158,7 @@ or can be specified. .It Fl v Print the contents of the MBR, the Primary GPT and the Secondary GPT. +Also print more detailed GPT header and partition entry information. Cannot be used with .Fl i , .Fl u , @@ -204,7 +205,7 @@ Offset: 0 Signature: 0xAA55 .Pp This 1953525168 sector (931GB) disk drive is divided into two MBR partitions that span the whole disk. -The first MBR partition is a 200GB FAT-32 partition, +The first MBR partition is a 200GB FAT-32 partition; the second is a 731GB .Ox MBR partition using the remainder of the disk. @@ -243,41 +244,38 @@ If the disk contains a protective MBR and a valid GPT, the contents of the GPT are displayed. For example: .Bd -literal -offset 1n -Disk: sd1 ca501b80-5b85-40fd-a00e-abc6ffc5f97c [7907328 Sectors] - First usable LBA: 64 Last usable LBA: 7907264 - #: uuid lba size - type name ---------------------------------------------------------------------- - 1: 415afb62-3f56-43c5-a1b3-9405aace56f9 64 960 - EFI Sys EFI System Area - 3: 6bcc08a8-66a6-43ae-aa1f-9869ab4c8a27 1024 7906241 - OpenBSD OpenBSD Area +Disk: sd2 Usable LBA: 64 to 7765952 [7766016 Sectors] + #: type [ start: size ] +------------------------------------------------------------------------ + 1: EFI Sys [ 64: 960 ] + 3: OpenBSD [ 1024: 7764929 ] .Ed .Pp -This 7907328 sector disk drive is divided into two +This 7766016 sector disk drive is divided into two partitions that span the whole disk. -The first partition is a 960 sector EFI Sys partition. -the second is a 7906241 sector +The first partition is a 960 sector EFI Sys partition; +the second is a 7764929 sector .Ox partition using the remainder of the disk. The fields of the output are: -.Bl -tag -width "uuid" +.Bl -tag -width "type" .It Em "#" Number identifying each partition table entry. -.It Em "uuid" -The UUID of the partition. -.It Em "lba" -The sector the partition starts on. -.It Em "size" -The number of sectors in the partition. .It Em "type" The partition type identifier. If the type is recognized the name of the type is displayed. -Otherwise the type UUID is displayed. -.It Em "name" -The partition's name. +Otherwise the type GUID is displayed. +.It Em "start" +The sector the partition starts on. +.It Em "size" +The number of sectors in the partition. .El .Pp +If the +.Fl v +option is specified, the disk GUID and each partition's GUID and name are +also displayed. +.Pp In either the MBR or GPT case the .Ox partition shown above is subdivided further using the diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 275345682e5..d409aed815a 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.9 2015/12/11 21:57:31 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.10 2016/01/09 18:10:57 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -219,7 +219,7 @@ GPT_get_gpt(int which) } void -GPT_print(char *units) +GPT_print(char *units, int verbosity) { const int secsize = unit_types[SECTORS].conversion; struct uuid guid; @@ -227,47 +227,48 @@ GPT_print(char *units) double size; int i, u, status; - printf("Disk: %s ", disk.name); - - uuid_dec_le(&gh.gh_guid, &guid); - uuid_to_string(&guid, &guidstr, &status); - if (status == uuid_s_ok) - printf("%s ", guidstr); - else - printf("<invalid header guid> "); - free(guidstr); - u = unit_lookup(units); size = ((double)DL_GETDSIZE(&dl) * secsize) / unit_types[u].conversion; - printf("[%.0f ", size); + printf("Disk: %s Usable LBA: %llu to %llu [%.0f ", + disk.name, letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end), size); + if (u == SECTORS && secsize != DEV_BSIZE) printf("%d-byte ", secsize); printf("%s]\n", unit_types[u].lname); - GPT_print_parthdr(); + if (verbosity) { + printf("GUID: "); + uuid_dec_le(&gh.gh_guid, &guid); + uuid_to_string(&guid, &guidstr, &status); + if (status == uuid_s_ok) + printf("%s\n", guidstr); + else + printf("<invalid header GUID>\n"); + free(guidstr); + } + GPT_print_parthdr(verbosity); for (i = 0; i < letoh32(gh.gh_part_num); i++) { if (uuid_is_nil(&gp[i].gp_type, NULL)) continue; - GPT_print_part(i, units); + GPT_print_part(i, units, verbosity); } + } void -GPT_print_parthdr() +GPT_print_parthdr(int verbosity) { - printf(" First usable LBA: %llu Last usable LBA: %llu\n", - letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end)); - - printf(" #: uuid " - "lba size \n"); - printf(" type name\n"); - printf("----------------------------------------------------" - "-----------------\n"); + printf(" #: type " + " [ start: size ]\n"); + if (verbosity) + printf(" guid name\n"); + printf("--------------------------------------------------------" + "----------------\n"); } void -GPT_print_part(int n, char *units) +GPT_print_part(int n, char *units, int verbosity) { struct uuid guid; const int secsize = unit_types[SECTORS].conversion; @@ -276,26 +277,25 @@ GPT_print_part(int n, char *units) double size; int u, status; - printf("%c%3d: ", (letoh64(partn->gp_attrs) & GPTDOSACTIVE)?'*':' ', n); - - uuid_dec_le(&partn->gp_guid, &guid); - uuid_to_string(&guid, &guidstr, &status); - if (status != uuid_s_ok) - printf("<invalid partition guid> "); - else - printf("%36s ", guidstr); - free(guidstr); - - printf("%12lld ", letoh64(partn->gp_lba_start)); - + uuid_dec_le(&partn->gp_type, &guid); u = unit_lookup(units); size = letoh64(partn->gp_lba_end) - letoh64(partn->gp_lba_start) + 1; size = (size * secsize) / unit_types[u].conversion; - printf("%12.0f%s\n", size, unit_types[u].abbr); - - uuid_dec_le(&partn->gp_type, &guid); - printf(" %-36s %-36s\n", PRT_uuid_to_typename(&guid), - utf16le_to_string(partn->gp_name)); + printf("%c%3d: %-36s [%12lld: %12.0f%s]\n", + (letoh64(partn->gp_attrs) & GPTDOSACTIVE)?'*':' ', n, + PRT_uuid_to_typename(&guid), letoh64(partn->gp_lba_start), + size, unit_types[u].abbr); + + if (verbosity) { + uuid_dec_le(&partn->gp_guid, &guid); + uuid_to_string(&guid, &guidstr, &status); + if (status != uuid_s_ok) + printf(" <invalid partition guid> "); + else + printf(" %-36s ", guidstr); + printf("%-36s\n", utf16le_to_string(partn->gp_name)); + free(guidstr); + } } int diff --git a/sbin/fdisk/gpt.h b/sbin/fdisk/gpt.h index 68ea92e2f90..ace4b2583c0 100644 --- a/sbin/fdisk/gpt.h +++ b/sbin/fdisk/gpt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.h,v 1.5 2015/12/11 21:57:31 krw Exp $ */ +/* $OpenBSD: gpt.h,v 1.6 2016/01/09 18:10:57 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -22,9 +22,9 @@ void GPT_get_gpt(int); int GPT_init(void); int GPT_write(void); -void GPT_print(char *); -void GPT_print_part(int, char *); -void GPT_print_parthdr(void); +void GPT_print(char *, int); +void GPT_print_part(int, char *, int); +void GPT_print_parthdr(int); extern struct gpt_header gh; extern struct gpt_partition gp[NGPTPARTITIONS]; diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 372032a69b5..fb75301ddc8 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.49 2015/12/11 21:57:31 krw Exp $ */ +/* $OpenBSD: user.c,v 1.50 2016/01/09 18:10:57 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -158,7 +158,7 @@ USER_print_disk(int verbosity) GPT_get_gpt(1); /* Get Primary */ } if (letoh64(gh.gh_sig) == GPTSIGNATURE) - GPT_print("s"); + GPT_print("s", verbosity); else printf("\tNot Found\n"); if (verbosity) { @@ -166,7 +166,7 @@ USER_print_disk(int verbosity) printf("Secondary GPT:\n"); GPT_get_gpt(2); /* Get Secondary */ if (letoh64(gh.gh_sig) == GPTSIGNATURE) - GPT_print("s"); + GPT_print("s", verbosity); else printf("\tNot Found\n"); printf("\nMBR:\n"); |