1 From ddfb160353df14e9f88affe7498512a553146872 Mon Sep 17 00:00:00 2001
2 From: Fedora Ninjas <grub2-owner@fedoraproject.org>
3 Date: Tue, 22 Jan 2013 06:31:38 +0100
4 Subject: [PATCH 101/152] blscfg: add blscfg module to parse Boot Loader
7 http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec
14 Done! You should now have menu items for your snippets in place.
16 Signed-off-by: Peter Jones <grub2-owner@fedoraproject.org>
18 grub-core/Makefile.core.def | 8 ++
19 grub-core/commands/blscfg.c | 201 ++++++++++++++++++++++++++++++++++++++++++++
20 2 files changed, 209 insertions(+)
21 create mode 100644 grub-core/commands/blscfg.c
23 diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
24 index ec46506..7bf1c8a 100644
25 --- a/grub-core/Makefile.core.def
26 +++ b/grub-core/Makefile.core.def
27 @@ -747,6 +747,14 @@ module = {
32 + common = commands/blscfg.c;
34 + enable = x86_64_efi;
40 common = commands/boot.c;
41 i386_pc = lib/i386/pc/biosnum.c;
42 diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
44 index 0000000..4274aca
46 +++ b/grub-core/commands/blscfg.c
48 +/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/
50 +/* bls.c - implementation of the boot loader spec */
53 + * GRUB -- GRand Unified Bootloader
55 + * GRUB is free software: you can redistribute it and/or modify
56 + * it under the terms of the GNU General Public License as published by
57 + * the Free Software Foundation, either version 3 of the License, or
58 + * (at your option) any later version.
60 + * GRUB is distributed in the hope that it will be useful,
61 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + * GNU General Public License for more details.
65 + * You should have received a copy of the GNU General Public License
66 + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
69 +#include <grub/types.h>
70 +#include <grub/misc.h>
72 +#include <grub/err.h>
74 +#include <grub/extcmd.h>
75 +#include <grub/i18n.h>
77 +#include <grub/env.h>
78 +#include <grub/file.h>
79 +#include <grub/normal.h>
81 +GRUB_MOD_LICENSE ("GPLv3+");
83 +#ifdef GRUB_MACHINE_EFI
84 +#define GRUB_LINUX_CMD "linuxefi"
85 +#define GRUB_INITRD_CMD "initrdefi"
86 +#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/"
87 +#define GRUB_BOOT_DEVICE "($boot)"
89 +#define GRUB_LINUX_CMD "linux"
90 +#define GRUB_INITRD_CMD "initrd"
91 +#define GRUB_BLS_CONFIG_PATH "/loader/entries/"
92 +#define GRUB_BOOT_DEVICE "($root)"
95 +static int parse_entry (
96 + const char *filename,
97 + const struct grub_dirhook_info *info __attribute__ ((unused)),
98 + void *data __attribute__ ((unused)))
102 + grub_file_t f = NULL;
104 + char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL;
105 + const char *args[2] = { NULL, NULL };
107 + if (filename[0] == '.')
110 + n = grub_strlen (filename);
114 + if (grub_strcmp (filename + n - 5, ".conf") != 0)
117 + p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename);
119 + f = grub_file_open (p);
123 + sz = grub_file_size (f);
124 + if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024)
131 + buf = grub_file_getline (f);
135 + if (grub_strncmp (buf, "title ", 6) == 0)
138 + title = grub_strdup (buf + 6);
142 + else if (grub_strncmp (buf, "options ", 8) == 0)
144 + grub_free (options);
145 + options = grub_strdup (buf + 8);
149 + else if (grub_strncmp (buf, "linux ", 6) == 0)
151 + grub_free (clinux);
152 + clinux = grub_strdup (buf + 6);
156 + else if (grub_strncmp (buf, "initrd ", 7) == 0)
158 + grub_free (initrd);
159 + initrd = grub_strdup (buf + 7);
169 + grub_printf ("Skipping file %s with no 'linux' key.", p);
173 + args[0] = title ? title : filename;
175 + src = grub_xasprintf ("load_video\n"
176 + "set gfx_payload=keep\n"
178 + GRUB_LINUX_CMD " %s%s%s%s\n"
180 + GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
181 + initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : "");
183 + grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0);
188 + grub_free (options);
189 + grub_free (clinux);
190 + grub_free (initrd);
194 + grub_file_close (f);
200 +grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)),
201 + int argc __attribute__ ((unused)),
202 + char **args __attribute__ ((unused)))
206 + static grub_err_t r;
209 + devid = grub_env_get ("root");
211 + return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root");
213 + dev = grub_device_open (devid);
217 + fs = grub_fs_probe (dev);
224 + r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL);
228 + grub_device_close (dev);
233 +static grub_extcmd_t cmd;
237 + cmd = grub_register_extcmd ("bls_import",
238 + grub_cmd_bls_import,
241 + N_("Import Boot Loader Specification snippets."),
247 + grub_unregister_extcmd (cmd);