Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1q1pud-0002AO-FT for mharc-grub-devel@gnu.org; Wed, 24 May 2023 10:56:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1puX-0001zi-VL for grub-devel@gnu.org; Wed, 24 May 2023 10:56:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1puW-0004hy-D0 for grub-devel@gnu.org; Wed, 24 May 2023 10:56:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684940179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KDQpHyjawbzRW3lcq5iwJHjsU7QpFlJdFRYql/v019A=; b=BZx7BPDtDFPuigSHs9HeKqYwBQeqxxI7vbyswRCqj8tlu2KIHiFSObQOhYTKujB+8np64G 7ZcWcs/8p5bZScXuR0qGQogbTda3uQt763X9mU89ZvJHR6zjbumo3Cpj8sgyPaz0dIT/Bo qqHxV84JWxbTlqaWc7XIkERBrJHhBpA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-5rp7AOOIPomRWKVbYg1kdA-1; Wed, 24 May 2023 10:56:16 -0400 X-MC-Unique: 5rp7AOOIPomRWKVbYg1kdA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81DAD811E7F; Wed, 24 May 2023 14:56:15 +0000 (UTC) Received: from osteffen-laptop.redhat.com (unknown [10.39.194.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5ECA1121314; Wed, 24 May 2023 14:56:14 +0000 (UTC) From: Oliver Steffen To: grub-devel@gnu.org Cc: Daniel Kiper , Gerd Hoffmann , Oliver Steffen Subject: [PATCH v8 07/10] efi: Add grub_efi_set_variable_to_string() Date: Wed, 24 May 2023 16:55:55 +0200 Message-Id: <20230524145558.2219878-8-osteffen@redhat.com> In-Reply-To: <20230524145558.2219878-1-osteffen@redhat.com> References: <20230524145558.2219878-1-osteffen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.129.124; envelope-from=osteffen@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2023 14:56:26 -0000 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 --- 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