]> git.ozlabs.org Git - petitboot/blobdiff - discover/parser-utils.c
Hook up parsers to device discovery
[petitboot] / discover / parser-utils.c
diff --git a/discover/parser-utils.c b/discover/parser-utils.c
new file mode 100644 (file)
index 0000000..4982112
--- /dev/null
@@ -0,0 +1,53 @@
+
+#include <string.h>
+
+#include <talloc/talloc.h>
+
+#include "pb-protocol/pb-protocol.h"
+#include "udev.h"
+#include "device-handler.h"
+#include "parser-utils.h"
+
+void device_add_boot_option(struct device *device,
+               struct boot_option *boot_option)
+{
+       list_add(&device->boot_options, &boot_option->list);
+       talloc_steal(device, boot_option);
+}
+
+const char *generic_icon_file(enum generic_icon_type type)
+{
+       switch (type) {
+       case ICON_TYPE_DISK:
+               return artwork_pathname("hdd.png");
+       case ICON_TYPE_USB:
+               return artwork_pathname("usbpen.png");
+       case ICON_TYPE_OPTICAL:
+               return artwork_pathname("cdrom.png");
+       case ICON_TYPE_NETWORK:
+       case ICON_TYPE_UNKNOWN:
+               break;
+       }
+       return artwork_pathname("hdd.png");
+}
+
+enum generic_icon_type guess_device_type(struct discover_context *ctx)
+{
+       struct udev_event *event;
+       const char *type, *bus;
+
+       event = ctx->event;
+
+       type = udev_event_param(event, "ID_TYPE");
+       bus = udev_event_param(event, "ID_BUS");
+
+       if (type && streq(type, "cd"))
+               return ICON_TYPE_OPTICAL;
+       if (!bus)
+               return ICON_TYPE_UNKNOWN;
+       if (streq(bus, "usb"))
+               return ICON_TYPE_USB;
+       if (streq(bus, "ata") || streq(bus, "scsi"))
+               return ICON_TYPE_DISK;
+       return ICON_TYPE_UNKNOWN;
+}