Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Apr 2018 18:10:38 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r332123 - in stable/11: lib/libefivar usr.sbin/efidp usr.sbin/efivar
Message-ID:  <201804061810.w36IAcs1087134@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Fri Apr  6 18:10:38 2018
New Revision: 332123
URL: https://svnweb.freebsd.org/changeset/base/332123

Log:
  MFC efivar changes: r321429, r323056-r323057, r323066, r323259-r323260,
  r323519, r325684, r326050-r326051, r326231, r326287, r326457-r326459,
  r326472, r326658, r326805, r327574-r327575, r330279
  
  r321429:
  fix typo
  
  r323056:
  Fix printing File() nodes in device paths.
  
  Device paths encoded into the FILEPATH_DEVICE_PATH are UCS2 not
  ASCII/UTF8. Convert to utf8 and print that when printing File
  paths. Also, since File may be at the end of a long device path,
  output File() around the path so it doesn't just show up as random
  nodes that might accidentally match real node paths names and cause
  errors.
  
  r323057:
  Fix parsing File() nodes in device paths.
  
  o Add File to the mUefiDevicePathLibDevPathFromTextTable table so we
    don't include 'File()' in the supposed path name. This happens because
    of a possible misfeature in the EDK2 code where any path that's not
    recognized is treated as a File() node.
  o Convert utf8 input into ucs2 output rather than just copying the
    utf8 and hoping for the best (no good comes from that).
  o Remove bogus comment about needing to add 1. The dummy array already
    is length 1, so that's included in sizeof the struct, so there's no
    need to add it.
  
  Sponsored by: Netflix
  
  r323066:
  Add UCS2->UTF8 option.
  
  Many UEFI variables are UCS2 strings (some NUL terminated, others
  not). Add --utf8 (-u) to convert UCS2 strings to UTF8 before printing.
  
  Sponsored by: Netflix
  
  r323259:
  Implement efidp_size
  
  efidp_size will return the size, in bytes, of a EFI device path
  structure. This is a convenience wrapper in the same style as the
  other linux routines. It's implemented by GetDevicePathSize from EDK2
  we already needed for other things.
  
  Sponsored by: Netflix
  
  r323260:
  Create efi utility printing routines
  
  Split out asciidump, utf8dump, bindump, and hexdump into a separate
  file efiutil.c. Implement new efi_print_load_option for printing out
  the EFI_LOADER_OPTION data structure used to specify different options
  to the UEFI boot manager.
  
  Sponsored by: Netflix
  
  r323519:
  Minor fixes to edge cases in efi_get_next_variable_name
  
  Fix allocating more memory for the names (unlikely to be needed, but
  still best to get right) to ask for the length the kernel told use we
  needed, not the old length of the variable. Mind the proper NUL that
  we add in the space we allocate. Free the old name string before we
  allcoate a new one to limit what we leak to the last one (free passed
  in name for the last one in the list), and detect the last one by rv
  != 0 and errno == ENOENT, rather then just the former to avoid false
  positives if errno happens to be ENOENT on entry.
  
  Sponsored by: Netflix
  
  r325684:
  Simplify the efivar interface a little.
  
  We started out having Linux compatible libefivar interfaces. This was
  in anticipation of porting the GPL'd efibootmgr to FreeBSD via a
  port. However, since we need that functionality in the base, that port
  isn't going to happened. It also appears that efivar is a private
  library that's not used much outside a command line util and
  efibootmgr. Reduce compatibility with the Linux version a little by
  removing the mode parameter to efi_set_variable (which was unused on
  FreeBSD, and not set to something useful in the code we'd
  written). Also remove some efi error routines that were never
  implemented and existed only to placate early GPL efibootmgr porting
  experiments.
  
  Suggested by: Matt Williams
  Sponsored by: Netflix
  
  r326050:
  Document what the command line arguments actually do. List some of the
  size limitations.
  
  Sponsored by: Netflix
  
  r326051:
  This program is more useful if it skips leading whitespace when
  parsing a textual UEFI Device Path, since otherwise it things the
  passed in path is a filename. While here, reduce the repetition of
  8192.
  
  Sponsored by: Netflix
  
  r326231:
  Add efidp_format_device_path_node to format a single node in a device
  path, much like efidp_format_device_path will format the entire path.
  
  Sponsored by: Netflix
  
  r326287:
  efivar: add missing getopt 'u' option
  
  r326457:
  Read multiple lines when parsing the data. Allow multiple device paths
  to be read when formatting device paths. Set the upper limit to 64k
  (most of these paths are < 64 bytes).
  
  Sponsored by: Netflix
  
  r326458:
  Create a function to translate UEFI paths to unix paths
  
  efivar_device_path_to_unix_path translates from UEFI to Unix
  efivar_unix_path_to_device_path translates from Unix to UEFI
  
  At present, only HD() device types are supported (both GPT and
  MBR). CdRom and floppy devices aren't supported. ZFS isn't supported
  because there's no way in the UEFI standard to specify a ZFS datastore.
  Network devices aren't supported either.
  
  Three forms of Unix path are accepted: /path/to/file (for a mounted
  filesystem), //path/to/file (uses the EFI partition on the same disk
  as /), and dev:/path/to/file (for unmounted filesystem). Two forms are
  produced (the first and last).
  
  Sponsored by: Netflix
  
  r326459:
  Add -u (--to-unix) and -e (--to-efi) to convert unix or efi paths to
  the other.
  
  Sponsored by: Netflix
  
  r326472:
  Add forgotten libgeom.
  
  Sponsored by: Netflix
  
  r326658:
  Ensure that "out" is initialized in all error paths.
  
  Reported by:	gcc
  Reviewed by:	cem
  Differential Revision:	https://reviews.freebsd.org/D13402
  
  r326805:
  Iniailize str so ucs2_to_utf8 won't free stack garbage.
  
  CID: 1381037
  Sponsored by: Netflix
  
  r327574:
  Set dp to NULL when we free it, and tree a NULL dp as an error
  condition. This should prevent a double free. In addition, prevent a
  leak by freeing dp each loop and when we're done.
  
  CID: 1383577
  Sponsored by: Netflix
  
  r327575:
  Need to convert '/' back to '\' when creating a path. Ideally, this
  would be filesystem type dependent, but that's difficult to accomplish
  and it's unclear how the UEFI firmware will cope. Be conservative and
  make boot loaders cope instead.
  
  Sponsored by: Netflix
  
  r330279:
  libefivar: use standard 2-Clause FreeBSD license
  
  Approved by:	imp
  Sponsored by:	The FreeBSD Foundation

Added:
  stable/11/lib/libefivar/efivar-dp-xlate.c
     - copied, changed from r326459, head/lib/libefivar/efivar-dp-xlate.c
  stable/11/usr.sbin/efivar/efiutil.c
     - copied, changed from r323260, head/usr.sbin/efivar/efiutil.c
  stable/11/usr.sbin/efivar/efiutil.h
     - copied unchanged from r323260, head/usr.sbin/efivar/efiutil.h
Modified:
  stable/11/lib/libefivar/Makefile
  stable/11/lib/libefivar/efi-osdep.h
  stable/11/lib/libefivar/efivar-dp-format.c
  stable/11/lib/libefivar/efivar-dp-parse.c
  stable/11/lib/libefivar/efivar-dp.h
  stable/11/lib/libefivar/efivar.c
  stable/11/lib/libefivar/efivar.h
  stable/11/lib/libefivar/uefi-dplib.h
  stable/11/lib/libefivar/uefi-dputil.c
  stable/11/usr.sbin/efidp/Makefile
  stable/11/usr.sbin/efidp/efidp.8
  stable/11/usr.sbin/efidp/efidp.c
  stable/11/usr.sbin/efivar/Makefile
  stable/11/usr.sbin/efivar/efivar.8
  stable/11/usr.sbin/efivar/efivar.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libefivar/Makefile
==============================================================================
--- stable/11/lib/libefivar/Makefile	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/Makefile	Fri Apr  6 18:10:38 2018	(r332123)
@@ -35,6 +35,7 @@ PACKAGE=lib${LIB}
 LIB=		efivar
 SRCS=		efivar.c efichar.c efivar-dp-format.c \
 		efivar-dp-parse.c \
+		efivar-dp-xlate.c \
 		uefi-guid.c uefi-dputil.c
 INCS=		efivar.h efivar-dp.h
 SHLIB_MAJOR=	1

Modified: stable/11/lib/libefivar/efi-osdep.h
==============================================================================
--- stable/11/lib/libefivar/efi-osdep.h	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efi-osdep.h	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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$
  */

Modified: stable/11/lib/libefivar/efivar-dp-format.c
==============================================================================
--- stable/11/lib/libefivar/efivar-dp-format.c	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efivar-dp-format.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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.
  */
 
 /*
@@ -36,6 +36,8 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <string.h>
 
+#include "efichar.h"
+
 #include "efi-osdep.h"
 #include "efivar-dp.h"
 
@@ -1872,9 +1874,12 @@ DevPathToTextFilePath (
   )
 {
   FILEPATH_DEVICE_PATH  *Fp;
+  char *name = NULL;
 
   Fp = DevPath;
-  UefiDevicePathLibCatPrint (Str, "%s", Fp->PathName);
+  ucs2_to_utf8(Fp->PathName, &name);
+  UefiDevicePathLibCatPrint (Str, "File(%s)", name);
+  free(name);
 }
 
 /**
@@ -2267,7 +2272,6 @@ static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePath
   {0, 0, NULL}
 };
 
-#ifndef __FreeBSD__
 /**
   Converts a device node to its string representation.
 
@@ -2283,7 +2287,7 @@ static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePath
           is NULL or there was insufficient memory.
 
 **/
-CHAR16 *
+static char *
 EFIAPI
 UefiDevicePathLibConvertDeviceNodeToText (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,
@@ -2294,6 +2298,7 @@ UefiDevicePathLibConvertDeviceNodeToText (
   POOL_PRINT          Str;
   UINTN               Index;
   DEVICE_PATH_TO_TEXT ToText;
+  EFI_DEVICE_PATH_PROTOCOL *Node;
 
   if (DeviceNode == NULL) {
     return NULL;
@@ -2305,6 +2310,7 @@ UefiDevicePathLibConvertDeviceNodeToText (
   // Process the device path node
   // If not found, use a generic function
   //
+  Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DeviceNode);
   ToText = DevPathToTextNodeGeneric;
   for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) {
     if (DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type &&
@@ -2318,12 +2324,11 @@ UefiDevicePathLibConvertDeviceNodeToText (
   //
   // Print this node
   //
-  ToText (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts);
+  ToText (&Str, (VOID *) Node, DisplayOnly, AllowShortcuts);
 
   ASSERT (Str.Str != NULL);
   return Str.Str;
 }
-#endif
 
 /**
   Converts a device path to its text representation.
@@ -2424,4 +2429,39 @@ efidp_format_device_path(char *buf, size_t len, const_
 	free(str);
 
 	return retval;
+}
+
+ssize_t
+efidp_format_device_path_node(char *buf, size_t len, const_efidp dp)
+{
+	char *str;
+	ssize_t retval;
+
+	str = UefiDevicePathLibConvertDeviceNodeToText (
+		__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);
+	if (str == NULL)
+		return -1;
+	strlcpy(buf, str, len);
+	retval = strlen(str);
+	free(str);
+
+	return retval;
+}
+
+size_t
+efidp_size(const_efidp dp)
+{
+
+	return GetDevicePathSize(__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp));
+}
+
+char *
+efidp_extract_file_path(const_efidp dp)
+{
+	const FILEPATH_DEVICE_PATH  *fp;
+	char *name = NULL;
+
+	fp = (const void *)dp;
+	ucs2_to_utf8(fp->PathName, &name);
+	return name;
 }

Modified: stable/11/lib/libefivar/efivar-dp-parse.c
==============================================================================
--- stable/11/lib/libefivar/efivar-dp-parse.c	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efivar-dp-parse.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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.
  */
 
 /*
@@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <wchar.h>
 
+#include "efichar.h"
+
 #include "efi-osdep.h"
 #include "efivar-dp.h"
 
@@ -3031,21 +3033,15 @@ DevPathFromTextFilePath (
 
   StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
 #else
+  size_t len = (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2);
+  efi_char * v;
   File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
                                     MEDIA_DEVICE_PATH,
                                     MEDIA_FILEPATH_DP,
-                                    (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) + 1)
+				    (UINT16)len
                                     );
-
-  /* 
-   * Note: We'd have to change the Tianocore header files to fix this
-   * to not need a cast.  Instead we just cast it here. The Interface
-   * to the user may have issues since this won't be a UCS-2
-   * string. Also note that in the original code, a NUL wasn't
-   * allocated for the end of the string, but we copy that below. This
-   * has been corrected.
-   */
-  StrCpyS ((char *)File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
+  v = File->PathName;
+  utf8_to_ucs2(TextDeviceNode, &v, &len);
 #endif
 
   return (EFI_DEVICE_PATH_PROTOCOL *) File;
@@ -3560,6 +3556,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TA
   {"Media",                   DevPathFromTextMedia                   },
   {"Fv",                      DevPathFromTextFv                      },
   {"FvFile",                  DevPathFromTextFvFile                  },
+  {"File",                    DevPathFromTextFilePath                },
   {"Offset",                  DevPathFromTextRelativeOffsetRange     },
   {"RamDisk",                 DevPathFromTextRamDisk                 },
   {"VirtualDisk",             DevPathFromTextVirtualDisk             },

Copied and modified: stable/11/lib/libefivar/efivar-dp-xlate.c (from r326459, head/lib/libefivar/efivar-dp-xlate.c)
==============================================================================
--- head/lib/libefivar/efivar-dp-xlate.c	Sat Dec  2 07:29:24 2017	(r326459, copy source)
+++ stable/11/lib/libefivar/efivar-dp-xlate.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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>
@@ -527,12 +527,17 @@ find_geom_efimedia(struct gmesh *mesh, const char *dev
 static int
 build_dp(const char *efimedia, const char *relpath, efidp *dp)
 {
-	char *fp, *dptxt = NULL;
+	char *fp, *dptxt = NULL, *cp, *rp;
 	int rv = 0;
-	efidp out;
+	efidp out = NULL;
 	size_t len;
 
-	fp = path_to_file_dp(relpath);
+	rp = strdup(relpath);
+	for (cp = rp; *cp; cp++)
+		if (*cp == '/')
+			*cp = '\\';
+	fp = path_to_file_dp(rp);
+	free(rp);
 	if (fp == NULL) {
 		rv = ENOMEM;
 		goto errout;
@@ -663,6 +668,7 @@ errout:
 	free(rp);
 	if (rv != 0) {
 		free(*dp);
+		*dp = NULL;
 	}
 	return (rv);
 }

Modified: stable/11/lib/libefivar/efivar-dp.h
==============================================================================
--- stable/11/lib/libefivar/efivar-dp.h	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efivar-dp.h	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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$
  */
@@ -60,6 +60,13 @@ typedef const efidp_data *const_efidp;
  */
 ssize_t efidp_format_device_path(char *buf, size_t len, const_efidp dp,
     ssize_t max);
+ssize_t efidp_format_device_path_node(char *buf, size_t len, const_efidp dp);
 ssize_t efidp_parse_device_path(char *path, efidp out, size_t max);
+char * efidp_extract_file_path(const_efidp dp);
+
+size_t efidp_size(const_efidp);
+
+int efivar_device_path_to_unix_path(const_efidp dp, char **dev, char **relpath, char **abspath);
+int efivar_unix_path_to_device_path(const char *path, efidp *dp);
 
 #endif /* _EFIVAR_DP_H_ */

Modified: stable/11/lib/libefivar/efivar.c
==============================================================================
--- stable/11/lib/libefivar/efivar.c	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efivar.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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>
@@ -150,7 +150,7 @@ efi_append_variable(efi_guid_t guid, const char *name,
 {
 
 	return efi_set_variable(guid, name, data, data_size,
-	    attributes | EFI_VARIABLE_APPEND_WRITE, 0);
+	    attributes | EFI_VARIABLE_APPEND_WRITE);
 }
 
 int
@@ -158,7 +158,7 @@ efi_del_variable(efi_guid_t guid, const char *name)
 {
 
 	/* data_size of 0 deletes the variable */
-	return efi_set_variable(guid, name, NULL, 0, 0, 0);
+	return efi_set_variable(guid, name, NULL, 0, 0);
 }
 
 int
@@ -225,8 +225,13 @@ efi_get_next_variable_name(efi_guid_t **guid, char **n
 	if (efi_open_dev() == -1)
 		return -1;
 
+	/*
+	 * Always allocate enough for an extra NUL on the end, but don't tell
+	 * the IOCTL about it so we can NUL terminate the name before converting
+	 * it to UTF8.
+	 */
 	if (buf == NULL)
-		buf = malloc(buflen);
+		buf = malloc(buflen + sizeof(efi_char));
 
 again:
 	efi_var_reset(&var);
@@ -244,21 +249,23 @@ again:
 	rv = ioctl(efi_fd, EFIIOC_VAR_NEXT, &var);
 	if (rv == 0 && var.name == NULL) {
 		/*
-		 * oops, too little space. Try again.
+		 * Variable name not long enough, so allocate more space for the
+		 * name and try again. As above, mind the NUL we add.
 		 */
-		void *new = realloc(buf, buflen);
-		buflen = var.namesize;
+		void *new = realloc(buf, var.namesize + sizeof(efi_char));
 		if (new == NULL) {
 			rv = -1;
 			errno = ENOMEM;
 			goto done;
 		}
+		buflen = var.namesize;
 		buf = new;
 		goto again;
 	}
 
 	if (rv == 0) {
-		*name = NULL; /* XXX */
+		free(*name);			/* Free last name, to avoid leaking */
+		*name = NULL;			/* Force ucs2_to_utf8 to malloc new space */
 		var.name[var.namesize / sizeof(efi_char)] = 0;	/* EFI doesn't NUL terminate */
 		rv = ucs2_to_utf8(var.name, name);
 		if (rv != 0)
@@ -269,9 +276,11 @@ again:
 errout:
 
 	/* XXX The linux interface expects name to be a static buffer -- fix or leak memory? */
+	/* XXX for the moment, we free just before we'd leak, but still leak last one */
 done:
-	if (errno == ENOENT) {
+	if (rv != 0 && errno == ENOENT) {
 		errno = 0;
+		free(*name);			/* Free last name, to avoid leaking */
 		return 0;
 	}
 
@@ -349,7 +358,7 @@ efi_name_to_guid(const char *name, efi_guid_t *guid)
 
 int
 efi_set_variable(efi_guid_t guid, const char *name,
-    uint8_t *data, size_t data_size, uint32_t attributes, mode_t mode __unused)
+    uint8_t *data, size_t data_size, uint32_t attributes)
 {
 	struct efi_var_ioc var;
 	int rv;

Modified: stable/11/lib/libefivar/efivar.h
==============================================================================
--- stable/11/lib/libefivar/efivar.h	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/efivar.h	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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$
  */
@@ -83,7 +83,7 @@ int efi_guid_to_symbol(efi_guid_t *guid, char **symbol
 int efi_guid_to_str(const efi_guid_t *guid, char **sp);
 int efi_name_to_guid(const char *name, efi_guid_t *guid);
 int efi_set_variable(efi_guid_t guid, const char *name,
-    uint8_t *data, size_t data_size, uint32_t attributes, mode_t mode);
+    uint8_t *data, size_t data_size, uint32_t attributes);
 int efi_str_to_guid(const char *s, efi_guid_t *guid);
 int efi_variables_supported(void);
 
@@ -98,38 +98,5 @@ struct uuid_table
 int efi_known_guid(struct uuid_table **);
 
 extern const efi_guid_t efi_guid_empty;
-
-/* Stubs that are expected, but aren't really used */
-static inline int
-efi_error_get(unsigned int n __unused, char ** const fn __unused,
-    char ** const func __unused, int *line __unused,
-    char ** const msg __unused, int *err __unused)
-{
-	return 0;
-}
-
-static inline int
-efi_error_set(const char *fn __unused, const char *func __unused,
-    int line __unused, int err __unused, const char *fmt __unused, ...)
-{
-	return 0;
-}
-
-static inline void
-efi_error_clear(void)
-{
-}
-
-static inline int
-efi_error(const char *fmt __unused, ...)
-{
-	return 0;
-}
-
-static inline int
-efi_error_val(int val __unused, const char *fmt __unused, ...)
-{
-	return 0;
-}
 
 #endif /* _EFIVAR_H_ */

Modified: stable/11/lib/libefivar/uefi-dplib.h
==============================================================================
--- stable/11/lib/libefivar/uefi-dplib.h	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/uefi-dplib.h	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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$
  */

Modified: stable/11/lib/libefivar/uefi-dputil.c
==============================================================================
--- stable/11/lib/libefivar/uefi-dputil.c	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/lib/libefivar/uefi-dputil.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -6,22 +6,22 @@
  * 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
- *    in this position and unchanged.
+ *    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 ``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 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.
+ * 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.
  */
 
 /*
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
 
 #include "uefi-dplib.h"
 
-/* XXX maybe I sould include the entire DevicePathUtiltiies.c and ifdef out what we don't use */
+/* XXX maybe I should include the entire DevicePathUtiltiies.c and ifdef out what we don't use */
 
 /*
  * Taken from MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c

Modified: stable/11/usr.sbin/efidp/Makefile
==============================================================================
--- stable/11/usr.sbin/efidp/Makefile	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/usr.sbin/efidp/Makefile	Fri Apr  6 18:10:38 2018	(r332123)
@@ -3,6 +3,6 @@
 PROG=	efidp
 MAN=	efidp.8
 
-LIBADD= efivar
+LIBADD= efivar geom
 
 .include <bsd.prog.mk>

Modified: stable/11/usr.sbin/efidp/efidp.8
==============================================================================
--- stable/11/usr.sbin/efidp/efidp.8	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/usr.sbin/efidp/efidp.8	Fri Apr  6 18:10:38 2018	(r332123)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 24, 2017
+.Dd December 1, 2017
 .Dt EFIDP 8
 .Os
 .Sh NAME
@@ -36,16 +36,44 @@
 .Op Fl -parse
 .Op Fl -format
 .Sh DESCRIPTION
-This program manages
+This program converts
 .Dq Unified Extensible Firmware Interface
 .Pq UEFI
-Device Paths, as defined in the UEFI standard.
+Device Paths, as defined in the UEFI standard, to and from binary form.
+Binary and textual forms are defined in Chapter 9 of the UEFI
+Specification.
+.Pp
+.Bl -tag -width 20m
+.It Fl f Fl -format
+Formats a binary UEFI Device Path into its canonical UTF-8 textual form.
+A binary Device Path can be no longer than 65536 bytes.
+The textual form must fit into 65536 bytes.
+Multiple binary device paths may be specified.
+.It Fl p Fl -parse
+Parses a UEFI Device Path UTF-8 specification and outputs the binary
+Device Path form.
+Only one device path is parsed, even if there are multiple present in
+the input.
+Leading white space is ignored.
+The resulting binary Device Path can be no longer than 65536 bytes.
+Multiple lines may be specified.
+Each one will be translated.
+.It Fl e Fl --to-efi
+Translate a Unix file path to an EFI Device Path.
+The output is the textual representation of the EFI Device Path.
+.It Fl u Fl --to-unix
+Translate an EFI device path to a Unix file path.
+The input is the textual representation of the EFI Device Path.
+.El
 .Sh SEE ALSO
 Appendix A of the UEFI specification has the format for GUIDs.
 All GUIDs
 .Dq Globally Unique Identifiers
 have the format described in RFC 4122.
-.El
+.Pp
+The Unified Extensible Firmware Interface Specification is available
+from
+.Pa www.uefi.org .
 .Sh HISTORY
 The
 .Nm

Modified: stable/11/usr.sbin/efidp/efidp.c
==============================================================================
--- stable/11/usr.sbin/efidp/efidp.c	Fri Apr  6 17:35:35 2018	(r332122)
+++ stable/11/usr.sbin/efidp/efidp.c	Fri Apr  6 18:10:38 2018	(r332123)
@@ -27,9 +27,11 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <ctype.h>
 #include <efivar.h>
 #include <efivar-dp.h>
 #include <err.h>
+#include <errno.h>
 #include <getopt.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -37,21 +39,25 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
+#define MAXSIZE 65536	/* Everyting will be smaller than this, most 1000x smaller */
+
 /* options descriptor */
 static struct option longopts[] = {
+	{ "to-unix",		no_argument,		NULL,	'u' },
+	{ "to-efi",		no_argument,		NULL,	'e' },
 	{ "format",		no_argument,		NULL,	'f' },
 	{ "parse",		no_argument,		NULL,	'p' },
 	{ NULL,			0,			NULL,	0 }
 };
 
 
-static int flag_format, flag_parse;
+static int flag_format, flag_parse, flag_unix, flag_efi;
 
 static void
 usage(void)
 {
 
-	errx(1, "efidp [-fp]");
+	errx(1, "efidp [-efpu]");
 }
 
 static ssize_t
@@ -62,18 +68,16 @@ read_file(int fd, void **rv) 
 	off_t off;
 	ssize_t red;
 
-	len = 4096;
+	len = MAXSIZE;
 	off = 0;
 	retval = malloc(len);
 	do {
 		red = read(fd, retval + off, len - off);
+		if (red == 0)
+			break;
 		off += red;
-		if (red < (ssize_t)(len - off))
+		if (off == (off_t)len)
 			break;
-		len *= 2;
-		retval = reallocf(retval, len);
-		if (retval == NULL)
-			return -1;
 	} while (1);
 	*rv = retval;
 
@@ -85,15 +89,21 @@ parse_args(int argc, char **argv)
 {
 	int ch;
 
-	while ((ch = getopt_long(argc, argv, "fp",
+	while ((ch = getopt_long(argc, argv, "efpu",
 		    longopts, NULL)) != -1) {
 		switch (ch) {
+		case 'e':
+			flag_efi++;
+			break;
 		case 'f':
 			flag_format++;
 			break;
 		case 'p':
 			flag_parse++;
 			break;
+		case 'u':
+			flag_unix++;
+			break;
 		default:
 			usage();
 		}
@@ -104,45 +114,139 @@ parse_args(int argc, char **argv)
 	if (argc >= 1)
 		usage();
 	
-	if (flag_parse + flag_format != 1) {
+	if (flag_parse + flag_format + flag_efi + flag_unix != 1) {
 		warnx("Can only use one of -p (--parse), "
 		    "and -f (--format)");
 		usage();
 	}
 }
 
-int
-main(int argc, char **argv)
+static char *
+trim(char *s)
 {
-	void *data;
+	char *t;
+
+	while (isspace(*s))
+		s++;
+	t = s + strlen(s) - 1;
+	while (t > s && isspace(*t))
+		*t-- = '\0';
+	return s;
+}
+
+static void
+unix_to_efi(void)
+{
+	char buffer[MAXSIZE];
+	char efi[MAXSIZE];
+	efidp dp;
+	char *walker;
+	int rv;
+
+	dp = NULL;
+	while (fgets(buffer, sizeof(buffer), stdin)) {
+		walker= trim(buffer);
+		free(dp);
+		dp = NULL;
+		rv = efivar_unix_path_to_device_path(walker, &dp);
+		if (rv != 0 || dp == NULL) {
+			errno = rv;
+			warn("Can't convert '%s' to efi", walker);
+			continue;
+		}
+		if (efidp_format_device_path(efi, sizeof(efi),
+		    dp, efidp_size(dp)) < 0) {
+			warnx("Can't format dp for '%s'", walker);
+			continue;
+		}
+		printf("%s\n", efi);
+	}
+	free(dp);
+}
+
+static void
+efi_to_unix(void)
+{
+	char buffer[MAXSIZE];
+	char dpbuf[MAXSIZE];
+	efidp dp;
+	size_t dplen;
+	char *walker, *dev, *relpath, *abspath;
+	int rv;
+
+	dp = (efidp)dpbuf;
+	while (fgets(buffer, sizeof(buffer), stdin)) {
+		walker= trim(buffer);
+		dplen = efidp_parse_device_path(walker, dp, sizeof(dpbuf));
+		rv = efivar_device_path_to_unix_path(dp, &dev, &relpath, &abspath);
+		if (rv == 0)
+			printf("%s:%s %s\n", dev, relpath, abspath);
+		else {
+			errno = rv;
+			warn("Can't convert '%s' to unix", walker);
+		}
+	}
+}
+
+static void
+format(void)
+{
+	char buffer[MAXSIZE];
+	ssize_t fmtlen;
 	ssize_t len;
+	void *data;
+	size_t dplen;
+	const_efidp dp;
 
-	parse_args(argc, argv);
 	len = read_file(STDIN_FILENO, &data);
 	if (len == -1)
 		err(1, "read");
-	if (flag_format) {
-		char buffer[4096];
-		ssize_t fmtlen;
-
+	dp = (const_efidp)data;
+	while (len > 0) {
+		dplen = efidp_size(dp);
 		fmtlen = efidp_format_device_path(buffer, sizeof(buffer),
-		    (const_efidp)data, len);
+		    dp, dplen);
 		if (fmtlen > 0)
 			printf("%s\n", buffer);
-		free(data);
-	} else if (flag_parse) {
-		efidp dp;
-		ssize_t dplen;
-		char *str;
+		len -= dplen;
+		dp = (const_efidp)((const char *)dp + dplen);
+	}
+	free(data);
+}
 
-		dp = malloc(8192);
-		str = realloc(data, len + 1);
-		if (str == NULL || dp == NULL)
-			errx(1, "Can't allocate memory.");
-		str[len] = '\0';
-		dplen = efidp_parse_device_path(str, dp, 8192);
+static void
+parse(void)
+{
+	char buffer[MAXSIZE];
+	efidp dp;
+	ssize_t dplen;
+	char *walker;
+
+	dplen = MAXSIZE;
+	dp = malloc(dplen);
+	if (dp == NULL)
+		errx(1, "Can't allocate memory.");
+	while (fgets(buffer, sizeof(buffer), stdin)) {
+		walker= trim(buffer);
+		dplen = efidp_parse_device_path(walker, dp, dplen);
 		if (dplen == -1)
-			errx(1, "Can't parse %s", str);
+			errx(1, "Can't parse %s", walker);
 		write(STDOUT_FILENO, dp, dplen);
 	}
+	free(dp);
+}
+
+int
+main(int argc, char **argv)
+{
+
+	parse_args(argc, argv);
+	if (flag_unix)
+		efi_to_unix();
+	else if (flag_efi)
+		unix_to_efi();
+	else if (flag_format)
+		format();
+	else if (flag_parse)
+		parse();
 }

Modified: stable/11/usr.sbin/efivar/Makefile
==============================================================================
--- stable/11/usr.sbin/efivar/Makefile	Fri Apr  6 17:35:35 2018	(r332122)

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



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