]> git.ozlabs.org Git - petitboot/blobdiff - discover/resource.c
discover: Recognise and open LUKS encrypted partitions
[petitboot] / discover / resource.c
index 917a6dcbf4f8fdbedff2e544d648978d1ea6b353..c09c1c51051679900b11dfc513b8f115436239f5 100644 (file)
@@ -1,11 +1,14 @@
 
-#define _GNU_SOURCE
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdbool.h>
 #include <string.h>
 
 #include <url/url.h>
+#include <log/log.h>
 #include <talloc/talloc.h>
 
 #include "device-handler.h"
@@ -33,7 +36,8 @@ static struct discover_device *parse_device_string(
 
        return device_lookup_by_name(handler, devstr);
 }
-static void resolve_devpath_against_device(struct resource *res,
+
+void resolve_resource_against_device(struct resource *res,
        struct discover_device *dev, const char *path)
 {
        char *resolved_path = join_paths(res, dev->mount_path, path);
@@ -41,7 +45,7 @@ static void resolve_devpath_against_device(struct resource *res,
        res->resolved = true;
 }
 
-struct resource *create_devpath_resource(void *ctx,
+struct resource *create_devpath_resource(struct discover_boot_option *opt,
        struct discover_device *orig_device,
        const char *devpath)
 {
@@ -50,7 +54,7 @@ struct resource *create_devpath_resource(void *ctx,
        struct resource *res;
        struct pb_url *url;
 
-       res = talloc(ctx, struct resource);
+       res = talloc(opt, struct resource);
 
        pos = strchr(devpath, ':');
 
@@ -66,7 +70,7 @@ struct resource *create_devpath_resource(void *ctx,
                        /* we've been passed a file:// URL, which has no device
                         * specifier. We can resolve against the original
                         * device */
-                       resolve_devpath_against_device(res, orig_device,
+                       resolve_resource_against_device(res, orig_device,
                                        url->path);
                        talloc_free(url);
                }
@@ -75,13 +79,15 @@ struct resource *create_devpath_resource(void *ctx,
 
        /* if there was no device specified, we can resolve now */
        if (!pos) {
-               resolve_devpath_against_device(res, orig_device, devpath);
+               resolve_resource_against_device(res, orig_device, devpath);
                return res;
        }
 
        devstr = talloc_strndup(res, devpath, pos - devpath);
        path = talloc_strdup(res, pos + 1);
 
+       pb_log_fn("resource depends on device %s\n", devstr);
+
        /* defer resolution until we can find a suitable matching device */
        info = talloc(res, struct devpath_resource_info);
        info->dev = devstr;
@@ -106,8 +112,21 @@ bool resolve_devpath_resource(struct device_handler *handler,
        if (!dev)
                return false;
 
-       resolve_devpath_against_device(res, dev, info->path);
+       resolve_resource_against_device(res, dev, info->path);
        talloc_free(info);
 
        return true;
 }
+
+struct resource *create_url_resource(struct discover_boot_option *opt,
+               struct pb_url *url)
+{
+       struct resource *res;
+
+       res = talloc(opt, struct resource);
+       talloc_steal(res, url);
+       res->url = url;
+       res->resolved = true;
+
+       return res;
+}