#include "discover/parser-conf.h"
#include "discover/parser.h"
-#define BLS_DIR "/loader/entries"
+static const char *const bls_dirs[] = {
+ "/loader/entries",
+ "/boot/loader/entries",
+ NULL
+};
struct bls_state {
struct discover_boot_option *opt;
struct grub2_script *script;
+ unsigned int idx;
const char *filename;
const char *title;
const char *version;
}
}
-static bool option_is_default(struct grub2_script *script,
+static bool option_is_default(struct bls_state *state,
struct boot_option *option)
{
+ unsigned int idx;
const char *var;
+ char *end;
- var = script_env_get(script, "default");
+ var = script_env_get(state->script, "default");
if (!var)
return false;
if (!strcmp(var, option->id))
return true;
- return !strcmp(var, option->name);
+ if (!strcmp(var, option->name))
+ return true;
+
+ idx = strtoul(var, &end, 10);
+ return end != var && *end == '\0' && idx == state->idx;
}
static void bls_finish(struct conf_context *conf)
opt->dtb = create_grub2_resource(opt, conf->dc->device,
root, state->dtb);
- option->is_default = option_is_default(state->script, option);
+ char* args_sigfile_default = talloc_asprintf(opt,
+ "%s.cmdline.sig", state->image);
+ opt->args_sig_file = create_grub2_resource(opt, conf->dc->device,
+ root, args_sigfile_default);
+ talloc_free(args_sigfile_default);
+
+ option->is_default = option_is_default(state, option);
- discover_context_add_boot_option(dc, opt);
+ list_add_tail(&state->script->options, &opt->list);
+ state->script->n_options++;
device_handler_status_dev_info(dc->handler, dc->device,
_("Created menu entry from BLS file %s"),
static int bls_sort(const struct dirent **ent_a, const struct dirent **ent_b)
{
- return strverscmp((*ent_b)->d_name, (*ent_a)->d_name);
+ return strverscmp((*ent_a)->d_name, (*ent_b)->d_name);
}
int builtin_blscfg(struct grub2_script *script,
int argc __attribute__((unused)),
char *argv[] __attribute__((unused)))
{
+ unsigned int current_idx = script->n_options;
struct discover_context *dc = script->ctx;
struct dirent **bls_entries;
struct conf_context *conf;
struct bls_state *state;
char *buf, *filename;
+ const char * const *dir;
const char *blsdir;
int n, len, rc = -1;
+ struct stat statbuf;
conf = talloc_zero(dc, struct conf_context);
if (!conf)
blsdir = script_env_get(script, "blsdir");
if (!blsdir)
- blsdir = BLS_DIR;
+ for (dir = bls_dirs; *dir; dir++)
+ if (!parser_stat_path(dc, dc->device, *dir, &statbuf)) {
+ blsdir = *dir;
+ break;
+ }
+
+ if (!blsdir) {
+ device_handler_status_dev_info(dc->handler, dc->device,
+ _("BLS directory wasn't found"));
+ goto err;
+ }
n = parser_scandir(dc, blsdir, &bls_entries, bls_filter, bls_sort);
if (n <= 0)
state->script = script;
state->filename = filename;
+ state->idx = current_idx++;
conf->parser_info = state;
rc = parser_request_file(dc, dc->device, filename, &buf, &len);
if (n > 0) {
device_handler_status_dev_info(dc->handler, dc->device,
_("Scanning %s failed"),
- BLS_DIR);
+ blsdir);
do {
free(bls_entries[n]);
} while (n-- > 0);