X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fgrub2-parser.c;h=05893292ea2b4cf93caa30f0a2d34e4bcb9bc605;hp=3c756c1b0f5230f120253d0d62568870459af349;hb=5e7c90eddd7ac2e4a3b05a7a5f6e29166edfa161;hpb=06a49ebdfc795a70b938f5aee29f3c488ef9fc21 diff --git a/discover/grub2-parser.c b/discover/grub2-parser.c index 3c756c1..0589329 100644 --- a/discover/grub2-parser.c +++ b/discover/grub2-parser.c @@ -30,10 +30,10 @@ #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; @@ -43,6 +43,7 @@ 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__, dev->id); @@ -50,26 +51,30 @@ static void grub2_finish(struct conf_context *conf) } assert(state->opt); - assert(state->opt->name); - assert(state->opt->boot_args); + opt = state->opt->option; - state->opt->description = talloc_asprintf(state->opt, "%s %s %s", + assert(opt); + assert(opt->name); + assert(opt->boot_args); + + 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 */ discover_context_add_boot_option(conf->dc, state->opt); - state->opt = talloc_zero(conf->dc, struct boot_option); - state->opt->boot_args = talloc_strdup(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; @@ -80,6 +85,7 @@ static void grub2_process_pair(struct conf_context *conf, const char *name, { 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; @@ -96,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", - dev->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; } @@ -111,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->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->device_path); + opt->initrd = create_devpath_resource(opt, + conf->dc->device, value); state->desc_initrd = talloc_asprintf(state, "initrd=%s", value); return; @@ -177,8 +182,8 @@ static int grub2_parse(struct discover_context *dc, char *buf, int len) /* 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, ""); conf_parse_buf(conf, buf, len); @@ -186,8 +191,11 @@ static int grub2_parse(struct discover_context *dc, char *buf, int len) return 1; } -struct parser __grub2_parser = { +static struct parser grub2_parser = { .name = "grub2", + .method = CONF_METHOD_LOCAL_FILE, .parse = grub2_parse, .filenames = grub2_conf_files, }; + +register_parser(grub2_parser);