]> TLD Linux GIT Repositories - packages/grub2.git/blob - blscfg.patch
- updated to 2.02-rc1
[packages/grub2.git] / blscfg.patch
1 diff -urNp grub-2.02-rc1.orig/grub-core/commands/blscfg.c grub-2.02-rc1/grub-core/commands/blscfg.c
2 --- grub-2.02-rc1.orig/grub-core/commands/blscfg.c      1970-01-01 00:00:00.000000000 +0000
3 +++ grub-2.02-rc1/grub-core/commands/blscfg.c   2017-02-08 15:09:21.548315239 +0000
4 @@ -0,0 +1,201 @@
5 +/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
6 +
7 +/* bls.c - implementation of the boot loader spec */
8 +
9 +/*
10 + *  GRUB  --  GRand Unified Bootloader
11 + *
12 + *  GRUB is free software: you can redistribute it and/or modify
13 + *  it under the terms of the GNU General Public License as published by
14 + *  the Free Software Foundation, either version 3 of the License, or
15 + *  (at your option) any later version.
16 + *
17 + *  GRUB is distributed in the hope that it will be useful,
18 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 + *  GNU General Public License for more details.
21 + *
22 + *  You should have received a copy of the GNU General Public License
23 + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
24 + */
25 +
26 +#include <grub/types.h>
27 +#include <grub/misc.h>
28 +#include <grub/mm.h>
29 +#include <grub/err.h>
30 +#include <grub/dl.h>
31 +#include <grub/extcmd.h>
32 +#include <grub/i18n.h>
33 +#include <grub/fs.h>
34 +#include <grub/env.h>
35 +#include <grub/file.h>
36 +#include <grub/normal.h>
37 +
38 +GRUB_MOD_LICENSE ("GPLv3+");
39 +
40 +#ifdef GRUB_MACHINE_EFI
41 +#define GRUB_LINUX_CMD "linuxefi"
42 +#define GRUB_INITRD_CMD "initrdefi"
43 +#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/"
44 +#define GRUB_BOOT_DEVICE "($boot)"
45 +#else
46 +#define GRUB_LINUX_CMD "linux"
47 +#define GRUB_INITRD_CMD "initrd"
48 +#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
49 +#define GRUB_BOOT_DEVICE "($root)"
50 +#endif
51 +
52 +static int parse_entry (
53 +    const char *filename,
54 +    const struct grub_dirhook_info *info __attribute__ ((unused)),
55 +    void *data __attribute__ ((unused)))
56 +{
57 +  grub_size_t n;
58 +  char *p;
59 +  grub_file_t f = NULL;
60 +  grub_off_t sz;
61 +  char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL;
62 +  const char *args[2] = { NULL, NULL };
63 +
64 +  if (filename[0] == '.')
65 +    return 0;
66 +
67 +  n = grub_strlen (filename);
68 +  if (n <= 5)
69 +    return 0;
70 +
71 +  if (grub_strcmp (filename + n - 5, ".conf") != 0)
72 +    return 0;
73 +
74 +  p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename);
75 +
76 +  f = grub_file_open (p);
77 +  if (!f)
78 +    goto finish;
79 +
80 +  sz = grub_file_size (f);
81 +  if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024)
82 +    goto finish;
83 +
84 +  for (;;)
85 +    {
86 +      char *buf;
87 +
88 +      buf = grub_file_getline (f);
89 +      if (!buf)
90 +       break;
91 +
92 +      if (grub_strncmp (buf, "title ", 6) == 0)
93 +       {
94 +         grub_free (title);
95 +         title = grub_strdup (buf + 6);
96 +         if (!title)
97 +           goto finish;
98 +       }
99 +      else if (grub_strncmp (buf, "options ", 8) == 0)
100 +       {
101 +         grub_free (options);
102 +         options = grub_strdup (buf + 8);
103 +         if (!options)
104 +           goto finish;
105 +       }
106 +      else if (grub_strncmp (buf, "linux ", 6) == 0)
107 +       {
108 +         grub_free (clinux);
109 +         clinux = grub_strdup (buf + 6);
110 +         if (!clinux)
111 +           goto finish;
112 +       }
113 +      else if (grub_strncmp (buf, "initrd ", 7) == 0)
114 +       {
115 +         grub_free (initrd);
116 +         initrd = grub_strdup (buf + 7);
117 +         if (!initrd)
118 +           goto finish;
119 +       }
120 +
121 +      grub_free(buf);
122 +    }
123 +
124 +  if (!linux)
125 +    {
126 +      grub_printf ("Skipping file %s with no 'linux' key.", p);
127 +      goto finish;
128 +    }
129 +
130 +  args[0] = title ? title : filename;
131 +
132 +  src = grub_xasprintf ("load_video\n"
133 +                       "set gfx_payload=keep\n"
134 +                       "insmod gzio\n"
135 +                       GRUB_LINUX_CMD " %s%s%s%s\n"
136 +                       "%s%s%s%s",
137 +                       GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
138 +                       initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : "");
139 +
140 +  grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0);
141 +
142 +finish:
143 +  grub_free (p);
144 +  grub_free (title);
145 +  grub_free (options);
146 +  grub_free (clinux);
147 +  grub_free (initrd);
148 +  grub_free (src);
149 +
150 +  if (f)
151 +    grub_file_close (f);
152 +
153 +  return 0;
154 +}
155 +
156 +static grub_err_t
157 +grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
158 +                    int argc __attribute__ ((unused)),
159 +                    char **args __attribute__ ((unused)))
160 +{
161 +  grub_fs_t fs;
162 +  grub_device_t dev;
163 +  static grub_err_t r;
164 +  const char *devid;
165 +
166 +  devid = grub_env_get ("root");
167 +  if (!devid)
168 +    return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root");
169 +
170 +  dev = grub_device_open (devid);
171 +  if (!dev)
172 +    return grub_errno;
173 +
174 +  fs = grub_fs_probe (dev);
175 +  if (!fs)
176 +    {
177 +      r = grub_errno;
178 +      goto finish;
179 +    }
180 +
181 +  r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL);
182 +
183 +finish:
184 +  if (dev)
185 +    grub_device_close (dev);
186 +
187 +  return r;
188 +}
189 +
190 +static grub_extcmd_t cmd;
191 +
192 +GRUB_MOD_INIT(bls)
193 +{
194 +  cmd = grub_register_extcmd ("bls_import",
195 +                             grub_cmd_bls_import,
196 +                             0,
197 +                             NULL,
198 +                             N_("Import Boot Loader Specification snippets."),
199 +                             NULL);
200 +}
201 +
202 +GRUB_MOD_FINI(bls)
203 +{
204 +  grub_unregister_extcmd (cmd);
205 +}
206 diff -urNp grub-2.02-rc1.orig/grub-core/Makefile.core.def grub-2.02-rc1/grub-core/Makefile.core.def
207 --- grub-2.02-rc1.orig/grub-core/Makefile.core.def      2017-02-08 15:09:05.594315418 +0000
208 +++ grub-2.02-rc1/grub-core/Makefile.core.def   2017-02-08 15:09:21.549315239 +0000
209 @@ -742,6 +742,14 @@ module = {
210  };
211  
212  module = {
213 +  name = blscfg;
214 +  common = commands/blscfg.c;
215 +  enable = i386_efi;
216 +  enable = x86_64_efi;
217 +  enable = i386_pc;
218 +};
219 +
220 +module = {
221    name = boot;
222    common = commands/boot.c;
223    i386_pc = lib/i386/pc/biosnum.c;