Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jan 2010 04:24:03 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r203181 - in head/lib: . libefi
Message-ID:  <201001300424.o0U4O370082276@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Jan 30 04:24:03 2010
New Revision: 203181
URL: http://svn.freebsd.org/changeset/base/203181

Log:
  Introduce libefi -- a library around EFI runtime services and protocols.
  This first commit brings 3 functions for enumerating, retrieving,
  adding, removing and modifying EFI variables. The immediate use of these
  include the insertion of a new boot option as part of the installation
  process.
  
  This library uses ioctl(2) requests implemented by io(4) to pass the
  requests down through the kernel to EFI. These ioctl requests are only
  implemented on ia64, so libefi is currently only enabled on ia64. The
  interface is generic and io(4) on mad64/i386 can easily be taught to
  handle these once EFI support has been added to the kernel there.

Added:
  head/lib/libefi/
  head/lib/libefi/Makefile   (contents, props changed)
  head/lib/libefi/efi_getvar.c   (contents, props changed)
  head/lib/libefi/efi_nextvarname.c   (contents, props changed)
  head/lib/libefi/efi_setvar.c   (contents, props changed)
  head/lib/libefi/libefi.3   (contents, props changed)
  head/lib/libefi/libefi.c   (contents, props changed)
  head/lib/libefi/libefi.h   (contents, props changed)
  head/lib/libefi/libefi_int.h   (contents, props changed)
Modified:
  head/lib/Makefile

Modified: head/lib/Makefile
==============================================================================
--- head/lib/Makefile	Sat Jan 30 01:54:29 2010	(r203180)
+++ head/lib/Makefile	Sat Jan 30 04:24:03 2010	(r203181)
@@ -33,8 +33,8 @@ SUBDIR=	${_csu} libc libbsm libauditd li
 	libtacplus libutil ${_libypclnt} libalias libarchive \
 	${_libatm} libbegemot ${_libbluetooth} ${_libbsnmp} libbz2 \
 	libcalendar libcam libcompat libdevinfo libdevstat libdisk \
-	libdwarf libedit libexpat libfetch libftpio libgeom ${_libgpib} \
-	${_libgssapi} ${_librpcsec_gss} libipsec \
+	libdwarf libedit ${_libefi} libexpat libfetch libftpio libgeom \
+	${_libgpib} ${_libgssapi} ${_librpcsec_gss} libipsec \
 	${_libipx} libjail libkiconv libmagic libmemstat ${_libmilter} \
 	${_libmp} ${_libncp} ${_libngatm} libopie libpam libpcap \
 	${_libpmc} libproc librt ${_libsdp} ${_libsm} ${_libsmb} \
@@ -104,6 +104,7 @@ _libvgl=	libvgl
 .endif
 
 .if ${MACHINE_ARCH} == "ia64"
+_libefi=	libefi
 _libsmb=	libsmb
 .endif
 

Added: head/lib/libefi/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/Makefile	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB=	efi
+SHLIB_MAJOR= 1
+
+SRCS=	libefi.c \
+	efi_getvar.c \
+	efi_nextvarname.c \
+	efi_setvar.c
+
+CFLAGS+= -I${.CURDIR}
+
+INCS=	libefi.h
+
+MAN+=	libefi.3
+MLINKS+=libefi.3 efi_getvar.3 \
+	libefi.3 efi_nextvarname.3 \
+	libefi.3 efi_setvar.3
+
+.include <bsd.lib.mk>

Added: head/lib/libefi/efi_getvar.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/efi_getvar.c	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <libefi.h>
+#include <stdlib.h>
+
+#include "libefi_int.h"
+
+/*
+ * EFI_STATUS
+ * GetVariable(
+ *	IN CHAR16	*VariableName,
+ *	IN EFI_GUID	*VendorGuid,
+ *	OUT UINT32	*Attributes OPTIONAL,
+ *	IN OUT UINTN	*DataSize,
+ *	OUT VOID	*Data
+ *   );
+ */
+
+int
+efi_getvar(char *name, uuid_t *vendor, uint32_t *attrib, size_t *datasize,
+    void *data)
+{
+	struct iodev_efivar_req req;
+	int error;
+
+	req.namesize = 0;
+	error = libefi_utf8_to_ucs2(name, &req.namesize, &req.name);
+	if (error)
+		return (error);
+
+	req.vendor = *vendor;
+	req.datasize = *datasize;
+	req.data = data;
+	req.access = IODEV_EFIVAR_GETVAR;
+	error = libefi_efivar(&req);
+	*datasize = req.datasize;
+	if (!error && attrib != NULL)
+		*attrib = req.attrib;
+	free(req.name);
+	return (error);
+}

Added: head/lib/libefi/efi_nextvarname.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/efi_nextvarname.c	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <libefi.h>
+#include <stdlib.h>
+
+#include "libefi_int.h"
+
+/*
+ * EFI_STATUS
+ * GetNextVariableName(
+ *	IN OUT UINTN	*VariableNameSize,
+ *	IN OUT CHAR16	*VariableName,
+ *	IN OUT EFI_GUID	*VendorGuid
+ *    );
+ */
+
+int
+efi_nextvarname(size_t *namesize, char *name, uuid_t *vendor)
+{
+	struct iodev_efivar_req req;
+	int error;
+
+	req.namesize = *namesize;
+	error = libefi_utf8_to_ucs2(name, &req.namesize, &req.name);
+	if (error)
+		return (error);
+
+	req.vendor = *vendor;
+	req.access = IODEV_EFIVAR_NEXTNAME;
+	error = libefi_efivar(&req);
+	*namesize = req.namesize;
+	if (!error) {
+		error = libefi_ucs2_to_utf8(req.name, namesize, name);
+		if (!error)
+			*vendor = req.vendor;
+	}
+	free(req.name);
+	return (error);
+}

Added: head/lib/libefi/efi_setvar.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/efi_setvar.c	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <libefi.h>
+#include <stdlib.h>
+
+#include "libefi_int.h"
+
+/*
+ * EFI_STATUS
+ * SetVariable(
+ *	IN CHAR16	*VariableName,
+ *	IN EFI_GUID	*VendorGuid,
+ *	IN UINT32	Attributes,
+ *	IN UINTN	DataSize,
+ *	IN VOID		*Data
+ *    );
+ */
+
+int
+efi_setvar(char *name, uuid_t *vendor, uint32_t attrib, size_t datasize,
+    void *data)
+{
+	struct iodev_efivar_req req;
+	int error;
+
+	req.namesize = 0;
+	error = libefi_utf8_to_ucs2(name, &req.namesize, &req.name);
+	if (error)
+		return (error);
+
+	req.vendor = *vendor;
+	req.attrib = attrib;
+	req.datasize = datasize;
+	req.data = data;
+	req.access = IODEV_EFIVAR_SETVAR;
+	error = libefi_efivar(&req);
+	free(req.name);
+	return (error);
+}

Added: head/lib/libefi/libefi.3
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/libefi.3	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,136 @@
+.\"-
+.\" Copyright (c) 2010 Marcel Moolenaar
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd Januari 29, 2010
+.Dt LIBEFI 3
+.Os
+.Sh NAME
+.Nm efi_getvar , efi_nextvarname , efi_setvar
+.Nd Interface for accessing the EFI variable services
+.Sh LIBRARY
+.Lb libefi
+.Sh SYNOPSIS
+.In libefi.h
+.Ft int
+.Fn efi_getvar "char *name" "uuid_t *vendor" "uint32_t *attrib" \
+        "size_t *datasize" "void *data"
+.Ft int
+.Fn efi_nextvarname "size_t *namesize" "char *name" "uuid_t *vendor"
+.Ft int
+.Fn efi_setvar "char *name" "uuid_t *vendor" "uint32_t attrib" \
+        "size_t datasize" "void *data"
+.Sh DESCRIPTION
+The
+.Nm libefi
+library provides access to a select set of the runtime services of the
+Extensible Firmware Interface (EFI).
+.Pp
+The
+.Fn efi_nextvarname
+function is used to enumerate the variables.
+The
+.Nm namesize
+parameter needs to be set to the size of the buffer pointed to by
+.Nm name .
+On return,
+.Nm namesize
+is set to the length of the variable name (including the terminating '\\0')
+irrespective of whether the buffer was big enough.
+The buffer pointed to by
+.Nm name
+contains the full or partial variable name on return.
+Only on successful completion of the request is the
+.Nm vendor
+updated.
+The values returned should be passed to successive calls to
+.Fn efi_nextvarname
+until all variables have been enumerated.
+.Pp
+The variable name and vendor as returned by
+.Fn efi_nextvarname
+can be passed to
+.Fn efi_getvar
+to obtain the value and attribute of the variable.
+The buffer that is to contain the value is specified by
+.Nm data
+and the size of the buffer is given by
+.Nm datasize .
+The attribute pointed to by
+.Nm attrib
+consists of the bit values defined by the EFI specification.
+.Pp
+Variables can be created, modified and deleted using the
+.Fn efi_setvar
+function.
+All new variables must be non-volatile and runtime accessable in
+order for the request to succeed.
+Note that for runtime accessable variables the boottime accessable bit must
+be set as well.
+To delete a variable, set
+.Nm datasize
+to 0.
+.Pp
+The vendor UUID is used to avoid collisions between variable names of
+different vendors.
+Variables created for use by FreeBSD should use the
+.Nm EFI_FREEBSD_VENDOR
+UUID as defined in the
+.Nm libefi
+header file.
+.Sh RETURN VALUES
+Upon successful completion, these functions return 0.
+Otherwise, the error number is returned.
+These functions will fail if:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Insufficient permissions to access the EFI services.
+.It Bq Er EILSEQ
+The variable name is not in UTF-8.
+.It Bq Er EINVAL
+The request has invalid parameters.
+.It Bq Er ENOENT
+The variable does not exist or no more variables exist.
+.It Bq Er ENOMEM
+Temporary storage could not be allocated.
+.It Bq Er EOVERFLOW
+The variable name is too long or the data is too big to fit in
+the buffer provided.
+.El
+.Sh SEE ALSO
+.Xr errno 2 ,
+.Xr uuid 3
+.Sh HISTORY
+The
+.Nm libefi
+library first appeared in
+.Fx 9
+for the ia64 architecture.
+.Sh AUTHORS
+The
+.Nm libefi
+library and corresponding manual page were written by
+.An Marcel Moolenaar Aq marcel@FreeBSD.org .

Added: head/lib/libefi/libefi.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/libefi.c	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,176 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libefi_int.h"
+
+static int __iofd = -1;
+
+static void
+iodev_fd_close(void)
+{
+
+	close(__iofd);
+}
+
+static int
+iodev_fd(int *fd)
+{
+
+	*fd = __iofd;
+	if (__iofd != -1)
+		return (0);
+
+	__iofd = open("/dev/io", O_RDWR);
+	if (__iofd == -1)
+		return (errno);
+
+	atexit(iodev_fd_close);
+	*fd = __iofd;
+	return (0);
+}
+
+int
+libefi_ucs2_to_utf8(u_short *nm, size_t *szp, char *name)
+{
+	size_t len, sz;
+	u_short c;
+
+	len = 0;
+	sz = *szp;
+	while (*nm) {
+		c = *nm++;
+		if (c > 0x7ff) {
+			if (len++ < sz)
+				*name++ = 0xE0 | (c >> 12);
+			if (len++ < sz)
+				*name++ = 0x80 | ((c >> 6) & 0x3f);
+			if (len++ < sz)
+				*name++ = 0x80 | (c & 0x3f);
+		} else if (c > 0x7f) {
+			if (len++ < sz)
+				*name++ = 0xC0 | ((c >> 6) & 0x1f);
+			if (len++ < sz)
+				*name++ = 0x80 | (c & 0x3f);
+		} else {
+			if (len++ < sz)
+				*name++ = (c & 0x7f);
+		}
+	}
+	if (len++ < sz)
+		*name++ = 0;
+
+	*szp = len;
+	return ((len <= sz) ? 0 : EOVERFLOW);
+}
+
+int
+libefi_utf8_to_ucs2(char *name, size_t *szp, u_short **nmp)
+{
+	u_short *nm;
+	size_t sz;
+	uint32_t ucs4;
+	int c, bytes;
+
+	*szp = sz = (*szp == 0) ? strlen(name) * 2 + 2 : *szp;
+	*nmp = nm = malloc(sz);
+
+	ucs4 = 0;
+	bytes = 0;
+	while (sz > 1 && *name != '\0') {
+		c = *name++;
+		/*
+		 * Conditionalize on the two major character types:
+		 * initial and followup characters.
+		 */
+		if ((c & 0xc0) != 0x80) {
+			/* Initial characters. */
+			if (bytes != 0) {
+				free(nm);
+				return (EILSEQ);
+			}
+			if ((c & 0xf8) == 0xf0) {
+				ucs4 = c & 0x07;
+				bytes = 3;
+			} else if ((c & 0xf0) == 0xe0) {
+				ucs4 = c & 0x0f;
+				bytes = 2;
+			} else if ((c & 0xe0) == 0xc0) {
+				ucs4 = c & 0x1f;
+				bytes = 1;
+			} else {
+				ucs4 = c & 0x7f;
+				bytes = 0;
+			}
+		} else {
+			/* Followup characters. */
+			if (bytes > 0) {
+				ucs4 = (ucs4 << 6) + (c & 0x3f);
+				bytes--;
+			} else if (bytes == 0) {
+				free(nm);
+				return (EILSEQ);
+			}
+		}
+		if (bytes == 0) {
+			if (ucs4 > 0xffff) {
+				free(nm);
+				return (EILSEQ);
+			}
+			*nm++ = (u_short)ucs4;
+			sz -= 2;
+		}
+	}
+	if (sz < 2) {
+		free(nm);
+		return (EDOOFUS);
+	}
+	*nm = 0;
+	return (0);
+}
+
+int
+libefi_efivar(struct iodev_efivar_req *req)
+{
+	int error, fd;
+
+	error = iodev_fd(&fd);
+	if (!error)
+		error = (ioctl(fd, IODEV_EFIVAR, req) == -1) ? errno : 0;
+	if (!error)
+		error = req->result;
+	return (error);
+}

Added: head/lib/libefi/libefi.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/libefi.h	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBEFI_H_
+#define	_LIBEFI_H_
+
+#include <sys/types.h>
+#include <sys/uuid.h>
+#include <stddef.h>
+
+/* Attributes. */
+#define	EFI_ATTR_NV	0x0001	/* Variable stored in NVRAM. */
+#define	EFI_ATTR_BS	0x0002	/* Boot services accessable. */
+#define	EFI_ATTR_RT	0x0004	/* Runtime accessable. */
+#define	EFI_ATTR_HR	0x0008	/* Hardware error record. */
+#define	EFI_ATTR_WR	0x0010	/* Authenticated write access. */
+
+/* Vendor for architecturally defined variables. */
+#define	EFI_GLOBAL_VARIABLE	\
+	{0x8be4df61,0x93ca,0x11d2,0xaa,0x0d,{0x00,0xe0,0x98,0x03,0x2b,0x8c}}
+
+/* Vendor for FreeBSD-specific variables. */
+#define	EFI_FREEBSD_VARIABLE	\
+	{0x13c32014,0x0c9c,0x11df,0xa2,0x38,{0x00,0x17,0xa4,0xab,0x91,0x2d}}
+
+__BEGIN_DECLS
+int	efi_getvar	(char *, uuid_t *, uint32_t *, size_t *, void *);
+int	efi_nextvarname	(size_t *, char *, uuid_t *);
+int	efi_setvar	(char *, uuid_t *, uint32_t, size_t, void *);
+__END_DECLS
+
+#endif /* _LIBEFI_H_ */

Added: head/lib/libefi/libefi_int.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libefi/libefi_int.h	Sat Jan 30 04:24:03 2010	(r203181)
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2010 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBEFI_INT_H_
+#define	_LIBEFI_INT_H_
+
+#include <sys/errno.h>
+#include <machine/iodev.h>
+
+int libefi_ucs2_to_utf8(u_short *, size_t *, char *);
+int libefi_utf8_to_ucs2(char *, size_t *, u_short **);
+
+int libefi_efivar(struct iodev_efivar_req *);
+
+#endif /* _LIBEFI_INT_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001300424.o0U4O370082276>