4 #include "yaboot-cfg.h"
14 #include <sys/param.h>
16 static struct device *dev;
17 static const char *mountpoint;
18 static char *defimage;
21 make_params(char *label, char *params)
24 static char buffer[2048];
29 p = cfg_get_strg(label, "literal");
41 p = cfg_get_strg(label, "root");
48 if (cfg_get_flag(label, "read-only")) {
52 if (cfg_get_flag(label, "read-write")) {
56 p = cfg_get_strg(label, "ramdisk");
58 strcpy (q, "ramdisk=");
63 p = cfg_get_strg(label, "initrd-size");
65 strcpy (q, "ramdisk_size=");
70 if (cfg_get_flag(label, "novideo")) {
71 strcpy (q, "video=ofonly");
75 p = cfg_get_strg (label, "append");
88 static int check_and_add_device(struct device *dev)
91 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
93 return !add_device(dev);
96 void process_image(char *label)
98 struct boot_option opt;
101 memset(&opt, 0, sizeof(opt));
104 cfgopt = cfg_get_strg(label, "image");
105 opt.boot_image_file = resolve_path(cfgopt, mountpoint);
106 if (cfgopt == defimage)
107 pb_log("This one is default. What do we do about it?\n");
109 cfgopt = cfg_get_strg(label, "initrd");
111 opt.initrd_file = resolve_path(cfgopt, mountpoint);
113 opt.boot_args = make_params(label, NULL);
115 add_boot_option(&opt);
118 free(opt.initrd_file);
121 static int yaboot_parse(const char *devicepath, const char *_mountpoint)
131 mountpoint = _mountpoint;
133 filepath = join_paths(mountpoint, "/etc/yaboot.conf");
135 fd = open(filepath, O_RDONLY);
138 filepath = join_paths(mountpoint, "/yaboot.conf");
139 fd = open(filepath, O_RDONLY);
145 if (fstat(fd, &st)) {
150 conf_file = malloc(st.st_size+1);
156 conf_len = read(fd, conf_file, st.st_size);
161 conf_file[conf_len] = 0;
165 if (cfg_parse(filepath, conf_file, conf_len)) {
166 pb_log("Error parsing yaboot.conf\n");
172 dev = malloc(sizeof(*dev));
173 memset(dev, 0, sizeof(*dev));
174 dev->id = strdup(devicepath);
175 if (cfg_get_strg(0, "init-message")) {
177 dev->description = strdup(cfg_get_strg(0, "init-message"));
178 newline = strchr(dev->description, '\n');
182 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
184 /* If we have a 'partiton=' directive, update the default mountpoint
185 * to use that instead of the current mountpoint */
186 tmpstr = cfg_get_strg(0, "partition");
189 int partnr = strtol(tmpstr, &endp, 10);
190 if (endp != tmpstr && !*endp) {
191 char *new_dev = malloc(strlen(devicepath) + strlen(tmpstr) + 1);
195 strcpy(new_dev, devicepath);
197 /* Strip digits (partition number) from string */
198 endp = &new_dev[strlen(devicepath) - 1];
199 while (isdigit(*endp))
202 /* and add our own... */
203 sprintf(endp+1, "%d", partnr);
205 mountpoint = mountpoint_for_device(new_dev);
210 defimage = cfg_get_default();
213 defimage = cfg_get_strg(defimage, "image");
215 label = cfg_next_image(NULL);
216 if (!label || !check_and_add_device(dev))
220 process_image(label);
221 } while ((label = cfg_next_image(label)));
226 struct parser yaboot_parser = {
227 .name = "yaboot.conf parser",
229 .parse = yaboot_parse