[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 07/10] efi: Add grub_efi_set_variable_to_string()
From: |
Oliver Steffen |
Subject: |
[PATCH v8 07/10] efi: Add grub_efi_set_variable_to_string() |
Date: |
Wed, 24 May 2023 16:55:55 +0200 |
Add a function that sets an EFI variable to a string value.
The string is converted from UTF-8 to UTF-16.
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
grub-core/kern/efi/efi.c | 22 ++++++++++++++++++++++
include/grub/efi/efi.h | 3 +++
2 files changed, 25 insertions(+)
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index 8fc3edfae..0ac321d1d 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -285,6 +285,28 @@ grub_efi_get_variable_with_attributes (const char *var,
return status;
}
+grub_err_t
+grub_efi_set_variable_to_string (const char *name, const grub_guid_t *guid,
+ const char *value, grub_efi_uint32_t
attributes)
+{
+ grub_efi_char16_t *value_16;
+ grub_ssize_t len16;
+ grub_err_t status;
+
+ len16 = grub_utf8_to_utf16_alloc (value, &value_16, NULL);
+
+ if (len16 < 0)
+ return grub_errno;
+
+ status = grub_efi_set_variable_with_attributes (name, guid,
+ (void *) value_16, (len16 + 1) * sizeof (value_16[0]),
+ attributes);
+
+ grub_free (value_16);
+
+ return status;
+}
+
grub_efi_status_t
grub_efi_get_variable (const char *var, const grub_guid_t *guid,
grub_size_t *datasize_out, void **data_out)
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index 8ab752912..9d839baa5 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -108,6 +108,9 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
const grub_guid_t *guid,
void *data,
grub_size_t datasize);
+grub_err_t
+EXPORT_FUNC (grub_efi_set_variable_to_string) (const char *name, const
grub_guid_t *guid,
+ const char *value,
grub_efi_uint32_t attributes);
int
EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
const grub_efi_device_path_t *dp2);
--
2.40.1
- [PATCH v8 00/10] Add basic Boot Loader Interface support, Oliver Steffen, 2023/05/24
- [PATCH v8 04/10] grub-core: Make use of guid printf format specifier, Oliver Steffen, 2023/05/24
- [PATCH v8 03/10] kern/misc: Add a format specifier GUIDs, Oliver Steffen, 2023/05/24
- [PATCH v8 02/10] Unify GUID types, Oliver Steffen, 2023/05/24
- [PATCH v8 01/10] efi: Add grub_efi_set_variable_with_attributes(), Oliver Steffen, 2023/05/24
- [PATCH v8 06/10] kern/misc, kern/efi: Extract UTF-8 to UTF-16 code, Oliver Steffen, 2023/05/24
- [PATCH v8 07/10] efi: Add grub_efi_set_variable_to_string(),
Oliver Steffen <=
- [PATCH v8 05/10] types.h: Add GRUB_SSIZE_MAX, Oliver Steffen, 2023/05/24
- [PATCH v8 08/10] docs: Reword section headings, Oliver Steffen, 2023/05/24
- [PATCH v8 10/10] util/grub.d: Activate bli module on EFI, Oliver Steffen, 2023/05/24
- [PATCH v8 09/10] Add a module for the Boot Loader Interface, Oliver Steffen, 2023/05/24
- Re: [PATCH v8 00/10] Add basic Boot Loader Interface support, Daniel Kiper, 2023/05/25