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