Replace some magic numbers with #define's. Rename GPT_get_gpt() to
authorkrw <krw@openbsd.org>
Mon, 10 May 2021 17:16:01 +0000 (17:16 +0000)
committerkrw <krw@openbsd.org>
Mon, 10 May 2021 17:16:01 +0000 (17:16 +0000)
GPT_read() to match MBR_read().

No intentional functional change.

sbin/fdisk/cmd.c
sbin/fdisk/fdisk.c
sbin/fdisk/gpt.c
sbin/fdisk/gpt.h
sbin/fdisk/user.c

index 70a1c34..0ee22c3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cmd.c,v 1.101 2021/05/07 22:15:13 krw Exp $   */
+/*     $OpenBSD: cmd.c,v 1.102 2021/05/10 17:16:01 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", 0);
+               GPT_print("s", TERSE);
        } else {
                memset(&gh, 0, sizeof(gh));
                MBR_init(mbr);
@@ -297,8 +297,8 @@ Xgsetpid(char *args)
        gg = &gp[pn];
 
        /* Print out current table entry */
-       GPT_print_parthdr(0);
-       GPT_print_part(pn, "s", 0);
+       GPT_print_parthdr(TERSE);
+       GPT_print_part(pn, "s", TERSE);
 
        /* Ask for partition type or GUID. */
        uuid_dec_le(&gg->gp_type, &guid);
@@ -395,7 +395,7 @@ Xprint(char *args, struct mbr *mbr)
 {
 
        if (MBR_protective_mbr(mbr) == 0 && letoh64(gh.gh_sig) == GPTSIGNATURE)
-               GPT_print(args, 1);
+               GPT_print(args, VERBOSE);
        else
                MBR_print(mbr, args);
 
index f84ad69..55ad12d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: fdisk.c,v 1.105 2021/05/07 22:15:13 krw Exp $ */
+/*     $OpenBSD: fdisk.c,v 1.106 2021/05/10 17:16:01 krw Exp $ */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
        ssize_t len;
        int ch, fd, error;
        int e_flag = 0, g_flag = 0, i_flag = 0, u_flag = 0;
-       int verbosity = 0;
+       int verbosity = TERSE;
        int c_arg = 0, h_arg = 0, s_arg = 0;
        uint32_t l_arg = 0;
        char *query;
@@ -146,7 +146,7 @@ main(int argc, char *argv[])
                        y_flag = 1;
                        break;
                case 'v':
-                       verbosity++;
+                       verbosity = VERBOSE;
                        break;
                default:
                        usage();
@@ -176,7 +176,7 @@ main(int argc, char *argv[])
 
        /* Get the GPT if present. Either primary or secondary is ok. */
        if (MBR_protective_mbr(&mbr) == 0)
-               GPT_get_gpt(0);
+               GPT_read(ANYGPT);
 
        if (!(i_flag || u_flag || e_flag)) {
                if (pledge("stdio", NULL) == -1)
index 7a15a0d..113ec56 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: gpt.c,v 1.13 2021/05/07 22:15:13 krw Exp $    */
+/*     $OpenBSD: gpt.c,v 1.14 2021/05/10 17:16:01 krw Exp $    */
 /*
  * Copyright (c) 2015 Markus Muller <mmu@grummel.net>
  * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -192,28 +192,24 @@ GPT_get_partition_table(off_t where)
 }
 
 void
-GPT_get_gpt(int which)
+GPT_read(int which)
 {
-       int privalid, altvalid;
+       int valid;
 
-       /*
-        * primary header && primary partition table ||
-        * alt header && alt partition table
-        */
-       privalid = GPT_get_header(GPTSECTOR);
-       if (privalid == 0)
-               privalid = GPT_get_partition_table(gh.gh_part_lba);
-       if (which == 1 || (which == 0 && privalid == 0))
+       valid = GPT_get_header(GPTSECTOR);
+       if (valid == 0)
+               valid = GPT_get_partition_table(gh.gh_part_lba);
+       if (which == PRIMARYGPT || (which == ANYGPT && valid == 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 (which == 2 || altvalid == 0)
+       valid = GPT_get_header(DL_GETDSIZE(&dl) - 1);
+       if (valid == 0)
+               valid = GPT_get_partition_table(gh.gh_part_lba);
+       if (which == SECONDARYGPT || valid == 0)
                return;
 
        /* No valid GPT found. Zap any artifacts. */
@@ -239,7 +235,7 @@ GPT_print(char *units, int verbosity)
                printf("%d-byte ", secsize);
        printf("%s]\n", unit_types[u].lname);
 
-       if (verbosity) {
+       if (verbosity == VERBOSE) {
                printf("GUID: ");
                uuid_dec_le(&gh.gh_guid, &guid);
                uuid_to_string(&guid, &guidstr, &status);
@@ -264,7 +260,7 @@ GPT_print_parthdr(int verbosity)
 {
        printf("   #: type                                "
            " [       start:         size ]\n");
-       if (verbosity)
+       if (verbosity == VERBOSE)
                printf("      guid                                 name\n");
        printf("--------------------------------------------------------"
            "----------------\n");
@@ -289,7 +285,7 @@ GPT_print_part(int n, char *units, int verbosity)
            PRT_uuid_to_typename(&guid), letoh64(partn->gp_lba_start),
            size, unit_types[u].abbr);
 
-       if (verbosity) {
+       if (verbosity == VERBOSE) {
                uuid_dec_le(&partn->gp_guid, &guid);
                uuid_to_string(&guid, &guidstr, &status);
                if (status != uuid_s_ok)
index e6f29f0..19c8bcf 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: gpt.h,v 1.8 2021/05/06 22:26:14 krw Exp $     */
+/*     $OpenBSD: gpt.h,v 1.9 2021/05/10 17:16:01 krw Exp $     */
 /*
  * Copyright (c) 2015 Markus Muller <mmu@grummel.net>
  * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -16,7 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-void           GPT_get_gpt(int);
+void           GPT_read(int);
 int            GPT_get_header(off_t);
 int            GPT_get_partition_table(off_t);
 int            GPT_get_lba_start(unsigned int);
@@ -30,3 +30,10 @@ void         GPT_print_parthdr(int);
 
 extern struct gpt_header gh;
 extern struct gpt_partition gp[NGPTPARTITIONS];
+
+#define        ANYGPT          0
+#define        PRIMARYGPT      1
+#define        SECONDARYGPT    2
+
+#define        TERSE           0
+#define        VERBOSE         1
index b1cf553..409ff36 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: user.c,v 1.52 2019/04/29 18:54:12 krw Exp $   */
+/*     $OpenBSD: user.c,v 1.53 2021/05/10 17:16:01 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -80,7 +80,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(0);
+                       GPT_read(ANYGPT);
        }
 
        printf("Enter 'help' for information\n");
@@ -153,19 +153,20 @@ USER_print_disk(int verbosity)
                        break;
                MBR_parse(&dos_mbr, offset, firstoff, &mbr);
                if (offset == 0) {
-                      if (verbosity || MBR_protective_mbr(&mbr) == 0) {
-                               if (verbosity) {
+                       if (verbosity == VERBOSE || MBR_protective_mbr(&mbr) ==
+                           0) {
+                               if (verbosity == VERBOSE) {
                                        printf("Primary GPT:\n");
-                                       GPT_get_gpt(1); /* Get Primary */
+                                       GPT_read(PRIMARYGPT);
                                }
                                if (letoh64(gh.gh_sig) == GPTSIGNATURE)
                                        GPT_print("s", verbosity);
                                else
                                        printf("\tNot Found\n");
-                               if (verbosity) {
+                               if (verbosity == VERBOSE) {
                                        printf("\n");
                                        printf("Secondary GPT:\n");
-                                       GPT_get_gpt(2); /* Get Secondary */
+                                       GPT_read(SECONDARYGPT);
                                        if (letoh64(gh.gh_sig) == GPTSIGNATURE)
                                                GPT_print("s", verbosity);
                                        else