diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-01-24 14:39:37 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-01-30 21:59:10 +0800 |
commit | 4896183708855fbfd0aa892537fbcc17ed7eb971 (patch) | |
tree | 5bbd851636871982cc26ca59ff1aa0970f6d8116 /discover/grub2 | |
parent | eea9a9fa697654ef26d7e2c1cee3b4ac610db643 (diff) | |
download | talos-petitboot-4896183708855fbfd0aa892537fbcc17ed7eb971.tar.gz talos-petitboot-4896183708855fbfd0aa892537fbcc17ed7eb971.zip |
discover: Add support for checking directories in parser API
This change adds a function to the parser API:
int parser_check_dir(struct discover_context *ctx,
struct discover_device *dev, const char *dirname)
- which allows parsers to check for the presence of a directory (path of
'dirname') on the device ('dev'). We use this in the GRUB2 parser to
implement the `test -d` check.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/grub2')
-rw-r--r-- | discover/grub2/builtins.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 7511076..6ada2a6 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -154,6 +154,15 @@ static bool builtin_test_op_file(struct grub2_script *script, char op, return result; } +static bool builtin_test_op_dir(struct grub2_script *script, char op, + const char *dir) +{ + if (op != 'd') + return false; + + return parser_check_dir(script->ctx, script->ctx->device, dir) == 0; +} + static bool builtin_test_op(struct grub2_script *script, int argc, char **argv, int *consumed) { @@ -207,6 +216,11 @@ static bool builtin_test_op(struct grub2_script *script, *consumed = 2; return builtin_test_op_file(script, op[1], a1); } + + if (!strcmp(op, "-d")) { + *consumed = 2; + return builtin_test_op_dir(script, op[1], a1); + } } op = argv[0]; |