discover/grub2: Add option state in menuentry processing
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Sep 2013 08:02:09 +0000 (16:02 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 24 Sep 2013 05:14:59 +0000 (13:14 +0800)
This will allow menuentry-specific commands to populate boot option
data.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/grub2/grub2.h
discover/grub2/script.c

index fca0fa2ee1525b86ef750cdf6548df73a0de52ad..1ac9f88db896b257d38c8c9c0347f0b7857b44d7 100644 (file)
@@ -84,6 +84,7 @@ struct grub2_script {
        struct list                     commands;
        struct list                     symtab;
        struct discover_context         *ctx;
        struct list                     commands;
        struct list                     symtab;
        struct discover_context         *ctx;
+       struct discover_boot_option     *opt;
 };
 
 struct grub2_parser {
 };
 
 struct grub2_parser {
index 5b38156822b5f6083eb59fe1bd74a60a6ec7b829..8b008c4b91e919172858ec9864b3b6f23dff763c 100644 (file)
@@ -2,6 +2,7 @@
 #include <sys/types.h>
 #include <string.h>
 
 #include <sys/types.h>
 #include <string.h>
 
+#include <types/types.h>
 #include <talloc/talloc.h>
 
 #include "grub2.h"
 #include <talloc/talloc.h>
 
 #include "grub2.h"
@@ -255,10 +256,24 @@ int statement_menuentry_execute(struct grub2_script *script,
                struct grub2_statement *statement)
 {
        struct grub2_statement_menuentry *st = to_stmt_menuentry(statement);
                struct grub2_statement *statement)
 {
        struct grub2_statement_menuentry *st = to_stmt_menuentry(statement);
+       struct discover_boot_option *opt;
 
        process_expansions(script, st->argv);
 
        process_expansions(script, st->argv);
+
+       opt = discover_boot_option_create(script->ctx, script->ctx->device);
+       if (st->argv->argc > 0) {
+               opt->option->name = talloc_strdup(opt, st->argv->argv[0]);
+       } else {
+               opt->option->name = talloc_strdup(opt, "(unknown)");
+       }
+
+       script->opt = opt;
+
        statements_execute(script, st->statements);
 
        statements_execute(script, st->statements);
 
+       discover_context_add_boot_option(script->ctx, opt);
+       script->opt = NULL;
+
        return 0;
 }
 
        return 0;
 }
 
@@ -309,6 +324,7 @@ struct grub2_script *create_script(struct grub2_parser *parser,
 
        init_env(script);
        script->ctx = ctx;
 
        init_env(script);
        script->ctx = ctx;
+       script->opt = NULL;
 
        list_init(&script->commands);
        register_builtins(script);
 
        list_init(&script->commands);
        register_builtins(script);