8 #include "talloc/talloc.h"
9 #include "types/types.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
14 static void kboot_process_pair(struct conf_context *conf, const char *name,
17 const char *const *ignored_names = conf->parser_info;
18 struct discover_boot_option *d_opt;
19 struct boot_option *opt;
25 /* ignore bare values */
30 if (conf_param_in_list(ignored_names, name))
33 if (conf_set_global_option(conf, name, value))
36 /* opt must be associated with dc */
38 d_opt = talloc_zero(conf->dc, struct discover_boot_option);
39 d_opt->device = conf->dc->device;
40 opt = talloc_zero(d_opt, struct boot_option);
45 opt->id = talloc_asprintf(opt, "%s#%s", conf->dc->device->device->id,
47 opt->name = talloc_strdup(opt, name);
50 args = talloc_strdup(opt, "");
51 initrd = conf_get_global_option(conf, "initrd");
52 root = conf_get_global_option(conf, "root");
54 pos = strchr(value, ' ');
56 /* if there's no space, it's only a kernel image with no params */
63 char *cl_name, *cl_value;
65 pos = conf_get_pair_equal(conf, pos, &cl_name, &cl_value, ' ');
68 args = talloc_asprintf_append(args, "%s ", cl_value);
72 if (streq(cl_name, "initrd")) {
77 if (streq(cl_name, "root")) {
82 args = talloc_asprintf_append(args, "%s=%s ", cl_name,
87 d_opt->boot_image = create_devpath_resource(d_opt,
88 conf->dc->device, value);
91 opt->boot_args = talloc_asprintf(opt, "root=%s %s", root, args);
94 opt->boot_args = args;
97 d_opt->initrd = create_devpath_resource(d_opt,
98 conf->dc->device, initrd);
100 opt->description = talloc_asprintf(opt, "%s initrd=%s %s",
101 value, initrd, opt->boot_args);
103 opt->description = talloc_asprintf(opt, "%s %s", value,
106 conf_strip_str(opt->boot_args);
107 conf_strip_str(opt->description);
109 discover_context_add_boot_option(conf->dc, d_opt);
112 static struct conf_global_option kboot_global_options[] = {
113 { .name = "initrd" },
119 static const char *const kboot_conf_files[] = {
131 static const char *const kboot_ignored_names[] = {
139 static int kboot_parse(struct discover_context *dc, char *buf, int len)
141 struct conf_context *conf;
143 conf = talloc_zero(dc, struct conf_context);
149 conf->global_options = kboot_global_options,
150 conf_init_global_options(conf);
151 conf->get_pair = conf_get_pair_equal;
152 conf->process_pair = kboot_process_pair;
153 conf->parser_info = (void *)kboot_ignored_names,
155 conf_parse_buf(conf, buf, len);
161 static struct parser kboot_parser = {
163 .method = CONF_METHOD_LOCAL_FILE,
164 .parse = kboot_parse,
165 .filenames = kboot_conf_files,
166 .resolve_resource = resolve_devpath_resource,
169 register_parser(kboot_parser);