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 static char *prepend_mountpoint(const char *path)
20 full_path = malloc(strlen(path) + strlen(mountpoint) + 2);
22 strcpy(full_path, mountpoint);
24 strcat(full_path, "/");
25 strcat(full_path, path);
30 int check_and_add_device(struct device *dev)
33 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
35 return !add_device(dev);
38 static int section(char *section_name)
40 if (!device_added++ && !check_and_add_device(dev))
44 add_boot_option(cur_opt);
45 free_boot_option(cur_opt);
48 cur_opt = malloc(sizeof(*cur_opt));
49 memset(cur_opt, 0, sizeof(*cur_opt));
54 static void set_boot_option_parameter(struct boot_option *opt,
55 const char *name, const char *value)
57 if (streq(name, "name"))
58 opt->name = strdup(value);
60 else if (streq(name, "description"))
61 opt->description = strdup(value);
63 else if (streq(name, "image"))
64 opt->boot_image_file = prepend_mountpoint(value);
66 else if (streq(name, "icon"))
67 opt->icon_file = prepend_mountpoint(value);
69 else if (streq(name, "initrd"))
70 opt->initrd_file = prepend_mountpoint(value);
72 else if (streq(name, "args"))
73 opt->boot_args = strdup(value);
76 fprintf(stderr, "Unknown parameter %s\n", name);
79 static void set_device_parameter(struct device *dev,
80 const char *name, const char *value)
82 if (streq(name, "name"))
83 dev->name = strdup(value);
85 else if (streq(name, "description"))
86 dev->description = strdup(value);
88 else if (streq(name, "icon"))
89 dev->icon_file = prepend_mountpoint(value);
92 static int parameter(char *param_name, char *param_value)
95 set_boot_option_parameter(cur_opt, param_name, param_value);
97 set_device_parameter(dev, param_name, param_value);
102 int parse(const char *devicepath, const char *_mountpoint)
107 mountpoint = _mountpoint;
109 filepath = prepend_mountpoint(conf_filename);
112 dev = malloc(sizeof(*dev));
113 memset(dev, 0, sizeof(*dev));
114 dev->id = strdup(devicepath);
116 rc = pm_process(filepath, section, parameter);
121 add_boot_option(cur_opt);
122 free_boot_option(cur_opt);
132 struct parser native_parser = {
133 .name = "native petitboot parser",