X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=devices%2Fyaboot-parser.c;h=27b4b782306594c05cbaec0fd3b01bc826a409de;hp=ee14cb1b41d144fcbcf1e59cd35791c8cff3a45a;hb=a57e4ef92b8e590643a325d309511306c5b941a9;hpb=f6de8493cf6645f8da027671f935cf22f8008a1b diff --git a/devices/yaboot-parser.c b/devices/yaboot-parser.c index ee14cb1..27b4b78 100644 --- a/devices/yaboot-parser.c +++ b/devices/yaboot-parser.c @@ -1,6 +1,7 @@ -#include "udev-helper.h" +#include "parser.h" #include "params.h" +#include "paths.h" #include "yaboot-cfg.h" #include @@ -14,8 +15,7 @@ #include static struct device *dev; -static const char *mountpoint; -static char partition_mntpoint[PATH_MAX]; +static char *devpath; static char *defimage; char * @@ -103,13 +103,13 @@ void process_image(char *label) opt.name = label; cfgopt = cfg_get_strg(label, "image"); - opt.boot_image_file = join_paths(mountpoint, cfgopt); + opt.boot_image_file = resolve_path(cfgopt, devpath); if (cfgopt == defimage) - printf("This one is default. What do we do about it?\n"); + pb_log("This one is default. What do we do about it?\n"); cfgopt = cfg_get_strg(label, "initrd"); if (cfgopt) - opt.initrd_file = join_paths(mountpoint, cfgopt); + opt.initrd_file = resolve_path(cfgopt, devpath); opt.boot_args = make_params(label, NULL); @@ -119,7 +119,7 @@ void process_image(char *label) free(opt.initrd_file); } -static int yaboot_parse(const char *devicepath, const char *_mountpoint) +static int yaboot_parse(const char *device) { char *filepath; char *conf_file; @@ -129,14 +129,14 @@ static int yaboot_parse(const char *devicepath, const char *_mountpoint) struct stat st; char *label; - mountpoint = _mountpoint; + devpath = strdup(device); - filepath = join_paths(mountpoint, "/etc/yaboot.conf"); + filepath = resolve_path("/etc/yaboot.conf", devpath); fd = open(filepath, O_RDONLY); if (fd < 0) { free(filepath); - filepath = join_paths(mountpoint, "/yaboot.conf"); + filepath = resolve_path("/yaboot.conf", devpath); fd = open(filepath, O_RDONLY); if (fd < 0) @@ -164,7 +164,7 @@ static int yaboot_parse(const char *devicepath, const char *_mountpoint) close(fd); if (cfg_parse(filepath, conf_file, conf_len)) { - printf("Error parsing yaboot.conf\n"); + pb_log("Error parsing yaboot.conf\n"); return 0; } @@ -172,7 +172,7 @@ static int yaboot_parse(const char *devicepath, const char *_mountpoint) dev = malloc(sizeof(*dev)); memset(dev, 0, sizeof(*dev)); - dev->id = strdup(devicepath); + dev->id = strdup(devpath); if (cfg_get_strg(0, "init-message")) { char *newline; dev->description = strdup(cfg_get_strg(0, "init-message")); @@ -182,37 +182,34 @@ static int yaboot_parse(const char *devicepath, const char *_mountpoint) } dev->icon_file = strdup(generic_icon_file(guess_device_type())); - /* Mount the 'partition' which is what all the image filenames - are relative to */ + /* If we have a 'partiton=' directive, update the default devpath + * to use that instead of the current device */ tmpstr = cfg_get_strg(0, "partition"); if (tmpstr) { char *endp; int partnr = strtol(tmpstr, &endp, 10); if (endp != tmpstr && !*endp) { - char *new_dev = malloc(strlen(devicepath) + strlen(tmpstr) + 1); + char *new_dev, *tmp; + + new_dev = malloc(strlen(devpath) + strlen(tmpstr) + 1); if (!new_dev) return 0; - strcpy(new_dev, devicepath); + strcpy(new_dev, devpath); /* Strip digits (partition number) from string */ - endp = &new_dev[strlen(devicepath) - 1]; + endp = new_dev + strlen(devpath) - 1; while (isdigit(*endp)) *(endp--) = 0; /* and add our own... */ - sprintf(endp+1, "%d", partnr); + sprintf(endp + 1, "%d", partnr); - /* FIXME: udev may not have created the device node - yet. And on removal, unmount_device() only unmounts - it once, while in fact it may be mounted twice. */ - if (mount_device(new_dev, partition_mntpoint)) { - printf("Error mounting image partition\n"); - return 0; - } - mountpoint = partition_mntpoint; - dev->id = new_dev; - } + tmp = devpath; + devpath = parse_device_path(new_dev, devpath); + free(tmp); + free(new_dev); + } } defimage = cfg_get_default();