Blame SOURCES/0031-Fix-partition-number-detection-when-it-s-not-provide.patch

994945
From cff35642eac6699e30549db2db3341e7657bf4a6 Mon Sep 17 00:00:00 2001
994945
From: Peter Jones <pjones@redhat.com>
994945
Date: Tue, 18 Sep 2018 14:57:13 -0400
994945
Subject: [PATCH] Fix partition number detection when it's not provided.
994945
994945
We need to actually get the partition number from the child device when
994945
we're called without it.
994945
994945
Resolves: rhbz#1616305
994945
994945
Signed-off-by: Peter Jones <pjones@redhat.com>
994945
---
994945
 src/creator.c | 43 +++++++++++++++++++++++++++++++++++++++++++
994945
 1 file changed, 43 insertions(+)
994945
994945
diff --git a/src/creator.c b/src/creator.c
994945
index ef782e2b6475..987fa033e5b7 100644
994945
--- a/src/creator.c
994945
+++ b/src/creator.c
994945
@@ -350,6 +350,36 @@ efi_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size,
994945
 	return ret;
994945
 }
994945
 
994945
+static int
994945
+get_part(char *devpath)
994945
+{
994945
+	int fd;
994945
+	int partition = -1;
994945
+	struct device *dev = NULL;
994945
+
994945
+	fd = open(devpath, O_RDONLY);
994945
+	if (fd < 0) {
994945
+		efi_error("could not open device for ESP");
994945
+		goto err;
994945
+	}
994945
+
994945
+	dev = device_get(fd, -1);
994945
+	if (dev == NULL) {
994945
+		efi_error("could not get ESP disk info");
994945
+		goto err;
994945
+	}
994945
+
994945
+	partition = dev->part;
994945
+	if (partition < 0)
994945
+		partition = 0;
994945
+err:
994945
+	if (dev)
994945
+		device_free(dev);
994945
+	if (fd >= 0)
994945
+		close(fd);
994945
+	return partition;
994945
+}
994945
+
994945
 ssize_t NONNULL(3) PUBLIC
994945
 efi_generate_file_device_path(uint8_t *buf, ssize_t size,
994945
 			      const char * const filepath,
994945
@@ -374,6 +404,19 @@ efi_generate_file_device_path(uint8_t *buf, ssize_t size,
994945
 		efi_error("could not find parent device for file");
994945
 		goto err;
994945
 	}
994945
+        debug("child_devpath:%s", child_devpath);
994945
+
994945
+	debug("parent_devpath:%s", parent_devpath);
994945
+	debug("child_devpath:%s", child_devpath);
994945
+	debug("rc:%d", rc);
994945
+
994945
+	rc = get_part(child_devpath);
994945
+	if (rc < 0) {
994945
+		efi_error("Couldn't get partition number for %s",
994945
+			  child_devpath);
994945
+		goto err;
994945
+	}
994945
+	debug("detected partition:%d", rc);
994945
 
994945
 	va_start(ap, options);
994945
 
994945
-- 
994945
2.19.1
994945