6 #include <talloc/talloc.h>
9 #include <discover/resource.h>
10 #include <discover/parser.h>
11 #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",
30 "/BOOT/GRUB/GRUB.CFG",
31 "/BOOT/GRUB/MENU.LST",
36 struct grub2_resource_info {
41 /* we use slightly different resources for grub2 */
42 struct resource *create_grub2_resource(struct discover_boot_option *opt,
43 struct discover_device *orig_device,
44 const char *root, const char *path)
46 struct grub2_resource_info *info;
49 if (strstr(path, "://")) {
50 struct pb_url *url = pb_url_parse(opt, path);
52 return create_url_resource(opt, url);
55 res = talloc(opt, struct resource);
58 info = talloc(res, struct grub2_resource_info);
59 talloc_reference(info, root);
60 info->root = talloc_strdup(info, root);
61 info->path = talloc_strdup(info, path);
63 res->resolved = false;
67 resolve_resource_against_device(res, orig_device, path);
72 bool resolve_grub2_resource(struct device_handler *handler,
75 struct grub2_resource_info *info = res->info;
76 struct discover_device *dev;
78 assert(!res->resolved);
80 dev = device_lookup_by_uuid(handler, info->root);
85 resolve_resource_against_device(res, dev, info->path);
91 static int grub2_parse(struct discover_context *dc)
93 const char * const *filename;
94 struct grub2_parser *parser;
98 /* Support block device boot only at present */
102 for (filename = grub2_conf_files; *filename; filename++) {
103 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
107 parser = grub2_parser_create(dc);
108 grub2_parser_parse(parser, *filename, buf, len);
109 device_handler_status_dev_info(dc->handler, dc->device,
110 _("Parsed GRUB configuration from %s"),
121 static struct parser grub2_parser = {
123 .parse = grub2_parse,
124 .resolve_resource = resolve_grub2_resource,
127 register_parser(grub2_parser);