diff mbox series

[1/3] diskpart: factorize retrieving partition table type

Message ID 20220410093518.308218-1-sbabic@denx.de
State Accepted
Headers show
Series [1/3] diskpart: factorize retrieving partition table type | expand

Commit Message

Stefano Babic April 10, 2022, 9:35 a.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 handlers/diskpart_handler.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index 0af4e60..1e81f50 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -104,6 +104,18 @@  static char *diskpart_get_lbtype(struct img_type *img)
 	return dict_get_value(&img->properties, "labeltype");
 }
 
+static bool diskpart_is_gpt(struct img_type *img)
+{
+	char *lbtype = diskpart_get_lbtype(img);
+	return (lbtype && !strcmp(lbtype, "gpt"));
+}
+
+static bool diskpart_is_dos(struct img_type *img)
+{
+	char *lbtype = diskpart_get_lbtype(img);
+	return (lbtype && !strcmp(lbtype, "dos"));
+}
+
 static int diskpart_assign_label(struct fdisk_context *cxt, struct img_type *img,
 		struct hnd_priv priv, struct create_table *createtable, unsigned long hybrid)
 {
@@ -125,7 +137,7 @@  static int diskpart_assign_label(struct fdisk_context *cxt, struct img_type *img
 		if (hybrid)
 			createtable->child = true;
 	} else if (lbtype) {
-		if (!strcmp(lbtype, "gpt")) {
+		if (diskpart_is_gpt(img)) {
 			priv.labeltype = FDISK_DISKLABEL_GPT;
 		} else {
 			priv.labeltype = FDISK_DISKLABEL_DOS;
@@ -800,7 +812,7 @@  static int diskpart(struct img_type *img,
 	};
 	struct create_table *createtable = NULL;
 
-	if (!lbtype || (strcmp(lbtype, "gpt") && strcmp(lbtype, "dos"))) {
+	if (!diskpart_is_gpt(img) && !diskpart_is_dos(img)) {
 		ERROR("Just GPT or DOS partition table are supported");
 		return -EINVAL;
 	}
@@ -935,7 +947,7 @@  static int diskpart(struct img_type *img,
 		}
 	}
 
-	if (hybrid && (!lbtype || strcmp(lbtype, "gpt"))) {
+	if (hybrid && !diskpart_is_gpt(img)) {
 		ERROR("Partitions have hybrid(dostype) entries but labeltype is not gpt !");
 		ret = -EINVAL;
 		goto handler_release;