Move waiter to library
[petitboot] / discover / parser-utils.c
1
2 #include <string.h>
3
4 #include <talloc/talloc.h>
5
6 #include "pb-protocol/pb-protocol.h"
7 #include "udev.h"
8 #include "device-handler.h"
9 #include "parser-utils.h"
10
11 void device_add_boot_option(struct device *device,
12                 struct boot_option *boot_option)
13 {
14         list_add(&device->boot_options, &boot_option->list);
15         talloc_steal(device, boot_option);
16 }
17
18 const char *generic_icon_file(enum generic_icon_type type)
19 {
20         switch (type) {
21         case ICON_TYPE_DISK:
22                 return artwork_pathname("hdd.png");
23         case ICON_TYPE_USB:
24                 return artwork_pathname("usbpen.png");
25         case ICON_TYPE_OPTICAL:
26                 return artwork_pathname("cdrom.png");
27         case ICON_TYPE_NETWORK:
28         case ICON_TYPE_UNKNOWN:
29                 break;
30         }
31         return artwork_pathname("hdd.png");
32 }
33
34 enum generic_icon_type guess_device_type(struct discover_context *ctx)
35 {
36         struct udev_event *event;
37         const char *type, *bus;
38
39         event = ctx->event;
40
41         type = udev_event_param(event, "ID_TYPE");
42         bus = udev_event_param(event, "ID_BUS");
43
44         if (type && streq(type, "cd"))
45                 return ICON_TYPE_OPTICAL;
46         if (!bus)
47                 return ICON_TYPE_UNKNOWN;
48         if (streq(bus, "usb"))
49                 return ICON_TYPE_USB;
50         if (streq(bus, "ata") || streq(bus, "scsi"))
51                 return ICON_TYPE_DISK;
52         return ICON_TYPE_UNKNOWN;
53 }