summaryrefslogtreecommitdiffstats
path: root/usr.sbin/efidp
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2017-05-20 16:12:44 +0000
committerkib <kib@FreeBSD.org>2017-05-20 16:12:44 +0000
commitf954c5056d909af5d65546fe9bce8951fdae0b70 (patch)
tree6e26ea5d1ee32f63a09c90b6e14accc3eac6e847 /usr.sbin/efidp
parent78abf039aa297d9b0021f82c669f194c4bfc611e (diff)
downloadFreeBSD-src-f954c5056d909af5d65546fe9bce8951fdae0b70.zip
FreeBSD-src-f954c5056d909af5d65546fe9bce8951fdae0b70.tar.gz
MFC efivar(8) (by imp):
List of revisions merged: r307070 r307071 r307072 r307074 r307189 r307224 r307339 r307390 r307391 r309776 r314231 r314232 r314615 r314616 r314617 r314618 r314619 r314620 r314621 r314623 r314890 r314925 r314926 r314927 r314928 r315770 r315771 Discussed with: gjb (re), imp Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/efidp')
-rw-r--r--usr.sbin/efidp/Makefile8
-rw-r--r--usr.sbin/efidp/Makefile.depend19
-rw-r--r--usr.sbin/efidp/efidp.853
-rw-r--r--usr.sbin/efidp/efidp.c148
4 files changed, 228 insertions, 0 deletions
diff --git a/usr.sbin/efidp/Makefile b/usr.sbin/efidp/Makefile
new file mode 100644
index 0000000..67358cb
--- /dev/null
+++ b/usr.sbin/efidp/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG= efidp
+MAN= efidp.8
+
+LIBADD= efivar
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/efidp/Makefile.depend b/usr.sbin/efidp/Makefile.depend
new file mode 100644
index 0000000..8af72d7
--- /dev/null
+++ b/usr.sbin/efidp/Makefile.depend
@@ -0,0 +1,19 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libefivar \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/usr.sbin/efidp/efidp.8 b/usr.sbin/efidp/efidp.8
new file mode 100644
index 0000000..94b298c
--- /dev/null
+++ b/usr.sbin/efidp/efidp.8
@@ -0,0 +1,53 @@
+.\" Copyright (c) 2017 Netflix, Inc
+.\" 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 March 5, 2017
+.Dt EFIDP 8
+.Os
+.Sh NAME
+.Nm efidp
+.Nd UEFI Device Path manipulation
+.Sh SYNOPSIS
+.Nm
+.Op Fl fp
+.Op Fl -parse
+.Op Fl -format
+.Sh DESCRIPTION
+This program manages
+.Dq Unified Extensible Firmware Interface
+.Pq UEFI
+Device Paths, as defined in the UEFI standard.
+.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
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 12.0 .
diff --git a/usr.sbin/efidp/efidp.c b/usr.sbin/efidp/efidp.c
new file mode 100644
index 0000000..a96cf9f
--- /dev/null
+++ b/usr.sbin/efidp/efidp.c
@@ -0,0 +1,148 @@
+/*-
+ * Copyright (c) 2016 Netflix, Inc.
+ * 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 <efivar.h>
+#include <efivar-dp.h>
+#include <err.h>
+#include <getopt.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* options descriptor */
+static struct option longopts[] = {
+ { "format", no_argument, NULL, 'f' },
+ { "parse", no_argument, NULL, 'p' },
+ { NULL, 0, NULL, 0 }
+};
+
+
+static int flag_format, flag_parse;
+
+static void
+usage(void)
+{
+
+ errx(1, "efidp [-fp]");
+}
+
+static ssize_t
+read_file(int fd, void **rv)
+{
+ uint8_t *retval;
+ size_t len;
+ off_t off;
+ ssize_t red;
+
+ len = 4096;
+ off = 0;
+ retval = malloc(len);
+ do {
+ red = read(fd, retval + off, len - off);
+ off += red;
+ if (red < (ssize_t)(len - off))
+ break;
+ len *= 2;
+ retval = reallocf(retval, len);
+ if (retval == NULL)
+ return -1;
+ } while (1);
+ *rv = retval;
+
+ return off;
+}
+
+static void
+parse_args(int argc, char **argv)
+{
+ int ch;
+
+ while ((ch = getopt_long(argc, argv, "fp",
+ longopts, NULL)) != -1) {
+ switch (ch) {
+ case 'f':
+ flag_format++;
+ break;
+ case 'p':
+ flag_parse++;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc >= 1)
+ usage();
+
+ if (flag_parse + flag_format != 1) {
+ warnx("Can only use one of -p (--parse), "
+ "and -f (--format)");
+ usage();
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ void *data;
+ ssize_t len;
+
+ 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;
+
+ fmtlen = efidp_format_device_path(buffer, sizeof(buffer),
+ (const_efidp)data, len);
+ if (fmtlen > 0)
+ printf("%s\n", buffer);
+ free(data);
+ } else if (flag_parse) {
+ efidp dp;
+ ssize_t dplen;
+ char *str;
+
+ 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);
+ if (dplen == -1)
+ errx(1, "Can't parse %s", str);
+ write(STDOUT_FILENO, dp, dplen);
+ }
+}
OpenPOWER on IntegriCloud