[PATCH v1 15/30] lib/efi: Add new routines to access efi variables
Samuel Mendoza-Jonas
sam at mendozajonas.com
Thu Aug 2 15:43:01 AEST 2018
On Wed, 2018-08-01 at 16:54 +1000, Samuel Mendoza-Jonas wrote:
> On Tue, 2018-07-24 at 22:15 +0000, Geoff Levand wrote:
> > From: Ge Song <ge.song at hxt-semitech.com>
> >
> > Provide methods to load/store petitboot's configuration on efi-based
> > platforms. A test case is also provided.
> >
> > Signed-off-by: Ge Song <ge.song at hxt-semitech.com>
> > [Cleanup file comments, make efivarfs_path static.]
> > Signed-off-by: Geoff Levand <geoff at infradead.org>
> > ---
> > lib/Makefile.am | 4 +-
> > lib/efi/efivar.c | 191 +++++++++++++++++++++++++++++++++++++++++++++++++
> > lib/efi/efivar.h | 46 ++++++++++++
> > test/lib/test-efivar.c | 127 ++++++++++++++++++++++++++++++++
> > 4 files changed, 367 insertions(+), 1 deletion(-)
> > create mode 100644 lib/efi/efivar.c
> > create mode 100644 lib/efi/efivar.h
> > create mode 100644 test/lib/test-efivar.c
>
> Hi Geoff,
>
> The new efivar test isn't added to test/lib/Makefile so it doesn't run.
> I added it in but it looks like it might have gone a bit stale, eg:
>
<snip>
Looks like just the use of set/get are stale; that and a small fixup to
efi_get_variable() makes everything green. Does this look sane?
---
lib/efi/efivar.c | 3 ++-
test/lib/Makefile.am | 3 ++-
test/lib/test-efivar.c | 25 +++++++++++++++----------
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c
index 0c4b462..4304562 100644
--- a/lib/efi/efivar.c
+++ b/lib/efi/efivar.c
@@ -148,7 +148,8 @@ int efi_get_variable(void *ctx, const char *guidstr, const char *name,
rc = 0;
exit:
talloc_free(path);
- close(fd);
+ if (fd >= 0)
+ close(fd);
return rc;
}
diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am
index 047fcb2..65991a5 100644
--- a/test/lib/Makefile.am
+++ b/test/lib/Makefile.am
@@ -23,7 +23,8 @@ lib_TESTS = \
test/lib/test-process-parent-stdout \
test/lib/test-process-both \
test/lib/test-process-stdout-eintr \
- test/lib/test-fold
+ test/lib/test-fold \
+ test/lib/test-efivar
if WITH_OPENSSL
lib_TESTS += \
diff --git a/test/lib/test-efivar.c b/test/lib/test-efivar.c
index 8ceb8f5..a85b73c 100644
--- a/test/lib/test-efivar.c
+++ b/test/lib/test-efivar.c
@@ -87,33 +87,38 @@ int main(void)
{
void *ctx = NULL;
int rc, errno_value;
- size_t size;
- uint8_t *data = NULL;
uint32_t attr = DEF_ATTR;
char *path = NULL;
+ struct efi_data *efi_data;
if(!probe())
return ENOENT;
talloc_new(ctx);
- size = strlen(test_data) + 1;
- rc = efi_set_variable(ctx, test_efivar_guid, test_varname,
- (uint8_t *)test_data, size, attr);
+ efi_data = talloc_zero(ctx, struct efi_data);
+ efi_data->attributes = attr;
+ efi_data->data = talloc_strdup(efi_data, test_data);
+ efi_data->data_size = strlen(test_data) + 1;
+
+ rc = efi_set_variable(test_efivar_guid, test_varname,
+ efi_data);
+
+ talloc_free(efi_data);
rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
- &data, &size, &attr);
+ &efi_data);
- assert(data != NULL);
- rc = strcmp((char *)data, test_data);
+ assert(efi_data->data != NULL);
+ rc = strcmp((char *)efi_data->data, test_data);
if (rc) {
talloc_free(ctx);
assert(0);
}
- rc = efi_del_variable(ctx, test_efivar_guid, test_varname);
+ rc = efi_del_variable(test_efivar_guid, test_varname);
rc = efi_get_variable(ctx, test_efivar_guid, test_varname,
- &data, &size, &attr);
+ &efi_data);
errno_value = errno;
talloc_free(ctx);
--
2.18.0
More information about the Petitboot
mailing list