git: 8d136fb027ba - main - efivar: Use struct guid_table instead of uuid_table

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 01 May 2025 18:06:45 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d136fb027ba2b12794d0501422def5d4e375643

commit 8d136fb027ba2b12794d0501422def5d4e375643
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2025-05-01 17:54:02 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-05-01 17:55:14 +0000

    efivar: Use struct guid_table instead of uuid_table
    
    uuid_table was the linux name. When libefivar was started, I tried to
    make it compatible with Linux. However, that's no longer relevant: (a)
    little to no Linux code was subsequently ported and (b) Linux compat has
    eroded. This erodes it a bit more to cope with the uuid_t -> efi_guid_t
    changes. This also moves a couple of functions around to reduce copying and
    updates consumers for the visible parts of this change.
    
    Sponsored by:           Netflix
    Reviewed by:            tsoome, kib
    Differential Revision:  https://reviews.freebsd.org/D50060
---
 lib/libefivar/efivar.c   | 41 +++++++++++++++++++----------------------
 lib/libefivar/efivar.h   |  4 ++--
 usr.sbin/efivar/efivar.c |  2 +-
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/lib/libefivar/efivar.c b/lib/libefivar/efivar.c
index 03efb3c5226a..a7cf13055bfe 100644
--- a/lib/libefivar/efivar.c
+++ b/lib/libefivar/efivar.c
@@ -42,7 +42,7 @@ static int efi_fd = -2;
 
 const efi_guid_t efi_guid_empty = Z;
 
-static struct uuid_table guid_tbl [] =
+static struct guid_table guid_tbl [] =
 {
 	{ "00000000-0000-0000-0000-000000000000", "zero", Z },
 	{ "093e0fae-a6c4-4f50-9f1b-d41e2b89c19a", "sha512", Z },
@@ -76,31 +76,39 @@ static struct uuid_table guid_tbl [] =
 	{ "e2b36190-879b-4a3d-ad8d-f2e7bba32784", "rsa2048_sha256", Z },
 	{ "ff3e5307-9fd0-48c9-85f1-8ad56c701e01", "sha384", Z },
 	{ "f46ee6f4-4785-43a3-923d-7f786c3c8479", "lenovo_startup_interrupt", Z },
-	{ "ffffffff-ffff-ffff-ffff-ffffffffffff", "zzignore-this-guid", Z },
 };
 
+int
+efi_str_to_guid(const char *s, efi_guid_t *guid)
+{
+	uint32_t status;
+
+	/* knows efi_guid_t is binary compatible with uuid_t */
+	uuid_from_string(s, (uuid_t *)guid, &status);
+
+	return (status == uuid_s_ok ? 0 : -1);
+}
+
 static void
 efi_guid_tbl_compile(void)
 {
 	size_t i;
-	uint32_t status;
 	static bool done = false;
+	struct guid_table *ent;
 
 	if (done)
 		return;
 	for (i = 0; i < nitems(guid_tbl); i++) {
-		uuid_from_string(guid_tbl[i].uuid_str, (uuid_t *)&guid_tbl[i].guid,
-		    &status);
-		/* all f's is a bad version, so ignore that error */
-		if (status != uuid_s_ok && status != uuid_s_bad_version)
-			fprintf(stderr, "Can't convert %s to a uuid for %s: %d\n",
-			    guid_tbl[i].uuid_str, guid_tbl[i].name, (int)status);
+		ent = &guid_tbl[i];
+		if (efi_str_to_guid(ent->uuid_str, &ent->guid) != 0)
+			fprintf(stderr, "Can't convert %s to a guid for %s\n",
+			    ent->uuid_str, ent->name);
 	}
 	done = true;
 }
 
 int
-efi_known_guid(struct uuid_table **tbl)
+efi_known_guid(struct guid_table **tbl)
 {
 
 	*tbl = guid_tbl;
@@ -327,7 +335,7 @@ efi_guid_to_str(const efi_guid_t *guid, char **sp)
 {
 	uint32_t status;
 
-	/* knows efi_guid_t is a typedef of uuid_t */
+	/* knows efi_guid_t is binary compatible with uuid_t */
 	uuid_to_string((const uuid_t *)guid, sp, &status);
 
 	return (status == uuid_s_ok ? 0 : -1);
@@ -373,17 +381,6 @@ errout:
 	return rv;
 }
 
-int
-efi_str_to_guid(const char *s, efi_guid_t *guid)
-{
-	uint32_t status;
-
-	/* knows efi_guid_t is a typedef of uuid_t */
-	uuid_from_string(s, (uuid_t *)guid, &status);
-
-	return (status == uuid_s_ok ? 0 : -1);
-}
-
 int
 efi_variables_supported(void)
 {
diff --git a/lib/libefivar/efivar.h b/lib/libefivar/efivar.h
index 980f261e9edc..e159f4cccd3d 100644
--- a/lib/libefivar/efivar.h
+++ b/lib/libefivar/efivar.h
@@ -80,14 +80,14 @@ int efi_str_to_guid(const char *s, efi_guid_t *guid);
 int efi_variables_supported(void);
 
 /* FreeBSD extensions */
-struct uuid_table
+struct guid_table
 {
 	const char *uuid_str;
 	const char *name;
 	efi_guid_t guid;
 };
 
-int efi_known_guid(struct uuid_table **);
+int efi_known_guid(struct guid_table **);
 
 extern const efi_guid_t efi_guid_empty;
 
diff --git a/usr.sbin/efivar/efivar.c b/usr.sbin/efivar/efivar.c
index a87c73abef36..c40ff1ea010f 100644
--- a/usr.sbin/efivar/efivar.c
+++ b/usr.sbin/efivar/efivar.c
@@ -298,7 +298,7 @@ print_variables(void)
 static void
 print_known_guid(void)
 {
-	struct uuid_table *tbl;
+	struct guid_table *tbl;
 	int i, n;
 
 	n = efi_known_guid(&tbl);