15a2072
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a2072
From: Javier Martinez Canillas <javierm@redhat.com>
15a2072
Date: Wed, 18 Jul 2018 08:08:06 +0200
15a2072
Subject: [PATCH] blscfg: Fallback to search BLS snippets in
15a2072
 /boot/loader/entries
15a2072
15a2072
The default path to search the BLS snippets is /loader/entries, this is
15a2072
only a correct assumption if $root ($root) is a boot partition but it's
15a2072
not true if /boot isn't a mount point.
15a2072
15a2072
A user can set a blsdir grub environment variable to choose a different
15a2072
path, but instead of failing when /boot is a directory inside the root
15a2072
partition fallback to search the BLS in /boot/loader/entries to cover
15a2072
that case as well.
15a2072
15a2072
Reported-by: Hans de Goede <hdegoede@redhat.com>
15a2072
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
15a2072
---
15a2072
 grub-core/commands/blscfg.c | 13 ++++++++++++-
15a2072
 1 file changed, 12 insertions(+), 1 deletion(-)
15a2072
15a2072
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
15a2072
index 80d8814fc3f..321c93069f2 100644
15a2072
--- a/grub-core/commands/blscfg.c
15a2072
+++ b/grub-core/commands/blscfg.c
15a2072
@@ -692,6 +692,7 @@ static int find_entry (const char *filename,
15a2072
   grub_device_t blsdir_dev = NULL;
15a2072
   const char *blsdir = NULL;
15a2072
   char *saved_env_buf = NULL;
15a2072
+  int fallback = 0;
15a2072
   int r = 0;
15a2072
   const char *devid = grub_env_get ("boot");
15a2072
 
15a2072
@@ -797,7 +798,9 @@ static int find_entry (const char *filename,
15a2072
   }
15a2072
   read_entry_info.dirname = blsdir;
15a2072
 
15a2072
-  r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info);
15a2072
+read_fallback:
15a2072
+  r = blsdir_fs->dir (blsdir_dev, read_entry_info.dirname, read_entry,
15a2072
+		      &read_entry_info);
15a2072
   if (r != 0) {
15a2072
       grub_dprintf ("blscfg", "read_entry returned error\n");
15a2072
       grub_err_t e;
15a2072
@@ -807,6 +810,14 @@ static int find_entry (const char *filename,
15a2072
 	} while (e);
15a2072
   }
15a2072
 
15a2072
+  if (!nentries && !fallback && info->platform != PLATFORM_EMU) {
15a2072
+    read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH;
15a2072
+    grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to %s\n",
15a2072
+		  blsdir, read_entry_info.dirname);
15a2072
+    fallback = 1;
15a2072
+    goto read_fallback;
15a2072
+  }
15a2072
+
15a2072
   grub_dprintf ("blscfg", "Sorting %d entries\n", nentries);
15a2072
   grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, NULL);
15a2072