Log new boot options
[petitboot] / discover / parser-utils.c
1
2 #include <string.h>
3
4 #include <log/log.h>
5 #include <talloc/talloc.h>
6
7 #include "pb-protocol/pb-protocol.h"
8 #include "udev.h"
9 #include "device-handler.h"
10 #include "parser-utils.h"
11
12 void device_add_boot_option(struct device *device,
13                 struct boot_option *boot_option)
14 {
15         pb_log("%s: %s\n", __func__, device->id);
16         pb_log(" id     '%s'\n", boot_option->id);
17         pb_log(" name   '%s'\n", boot_option->name);
18         pb_log(" descr  '%s'\n", boot_option->description);
19         pb_log(" icon   '%s'\n", boot_option->icon_file);
20         pb_log(" image  '%s'\n", boot_option->boot_image_file);
21         pb_log(" initrd '%s'\n", boot_option->initrd_file);
22         pb_log(" args   '%s'\n", boot_option->boot_args);
23         list_add(&device->boot_options, &boot_option->list);
24         talloc_steal(device, boot_option);
25 }
26
27 const char *generic_icon_file(enum generic_icon_type type)
28 {
29         switch (type) {
30         case ICON_TYPE_DISK:
31                 return artwork_pathname("hdd.png");
32         case ICON_TYPE_USB:
33                 return artwork_pathname("usbpen.png");
34         case ICON_TYPE_OPTICAL:
35                 return artwork_pathname("cdrom.png");
36         case ICON_TYPE_NETWORK:
37         case ICON_TYPE_UNKNOWN:
38                 break;
39         }
40         return artwork_pathname("hdd.png");
41 }
42
43 enum generic_icon_type guess_device_type(struct discover_context *ctx)
44 {
45         struct udev_event *event;
46         const char *type, *bus;
47
48         event = ctx->event;
49
50         type = udev_event_param(event, "ID_TYPE");
51         bus = udev_event_param(event, "ID_BUS");
52
53         if (type && streq(type, "cd"))
54                 return ICON_TYPE_OPTICAL;
55         if (!bus)
56                 return ICON_TYPE_UNKNOWN;
57         if (streq(bus, "usb"))
58                 return ICON_TYPE_USB;
59         if (streq(bus, "ata") || streq(bus, "scsi"))
60                 return ICON_TYPE_DISK;
61         return ICON_TYPE_UNKNOWN;
62 }