4 #include <talloc/talloc.h>
7 #include <discover/resource.h>
8 #include <discover/parser.h>
9 #include <discover/parser-utils.h>
15 static const char *const grub2_conf_files[] = {
21 "/boot/grub/grub.cfg",
22 "/boot/grub2/grub.cfg",
23 "/boot/grub/menu.lst",
29 "/BOOT/GRUB/GRUB.CFG",
30 "/BOOT/GRUB/MENU.LST",
34 struct grub2_resource_info {
39 /* we use slightly different resources for grub2 */
40 struct resource *create_grub2_resource(struct discover_boot_option *opt,
41 struct discover_device *orig_device,
42 const char *root, const char *path)
44 struct grub2_resource_info *info;
47 if (strstr(path, "://")) {
48 struct pb_url *url = pb_url_parse(opt, path);
50 return create_url_resource(opt, url);
53 res = talloc(opt, struct resource);
56 info = talloc(res, struct grub2_resource_info);
57 talloc_reference(info, root);
58 info->root = talloc_strdup(info, root);
59 info->path = talloc_strdup(info, path);
61 res->resolved = false;
65 resolve_resource_against_device(res, orig_device, path);
70 bool resolve_grub2_resource(struct device_handler *handler,
73 struct grub2_resource_info *info = res->info;
74 struct discover_device *dev;
76 assert(!res->resolved);
78 dev = device_lookup_by_uuid(handler, info->root);
83 resolve_resource_against_device(res, dev, info->path);
89 static int grub2_parse(struct discover_context *dc)
91 const char * const *filename;
92 struct grub2_parser *parser;
96 /* Support block device boot only at present */
100 parser = grub2_parser_create(dc);
102 for (filename = grub2_conf_files; *filename; filename++) {
103 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
107 grub2_parser_parse(parser, buf, len);
116 static struct parser grub2_parser = {
118 .parse = grub2_parse,
119 .resolve_resource = resolve_grub2_resource,
122 register_parser(grub2_parser);