2 #if defined(HAVE_CONFIG_H)
12 #include <talloc/talloc.h>
14 #include "device-handler.h"
18 static int is_prefix_ignorecase(const char *str, const char *prefix)
20 return !strncasecmp(str, prefix, strlen(prefix));
23 struct devpath_resource_info {
27 static struct discover_device *parse_device_string(
28 struct device_handler *handler, const char *devstr)
30 if (is_prefix_ignorecase(devstr, "uuid="))
31 return device_lookup_by_uuid(handler, devstr + strlen("uuid"));
33 if (is_prefix_ignorecase(devstr, "label="))
34 return device_lookup_by_label(handler,
35 devstr + strlen("label="));
37 return device_lookup_by_name(handler, devstr);
40 void resolve_resource_against_device(struct resource *res,
41 struct discover_device *dev, const char *path)
43 char *resolved_path = join_paths(res, dev->mount_path, path);
44 res->url = pb_url_parse(res, resolved_path);
48 struct resource *create_devpath_resource(struct discover_boot_option *opt,
49 struct discover_device *orig_device,
52 struct devpath_resource_info *info;
53 char *pos, *devstr, *path;
57 res = talloc(opt, struct resource);
59 pos = strchr(devpath, ':');
61 /* do we have a "://" scheme separator? */
62 if (pos && pos[1] && pos[1] == '/' && pos[2] && pos[2] == '/') {
63 url = pb_url_parse(res, devpath);
65 if (url->scheme != pb_url_file) {
66 /* not a file? we're ready to go */
70 /* we've been passed a file:// URL, which has no device
71 * specifier. We can resolve against the original
73 resolve_resource_against_device(res, orig_device,
80 /* if there was no device specified, we can resolve now */
82 resolve_resource_against_device(res, orig_device, devpath);
86 devstr = talloc_strndup(res, devpath, pos - devpath);
87 path = talloc_strdup(res, pos + 1);
89 pb_log_fn("resource depends on device %s\n", devstr);
91 /* defer resolution until we can find a suitable matching device */
92 info = talloc(res, struct devpath_resource_info);
96 res->resolved = false;
102 bool resolve_devpath_resource(struct device_handler *handler,
103 struct resource *res)
105 struct devpath_resource_info *info = res->info;
106 struct discover_device *dev;
108 assert(!res->resolved);
110 dev = parse_device_string(handler, info->dev);
115 resolve_resource_against_device(res, dev, info->path);
121 struct resource *create_url_resource(struct discover_boot_option *opt,
124 struct resource *res;
126 res = talloc(opt, struct resource);
127 talloc_steal(res, url);
129 res->resolved = true;