diff options
author | 2015-12-11 21:57:31 +0000 | |
---|---|---|
committer | 2015-12-11 21:57:31 +0000 | |
commit | fbf68f680395c0f0ac18a886cef8ff8a5ed3f2fd (patch) | |
tree | 53efb8b3779ee4822e0910011356cfb4afcef7a4 | |
parent | rename field member + whitespaces (diff) | |
download | wireguard-openbsd-fbf68f680395c0f0ac18a886cef8ff8a5ed3f2fd.tar.xz wireguard-openbsd-fbf68f680395c0f0ac18a886cef8ff8a5ed3f2fd.zip |
Add '-v' flag that forces the display of both GPT's and the MBR.
Useful for seeing exactly what is currently on the disk. Suggested
by a request from kettenis@.
Man page & usage ok jmc@
-rw-r--r-- | sbin/fdisk/fdisk.8 | 13 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 17 | ||||
-rw-r--r-- | sbin/fdisk/gpt.c | 12 | ||||
-rw-r--r-- | sbin/fdisk/gpt.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 33 | ||||
-rw-r--r-- | sbin/fdisk/user.h | 4 |
6 files changed, 58 insertions, 25 deletions
diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8 index 7a08cb192aa..d209e3941fe 100644 --- a/sbin/fdisk/fdisk.8 +++ b/sbin/fdisk/fdisk.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fdisk.8,v 1.88 2015/11/17 17:47:49 jmc Exp $ +.\" $OpenBSD: fdisk.8,v 1.89 2015/12/11 21:57:31 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: November 17 2015 $ +.Dd $Mdocdate: December 11 2015 $ .Dt FDISK 8 .Os .Sh NAME @@ -23,7 +23,7 @@ .Nd partition table maintenance program .Sh SYNOPSIS .Nm fdisk -.Op Fl egy +.Op Fl egvy .Op Fl i | u .Op Fl b Ar blocks .Oo @@ -156,6 +156,13 @@ Only one of or .Fl u can be specified. +.It Fl v +Print the contents of the MBR, the Primary GPT and the Secondary GPT. +Cannot be used with +.Fl i , +.Fl u , +or +.Fl e . .It Fl y Avoid asking yes/no questions when not desirable. .It Ar disk diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 5314713fa8c..cf5dc0b14ec 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.96 2015/12/01 06:25:43 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.97 2015/12/11 21:57:31 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -50,7 +50,7 @@ usage(void) extern char * __progname; fprintf(stderr, "usage: %s " - "[-egy] [-i|-u] [-b #] [-c # -h # -s #] " + "[-egvy] [-i|-u] [-b #] [-c # -h # -s #] " "[-f mbrfile] [-l # ] disk\n" "\t-b: specify special boot partition block count; requires -i\n" "\t-chs: specify disk geometry; all three must be specified\n" @@ -60,6 +60,7 @@ usage(void) "\t-i: initialize disk with MBR unless -g is also specified\n" "\t-l: specify LBA block count; cannot be used with -chs\n" "\t-u: update MBR code; preserve partition table\n" + "\t-v: print the MBR, the Primary GPT and the Secondary GPT\n" "\t-y: do not ask questions\n" "`disk' may be of the forms: sd0 or /dev/rsd0c.\n", __progname); @@ -72,6 +73,7 @@ main(int argc, char *argv[]) ssize_t len; int ch, fd, error; int e_flag = 0, f_flag = 0, g_flag = 0, i_flag = 0, u_flag = 0; + int verbosity = 0; int c_arg = 0, h_arg = 0, s_arg = 0; u_int32_t l_arg = 0; char *query; @@ -87,7 +89,7 @@ main(int argc, char *argv[]) if (pledge("stdio rpath wpath disklabel proc exec", NULL) == -1) err(1, "pledge"); - while ((ch = getopt(argc, argv, "ieguf:c:h:s:l:b:y")) != -1) { + while ((ch = getopt(argc, argv, "iegpuvf:c:h:s:l:b:y")) != -1) { const char *errstr; switch(ch) { @@ -148,6 +150,9 @@ main(int argc, char *argv[]) case 'y': y_flag = 1; break; + case 'v': + verbosity++; + break; default: usage(); } @@ -170,9 +175,9 @@ main(int argc, char *argv[]) errx(1, "Can't read sector 0!"); MBR_parse(&dos_mbr, 0, 0, &mbr); - /* Get the GPT if present. */ + /* Get the GPT if present. Either primary or secondary is ok. */ if (MBR_protective_mbr(&mbr) == 0) - GPT_get_gpt(); + GPT_get_gpt(0); if (letoh64(gh.gh_sig) != GPTSIGNATURE) { if (DL_GETDSIZE(&dl) > disk.size) @@ -183,7 +188,7 @@ main(int argc, char *argv[]) if ((i_flag + u_flag + e_flag) == 0) { if (pledge("stdio", NULL) == -1) err(1, "pledge"); - USER_print_disk(); + USER_print_disk(verbosity); goto done; } diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index f650dfbaa6f..275345682e5 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.8 2015/11/26 08:15:07 tim Exp $ */ +/* $OpenBSD: gpt.c,v 1.9 2015/12/11 21:57:31 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -189,7 +189,7 @@ GPT_get_partition_table(off_t where) } void -GPT_get_gpt(void) +GPT_get_gpt(int which) { int privalid, altvalid; @@ -200,13 +200,17 @@ GPT_get_gpt(void) privalid = GPT_get_header(GPTSECTOR); if (privalid == 0) privalid = GPT_get_partition_table(gh.gh_part_lba); - if (privalid == 0) + if (which == 1 || (which == 0 && privalid == 0)) return; + /* No valid GPT found. Zap any artifacts. */ + memset(&gh, 0, sizeof(gh)); + memset(&gp, 0, sizeof(gp)); + altvalid = GPT_get_header(DL_GETDSIZE(&dl) - 1); if (altvalid == 0) altvalid = GPT_get_partition_table(gh.gh_part_lba); - if (altvalid == 0) + if (which == 2 || altvalid == 0) return; /* No valid GPT found. Zap any artifacts. */ diff --git a/sbin/fdisk/gpt.h b/sbin/fdisk/gpt.h index 058435bd9d8..68ea92e2f90 100644 --- a/sbin/fdisk/gpt.h +++ b/sbin/fdisk/gpt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.h,v 1.4 2015/11/15 01:22:39 krw Exp $ */ +/* $OpenBSD: gpt.h,v 1.5 2015/12/11 21:57:31 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -18,7 +18,7 @@ int GPT_get_hdr(off_t); int GPT_get_partition_table(off_t); -void GPT_get_gpt(void); +void GPT_get_gpt(int); int GPT_init(void); int GPT_write(void); diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index e2e5b7e193e..372032a69b5 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.48 2015/11/19 16:14:08 krw Exp $ */ +/* $OpenBSD: user.c,v 1.49 2015/12/11 21:57:31 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -79,7 +79,7 @@ USER_edit(off_t offset, off_t reloff) memset(&gh, 0, sizeof(gh)); memset(&gp, 0, sizeof(gp)); if (MBR_protective_mbr(&mbr) == 0) - GPT_get_gpt(); + GPT_get_gpt(0); } printf("Enter 'help' for information\n"); @@ -137,7 +137,7 @@ done: } void -USER_print_disk(void) +USER_print_disk(int verbosity) { off_t offset, firstoff; int i, error; @@ -151,11 +151,28 @@ USER_print_disk(void) if (error == -1) break; MBR_parse(&dos_mbr, offset, firstoff, &mbr); - if (offset == 0 && MBR_protective_mbr(&mbr) == 0) { - if (letoh64(gh.gh_sig) == GPTSIGNATURE) { - GPT_print("s"); - break; - } + if (offset == 0) { + if (verbosity || MBR_protective_mbr(&mbr) == 0) { + if (verbosity) { + printf("Primary GPT:\n"); + GPT_get_gpt(1); /* Get Primary */ + } + if (letoh64(gh.gh_sig) == GPTSIGNATURE) + GPT_print("s"); + else + printf("\tNot Found\n"); + if (verbosity) { + printf("\n"); + printf("Secondary GPT:\n"); + GPT_get_gpt(2); /* Get Secondary */ + if (letoh64(gh.gh_sig) == GPTSIGNATURE) + GPT_print("s"); + else + printf("\tNot Found\n"); + printf("\nMBR:\n"); + } else + break; + } } MBR_print(&mbr, NULL); diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h index ded782f8ae9..d292fc284f2 100644 --- a/sbin/fdisk/user.h +++ b/sbin/fdisk/user.h @@ -1,4 +1,4 @@ -/* $OpenBSD: user.h,v 1.16 2015/03/18 14:46:59 krw Exp $ */ +/* $OpenBSD: user.h,v 1.17 2015/12/11 21:57:31 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -21,6 +21,6 @@ /* Prototypes */ void USER_edit(off_t, off_t); -void USER_print_disk(void); +void USER_print_disk(int); #endif /* _USER_H */ |