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

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