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);
49 args = talloc_strdup(opt, "");
50 initrd = conf_get_global_option(conf, "initrd");
51 root = conf_get_global_option(conf, "root");
53 pos = strchr(value, ' ');
55 /* if there's no space, it's only a kernel image with no params */
62 char *cl_name, *cl_value;
64 pos = conf_get_pair_equal(conf, pos, &cl_name, &cl_value, ' ');
67 args = talloc_asprintf_append(args, "%s ", cl_value);
71 if (streq(cl_name, "initrd")) {
76 if (streq(cl_name, "root")) {
81 args = talloc_asprintf_append(args, "%s=%s ", cl_name,
86 d_opt->boot_image = create_devpath_resource(opt,
87 conf->dc->device, value);
90 opt->boot_args = talloc_asprintf(opt, "root=%s %s", root, args);
93 opt->boot_args = args;
96 d_opt->initrd = create_devpath_resource(opt,
97 conf->dc->device, initrd);
99 opt->description = talloc_asprintf(opt, "%s initrd=%s %s",
100 value, initrd, opt->boot_args);
102 opt->description = talloc_asprintf(opt, "%s %s", value,
105 conf_strip_str(opt->boot_args);
106 conf_strip_str(opt->description);
108 discover_context_add_boot_option(conf->dc, d_opt);
111 static struct conf_global_option kboot_global_options[] = {
112 { .name = "initrd" },
118 static const char *const kboot_conf_files[] = {
130 static const char *const kboot_ignored_names[] = {
138 static int kboot_parse(struct discover_context *dc, char *buf, int len)
140 struct conf_context *conf;
142 conf = talloc_zero(dc, struct conf_context);
148 conf->global_options = kboot_global_options,
149 conf_init_global_options(conf);
150 conf->get_pair = conf_get_pair_equal;
151 conf->process_pair = kboot_process_pair;
152 conf->parser_info = (void *)kboot_ignored_names,
154 conf_parse_buf(conf, buf, len);
160 static struct parser kboot_parser = {
162 .method = CONF_METHOD_LOCAL_FILE,
163 .parse = kboot_parse,
164 .filenames = kboot_conf_files,
165 .resolve_resource = resolve_devpath_resource,
168 register_parser(kboot_parser);