[Midnightbsd-cvs] src [10447] trunk/lib/libefi: add libefi

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jun 6 19:34:32 EDT 2018


Revision: 10447
          http://svnweb.midnightbsd.org/src/?rev=10447
Author:   laffer1
Date:     2018-06-06 19:34:31 -0400 (Wed, 06 Jun 2018)
Log Message:
-----------
add libefi

Added Paths:
-----------
    trunk/lib/libefi/
    trunk/lib/libefi/Makefile
    trunk/lib/libefi/efi_getvar.c
    trunk/lib/libefi/efi_nextvarname.c
    trunk/lib/libefi/efi_setvar.c
    trunk/lib/libefi/libefi.3
    trunk/lib/libefi/libefi.c
    trunk/lib/libefi/libefi.h
    trunk/lib/libefi/libefi_int.h

Added: trunk/lib/libefi/Makefile
===================================================================
--- trunk/lib/libefi/Makefile	                        (rev 0)
+++ trunk/lib/libefi/Makefile	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,23 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libefi/Makefile 203181 2010-01-30 04:24:03Z marcel $
+
+.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>


Property changes on: trunk/lib/libefi/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/efi_getvar.c
===================================================================
--- trunk/lib/libefi/efi_getvar.c	                        (rev 0)
+++ trunk/lib/libefi/efi_getvar.c	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,69 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/efi_getvar.c 203181 2010-01-30 04:24:03Z marcel $");
+
+#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);
+}


Property changes on: trunk/lib/libefi/efi_getvar.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/efi_nextvarname.c
===================================================================
--- trunk/lib/libefi/efi_nextvarname.c	                        (rev 0)
+++ trunk/lib/libefi/efi_nextvarname.c	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,67 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/efi_nextvarname.c 203181 2010-01-30 04:24:03Z marcel $");
+
+#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);
+}


Property changes on: trunk/lib/libefi/efi_nextvarname.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/efi_setvar.c
===================================================================
--- trunk/lib/libefi/efi_setvar.c	                        (rev 0)
+++ trunk/lib/libefi/efi_setvar.c	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,67 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/efi_setvar.c 203181 2010-01-30 04:24:03Z marcel $");
+
+#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);
+}


Property changes on: trunk/lib/libefi/efi_setvar.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/libefi.3
===================================================================
--- trunk/lib/libefi/libefi.3	                        (rev 0)
+++ trunk/lib/libefi/libefi.3	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,144 @@
+.\" $MidnightBSD$
+.\"-
+.\" 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: stable/10/lib/libefi/libefi.3 210823 2010-08-03 17:40:09Z joel $
+.\"
+.Dd January 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
+.Fo efi_getvar
+.Fa "char *name" "uuid_t *vendor" "uint32_t *attrib"
+.Fa "size_t *datasize" "void *data"
+.Fc
+.Ft int
+.Fn efi_nextvarname "size_t *namesize" "char *name" "uuid_t *vendor"
+.Ft int
+.Fo efi_setvar
+.Fa "char *name" "uuid_t *vendor" "uint32_t attrib"
+.Fa "size_t datasize" "void *data"
+.Fc
+.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
+.Fa namesize
+parameter needs to be set to the size of the buffer pointed to by
+.Fa name .
+On return,
+.Fa namesize
+is set to the length of the variable name (including the terminating
+.Ql \e0 )
+irrespective of whether the buffer was big enough.
+The buffer pointed to by
+.Fa name
+contains the full or partial variable name on return.
+Only on successful completion of the request is the
+.Fa 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
+.Fa data
+and the size of the buffer is given by
+.Fa datasize .
+The attribute pointed to by
+.Fa 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 accessible 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
+.Fa datasize
+to 0.
+.Pp
+The vendor UUID is used to avoid collisions between variable names of
+different vendors.
+Variables created for use by
+.Fx
+should use the
+.Dv EFI_FREEBSD_VARIABLE
+UUID as defined in the
+.In libefi.h
+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.0
+for the ia64 architecture.
+.Sh AUTHORS
+The
+.Nm libefi
+library and this manual page were written by
+.An Marcel Moolenaar Aq marcel at FreeBSD.org .


Property changes on: trunk/lib/libefi/libefi.3
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/libefi.c
===================================================================
--- trunk/lib/libefi/libefi.c	                        (rev 0)
+++ trunk/lib/libefi/libefi.c	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,177 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/libefi.c 203181 2010-01-30 04:24:03Z marcel $");
+
+#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);
+}


Property changes on: trunk/lib/libefi/libefi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/libefi.h
===================================================================
--- trunk/lib/libefi/libefi.h	                        (rev 0)
+++ trunk/lib/libefi/libefi.h	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,58 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/libefi.h 203181 2010-01-30 04:24:03Z marcel $
+ */
+
+#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_ */


Property changes on: trunk/lib/libefi/libefi.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libefi/libefi_int.h
===================================================================
--- trunk/lib/libefi/libefi_int.h	                        (rev 0)
+++ trunk/lib/libefi/libefi_int.h	2018-06-06 23:34:31 UTC (rev 10447)
@@ -0,0 +1,41 @@
+/* $MidnightBSD$ */
+/*-
+ * 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: stable/10/lib/libefi/libefi_int.h 203181 2010-01-30 04:24:03Z marcel $
+ */
+
+#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_ */


Property changes on: trunk/lib/libefi/libefi_int.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list