- /* move boot options from the context to the device */
- list_for_each_entry_safe(&ctx->boot_options, opt, tmp, list) {
- list_remove(&opt->list);
- list_add(&dev->device->boot_options, &opt->list);
- dev->device->n_options++;
- discover_server_notify_boot_option_add(handler->server, opt);
+struct discover_device *device_lookup_by_name(struct device_handler *handler,
+ const char *name)
+{
+ if (!strncmp(name, "/dev/", strlen("/dev/")))
+ name += strlen("/dev/");
+
+ return device_lookup_by_id(handler, name);
+}
+
+struct discover_device *device_lookup_by_uuid(
+ struct device_handler *device_handler,
+ const char *uuid)
+{
+ return device_lookup(device_handler, device_match_uuid, uuid);
+}
+
+struct discover_device *device_lookup_by_label(
+ struct device_handler *device_handler,
+ const char *label)
+{
+ return device_lookup(device_handler, device_match_label, label);
+}
+
+struct discover_device *device_lookup_by_id(
+ struct device_handler *device_handler,
+ const char *id)
+{
+ return device_lookup(device_handler, device_match_id, id);
+}
+
+struct discover_device *device_lookup_by_serial(
+ struct device_handler *device_handler,
+ const char *serial)
+{
+ return device_lookup(device_handler, device_match_serial, serial);
+}
+
+void device_handler_destroy(struct device_handler *handler)
+{
+ talloc_free(handler);
+}
+
+static int destroy_device(void *arg)
+{
+ struct discover_device *dev = arg;
+
+ umount_device(dev);
+
+ return 0;
+}
+
+struct discover_device *discover_device_create(struct device_handler *handler,
+ const char *id)
+{
+ struct discover_device *dev;
+
+ dev = device_lookup_by_id(handler, id);
+ if (dev)
+ return dev;
+
+ dev = talloc_zero(handler, struct discover_device);
+ dev->device = talloc_zero(dev, struct device);
+ dev->device->id = talloc_strdup(dev->device, id);
+ list_init(&dev->params);
+ list_init(&dev->boot_options);
+
+ talloc_set_destructor(dev, destroy_device);
+
+ return dev;
+}
+
+struct discover_device_param {
+ char *name;
+ char *value;
+ struct list_item list;
+};
+
+void discover_device_set_param(struct discover_device *device,
+ const char *name, const char *value)
+{
+ struct discover_device_param *param;
+ bool found = false;
+
+ list_for_each_entry(&device->params, param, list) {
+ if (!strcmp(param->name, name)) {
+ found = true;
+ break;
+ }