]> git.ozlabs.org Git - petitboot/commitdiff
discover: populate udev device types
authorJeremy Kerr <jk@ozlabs.org>
Wed, 18 Sep 2013 03:44:41 +0000 (11:44 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 18 Sep 2013 03:44:41 +0000 (11:44 +0800)
Now that we have device types, populate from the udev info.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/udev.c
ui/test/discover-test.c

index a06dafc03c6f92808f6c0c35a28b9dfaed470e04..11fb115293fcd44076ac30cee7e695a4d7dc7e49 100644 (file)
@@ -304,6 +304,27 @@ static struct discover_device *find_device(struct device_handler *handler,
        return NULL;
 }
 
+static enum device_type event_device_type(struct device *device,
+               struct event *event)
+{
+       const char *param;
+
+       param = event_get_param(event, "type");
+       if (!param) {
+               pb_log("%s: empty type\n", device->id);
+               return DEVICE_TYPE_UNKNOWN;
+       }
+
+       if (!strcmp(param, "disk") || !strcmp(param, "partition"))
+               return DEVICE_TYPE_DISK;
+
+       if (!strcmp(param, "net"))
+               return DEVICE_TYPE_NETWORK;
+
+       pb_log("%s: unknown type '%s'\n", device->id, param);
+       return DEVICE_TYPE_UNKNOWN;
+}
+
 static struct discover_device *discover_device_create(
                struct device_handler *handler,
                struct discover_context *ctx,
@@ -325,6 +346,7 @@ static struct discover_device *discover_device_create(
                dev->device_path = talloc_strdup(dev, devname);
 
        dev->device->id = talloc_strdup(dev, event->device);
+       dev->device->type = event_device_type(dev->device, event);
 
        talloc_set_destructor(dev, destroy_device);
 
index 309a749acfbad20787e703f256216be11f017d08..d13ced7a22d175cf9684511d41e7ba52289d6020 100644 (file)
@@ -126,6 +126,7 @@ static int udev_handle_dev_action(struct udev_device *dev, const char *action)
        event->n_params = 0;
        event->params = NULL;
        event_set_param(event, "DEVNAME", devnode);
+       event_set_param(event, "type", devtype);
 
        udev_setup_event_params(dev, event);
 
index 45a4c7489719adc3f26fc106e7bef34096540e16..faf1d893677936fc9307b9329df8244ee33260d2 100644 (file)
@@ -3,6 +3,21 @@
 
 #include "ui/common/discover-client.h"
 
+static const char *device_type_string(enum device_type type)
+{
+       switch (type) {
+       case DEVICE_TYPE_DISK:
+               return "disk";
+       case DEVICE_TYPE_NETWORK:
+               return "network";
+       case DEVICE_TYPE_OPTICAL:
+               return "optical";
+       case DEVICE_TYPE_UNKNOWN:
+               return "unknown";
+       }
+       return "invalid";
+}
+
 static int print_device_add(struct device *device,
        void __attribute__((unused)) *arg)
 {
@@ -10,6 +25,7 @@ static int print_device_add(struct device *device,
 
        printf("new device:\n");
        printf("\tid:   %s\n", device->id);
+       printf("\ttype: %s\n", device_type_string(device->type));
        printf("\tname: %s\n", device->name);
        printf("\tdesc: %s\n", device->description);
        printf("\ticon: %s\n", device->icon_file);