From 08856ccda21f5e1b4ca90b1466e10114105795c8 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 25 Nov 2021 10:49:52 +0100 Subject: [PATCH] daemon/parted: simplify print_partition_table() prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit 994ca1f8ebcc ("daemon: Reimplement 'part_get_mbr_part_type' API in OCaml.", 2018-05-02), we've not had any calls to print_partition_table() that would pass a "false" argument for the "add_m_option" parameter. Remove the parameter, and inside part_get_mbr_part_type(), remove the dead branch. Relatedly, update the comment on the "print_partition_table_machine_readable" OCaml function, originally from commit 32e661f42169 ("daemon: Reimplement ‘part_list’ API in OCaml.", 2017-07-27). Because print_partition_table() now passes "-m" to "parted" unconditionally, and there are no use cases left that would *forbid* "-m", "print_partition_table_machine_readable" is almost equivalent to print_partition_table() -- modulo the enforcement of the "BYT;" header. Signed-off-by: Laszlo Ersek Acked-by: Richard W.M. Jones Message-Id: <20211125094954.9713-4-lersek@redhat.com> --- daemon/parted.c | 17 ++++++----------- daemon/parted.ml | 6 ++---- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/daemon/parted.c b/daemon/parted.c index ef7b90056..3a723762c 100644 --- a/daemon/parted.c +++ b/daemon/parted.c @@ -341,7 +341,7 @@ get_table_field (const char *line, int n) } static char * -print_partition_table (const char *device, bool add_m_option) +print_partition_table (const char *device) { char *out; CLEANUP_FREE char *err = NULL; @@ -349,14 +349,9 @@ print_partition_table (const char *device, bool add_m_option) udev_settle (); - if (add_m_option) - r = command (&out, &err, "parted", "-m", "-s", "--", device, - "unit", "b", - "print", NULL); - else - r = command (&out, &err, "parted", "-s", "--", device, - "unit", "b", - "print", NULL); + r = command (&out, &err, "parted", "-m", "-s", "--", device, + "unit", "b", + "print", NULL); udev_settle (); @@ -383,7 +378,7 @@ do_part_get_bootable (const char *device, int partnum) return -1; } - CLEANUP_FREE char *out = print_partition_table (device, true); + CLEANUP_FREE char *out = print_partition_table (device); if (!out) return -1; @@ -555,7 +550,7 @@ do_part_get_name (const char *device, int partnum) return NULL; if (STREQ (parttype, "gpt")) { - CLEANUP_FREE char *out = print_partition_table (device, true); + CLEANUP_FREE char *out = print_partition_table (device); if (!out) return NULL; diff --git a/daemon/parted.ml b/daemon/parted.ml index 45c387987..29b98c480 100644 --- a/daemon/parted.ml +++ b/daemon/parted.ml @@ -57,10 +57,8 @@ let part_get_mbr_id device partnum = (* It's printed in hex, possibly with a leading space. *) sscanf out " %x" identity -(* This is not equivalent to print_partition_table in the C code, as - * it only deals with the ‘-m’ option output, and it partially parses - * that. If we convert other functions that don't use the ‘-m’ version - * we'll have to refactor this. XXX +(* This is almost equivalent to print_partition_table in the C code. The + * difference is that here we enforce the "BYT;" header internally. *) let print_partition_table_machine_readable device = udev_settle ();