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