Blame SOURCES/0017-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch

80b73c
From bc215d06720b346ba0d888a6149cf90f544a90ad Mon Sep 17 00:00:00 2001
80b73c
From: Peter Jones <pjones@redhat.com>
80b73c
Date: Wed, 20 Jun 2018 17:00:24 -0400
80b73c
Subject: [PATCH 17/17] If we can't parse part of the device link, skip it and
80b73c
 set DEV_ABBREV_ONLY
80b73c
80b73c
If we can't parse some part of the device symlink, we can't write a full
80b73c
device path, but we can write an abbreviated HD() or File() path.  So if
80b73c
we've exausted all possibilities, skip to the next node, set
80b73c
DEV_ABBREV_ONLY in the device's flags, and try parsing again.  Then when
80b73c
creator.c checks if that flag conflicts, it'll throw an error if it
80b73c
does.
80b73c
80b73c
Signed-off-by: Peter Jones <pjones@redhat.com>
80b73c
---
80b73c
 src/linux.c | 62 ++++++++++++++++++++++++++++++++++++++++-------------
80b73c
 1 file changed, 47 insertions(+), 15 deletions(-)
80b73c
80b73c
diff --git a/src/linux.c b/src/linux.c
80b73c
index 1e7db4e3f61..8fe21f19f78 100644
80b73c
--- a/src/linux.c
80b73c
+++ b/src/linux.c
80b73c
@@ -429,14 +429,17 @@ struct device HIDDEN
80b73c
 
80b73c
         const char *current = dev->link;
80b73c
         bool needs_root = true;
80b73c
+        int last_successful_probe = -1;
80b73c
 
80b73c
         debug(DEBUG, "searching for device nodes in %s", dev->link);
80b73c
         for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) {
80b73c
                 struct dev_probe *probe = dev_probes[i];
80b73c
                 ssize_t pos;
80b73c
 
80b73c
-                if (!needs_root && (probe->flags & DEV_PROVIDES_ROOT)) {
80b73c
-                        debug(DEBUG, "not testing %s because flags is 0x%x", probe->name, probe->flags);
80b73c
+                if (!needs_root &&
80b73c
+                    (probe->flags & DEV_PROVIDES_ROOT)) {
80b73c
+                        debug(DEBUG, "not testing %s because flags is 0x%x",
80b73c
+                              probe->name, probe->flags);
80b73c
                         continue;
80b73c
                 }
80b73c
 
80b73c
@@ -445,22 +448,51 @@ struct device HIDDEN
80b73c
                 if (pos < 0) {
80b73c
                         efi_error("parsing %s failed", probe->name);
80b73c
                         goto err;
80b73c
-                } else if (pos == 0) {
80b73c
+                } else if (pos > 0) {
80b73c
+                        debug(DEBUG, "%s matched %s", probe->name, current);
80b73c
+                        dev->flags |= probe->flags;
80b73c
+
80b73c
+                        if (probe->flags & DEV_PROVIDES_HD ||
80b73c
+                            probe->flags & DEV_PROVIDES_ROOT ||
80b73c
+                            probe->flags & DEV_ABBREV_ONLY)
80b73c
+                                needs_root = false;
80b73c
+
80b73c
+                        dev->probes[n++] = dev_probes[i];
80b73c
+                        current += pos;
80b73c
+                        debug(DEBUG, "current:%s", current);
80b73c
+                        last_successful_probe = i;
80b73c
+
80b73c
+                        if (!*current || !strncmp(current, "block/", 6))
80b73c
+                                break;
80b73c
+
80b73c
                         continue;
80b73c
                 }
80b73c
-                debug(DEBUG, "%s matched %s", probe->name, current);
80b73c
-                dev->flags |= probe->flags;
80b73c
 
80b73c
-                if (probe->flags & DEV_PROVIDES_HD ||
80b73c
-                    probe->flags & DEV_PROVIDES_ROOT ||
80b73c
-                    probe->flags & DEV_ABBREV_ONLY)
80b73c
-                        needs_root = false;
80b73c
-                dev->probes[n++] = dev_probes[i];
80b73c
-                current += pos;
80b73c
-                debug(DEBUG, "current:%s", current);
80b73c
-
80b73c
-                if (!*current || !strncmp(current, "block/", 6))
80b73c
-                        break;
80b73c
+                debug(DEBUG, "dev_probes[i+1]: %p dev->interface_type: %d\n",
80b73c
+                      dev_probes[i+1], dev->interface_type);
80b73c
+                if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
80b73c
+                        int new_pos = 0;
80b73c
+                        rc = sscanf(current, "%*[^/]/%n", &new_pos);
80b73c
+                        if (rc < 0) {
80b73c
+                                efi_error(
80b73c
+                                     "Cannot parse device link segment \"%s\"",
80b73c
+                                     current);
80b73c
+                                goto err;
80b73c
+                        }
80b73c
+                        debug(DEBUG,
80b73c
+                              "Cannot parse device link segment \"%s\"",
80b73c
+                              current);
80b73c
+                        debug(DEBUG, "Skipping to \"%s\"", current + new_pos);
80b73c
+                        debug(DEBUG,
80b73c
+                              "This means we can only write abbreviated paths");
80b73c
+                        if (rc < 0)
80b73c
+                                goto err;
80b73c
+                        if (new_pos == 0)
80b73c
+                                goto err;
80b73c
+                        dev->flags |= DEV_ABBREV_ONLY;
80b73c
+                        i = last_successful_probe;
80b73c
+                        current += new_pos;
80b73c
+                }
80b73c
         }
80b73c
 
80b73c
         if (dev->interface_type == unknown) {
80b73c
-- 
80b73c
2.17.1
80b73c