2 #include "udev-helper.h"
9 const char *conf_filename = "/boot/petitboot.conf";
11 static struct boot_option *cur_opt;
12 static struct device *dev;
13 static const char *mountpoint;
16 int check_and_add_device(struct device *dev)
19 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
21 return !add_device(dev);
24 static int section(char *section_name)
26 if (!device_added++ && !check_and_add_device(dev))
30 add_boot_option(cur_opt);
31 free_boot_option(cur_opt);
34 cur_opt = malloc(sizeof(*cur_opt));
35 memset(cur_opt, 0, sizeof(*cur_opt));
40 static void set_boot_option_parameter(struct boot_option *opt,
41 const char *name, const char *value)
43 if (streq(name, "name"))
44 opt->name = strdup(value);
46 else if (streq(name, "description"))
47 opt->description = strdup(value);
49 else if (streq(name, "image"))
50 opt->boot_image_file = join_paths(mountpoint, value);
52 else if (streq(name, "icon"))
53 opt->icon_file = join_paths(mountpoint, value);
55 else if (streq(name, "initrd"))
56 opt->initrd_file = join_paths(mountpoint, value);
58 else if (streq(name, "args"))
59 opt->boot_args = strdup(value);
62 fprintf(stderr, "Unknown parameter %s\n", name);
65 static void set_device_parameter(struct device *dev,
66 const char *name, const char *value)
68 if (streq(name, "name"))
69 dev->name = strdup(value);
71 else if (streq(name, "description"))
72 dev->description = strdup(value);
74 else if (streq(name, "icon"))
75 dev->icon_file = join_paths(mountpoint, value);
78 static int parameter(char *param_name, char *param_value)
81 set_boot_option_parameter(cur_opt, param_name, param_value);
83 set_device_parameter(dev, param_name, param_value);
88 int parse(const char *devicepath, const char *_mountpoint)
93 mountpoint = _mountpoint;
95 filepath = join_paths(mountpoint, conf_filename);
98 dev = malloc(sizeof(*dev));
99 memset(dev, 0, sizeof(*dev));
100 dev->id = strdup(devicepath);
102 rc = pm_process(filepath, section, parameter);
107 add_boot_option(cur_opt);
108 free_boot_option(cur_opt);
118 struct parser native_parser = {
119 .name = "native petitboot parser",