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

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