10 #include <talloc/talloc.h>
12 #include "device-handler.h"
16 static int is_prefix_ignorecase(const char *str, const char *prefix)
18 return !strncasecmp(str, prefix, strlen(prefix));
21 struct devpath_resource_info {
25 static struct discover_device *parse_device_string(
26 struct device_handler *handler, const char *devstr)
28 if (is_prefix_ignorecase(devstr, "uuid="))
29 return device_lookup_by_uuid(handler, devstr + strlen("uuid"));
31 if (is_prefix_ignorecase(devstr, "label="))
32 return device_lookup_by_label(handler,
33 devstr + strlen("label="));
35 return device_lookup_by_name(handler, devstr);
38 void resolve_resource_against_device(struct resource *res,
39 struct discover_device *dev, const char *path)
41 char *resolved_path = join_paths(res, dev->mount_path, path);
42 res->url = pb_url_parse(res, resolved_path);
46 struct resource *create_devpath_resource(struct discover_boot_option *opt,
47 struct discover_device *orig_device,
50 struct devpath_resource_info *info;
51 char *pos, *devstr, *path;
55 res = talloc(opt, struct resource);
57 pos = strchr(devpath, ':');
59 /* do we have a "://" scheme separator? */
60 if (pos && pos[1] && pos[1] == '/' && pos[2] && pos[2] == '/') {
61 url = pb_url_parse(res, devpath);
63 if (url->scheme != pb_url_file) {
64 /* not a file? we're ready to go */
68 /* we've been passed a file:// URL, which has no device
69 * specifier. We can resolve against the original
71 resolve_resource_against_device(res, orig_device,
78 /* if there was no device specified, we can resolve now */
80 resolve_resource_against_device(res, orig_device, devpath);
84 devstr = talloc_strndup(res, devpath, pos - devpath);
85 path = talloc_strdup(res, pos + 1);
87 pb_log("%s: resource depends on device %s\n", __func__, devstr);
89 /* defer resolution until we can find a suitable matching device */
90 info = talloc(res, struct devpath_resource_info);
94 res->resolved = false;
100 bool resolve_devpath_resource(struct device_handler *handler,
101 struct resource *res)
103 struct devpath_resource_info *info = res->info;
104 struct discover_device *dev;
106 assert(!res->resolved);
108 dev = parse_device_string(handler, info->dev);
113 resolve_resource_against_device(res, dev, info->path);
119 struct resource *create_url_resource(struct discover_boot_option *opt,
122 struct resource *res;
124 res = talloc(opt, struct resource);
126 res->resolved = true;