Split PRT_print() into PRT_print_parthdr() and PRT_print_part()
authorkrw <krw@openbsd.org>
Fri, 21 Jan 2022 17:29:24 +0000 (17:29 +0000)
committerkrw <krw@openbsd.org>
Fri, 21 Jan 2022 17:29:24 +0000 (17:29 +0000)
to align with GPT functions. Simplifies logic and eliminates the
magic invocations to print the header.

No functional change.

sbin/fdisk/cmd.c
sbin/fdisk/mbr.c
sbin/fdisk/part.c
sbin/fdisk/part.h

index 82a5290..0216a7f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cmd.c,v 1.147 2021/10/21 13:16:49 krw Exp $   */
+/*     $OpenBSD: cmd.c,v 1.148 2022/01/21 17:29:24 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -316,8 +316,8 @@ setpid(const int pn, struct mbr *mbr)
 
        pp = &mbr->mbr_prt[pn];
 
-       PRT_print(0, NULL, "s");
-       PRT_print(pn, pp, "s");
+       PRT_print_parthdr();
+       PRT_print_part(pn, pp, "s");
 
        pp->prt_id = ask_pid(pp->prt_id);
 
index ad11fa1..90d2def 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mbr.c,v 1.114 2021/12/11 20:09:28 krw Exp $   */
+/*     $OpenBSD: mbr.c,v 1.115 2022/01/21 17:29:24 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -148,10 +148,10 @@ MBR_print(const struct mbr *mbr, const char *units)
 
        printf("Offset: %lld\t", (long long)mbr->mbr_lba_self);
        printf("Signature: 0x%X\n", (int)mbr->mbr_signature);
-       PRT_print(0, NULL, units);
+       PRT_print_parthdr();
 
        for (i = 0; i < NDOSPART; i++)
-               PRT_print(i, &mbr->mbr_prt[i], units);
+               PRT_print_part(i, &mbr->mbr_prt[i], units);
 }
 
 int
index f7525ba..4a7dfa6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: part.c,v 1.111 2022/01/18 19:37:27 krw Exp $  */
+/*     $OpenBSD: part.c,v 1.112 2022/01/21 17:29:24 krw Exp $  */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -351,28 +351,30 @@ PRT_make(const struct prt *prt, const uint64_t lba_self, const uint64_t lba_firs
 }
 
 void
-PRT_print(const int num, const struct prt *prt, const char *units)
+PRT_print_parthdr(void)
+{
+       printf("            Starting         Ending    "
+           "     LBA Info:\n");
+       printf(" #: id      C   H   S -      C   H   S "
+           "[       start:        size ]\n");
+       printf("---------------------------------------"
+           "----------------------------------------\n");
+}
+
+void
+PRT_print_part(const int num, const struct prt *prt, const char *units)
 {
        const struct unit_type  *ut;
        double                   size;
 
-       if (prt == NULL) {
-               printf("            Starting         Ending    "
-                   "     LBA Info:\n");
-               printf(" #: id      C   H   S -      C   H   S "
-                   "[       start:        size ]\n");
-               printf("---------------------------------------"
-                   "----------------------------------------\n");
-       } else {
-               size = units_size(units, prt->prt_ns, &ut);
-               printf("%c%1d: %.2X %6u %3u %3u - %6u %3u %3u "
-                   "[%12llu:%12.0f%s] %s\n",
-                   (prt->prt_flag == DOSACTIVE)?'*':' ',
-                   num, prt->prt_id,
-                   prt->prt_scyl, prt->prt_shead, prt->prt_ssect,
-                   prt->prt_ecyl, prt->prt_ehead, prt->prt_esect,
-                   prt->prt_bs, size, ut->ut_abbr, ascii_id(prt->prt_id));
-       }
+       size = units_size(units, prt->prt_ns, &ut);
+       printf("%c%1d: %.2X %6u %3u %3u - %6u %3u %3u "
+           "[%12llu:%12.0f%s] %s\n",
+           (prt->prt_flag == DOSACTIVE)?'*':' ',
+           num, prt->prt_id,
+           prt->prt_scyl, prt->prt_shead, prt->prt_ssect,
+           prt->prt_ecyl, prt->prt_ehead, prt->prt_esect,
+           prt->prt_bs, size, ut->ut_abbr, ascii_id(prt->prt_id));
 }
 
 void
index cfbc48d..97e88d4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: part.h,v 1.31 2021/10/25 13:51:25 krw Exp $   */
+/*     $OpenBSD: part.h,v 1.32 2022/01/21 17:29:24 krw Exp $   */
 
 /*
  * Copyright (c) 1997 Tobias Weingartner
@@ -31,7 +31,8 @@ void           PRT_parse(const struct dos_partition *, const uint64_t,
     const uint64_t, struct prt *);
 void            PRT_make(const struct prt *,const uint64_t, const uint64_t,
     struct dos_partition *);
-void            PRT_print(const int, const struct prt *, const char *);
+void            PRT_print_part(const int, const struct prt *, const char *);
+void            PRT_print_parthdr(void);
 char           *PRT_uuid_to_typename(const struct uuid *);
 int             PRT_uuid_to_type(const struct uuid *);
 struct uuid    *PRT_type_to_uuid(const int);