Skip to content

Commit

Permalink
discover/grub2: Add parsing code for grub2 file specifiers
Browse files Browse the repository at this point in the history
This change adds a (currently unused) function to parse (device)/path
references from grub scripts.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
  • Loading branch information
jk-ozlabs committed Nov 29, 2019
1 parent 8cb74c4 commit 51f7117
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions discover/grub2/grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ bool resolve_grub2_resource(struct device_handler *handler,
return true;
}

struct grub2_file *grub2_parse_file(struct grub2_script *script,
const char *str)
{
struct grub2_file *file;
size_t dev_len;
char *pos;

if (!str)
return NULL;

file = talloc_zero(script, struct grub2_file);

if (*str != '(') {
/* just a path - no device, return path as-is */
file->path = talloc_strdup(file, str);

} else {
/* device plus path - split into components */

pos = strchr(str, ')');

/* no closing bracket, or zero-length path? */
if (!pos || *(pos+1) == '\0') {
talloc_free(file);
return NULL;
}

file->path = talloc_strdup(file, pos + 1);

dev_len = pos - str - 1;
if (dev_len)
file->dev = talloc_strndup(file, str + 1, dev_len);
}

return file;
}


static int grub2_parse(struct discover_context *dc)
{
const char * const *filename;
Expand Down
4 changes: 4 additions & 0 deletions discover/grub2/grub2.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt,
bool resolve_grub2_resource(struct device_handler *handler,
struct resource *res);

/* grub-style device+path parsing */
struct grub2_file *grub2_parse_file(struct grub2_script *script,
const char *str);

/* external parser api */
struct grub2_parser *grub2_parser_create(struct discover_context *ctx);
void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
Expand Down

0 comments on commit 51f7117

Please sign in to comment.