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

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