+static struct discover_boot_option *state_start_new_option(
+ struct conf_context *conf,
+ struct yaboot_state *state)
+{
+ state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
+ state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
+
+ /* old allocated values will get freed with the state */
+ state->device = conf_get_global_option(conf, "device");
+ state->partition = conf_get_global_option(conf, "partition");
+ state->initrd_size = conf_get_global_option(conf, "initrd_size");
+ state->literal = conf_get_global_option(conf, "literal");
+ state->ramdisk = conf_get_global_option(conf, "ramdisk");
+ state->root = conf_get_global_option(conf, "root");
+
+ return state->opt;
+}
+
+static struct resource *create_yaboot_devpath_resource(
+ struct yaboot_state *state,
+ struct conf_context *conf,
+ const char *path)
+{
+ struct discover_boot_option *opt = state->opt;
+ const char *dev, *part, *devpos;
+ struct resource *res;
+ char *devpath, *devstr;
+
+ dev = state->device;
+ part = state->partition;
+
+ if (!dev)
+ dev = conf_get_global_option(conf, "device");
+ if (!part)
+ part = conf_get_global_option(conf, "partition");
+
+ if (strchr(path, ':')) {
+ devpath = talloc_strdup(conf, path);
+
+ } else if (dev && part) {
+ devpos = &dev[strlen(dev) - 1];
+ if (isdigit(*devpos)) {
+ while (isdigit(*devpos))
+ devpos--;
+
+ devstr = talloc_strndup(conf, dev, devpos - dev + 1);
+ devpath = talloc_asprintf(conf, "%s%s:%s", devstr,
+ part, path);
+ talloc_free(devstr);
+ } else {
+ devpath = talloc_asprintf(conf,
+ "%s%s:%s", dev, part, path);
+ }
+ } else if (dev) {
+ devpath = talloc_asprintf(conf, "%s:%s", dev, path);
+ } else {
+ devpath = talloc_strdup(conf, path);
+ }
+
+ res = create_devpath_resource(opt, conf->dc->device, devpath);
+
+ talloc_free(devpath);
+
+ return res;
+}
+