Add initial dtb support
[petitboot] / discover / device-handler.h
1 #ifndef _DEVICE_HANDLER_H
2 #define _DEVICE_HANDLER_H
3
4 #include <list/list.h>
5
6 #define DEFAULT_BOOT_TIMEOUT_SEC        10
7
8 struct device_handler;
9 struct discover_device;
10 struct discover_server;
11 struct boot_option;
12 struct boot_command;
13 struct event;
14 struct device;
15 struct waitset;
16
17 enum conf_method {
18         CONF_METHOD_LOCAL_FILE, /* discover by looking at local files on this
19                                    block device */
20
21         CONF_METHOD_DHCP,       /* configuration from a DHCP response */
22
23         CONF_METHOD_UNKNOWN = -1,
24 };
25
26 struct discover_device {
27         struct device           *device;
28
29         char                    **links;
30         int                     n_links;
31
32         char                    *uuid;
33         char                    *label;
34
35         char                    *mount_path;
36         char                    *device_path;
37
38         struct list             boot_options;
39 };
40
41 struct discover_boot_option {
42         struct parser           *source;
43         struct discover_device  *device;
44         struct boot_option      *option;
45         struct list_item        list;
46
47         struct resource         *boot_image;
48         struct resource         *initrd;
49         struct resource         *dtb;
50         struct resource         *icon;
51 };
52
53
54 struct discover_context {
55         struct parser           *parser;
56         struct event            *event;
57         struct discover_device  *device;
58         struct list             boot_options;
59         struct pb_url           *conf_url;
60         enum conf_method        method;
61 };
62
63 struct device_handler *device_handler_init(struct discover_server *server,
64                 struct waitset *waitset, int dry_run);
65
66 void device_handler_destroy(struct device_handler *devices);
67
68 int device_handler_get_device_count(const struct device_handler *handler);
69 const struct discover_device *device_handler_get_device(
70         const struct device_handler *handler, unsigned int index);
71
72 struct device *discover_context_device(struct discover_context *ctx);
73 struct discover_boot_option *discover_boot_option_create(
74                 struct discover_context *ctx,
75                 struct discover_device *dev);
76 void discover_context_add_boot_option(struct discover_context *ctx,
77                 struct discover_boot_option *opt);
78
79 int device_handler_event(struct device_handler *handler, struct event *event);
80
81 struct discover_device *device_lookup_by_name(struct device_handler *handler,
82                 const char *name);
83 struct discover_device *device_lookup_by_path(struct device_handler *handler,
84                 const char *path);
85 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
86                 const char *uuid);
87 struct discover_device *device_lookup_by_label(struct device_handler *handler,
88                 const char *label);
89 struct discover_device *device_lookup_by_id(struct device_handler *handler,
90                 const char *id);
91
92 void device_handler_boot(struct device_handler *handler,
93                 struct boot_command *cmd);
94 void device_handler_cancel_default(struct device_handler *handler);
95
96 #endif /* _DEVICE_HANDLER_H */