Skip to content

Commit 8d136fb

Browse files
committed
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
1 parent daeb975 commit 8d136fb

3 files changed

Lines changed: 22 additions & 25 deletions

File tree

lib/libefivar/efivar.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int efi_fd = -2;
4242

4343
const efi_guid_t efi_guid_empty = Z;
4444

45-
static struct uuid_table guid_tbl [] =
45+
static struct guid_table guid_tbl [] =
4646
{
4747
{ "00000000-0000-0000-0000-000000000000", "zero", Z },
4848
{ "093e0fae-a6c4-4f50-9f1b-d41e2b89c19a", "sha512", Z },
@@ -76,31 +76,39 @@ static struct uuid_table guid_tbl [] =
7676
{ "e2b36190-879b-4a3d-ad8d-f2e7bba32784", "rsa2048_sha256", Z },
7777
{ "ff3e5307-9fd0-48c9-85f1-8ad56c701e01", "sha384", Z },
7878
{ "f46ee6f4-4785-43a3-923d-7f786c3c8479", "lenovo_startup_interrupt", Z },
79-
{ "ffffffff-ffff-ffff-ffff-ffffffffffff", "zzignore-this-guid", Z },
8079
};
8180

81+
int
82+
efi_str_to_guid(const char *s, efi_guid_t *guid)
83+
{
84+
uint32_t status;
85+
86+
/* knows efi_guid_t is binary compatible with uuid_t */
87+
uuid_from_string(s, (uuid_t *)guid, &status);
88+
89+
return (status == uuid_s_ok ? 0 : -1);
90+
}
91+
8292
static void
8393
efi_guid_tbl_compile(void)
8494
{
8595
size_t i;
86-
uint32_t status;
8796
static bool done = false;
97+
struct guid_table *ent;
8898

8999
if (done)
90100
return;
91101
for (i = 0; i < nitems(guid_tbl); i++) {
92-
uuid_from_string(guid_tbl[i].uuid_str, (uuid_t *)&guid_tbl[i].guid,
93-
&status);
94-
/* all f's is a bad version, so ignore that error */
95-
if (status != uuid_s_ok && status != uuid_s_bad_version)
96-
fprintf(stderr, "Can't convert %s to a uuid for %s: %d\n",
97-
guid_tbl[i].uuid_str, guid_tbl[i].name, (int)status);
102+
ent = &guid_tbl[i];
103+
if (efi_str_to_guid(ent->uuid_str, &ent->guid) != 0)
104+
fprintf(stderr, "Can't convert %s to a guid for %s\n",
105+
ent->uuid_str, ent->name);
98106
}
99107
done = true;
100108
}
101109

102110
int
103-
efi_known_guid(struct uuid_table **tbl)
111+
efi_known_guid(struct guid_table **tbl)
104112
{
105113

106114
*tbl = guid_tbl;
@@ -327,7 +335,7 @@ efi_guid_to_str(const efi_guid_t *guid, char **sp)
327335
{
328336
uint32_t status;
329337

330-
/* knows efi_guid_t is a typedef of uuid_t */
338+
/* knows efi_guid_t is binary compatible with uuid_t */
331339
uuid_to_string((const uuid_t *)guid, sp, &status);
332340

333341
return (status == uuid_s_ok ? 0 : -1);
@@ -373,17 +381,6 @@ efi_set_variable(efi_guid_t guid, const char *name,
373381
return rv;
374382
}
375383

376-
int
377-
efi_str_to_guid(const char *s, efi_guid_t *guid)
378-
{
379-
uint32_t status;
380-
381-
/* knows efi_guid_t is a typedef of uuid_t */
382-
uuid_from_string(s, (uuid_t *)guid, &status);
383-
384-
return (status == uuid_s_ok ? 0 : -1);
385-
}
386-
387384
int
388385
efi_variables_supported(void)
389386
{

lib/libefivar/efivar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ int efi_str_to_guid(const char *s, efi_guid_t *guid);
8080
int efi_variables_supported(void);
8181

8282
/* FreeBSD extensions */
83-
struct uuid_table
83+
struct guid_table
8484
{
8585
const char *uuid_str;
8686
const char *name;
8787
efi_guid_t guid;
8888
};
8989

90-
int efi_known_guid(struct uuid_table **);
90+
int efi_known_guid(struct guid_table **);
9191

9292
extern const efi_guid_t efi_guid_empty;
9393

usr.sbin/efivar/efivar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ print_variables(void)
298298
static void
299299
print_known_guid(void)
300300
{
301-
struct uuid_table *tbl;
301+
struct guid_table *tbl;
302302
int i, n;
303303

304304
n = efi_known_guid(&tbl);

0 commit comments

Comments
 (0)