Klaus Heinrich Kiwi | d1cd8c5 | 2020-02-27 12:43:47 -0300 | [diff] [blame] | 1 | From 108772a058d1bbecf8a1d413a0c365e90cd8b6c0 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jeremy Kerr <jk@ozlabs.org> |
| 3 | Date: Tue, 5 Nov 2019 16:42:14 +0800 |
| 4 | Subject: [PATCH 08/18] discover/grub2: expose a struct for grub2 file |
| 5 | references |
| 6 | |
| 7 | Currently, we have struct grub2_resource_info to keep references to boot |
| 8 | payloads that may be returned in boot options, and be (conditionally) |
| 9 | resolved by the parser. |
| 10 | |
| 11 | We'd also like to use the same semantics for other file references in |
| 12 | the grub2 parser, for arbitrary usage in scripts - where files are |
| 13 | also referenced by a path and an optional device. |
| 14 | |
| 15 | To do this, this change moves struct grub2_resource_info to grub2.h, and |
| 16 | renames to struct grub2_file. Future changes will use this for |
| 17 | script-internal file handling. |
| 18 | |
| 19 | Signed-off-by: Jeremy Kerr <jk@ozlabs.org> |
| 20 | (cherry picked from commit 8cb74c4502712162ba899bc06e2d0cf249a8697b) |
| 21 | Signed-off-by: Klaus Heinrich Kiwi <klaus@linux.vnet.ibm.com> |
| 22 | --- |
| 23 | discover/grub2/grub2.c | 24 +++++++++--------------- |
| 24 | discover/grub2/grub2.h | 8 ++++++++ |
| 25 | 2 files changed, 17 insertions(+), 15 deletions(-) |
| 26 | |
| 27 | diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c |
| 28 | index f62ccdd..412298b 100644 |
| 29 | --- a/discover/grub2/grub2.c |
| 30 | +++ b/discover/grub2/grub2.c |
| 31 | @@ -33,17 +33,12 @@ static const char *const grub2_conf_files[] = { |
| 32 | NULL |
| 33 | }; |
| 34 | |
| 35 | -struct grub2_resource_info { |
| 36 | - char *root; |
| 37 | - char *path; |
| 38 | -}; |
| 39 | - |
| 40 | /* we use slightly different resources for grub2 */ |
| 41 | struct resource *create_grub2_resource(struct discover_boot_option *opt, |
| 42 | struct discover_device *orig_device, |
| 43 | const char *root, const char *path) |
| 44 | { |
| 45 | - struct grub2_resource_info *info; |
| 46 | + struct grub2_file *file; |
| 47 | struct resource *res; |
| 48 | |
| 49 | if (strstr(path, "://")) { |
| 50 | @@ -55,13 +50,12 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, |
| 51 | res = talloc(opt, struct resource); |
| 52 | |
| 53 | if (root) { |
| 54 | - info = talloc(res, struct grub2_resource_info); |
| 55 | - talloc_reference(info, root); |
| 56 | - info->root = talloc_strdup(info, root); |
| 57 | - info->path = talloc_strdup(info, path); |
| 58 | + file = talloc(res, struct grub2_file); |
| 59 | + file->dev = talloc_strdup(file, root); |
| 60 | + file->path = talloc_strdup(file, path); |
| 61 | |
| 62 | res->resolved = false; |
| 63 | - res->info = info; |
| 64 | + res->info = file; |
| 65 | |
| 66 | } else |
| 67 | resolve_resource_against_device(res, orig_device, path); |
| 68 | @@ -72,18 +66,18 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, |
| 69 | bool resolve_grub2_resource(struct device_handler *handler, |
| 70 | struct resource *res) |
| 71 | { |
| 72 | - struct grub2_resource_info *info = res->info; |
| 73 | + struct grub2_file *file = res->info; |
| 74 | struct discover_device *dev; |
| 75 | |
| 76 | assert(!res->resolved); |
| 77 | |
| 78 | - dev = device_lookup_by_uuid(handler, info->root); |
| 79 | + dev = device_lookup_by_uuid(handler, file->dev); |
| 80 | |
| 81 | if (!dev) |
| 82 | return false; |
| 83 | |
| 84 | - resolve_resource_against_device(res, dev, info->path); |
| 85 | - talloc_free(info); |
| 86 | + resolve_resource_against_device(res, dev, file->path); |
| 87 | + talloc_free(file); |
| 88 | |
| 89 | return true; |
| 90 | } |
| 91 | diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h |
| 92 | index 68176fb..73d91b2 100644 |
| 93 | --- a/discover/grub2/grub2.h |
| 94 | +++ b/discover/grub2/grub2.h |
| 95 | @@ -107,6 +107,14 @@ struct grub2_parser { |
| 96 | bool inter_word; |
| 97 | }; |
| 98 | |
| 99 | +/* References to files in grub2 consist of an optional device and a path |
| 100 | + * (specified here by UUID). If the dev is unspecified, we fall back to a |
| 101 | + * default - usually the 'root' environment variable. */ |
| 102 | +struct grub2_file { |
| 103 | + char *dev; |
| 104 | + char *path; |
| 105 | +}; |
| 106 | + |
| 107 | /* type for builtin functions */ |
| 108 | typedef int (*grub2_function)(struct grub2_script *script, void *data, |
| 109 | int argc, char *argv[]); |
| 110 | -- |
| 111 | 2.17.1 |
| 112 | |