Share UCS2/UTF8 routines between boot loader and userland.

Move the UCS2 to UTF8 routines over into sys/boot/efi and have
libefivar grab them from there.

Sponsored by: Netflix
This commit is contained in:
imp 2017-03-09 00:24:01 +00:00
parent 30cd7c65c0
commit c993c1b8eb
4 changed files with 20 additions and 17 deletions

View File

@ -26,13 +26,19 @@
.include <src.opts.mk>
EFIBOOT=${SRCTOP}/sys/boot/efi
.PATH: ${EFIBOOT}/libefi
PACKAGE=lib${LIB}
LIB= efivar
SRCS= efivar.c libefivar.c
SRCS= efivar.c efichar.c
INCS= efivar.h
SHLIB_MAJOR= 1
MAN= efivar.3
CFLAGS+= -I${EFIBOOT}/include
MLINKS+=efivar.3 efi_set_variables_supported.3 \
efivar.3 efi_del_variable.3 \
efivar.3 efi_get_variable.3 \

View File

@ -36,8 +36,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include "efivar.h"
#include "libefivar_int.h"
#include "efichar.h"
static int efi_fd = -2;
@ -174,7 +173,7 @@ efi_get_variable(efi_guid_t guid, const char *name,
return -1;
efi_var_reset(&var);
rv = libefi_utf8_to_ucs2(name, &var.name, &var.namesize);
rv = utf8_to_ucs2(name, &var.name, &var.namesize);
if (rv != 0)
goto errout;
var.vendor = guid;
@ -237,7 +236,7 @@ efi_get_next_variable_name(efi_guid_t **guid, char **name)
*buf = 0;
/* GUID zeroed in var_reset */
} else {
rv = libefi_utf8_to_ucs2(*name, &var.name, &size);
rv = utf8_to_ucs2(*name, &var.name, &size);
if (rv != 0)
goto errout;
var.vendor = **guid;
@ -261,7 +260,7 @@ efi_get_next_variable_name(efi_guid_t **guid, char **name)
if (rv == 0) {
*name = NULL; /* XXX */
var.name[var.namesize / sizeof(efi_char)] = 0; /* EFI doesn't NUL terminate */
rv = libefi_ucs2_to_utf8(var.name, name);
rv = ucs2_to_utf8(var.name, name);
if (rv != 0)
goto errout;
retguid = var.vendor;
@ -359,7 +358,7 @@ efi_set_variable(efi_guid_t guid, const char *name,
return -1;
efi_var_reset(&var);
rv = libefi_utf8_to_ucs2(name, &var.name, &var.namesize);
rv = utf8_to_ucs2(name, &var.name, &var.namesize);
if (rv != 0)
goto errout;
var.vendor = guid;

View File

@ -26,10 +26,10 @@
* $FreeBSD$
*/
#ifndef _LIBEFI_INT_H_
#define _LIBEFI_INT_H_
#ifndef _BOOT_EFI_EFICHAR_H_
#define _BOOT_EFI_EFICHAR_H_
int libefi_ucs2_to_utf8(const efi_char *, char **);
int libefi_utf8_to_ucs2(const char *, efi_char **, size_t *);
int ucs2_to_utf8(const efi_char *, char **);
int utf8_to_ucs2(const char *, efi_char **, size_t *);
#endif /* _LIBEFI_INT_H_ */
#endif /* _BOOT_EFI_EFICHAR_H_ */

View File

@ -36,9 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/efi.h>
#include <machine/efi.h>
#include "libefivar_int.h"
#include <stdio.h>
#include "efichar.h"
/*
* If nm were converted to utf8, what what would strlen
@ -65,7 +63,7 @@ utf8_len_of_ucs2(const efi_char *nm)
}
int
libefi_ucs2_to_utf8(const efi_char *nm, char **name)
ucs2_to_utf8(const efi_char *nm, char **name)
{
size_t len, sz;
efi_char c;
@ -113,7 +111,7 @@ libefi_ucs2_to_utf8(const efi_char *nm, char **name)
}
int
libefi_utf8_to_ucs2(const char *name, efi_char **nmp, size_t *len)
utf8_to_ucs2(const char *name, efi_char **nmp, size_t *len)
{
efi_char *nm;
size_t sz;