Date: Tue, 28 Apr 2026 20:59:08 +0000 From: Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: =?utf-8?Q?St=C3=A9pha?=ne Rochoy <stephane.rochoy@stormshield.eu> Subject: git: 48363f39f141 - main - efivar: Move dump functions into libefivar Message-ID: <69f11f9c.3c305.57a589ae@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by pouria: URL: https://cgit.FreeBSD.org/src/commit/?id=48363f39f1417df3e39da53f219596f8501c9452 commit 48363f39f1417df3e39da53f219596f8501c9452 Author: Stéphane Rochoy <stephane.rochoy@stormshield.eu> AuthorDate: 2026-04-24 12:10:19 +0000 Commit: Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org> CommitDate: 2026-04-28 20:58:54 +0000 efivar: Move dump functions into libefivar To allow their use by efibootmgr. Signed-off-by: stephane.rochoy@stormshield.eu Reviewed by: imp Sponsored by: Stormshield Pull-Request: https://github.com/freebsd/freebsd-src/pull/2167 --- lib/libefivar/Makefile | 1 + {usr.sbin/efivar => lib/libefivar}/efiutil.c | 33 ++++++++++++++------------ lib/libefivar/efivar.h | 10 ++++++++ usr.sbin/efibootmgr/Makefile | 7 +++--- usr.sbin/efibootmgr/efibootmgr.c | 1 - usr.sbin/efivar/Makefile | 2 +- usr.sbin/efivar/efiutil.h | 35 ---------------------------- usr.sbin/efivar/efivar.c | 9 ++++--- 8 files changed, 37 insertions(+), 61 deletions(-) diff --git a/lib/libefivar/Makefile b/lib/libefivar/Makefile index bc31ee6c47e3..339ba9d18a5e 100644 --- a/lib/libefivar/Makefile +++ b/lib/libefivar/Makefile @@ -35,6 +35,7 @@ LIB= efivar SRCS= efivar.c efichar.c efivar-dp-format.c \ efivar-dp-parse.c \ efivar-dp-xlate.c \ + efiutil.c \ uefi-guid.c uefi-dputil.c INCS= efivar.h efivar-dp.h SHLIB_MAJOR= 1 diff --git a/usr.sbin/efivar/efiutil.c b/lib/libefivar/efiutil.c similarity index 88% rename from usr.sbin/efivar/efiutil.c rename to lib/libefivar/efiutil.c index fc2a309a81ef..a6dce1981101 100644 --- a/usr.sbin/efivar/efiutil.c +++ b/lib/libefivar/efiutil.c @@ -35,16 +35,15 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "efiutil.h" #include "efichar.h" #include <efivar-dp.h> /* * Dump the data as ASCII data, which is a pretty - * printed form + * printed form. */ void -asciidump(uint8_t *data, size_t datalen) +efi_asciidump(uint8_t *data, size_t datalen, int indent) { size_t i; int len; @@ -55,14 +54,14 @@ asciidump(uint8_t *data, size_t datalen) len++; if (len > 80) { len = 0; - printf("\n"); + printf("\n%*s", indent, ""); } printf("%c", data[i]); } else { len +=3; if (len > 80) { len = 0; - printf("\n"); + printf("\n%*s", indent, ""); } printf("%%%02x", data[i]); } @@ -71,7 +70,7 @@ asciidump(uint8_t *data, size_t datalen) } void -utf8dump(uint8_t *data, size_t datalen) +efi_utf8dump(uint8_t *data, size_t datalen, int indent) { char *utf8 = NULL; efi_char *ucs2; @@ -84,21 +83,25 @@ utf8dump(uint8_t *data, size_t datalen) memcpy(ucs2, data, datalen); ucs2[datalen / sizeof(efi_char)] = 0; ucs2_to_utf8(ucs2, &utf8); - printf("%s\n", utf8); + printf("%*s%s\n", indent, "", utf8); free(utf8); free(ucs2); } void -hexdump(uint8_t *data, size_t datalen) +efi_hexdump(uint8_t *data, size_t datalen, int indent) { size_t i; - for (i = 0; i < datalen; i++) { + if (datalen == 0) + return; + + printf("0000: %02x ", data[0]); + for (i = 1; i < datalen; i++) { if (i % 16 == 0) { if (i != 0) printf("\n"); - printf("%04x: ", (int)i); + printf("%*s%04x: ", indent, "", (int)i); } printf("%02x ", data[i]); } @@ -106,7 +109,7 @@ hexdump(uint8_t *data, size_t datalen) } void -bindump(uint8_t *data, size_t datalen) +efi_bindump(uint8_t *data, size_t datalen) { write(1, data, datalen); } @@ -180,11 +183,11 @@ efi_print_load_option(uint8_t *data, size_t datalen, int Aflag, int bflag, int u return; printf("Option:\n"); if (Aflag) - asciidump(opt, optlen); + efi_asciidump(opt, optlen, 0); else if (bflag) - bindump(opt, optlen); + efi_bindump(opt, optlen); else if (uflag) - utf8dump(opt, optlen); + efi_utf8dump(opt, optlen, 0); else - hexdump(opt, optlen); + efi_hexdump(opt, optlen, 0); } diff --git a/lib/libefivar/efivar.h b/lib/libefivar/efivar.h index 238b23a8b2b8..563715d96ed0 100644 --- a/lib/libefivar/efivar.h +++ b/lib/libefivar/efivar.h @@ -79,6 +79,16 @@ int efi_set_variable(efi_guid_t guid, const char *name, int efi_str_to_guid(const char *s, efi_guid_t *guid); int efi_variables_supported(void); +/* + * different routines to dump data. + */ + +void efi_asciidump(uint8_t *data, size_t datalen, int indent); +void efi_bindump(uint8_t *data, size_t datalen); +void efi_print_load_option(uint8_t *, size_t, int, int, int); +void efi_hexdump(uint8_t *data, size_t datalen, int indent); +void efi_utf8dump(uint8_t *data, size_t datalen, int indent); + /* FreeBSD extensions */ struct guid_table { diff --git a/usr.sbin/efibootmgr/Makefile b/usr.sbin/efibootmgr/Makefile index d976656a99c9..6f0a2a1dddbb 100644 --- a/usr.sbin/efibootmgr/Makefile +++ b/usr.sbin/efibootmgr/Makefile @@ -1,14 +1,13 @@ EFIBOOT=${SRCTOP}/stand/efi EFIINCL=${SRCTOP}/stand/efi/include -EFIVAR=${SRCTOP}/usr.sbin/efivar -.PATH: ${EFIBOOT}/libefi ${EFIVAR} -CFLAGS+= -I${EFIVAR} -I${EFIINCL} +.PATH: ${EFIBOOT}/libefi +CFLAGS+= -I${EFIINCL} PACKAGE= efi-tools PROG=efibootmgr MAN= efibootmgr.8 -SRCS= efichar.c efiutil.c efibootmgr.c +SRCS= efichar.c efibootmgr.c LIBADD= efivar geom diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c index b919130d9c11..1b572b613e05 100644 --- a/usr.sbin/efibootmgr/efibootmgr.c +++ b/usr.sbin/efibootmgr/efibootmgr.c @@ -50,7 +50,6 @@ #include <geom/geom_int.h> #include <efivar.h> -#include <efiutil.h> #include <efichar.h> #include <efivar-dp.h> diff --git a/usr.sbin/efivar/Makefile b/usr.sbin/efivar/Makefile index dd655f6b953d..4d71ec7d4dc4 100644 --- a/usr.sbin/efivar/Makefile +++ b/usr.sbin/efivar/Makefile @@ -5,7 +5,7 @@ MAN= efivar.8 LIBADD= efivar geom -SRCS= efivar.c efiutil.c +SRCS= efivar.c EFIBOOT=${SRCTOP}/stand/efi CFLAGS+= -I${EFIBOOT}/include diff --git a/usr.sbin/efivar/efiutil.h b/usr.sbin/efivar/efiutil.h deleted file mode 100644 index c9fcb99ec1eb..000000000000 --- a/usr.sbin/efivar/efiutil.h +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * Copyright (c) 2017 Netflix, Inc. - * - * 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. - */ - -/* - * different routines to dump data. - */ - -void asciidump(uint8_t *data, size_t datalen); -void bindump(uint8_t *data, size_t datalen); -void efi_print_load_option(uint8_t *, size_t, int, int, int); -void hexdump(uint8_t *data, size_t datalen); -void utf8dump(uint8_t *data, size_t datalen); - diff --git a/usr.sbin/efivar/efivar.c b/usr.sbin/efivar/efivar.c index c40ff1ea010f..6d252959e7de 100644 --- a/usr.sbin/efivar/efivar.c +++ b/usr.sbin/efivar/efivar.c @@ -38,7 +38,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "efiutil.h" #include "efichar.h" /* options descriptor */ @@ -254,15 +253,15 @@ print_var(efi_guid_t *guid, char *name) if (load_opt_flag) efi_print_load_option(data, datalen, Aflag, bflag, uflag); else if (Aflag) - asciidump(data, datalen); + efi_asciidump(data, datalen, 0); else if (uflag) - utf8dump(data, datalen); + efi_utf8dump(data, datalen, 0); else if (bflag) - bindump(data, datalen); + efi_bindump(data, datalen); else if (dflag) devpath_dump(data, datalen); else - hexdump(data, datalen); + efi_hexdump(data, datalen, 0); } else { printf("%s-%s", gname, name); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f11f9c.3c305.57a589ae>
