9 #include <talloc/talloc.h>
11 #include "device-handler.h"
15 static int is_prefix_ignorecase(const char *str, const char *prefix)
17 return !strncasecmp(str, prefix, strlen(prefix));
20 struct devpath_resource_info {
24 static struct discover_device *parse_device_string(
25 struct device_handler *handler, const char *devstr)
27 if (is_prefix_ignorecase(devstr, "uuid="))
28 return device_lookup_by_uuid(handler, devstr + strlen("uuid"));
30 if (is_prefix_ignorecase(devstr, "label="))
31 return device_lookup_by_label(handler,
32 devstr + strlen("label="));
34 return device_lookup_by_name(handler, devstr);
36 static void resolve_devpath_against_device(struct resource *res,
37 struct discover_device *dev, const char *path)
39 char *resolved_path = join_paths(res, dev->mount_path, path);
40 res->url = pb_url_parse(res, resolved_path);
44 struct resource *create_devpath_resource(struct discover_boot_option *opt,
45 struct discover_device *orig_device,
48 struct devpath_resource_info *info;
49 char *pos, *devstr, *path;
53 res = talloc(opt, struct resource);
55 pos = strchr(devpath, ':');
57 /* do we have a "://" scheme separator? */
58 if (pos && pos[1] && pos[1] == '/' && pos[2] && pos[2] == '/') {
59 url = pb_url_parse(res, devpath);
61 if (url->scheme != pb_url_file) {
62 /* not a file? we're ready to go */
66 /* we've been passed a file:// URL, which has no device
67 * specifier. We can resolve against the original
69 resolve_devpath_against_device(res, orig_device,
76 /* if there was no device specified, we can resolve now */
78 resolve_devpath_against_device(res, orig_device, devpath);
82 devstr = talloc_strndup(res, devpath, pos - devpath);
83 path = talloc_strdup(res, pos + 1);
85 /* defer resolution until we can find a suitable matching device */
86 info = talloc(res, struct devpath_resource_info);
90 res->resolved = false;
96 bool resolve_devpath_resource(struct device_handler *handler,
99 struct devpath_resource_info *info = res->info;
100 struct discover_device *dev;
102 assert(!res->resolved);
104 dev = parse_device_string(handler, info->dev);
109 resolve_devpath_against_device(res, dev, info->path);
115 struct resource *create_url_resource(struct discover_boot_option *opt,
118 struct resource *res;
120 res = talloc(opt, struct resource);
122 res->resolved = true;