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

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