grub2/grub2-btrfs-08-workaround-snapshot-menu-default-entry.patch

59 lines
1.8 KiB
Diff
Raw Normal View History

Index: grub-2.02~beta2/grub-core/normal/menu.c
===================================================================
--- grub-2.02~beta2.orig/grub-core/normal/menu.c
+++ grub-2.02~beta2/grub-core/normal/menu.c
@@ -575,6 +575,44 @@ print_countdown (struct grub_term_coordi
grub_refresh ();
}
+/* bsc#956046 - The first entry titled 'Bootable snapshot #$NUM' is inserted on
+ top at runtime to display current snapshot information. If default entry is
+ using number as key to index the entry, the result will be shifted so here we
+ add specical handling to shift it back. We apply this workaround until a better
+ solution can be found. */
+static void
+workaround_snapshot_menu_default_entry (grub_menu_t menu, const char *name, int *default_entry)
+{
+ grub_menu_entry_t entry;
+
+ if ((entry = grub_menu_get_entry (menu, 0))
+ && entry->submenu
+ && grub_strncmp (entry->title, "Bootable snapshot", sizeof("Bootable snapshot") - 1) == 0)
+ {
+ const char *val;
+
+ if (*default_entry == -1 && menu->size > 1)
+ {
+ *default_entry = 1;
+ return;
+ }
+
+ val = grub_env_get (name);
+
+ grub_error_push ();
+
+ if (val)
+ grub_strtoul (val, 0, 0);
+
+ if (*default_entry < (menu->size - 1) && grub_errno == GRUB_ERR_NONE)
+ ++(*default_entry);
+
+ grub_error_pop ();
+ }
+
+ return;
+}
+
#define GRUB_MENU_PAGE_SIZE 10
/* Show the menu and handle menu entry selection. Returns the menu entry
@@ -593,6 +631,8 @@ run_menu (grub_menu_t menu, int nested,
default_entry = get_entry_number (menu, "default");
+ workaround_snapshot_menu_default_entry (menu, "default", &default_entry);
+
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
the first entry. */
if (default_entry < 0 || default_entry >= menu->size)