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