5 #include <talloc/talloc.h>
8 #include <discover/resource.h>
9 #include <discover/parser.h>
10 #include <discover/parser-utils.h>
14 static const char *const grub2_conf_files[] = {
20 "/boot/grub/grub.cfg",
21 "/boot/grub2/grub.cfg",
22 "/boot/grub/menu.lst",
28 "/BOOT/GRUB/GRUB.CFG",
29 "/BOOT/GRUB/MENU.LST",
33 struct grub2_resource_info {
38 /* we use slightly different resources for grub2 */
39 struct resource *create_grub2_resource(struct discover_boot_option *opt,
40 struct discover_device *orig_device,
41 const char *root, const char *path)
43 struct grub2_resource_info *info;
46 if (strstr(path, "://")) {
47 struct pb_url *url = pb_url_parse(opt, path);
49 return create_url_resource(opt, url);
52 res = talloc(opt, struct resource);
55 info = talloc(res, struct grub2_resource_info);
56 talloc_reference(info, root);
57 info->root = talloc_strdup(info, root);
58 info->path = talloc_strdup(info, path);
60 res->resolved = false;
64 resolve_resource_against_device(res, orig_device, path);
69 bool resolve_grub2_resource(struct device_handler *handler,
72 struct grub2_resource_info *info = res->info;
73 struct discover_device *dev;
75 assert(!res->resolved);
77 dev = device_lookup_by_uuid(handler, info->root);
82 resolve_resource_against_device(res, dev, info->path);
88 static int grub2_parse(struct discover_context *dc)
90 const char * const *filename;
91 struct grub2_parser *parser;
95 /* Support block device boot only at present */
99 for (filename = grub2_conf_files; *filename; filename++) {
100 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
104 parser = grub2_parser_create(dc);
105 grub2_parser_parse(parser, *filename, buf, len);
115 static struct parser grub2_parser = {
117 .parse = grub2_parse,
118 .resolve_resource = resolve_grub2_resource,
121 register_parser(grub2_parser);