]> git.ozlabs.org Git - petitboot/blob - discover/device-handler.h
discover/boot: Fix log message with no newline
[petitboot] / discover / device-handler.h
1 #ifndef _DEVICE_HANDLER_H
2 #define _DEVICE_HANDLER_H
3
4 #include <stdbool.h>
5
6 #include <list/list.h>
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
27 struct discover_device {
28         struct device           *device;
29
30         char                    **links;
31         int                     n_links;
32
33         const char              *uuid;
34         const char              *label;
35
36         const char              *mount_path;
37         const char              *device_path;
38
39         bool                    notified;
40
41         struct list             boot_options;
42         struct list             params;
43 };
44
45 struct discover_boot_option {
46         struct parser           *source;
47         struct discover_device  *device;
48         struct boot_option      *option;
49         struct list_item        list;
50
51         struct resource         *boot_image;
52         struct resource         *initrd;
53         struct resource         *dtb;
54         struct resource         *icon;
55 };
56
57
58 struct discover_context {
59         struct parser           *parser;
60         struct event            *event;
61         struct discover_device  *device;
62         struct list             boot_options;
63         struct pb_url           *conf_url;
64         enum conf_method        method;
65 };
66
67 struct device_handler *device_handler_init(struct discover_server *server,
68                 struct waitset *waitset, int dry_run);
69
70 void device_handler_destroy(struct device_handler *devices);
71
72 int device_handler_get_device_count(const struct device_handler *handler);
73 const struct discover_device *device_handler_get_device(
74         const struct device_handler *handler, unsigned int index);
75
76 struct discover_device *discover_device_create(struct device_handler *handler,
77                 const char *id);
78 void device_handler_add_device(struct device_handler *handler,
79                 struct discover_device *device);
80 int device_handler_discover(struct device_handler *handler,
81                 struct discover_device *dev, enum conf_method method);
82 int device_handler_conf(struct device_handler *handler,
83                 struct discover_device *dev, struct pb_url *url,
84                 enum conf_method method);
85 void device_handler_remove(struct device_handler *handler,
86                 struct discover_device *device);
87
88 struct discover_context *device_handler_discover_context_create(
89                 struct device_handler *handler,
90                 struct discover_device *device);
91 void device_handler_discover_context_commit(struct device_handler *handler,
92                 struct discover_context *ctx);
93
94 struct discover_boot_option *discover_boot_option_create(
95                 struct discover_context *ctx,
96                 struct discover_device *dev);
97 void discover_context_add_boot_option(struct discover_context *ctx,
98                 struct discover_boot_option *opt);
99
100 int device_handler_user_event(struct device_handler *handler,
101                                 struct event *event);
102
103 struct discover_device *device_lookup_by_name(struct device_handler *handler,
104                 const char *name);
105 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
106                 const char *uuid);
107 struct discover_device *device_lookup_by_label(struct device_handler *handler,
108                 const char *label);
109 struct discover_device *device_lookup_by_id(struct device_handler *handler,
110                 const char *id);
111
112 void discover_device_set_param(struct discover_device *device,
113                 const char *name, const char *value);
114 const char *discover_device_get_param(struct discover_device *device,
115                 const char *name);
116
117 void device_handler_boot(struct device_handler *handler,
118                 struct boot_command *cmd);
119 void device_handler_cancel_default(struct device_handler *handler);
120
121 #endif /* _DEVICE_HANDLER_H */