grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v9 07/11] efi: Add grub_efi_set_variable_to_string()


From: Oliver Steffen
Subject: [PATCH v9 07/11] efi: Add grub_efi_set_variable_to_string()
Date: Fri, 26 May 2023 13:35:48 +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>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.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 0583a7b5c..6b0aef115 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -286,6 +286,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 3d056a0a4..cd977cbbc 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]