]> git.ozlabs.org Git - petitboot/blob - discover/parser.h
discover/boot: Set boot_tty variable before kexec
[petitboot] / discover / parser.h
1 #ifndef _PARSER_H
2 #define _PARSER_H
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8
9 #include "device-handler.h"
10
11 struct discover_context;
12 struct device_handler;
13 struct resource;
14
15 /**
16  * Our config parser.
17  *
18  * Each parser is responsible for creating discover_boot_options from config
19  * files found on new devices. The boot items discovered during parse will have
20  * 'resources' attached (see @discover_boot_option), which may already be
21  * resolved (in the case of a device-local filename, or a URL), or unresolved
22  * (in the case of a filename on another device).
23  *
24  * If the boot option contains references to unresolved resources, the
25  * device handler will not inform clients about the boot options, as
26  * they're not properly "available" at this stage. The handler will attempt to
27  * resolve them whenever new devices are discovered, by calling the parser's
28  * resolve_resource function. Once a boot option's resources are full resolved,
29  * the option can be sent to clients.
30  */
31 struct parser {
32         char                    *name;
33         int                     (*parse)(struct discover_context *ctx);
34         bool                    (*resolve_resource)(
35                                                 struct device_handler *handler,
36                                                 struct resource *res);
37 };
38
39 enum generic_icon_type {
40         ICON_TYPE_DISK,
41         ICON_TYPE_USB,
42         ICON_TYPE_OPTICAL,
43         ICON_TYPE_NETWORK,
44         ICON_TYPE_UNKNOWN
45 };
46
47 #define streq(a,b) (!strcasecmp((a),(b)))
48
49 void parser_init(void);
50
51 void iterate_parsers(struct discover_context *ctx);
52 int parse_user_event(struct discover_context *ctx, struct event *event);
53
54 /* File IO functions for parsers; these should be the only interface that
55  * parsers use to access a device's filesystem.
56  *
57  * These are intended for small amounts of data, typically text
58  * configuration and state files.  Note that parser_request_file,
59  * and parser_replace_file work only on non-directories.
60  */
61 int parser_request_file(struct discover_context *ctx,
62                 struct discover_device *dev, const char *filename,
63                 char **buf, int *len);
64 int parser_replace_file(struct discover_context *ctx,
65                 struct discover_device *dev, const char *filename,
66                 char *buf, int len);
67 int parser_request_url(struct discover_context *ctx, struct pb_url *url,
68                 char **buf, int *len);
69 /* parser_stat_path returns 0 if path can be stated on dev by the
70  * running user.  Note that this function follows symlinks, like the
71  * stat system call.  When the function returns 0, also fills in
72  * statbuf for the path.  Returns non-zero on error.  This function
73  * does not have the limitations on file size that the functions above
74  * do.  Unlike some of the functions above, this function also works
75  * on directories. */
76 int parser_stat_path(struct discover_context *ctx,
77                 struct discover_device *dev, const char *path,
78                 struct stat *statbuf);
79
80 #endif /* _PARSER_H */