]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2-parser.c
parsers: populate resolve_resource members
[petitboot] / discover / grub2-parser.c
index f6cbccbaa6e6311aaa402c87199c3c1526ce669c..97b96537482f7b1bc83f31855f052e4ea041138b 100644 (file)
 
 #include "log/log.h"
 #include "talloc/talloc.h"
-#include "pb-protocol/pb-protocol.h"
+#include "types/types.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
-#include "paths.h"
+#include "resource.h"
 
 struct grub2_state {
-       struct boot_option *opt;
+       struct discover_boot_option *opt;
        char *desc_image;
        char *desc_initrd;
        const char *const *known_names;
@@ -41,34 +41,40 @@ struct grub2_state {
 
 static void grub2_finish(struct conf_context *conf)
 {
+       struct device *dev = conf->dc->device->device;
        struct grub2_state *state = conf->parser_info;
+       struct boot_option *opt;
 
        if (!state->desc_image) {
-               pb_log("%s: %s: no image found\n", __func__,
-                       conf->dc->device->id);
+               pb_log("%s: %s: no image found\n", __func__, dev->id);
                return;
        }
 
        assert(state->opt);
-       assert(state->opt->name);
-       assert(state->opt->boot_args);
+       opt = state->opt->option;
+
+       assert(opt);
+       assert(opt->name);
+       assert(opt->boot_args);
 
-       state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
+       opt->description = talloc_asprintf(opt, "%s %s %s",
                state->desc_image,
                (state->desc_initrd ? state->desc_initrd : ""),
-               state->opt->boot_args);
+               opt->boot_args);
 
        talloc_free(state->desc_initrd);
        state->desc_initrd = NULL;
 
-       conf_strip_str(state->opt->boot_args);
-       conf_strip_str(state->opt->description);
+       conf_strip_str(opt->boot_args);
+       conf_strip_str(opt->description);
 
        /* opt is persistent, so must be associated with device */
 
-       device_add_boot_option(conf->dc->device, state->opt);
-       state->opt = talloc_zero(conf->dc->device, struct boot_option);
-       state->opt->boot_args = talloc_strdup(state->opt, "");
+       discover_context_add_boot_option(conf->dc, state->opt);
+
+       state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
+       opt = state->opt->option;
+       opt->boot_args = talloc_strdup(opt, "");
 
        talloc_free(state->desc_image);
        state->desc_image = NULL;
@@ -77,7 +83,9 @@ static void grub2_finish(struct conf_context *conf)
 static void grub2_process_pair(struct conf_context *conf, const char *name,
                char *value)
 {
+       struct device *dev = conf->dc->device->device;
        struct grub2_state *state = conf->parser_info;
+       struct discover_boot_option *opt = state->opt;
 
        if (!name || !conf_param_in_list(state->known_names, name))
                return;
@@ -94,9 +102,9 @@ static void grub2_process_pair(struct conf_context *conf, const char *name,
                if (sep)
                        *sep = 0;
 
-               state->opt->id = talloc_asprintf(state->opt, "%s#%s",
-                       conf->dc->device->id, value);
-               state->opt->name = talloc_strdup(state->opt, value);
+               opt->option->id = talloc_asprintf(opt->option,
+                                       "%s#%s", dev->id, value);
+               opt->option->name = talloc_strdup(opt->option, value);
 
                return;
        }
@@ -109,20 +117,19 @@ static void grub2_process_pair(struct conf_context *conf, const char *name,
                if (sep)
                        *sep = 0;
 
-               state->opt->boot_image_file = resolve_path(state->opt,
-                       value, conf->dc->device_path);
-               state->desc_image = talloc_strdup(state->opt, value);
+               opt->boot_image = create_devpath_resource(opt,
+                                       conf->dc->device, value);
+               state->desc_image = talloc_strdup(opt, value);
 
                if (sep)
-                       state->opt->boot_args = talloc_strdup(state->opt,
-                               sep + 1);
+                       opt->option->boot_args = talloc_strdup(opt, sep + 1);
 
                return;
        }
 
        if (streq(name, "initrd")) {
-               state->opt->initrd_file = resolve_path(state->opt,
-                       value, conf->dc->device_path);
+               opt->initrd = create_devpath_resource(opt,
+                                       conf->dc->device, value);
                state->desc_initrd = talloc_asprintf(state, "initrd=%s",
                        value);
                return;
@@ -154,11 +161,10 @@ static const char *grub2_known_names[] = {
        NULL
 };
 
-static int grub2_parse(struct discover_context *dc)
+static int grub2_parse(struct discover_context *dc, char *buf, int len)
 {
        struct conf_context *conf;
        struct grub2_state *state;
-       int rc;
 
        conf = talloc_zero(dc, struct conf_context);
 
@@ -167,7 +173,6 @@ static int grub2_parse(struct discover_context *dc)
 
        conf->dc = dc;
        conf_init_global_options(conf);
-       conf->conf_files = grub2_conf_files,
        conf->get_pair = conf_get_pair_space;
        conf->process_pair = grub2_process_pair;
        conf->finish = grub2_finish;
@@ -177,13 +182,21 @@ static int grub2_parse(struct discover_context *dc)
 
        /* opt is persistent, so must be associated with device */
 
-       state->opt = talloc_zero(conf->dc->device, struct boot_option);
-       state->opt->boot_args = talloc_strdup(state->opt, "");
+       state->opt = discover_boot_option_create(dc, dc->device);
+       state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
 
-       rc = conf_parse(conf);
+       conf_parse_buf(conf, buf, len);
 
        talloc_free(conf);
-       return rc;
+       return 1;
 }
 
-define_parser(grub2, grub2_parse);
+static struct parser grub2_parser = {
+       .name                   = "grub2",
+       .method                 = CONF_METHOD_LOCAL_FILE,
+       .parse                  = grub2_parse,
+       .filenames              = grub2_conf_files,
+       .resolve_resource       = resolve_devpath_resource,
+};
+
+register_parser(grub2_parser);