discover/grub2: Allow to separate the --id argument using a space char
[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 #include <types/types.h>
8
9 struct device_handler;
10 struct discover_device;
11 struct discover_server;
12 struct boot_option;
13 struct boot_command;
14 struct process_info;
15 struct event;
16 struct device;
17 struct waitset;
18 struct config;
19
20 struct discover_device {
21         struct device           *device;
22
23         char                    **links;
24         int                     n_links;
25
26         const char              *uuid;
27         const char              *label;
28
29         char                    *mount_path;
30         char                    *root_path;
31         const char              *device_path;
32         struct ramdisk_device   *ramdisk;
33         bool                    mounted;
34         bool                    mounted_rw;
35         bool                    unmount;
36         bool                    crypt_device;
37
38         bool                    notified;
39
40         struct list             boot_options;
41         struct list             params;
42
43         struct waiter           *requery_waiter;
44 };
45
46 struct discover_boot_option {
47         struct parser           *source;
48         struct discover_device  *device;
49         struct boot_option      *option;
50         struct list_item        list;
51         const char              *proxy;
52
53         struct resource         *boot_image;
54         struct resource         *initrd;
55         struct resource         *dtb;
56         struct resource         *args_sig_file;
57         struct resource         *icon;
58 };
59
60
61 struct discover_context {
62         struct device_handler   *handler;
63         struct parser           *parser;
64         struct event            *event;
65         struct discover_device  *device;
66         struct list             boot_options;
67         struct pb_url           *conf_url;
68         void                    *test_data;
69 };
70
71 struct ramdisk_device {
72         const char      *path;
73         char            *snapshot;
74         char            *origin;
75         char            *base;
76         uint64_t        sectors;
77 };
78
79 struct device_handler *device_handler_init(struct discover_server *server,
80                 struct waitset *waitset, int dry_run);
81
82 void device_handler_destroy(struct device_handler *devices);
83
84 int device_handler_get_device_count(const struct device_handler *handler);
85 const struct discover_device *device_handler_get_device(
86         const struct device_handler *handler, unsigned int index);
87 int device_handler_get_plugin_count(const struct device_handler *handler);
88 const struct plugin_option *device_handler_get_plugin(
89         const struct device_handler *handler, unsigned int index);
90 struct network *device_handler_get_network(
91                 const struct device_handler *handler);
92
93 bool device_handler_found_crypt_device(struct device_handler *handler,
94                 const char *name);
95
96 struct discover_device *discover_device_create(struct device_handler *handler,
97                 const char *uuid, const char *id);
98 void device_handler_add_device(struct device_handler *handler,
99                 struct discover_device *device);
100 void device_handler_add_ramdisk(struct device_handler *handler,
101                 const char *path);
102 struct ramdisk_device *device_handler_get_ramdisk(
103                 struct device_handler *handler);
104 void device_handler_release_ramdisk(struct discover_device *device);
105 void device_handler_open_encrypted_dev(struct device_handler *handler,
106                 char *password, char *device_id);
107 void device_handler_add_encrypted_dev(struct device_handler *handler,
108                 struct discover_device *dev);
109 int device_handler_discover(struct device_handler *handler,
110                 struct discover_device *dev);
111 int device_handler_dhcp(struct device_handler *handler,
112                 struct discover_device *dev, struct event *event);
113 void device_handler_remove(struct device_handler *handler,
114                 struct discover_device *device);
115 void device_handler_start_requery_timeout( struct device_handler *handler,
116                 struct discover_device *dev, int timeout);
117
118 void device_handler_status(struct device_handler *handler,
119                 struct status *status);
120 void device_handler_status_info(struct device_handler *handler,
121                 const char *fmt, ...);
122 void device_handler_status_err(struct device_handler *handler,
123                 const char *fmt, ...);
124 void device_handler_status_dev_info(struct device_handler *handler,
125                 struct discover_device *dev, const char *fmt, ...);
126 void device_handler_status_dev_err(struct device_handler *handler,
127                 struct discover_device *dev, const char *fmt, ...);
128 void device_handler_status_download(struct device_handler *handler,
129                 const struct process_info *procinfo,
130                 unsigned int percentage, unsigned int size, char suffix);
131 void device_handler_status_download_remove(struct device_handler *handler,
132                 struct process_info *procinfo);
133
134 struct discover_context *device_handler_discover_context_create(
135                 struct device_handler *handler,
136                 struct discover_device *device);
137 void device_handler_discover_context_commit(struct device_handler *handler,
138                 struct discover_context *ctx);
139
140 struct discover_boot_option *discover_boot_option_create(
141                 struct discover_context *ctx,
142                 struct discover_device *dev);
143 void discover_context_add_boot_option(struct discover_context *ctx,
144                 struct discover_boot_option *opt);
145 void device_handler_add_plugin_option(struct device_handler *handler,
146                 struct plugin_option *opt);
147
148 int device_handler_user_event(struct device_handler *handler,
149                                 struct event *event);
150
151 struct discover_device *device_lookup_by_name(struct device_handler *handler,
152                 const char *name);
153 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
154                 const char *uuid);
155 struct discover_device *device_lookup_by_label(struct device_handler *handler,
156                 const char *label);
157 struct discover_device *device_lookup_by_id(struct device_handler *handler,
158                 const char *id);
159 struct discover_device *device_lookup_by_serial(
160                 struct device_handler *device_handler,
161                 const char *serial);
162
163 void discover_device_set_param(struct discover_device *device,
164                 const char *name, const char *value);
165 const char *discover_device_get_param(struct discover_device *device,
166                 const char *name);
167
168 struct discover_boot_option *device_handler_find_option_by_name(
169                 struct device_handler *handler, const char *device,
170                 const char *name);
171 void device_handler_boot(struct device_handler *handler,
172                 bool change_default, struct boot_command *cmd);
173 void device_handler_cancel_default(struct device_handler *handler);
174 void device_handler_update_config(struct device_handler *handler,
175                 struct config *config);
176 void device_handler_process_url(struct device_handler *handler,
177                 const char *url, const char *mac, const char *ip);
178 void device_handler_install_plugin(struct device_handler *handler,
179                 const char *plugin_file);
180 void device_handler_reinit(struct device_handler *handler);
181 void device_handler_apply_temp_autoboot(struct device_handler *handler,
182                 struct autoboot_option *opt);
183
184 int device_request_write(struct discover_device *dev, bool *release);
185 void device_release_write(struct discover_device *dev, bool release);
186 void device_sync_snapshots(struct device_handler *handler, const char *device);
187
188 #endif /* _DEVICE_HANDLER_H */