From owner-svn-src-all@freebsd.org Thu Mar 9 00:33:40 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2F236D01DC4; Thu, 9 Mar 2017 00:33:40 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E4C9D1231; Thu, 9 Mar 2017 00:33:39 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v290XdZD041997; Thu, 9 Mar 2017 00:33:39 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v290XcKR041992; Thu, 9 Mar 2017 00:33:38 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201703090033.v290XcKR041992@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 9 Mar 2017 00:33:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314928 - in head/usr.sbin: . efidp X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Mar 2017 00:33:40 -0000 Author: imp Date: Thu Mar 9 00:33:38 2017 New Revision: 314928 URL: https://svnweb.freebsd.org/changeset/base/314928 Log: efidp manipulates UEFI Device Paths in various ways. At the moment, it formats and parses UEFI standard Device Paths. In the future it will also translate between FreeBSD driver names and UEFI Device Paths. Sponsored by: Netflix Added: head/usr.sbin/efidp/ head/usr.sbin/efidp/Makefile (contents, props changed) head/usr.sbin/efidp/Makefile.depend (contents, props changed) head/usr.sbin/efidp/efidp.8 (contents, props changed) head/usr.sbin/efidp/efidp.c (contents, props changed) Modified: head/usr.sbin/Makefile Modified: head/usr.sbin/Makefile ============================================================================== --- head/usr.sbin/Makefile Thu Mar 9 00:31:36 2017 (r314927) +++ head/usr.sbin/Makefile Thu Mar 9 00:33:38 2017 (r314928) @@ -125,7 +125,7 @@ SUBDIR.${MK_BSNMP}+= bsnmpd SUBDIR.${MK_CTM}+= ctm SUBDIR.${MK_CXGBETOOL}+= cxgbetool SUBDIR.${MK_DIALOG}+= bsdconfig -SUBDIR.${MK_EFI}+= efivar +SUBDIR.${MK_EFI}+= efivar efidp SUBDIR.${MK_FLOPPY}+= fdcontrol SUBDIR.${MK_FLOPPY}+= fdformat SUBDIR.${MK_FLOPPY}+= fdread Added: head/usr.sbin/efidp/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/efidp/Makefile Thu Mar 9 00:33:38 2017 (r314928) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= efidp +MAN= efidp.8 + +LIBADD= efivar + +.include Added: head/usr.sbin/efidp/Makefile.depend ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/efidp/Makefile.depend Thu Mar 9 00:33:38 2017 (r314928) @@ -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 + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif Added: head/usr.sbin/efidp/efidp.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/efidp/efidp.8 Thu Mar 9 00:33:38 2017 (r314928) @@ -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 . Added: head/usr.sbin/efidp/efidp.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/efidp/efidp.c Thu Mar 9 00:33:38 2017 (r314928) @@ -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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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); + } +}