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

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