Hello community, here is the log from the commit of package efivar for openSUSE:Factory checked in at 2016-03-16 10:42:57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/efivar (Old) and /work/SRC/openSUSE:Factory/.efivar.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "efivar" Changes: -------- --- /work/SRC/openSUSE:Factory/efivar/efivar.changes 2015-12-23 08:48:18.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.efivar.new/efivar.changes 2016-03-16 10:42:58.000000000 +0100 @@ -1,0 +2,19 @@ +Wed Mar 9 04:23:29 UTC 2016 - [email protected] + +- Update to 0.23 +- Add efivar-nvme-rename.patch and efivar-nvme-no-kernel-header.patch + to work around the missing kernel header. +- Add efivar-no-static.patch to remove efivar-static since it + causes build failure and we don't really need it. +- Remove efivar-fix-initializer.patch since it's already in 0.23. +- Remove _smp_mflags since the Makefile doesn't work well with + the flag. + +------------------------------------------------------------------- +Wed Feb 10 15:31:35 UTC 2016 - [email protected] + +- Add efivar-0.21-gcc6.diff to fix strict-aliasing issue. +- Build with -Wno-nonnull as efivar tests nonnull args for zero + and that breaks with its use of -Werror. + +------------------------------------------------------------------- Old: ---- efivar-0.21.tar.bz2 efivar-fix-initializer.patch New: ---- efivar-0.21-gcc6.diff efivar-0.23.tar.bz2 efivar-no-static.patch efivar-nvme-no-kernel-header.patch efivar-nvme-rename.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ efivar.spec ++++++ --- /var/tmp/diff_new_pack.utvyp2/_old 2016-03-16 10:42:59.000000000 +0100 +++ /var/tmp/diff_new_pack.utvyp2/_new 2016-03-16 10:42:59.000000000 +0100 @@ -1,7 +1,7 @@ # # spec file for package efivar # -# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,14 +17,17 @@ Name: efivar -Version: 0.21 +Version: 0.23 Release: 0 Summary: Tools to manage UEFI variables License: LGPL-2.1 Group: Development/Libraries/Other Url: https://github.com/rhinstaller/efivar Source0: https://github.com/rhinstaller/efivar/releases/download/%{version}/%{name}-%{version}.tar.bz2 -Patch1: efivar-fix-initializer.patch +Patch1: efivar-0.21-gcc6.diff +Patch2: efivar-no-static.patch +Patch3: efivar-nvme-rename.patch +Patch4: efivar-nvme-no-kernel-header.patch BuildRequires: fdupes BuildRequires: pkg-config BuildRequires: popt-devel @@ -50,12 +53,14 @@ %prep %setup -q -%patch1 -p1 +%patch1 +%patch2 -p1 +%patch3 -p1 +%patch4 -p1 %build -export CFLAGS="%{optflags}" +export CFLAGS="%{optflags} -Wno-nonnull" make \ - %{?_smp_mflags} \ libdir=%{_libdir} \ bindir=%{_bindir} ++++++ efivar-0.21-gcc6.diff ++++++ --- src/util.h.orig 2016-02-10 15:29:15.245050330 +0000 +++ src/util.h 2016-02-10 15:29:18.957092775 +0000 @@ -175,14 +175,14 @@ } \ } \ if (_rc >= 0) { \ - uint8_t *_buf2 = alloca(_bufsize); \ + void *_buf2 = alloca(_bufsize); \ _saved_errno = errno; \ if (_buf2) { \ memcpy(_buf2, _buf, _bufsize); \ _rc = _bufsize; \ } \ free(_buf); \ - *((uint8_t **)buf) = _buf2; \ + *((void **)buf) = _buf2; \ errno = _saved_errno; \ } \ _rc; \ ++++++ efivar-0.21.tar.bz2 -> efivar-0.23.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/.gitignore new/efivar-0.23/.gitignore --- old/efivar-0.21/.gitignore 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/.gitignore 2016-02-15 20:38:42.000000000 +0100 @@ -11,8 +11,10 @@ *.tar.* .*.c.P .*.h.P +.*.d core.* *.spec src/efivar src/efivar-static src/makeguids +src/guid-symbols.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/Make.defaults new/efivar-0.23/Make.defaults --- old/efivar-0.21/Make.defaults 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/Make.defaults 2016-02-15 20:38:42.000000000 +0100 @@ -1,26 +1,38 @@ -INSTALL ?= install -libdir ?= /usr/lib64/ -mandir ?= /usr/share/man/ -includedir ?= /usr/include/ -bindir ?= /usr/bin/ +prefix ?= /usr/ +libdir ?= $(prefix)/lib64/ +datadir ?= $(prefix)/share/ +mandir ?= $(datadir)/man/ +includedir ?= $(prefix)/include/ +bindir ?= $(prefix)/bin/ PCDIR ?= $(libdir)/pkgconfig/ -CC := $(if $(filter default,$(origin CC)),gcc,$(CC)) +DESTDIR ?= + +INSTALL ?= install +CROSS_COMPILE ?= +PKG_CONFIG = $(CROSS_COMPILE)pkg-config +CC := $(if $(filter default,$(origin CC)),$(CROSS_COMPILE)gcc,$(CC)) CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD)) CFLAGS ?= -O2 -g +CFLAGS := $(CFLAGS) +LDFLAGS ?= +LDFLAGS := $(LDFLAGS) +AR := $(CROSS_COMPILE)gcc-ar +NM := $(CROSS_COMPILE)gcc-nm +RANLIB := $(CROSS_COMPILE)gcc-ranlib + +PKGS = -ARCH = $(shell uname -m) clang_cflags = -gcc_cflags = -Wmaybe-uninitialized -cflags := $(CFLAGS) \ - -Werror -Wall -Wsign-compare -Wstrict-aliasing \ - -std=gnu11 -fshort-wchar -fPIC \ - -fvisibility=hidden \ - -D_GNU_SOURCE -I${TOPDIR}/src/include/efivar/ \ - $(if $(filter $(CC),clang),$(clang_cflags),) \ - $(if $(filter $(CC),gcc),$(gcc_cflags),) +gcc_cflags = -specs=$(TOPDIR)/gcc.specs +cflags = $(CFLAGS) -I${TOPDIR}/src/include/efivar/ \ + $(if $(findstring clang,$(CC)),$(clang_cflags),) \ + $(if $(findstring gcc,$(CC)),$(gcc_cflags),) \ + $(call pkg-config-cflags) clang_ccldflags = -gcc_ccldflags = -fno-merge-constants -ccldflags := $(cflags) $(CCLDFLAGS) $(LDFLAGS) \ - $(if $(filter $(CCLD),clang),$(clang_ccldflags),) \ - $(if $(filter $(CCLD),gcc),$(gcc_ccldflags),) -LIBFLAGS += -shared +gcc_ccldflags = +ccldflags = $(cflags) -L. $(CCLDFLAGS) $(LDFLAGS) \ + $(if $(findstring clang,$(CCLD)),$(clang_ccldflags),) \ + $(if $(findstring gcc,$(CCLD)),$(gcc_ccldflags),) \ + $(call pkg-config-ccldflags) +SOFLAGS=-shared +LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/Make.rules new/efivar-0.23/Make.rules --- old/efivar-0.21/Make.rules 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/Make.rules 2016-02-15 20:38:42.000000000 +0100 @@ -1,26 +1,37 @@ +default : all + +.PHONY: default all deps clean install test + +include $(TOPDIR)/Make.version + %.a : $(AR) -cvqs $@ $^ -% : %.o - $(CCLD) $(ccldflags) -o $@ $^ $(foreach lib,$(LIBS),-l$(lib)) +% : %.c -%.so.$(VERSION) : - $(CCLD) $(cflags) -Wl,-soname,$(patsubst %.so.$(VERSION),%.so.$(MAJOR_VERSION),$@) $(ccldflags) $(LIBFLAGS) $^ -o $@ $(foreach lib,$(LIBS),-l$(lib)) +% : %.c + $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS) -%.so : %.so.$(VERSION) - ln -sf $< $@ +%-static : ccldflags+=-static +%-static : %.c + $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS) -%.so.$(MAJOR_VERSION) : %.so.$(VERSION) - ln -sf $< $@ +%.so : + $(CCLD) $(ccldflags) $(CPPFLAGS) $(SOFLAGS) \ + -Wl,-soname,$@.$(MAJOR_VERSION) \ + -o $@ $^ $(LDLIBS) -%.o: %.c - $(CC) $(cflags) $(CPPFLAGS) -c -o $@ $< +%.o : %.c + $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) -.%.c.P : %.c - $(CC) $(cflags) $(CPPFLAGS) -DEFIVAR_BUILD_ENVIRONMENT -M -MM -MF $@ $^ +%.static.o : %.c + $(CC) $(cflags) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) -.%.h.P : %.h - $(CC) $(cflags) $(CPPFLAGS) -DEFIVAR_BUILD_ENVIRONMENT -M -MM -MF $@ $^ +%.o : %.S + $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) + +%.static.o : %.S + $(CC) $(cflags) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) %.S: %.c $(CC) $(cflags) $(CPPFLAGS) -S $< -o $@ @@ -29,3 +40,27 @@ $(CC) $(cflags) $(CPPFLAGS) -E $< -o $@ %.c : %.h + +define substitute-version = + sed \ + -e "s,@@VERSION@@,$(VERSION),g" \ + -e "s,@@LIBDIR@@,$(libdir),g" \ + $(1) > $(2) +endef + +%.pc : %.pc.in + @$(call substitute-version,$<,$@) +%.spec : %.spec.in + @$(call substitute-version,$<,$@) + +pkg-config-cflags = \ + $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --cflags $(PKGS); fi) +pkg-config-ldflags = \ + $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --libs-only-L --libs-only-other $(PKGS) ; fi) +pkg-config-ldlibs = \ + $(shell if [ -n "$(PKGS)" ]; then $(PKG_CONFIG) --libs-only-l $(PKGS) ; fi) + +define deps-of = + $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \ + $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src))) +endef diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/Make.version new/efivar-0.23/Make.version --- old/efivar-0.21/Make.version 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/Make.version 2016-02-15 20:38:42.000000000 +0100 @@ -1,3 +1,3 @@ MAJOR_VERSION = 0 -MINOR_VERSION = 21 +MINOR_VERSION = 23 VERSION = $(MAJOR_VERSION).$(MINOR_VERSION) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/Makefile new/efivar-0.23/Makefile --- old/efivar-0.21/Makefile 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/Makefile 2016-02-15 20:38:42.000000000 +0100 @@ -1,26 +1,26 @@ TOPDIR = $(shell echo $$PWD) include $(TOPDIR)/Make.version +include $(TOPDIR)/Make.rules +include $(TOPDIR)/Make.defaults SUBDIRS := src docs -all : $(SUBDIRS) efivar.spec +all clean install deps :: | Make.version + @set -e ; for x in $(SUBDIRS) ; do \ + $(MAKE) -C $$x $@ ; \ + done + +all :: efivar.spec efivar efivar-static : - $(MAKE) -C src TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/$@/ ARCH=$(ARCH) $@ + $(MAKE) -C src $@ $(SUBDIRS) : - $(MAKE) -C $@ TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/$@/ ARCH=$(ARCH) - -clean : - @set -e ; for x in $(SUBDIRS) ; do $(MAKE) -C $${x} TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/$@/ ARCH=$(ARCH) $@ ; done - @rm -vf efivar.spec - -install : - @set -e ; for x in $(SUBDIRS) ; do $(MAKE) -C $${x} TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/$@/ ARCH=$(ARCH) DESTDIR=$(DESTDIR) includedir=$(includedir) bindir=$(bindir) libdir=$(libdir) PCDIR=$(PCDIR) $@ ; done + $(MAKE) -C $@ brick : all - @set -e ; for x in $(SUBDIRS) ; do $(MAKE) -C $${x} TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/$@/ ARCH=$(ARCH) test ; done + @set -e ; for x in $(SUBDIRS) ; do $(MAKE) -C $${x} test ; done a : @if [ $${EUID} != 0 ]; then \ @@ -28,13 +28,12 @@ exit 1 ; \ fi -.PHONY: $(SUBDIRS) all clean install a brick +.PHONY: $(SUBDIRS) a brick -include $(TOPDIR)/Make.defaults -include $(TOPDIR)/Make.rules +efivar.spec : | Makefile Make.version -efivar.spec : efivar.spec.in Makefile - @sed -e "s,@@VERSION@@,$(VERSION),g" $< > $@ +clean :: + @rm -vf efivar.spec GITTAG = $(VERSION) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/docs/Makefile new/efivar-0.23/docs/Makefile --- old/efivar-0.21/docs/Makefile 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/docs/Makefile 2016-02-15 20:38:42.000000000 +0100 @@ -1,8 +1,9 @@ -SRCDIR = . -TOPDIR = $(SRCDIR)/.. +SRCDIR = $(realpath .) +TOPDIR = $(realpath ..) -include $(TOPDIR)/Make.defaults include $(TOPDIR)/Make.version +include $(TOPDIR)/Make.rules +include $(TOPDIR)/Make.defaults MAN1TARGETS = efivar.1 MAN3TARGETS = efi_append_variable.3 \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/efivar.spec new/efivar-0.23/efivar.spec --- old/efivar-0.21/efivar.spec 2015-07-13 22:00:38.000000000 +0200 +++ new/efivar-0.23/efivar.spec 2016-02-15 21:02:55.000000000 +0100 @@ -1,5 +1,5 @@ Name: efivar -Version: 0.21 +Version: 0.23 Release: 1%{?dist} Summary: Tools to manage UEFI variables License: LGPLv2.1 @@ -38,7 +38,7 @@ git config --unset user.name %build -make libdir=%{_libdir} bindir=%{_bindir} OPT_FLAGS="$RPM_OPT_FLAGS" +make libdir=%{_libdir} bindir=%{_bindir} CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" %install rm -rf $RPM_BUILD_ROOT @@ -56,6 +56,7 @@ %license COPYING %doc README.md %{_bindir}/efivar +%exclude %{_bindir}/efivar-static %{_mandir}/man1/* %files devel diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/efivar.spec.in new/efivar-0.23/efivar.spec.in --- old/efivar-0.21/efivar.spec.in 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/efivar.spec.in 2016-02-15 20:38:42.000000000 +0100 @@ -38,7 +38,7 @@ git config --unset user.name %build -make libdir=%{_libdir} bindir=%{_bindir} OPT_FLAGS="$RPM_OPT_FLAGS" +make libdir=%{_libdir} bindir=%{_bindir} CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" %install rm -rf $RPM_BUILD_ROOT @@ -56,6 +56,7 @@ %license COPYING %doc README.md %{_bindir}/efivar +%exclude %{_bindir}/efivar-static %{_mandir}/man1/* %files devel diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/gcc.specs new/efivar-0.23/gcc.specs --- old/efivar-0.21/gcc.specs 1970-01-01 01:00:00.000000000 +0100 +++ new/efivar-0.23/gcc.specs 2016-02-15 20:38:42.000000000 +0100 @@ -0,0 +1,17 @@ +*cpp: ++ -D_GNU_SOURCE + +*efivar_cpp_options: + -Werror -Wall -std=gnu11 + +*cpp_options: ++ %(efivar_cpp_options) + +*cc1_options: ++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -flto -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} + +*self_spec: ++ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} + +*link: ++ %{!static:--fatal-warnings} --default-symver --no-undefined-version --no-allow-shlib-undefined --add-needed -z now --build-id %{!static:%{!shared:-PIE}} %{shared:-z relro -PIC} %{static:%<pie} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/Make.deps new/efivar-0.23/src/Make.deps --- old/efivar-0.21/src/Make.deps 1970-01-01 01:00:00.000000000 +0100 +++ new/efivar-0.23/src/Make.deps 2016-02-15 20:38:42.000000000 +0100 @@ -0,0 +1,16 @@ +SRCDIR = $(realpath .) +TOPDIR = $(realpath ..) + +include $(TOPDIR)/Make.version +include $(TOPDIR)/Make.rules +include $(TOPDIR)/Make.defaults + +.%.d : %.c + $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^ + +.%.d : %.S + $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^ + +SOURCES ?= + +deps : $(call deps-of,$(filter-out %.h,$(SOURCES))) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/Makefile new/efivar-0.23/src/Makefile --- old/efivar-0.21/src/Makefile 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/Makefile 2016-02-15 20:38:42.000000000 +0100 @@ -1,106 +1,95 @@ SRCDIR = $(realpath .) TOPDIR = $(realpath ..) -include $(TOPDIR)/Make.defaults include $(TOPDIR)/Make.version +include $(TOPDIR)/Make.rules +include $(TOPDIR)/Make.defaults +-include $(call deps-of,$(ALL_SOURCES)) + +LIBTARGETS=libefivar.so libefiboot.so +STATICLIBTARGETS=libefivar.a libefiboot.a +BINTARGETS=efivar efivar-static +PCTARGETS=efivar.pc efiboot.pc +TARGETS=$(LIBTARGETS) $(STATICLIBTARGETS) $(BINTARGETS) $(PCTARGETS) + +LIBEFIBOOT_SOURCES = crc32.c creator.c disk.c gpt.c linux.c loadopt.c +LIBEFIBOOT_OBJECTS = $(patsubst %.c,%.o,$(LIBEFIBOOT_SOURCES)) +LIBEFIVAR_SOURCES = dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \ + efivarfs.c export.c guid.c guids.S guid-symbols.c \ + lib.c vars.c +LIBEFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(LIBEFIVAR_SOURCES))) +EFIVAR_SOURCES = efivar.c +GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c +MAKEGUIDS_SOURCES = makeguids.c guid.c +ALL_SOURCES=$(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) $(MAKEGUIDS_SOURCES) \ + $(wildcard include/efivar/*.h) $(GENERATED_SOURCES) $(EFIVAR_SOURCES) + +all : deps $(TARGETS) + +./guid-symbols.c : include/efivar/efivar-guids.h +./guids.bin : include/efivar/efivar-guids.h +./names.bin : include/efivar/efivar-guids.h +include/efivar/efivar-guids.h : makeguids guids.txt + ./makeguids guids.txt guids.bin names.bin \ + guid-symbols.c include/efivar/efivar-guids.h -LIBTARGETS = $(foreach x,libefivar libefiboot,$(x).so.$(VERSION) $(x).so.$(MAJOR_VERSION)) -PCTARGETS = efivar.pc efiboot.pc -BINTARGETS = efivar -INCTARGETS = include/efivar/efivar-guids.h -all : $(EFIVAR_DEPS) $(INCTARGETS) deps -all : $(LIBTARGETS) $(PCTARGETS) $(BINTARGETS) libefiboot.so - @$(MAKE) -C test TOPDIR=$(TOPDIR) SRCDIR=$(SRCDIR)/test $@ - -EFIVAR_OBJECTS = dp.o dp-acpi.o dp-hw.o dp-media.o dp-message.o \ - efivarfs.o export.o guid.o guidlist.o guid-symbols.o \ - lib.o vars.o -# c files (alphabetically), then local headers (alphabetically), -# then target headers (again alphabetically) -EFIVAR_DEPS = .dp.c.P .dp-acpi.c.P .dp-hw.c.P .dp-media.c.P .dp-message.c.P \ - .efivar.c.P .efivarfs.c.P .export.c.P .guid.c.P .lib.c.P .vars.c.P \ - .dp.h.P .generics.h.P .guid.h.P .lib.h.P \ - include/efivar/.efivar.h.P include/efivar/.efivar-dp.h.P \ - include/efivar/.efivar-guids.h.P -EFIVAR_LIBS = dl - -MAKEGUIDS_DEPS = .makeguids.c.P include/efivar/.efivar.h.P .util.h.P .guid.h.P - -EFIBOOT_OBJECTS = \ - crc32.o creator.o disk.o gpt.o linux.o loadopt.o -EFIBOOT_DEPS = \ - .crc32.c.P .crc32.h.P .creator.c.P .disk.c.P .disk.h.P \ - .gpt.c.P .gpt.h.P .linux.c.P .linux.h.P .loadopt.c.P \ - include/efivar/.efiboot-creator.h.P \ - include/efivar/.efiboot-loadopt.h.P - -libefivar.a :: $(EFIVAR_OBJECTS) -libefivar.so.$(VERSION) : LIBS = $(EFIVAR_LIBS) -libefivar.so.$(VERSION) : $(EFIVAR_OBJECTS) - -libefiboot.a :: $(EFIBOOT_OBJECTS) -libefiboot.so.$(VERSION) : $(EFIBOOT_OBJECTS) libefivar.so - -efivar : efivar.o libefivar.so - $(CCLD) $(ccldflags) -L. -lefivar -o $@ $^ \ - -lpopt $(foreach lib,$(EFIVAR_LIBS),-l$(lib)) - -efivar-static : efivar.o libefivar.a - $(CCLD) $(ccldflags) -static -L. -o $@ $^ \ - -lpopt $(foreach lib,$(EFIVAR_LIBS),-l$(lib)) - -%.pc : %.pc.in - sed -e "s,@@VERSION@@,$(VERSION),g" \ - -e "s,@@LIBDIR@@,$(libdir),g" \ - $< > $@ - -include/efivar/efivar.h : include/efivar/efivar-guids.h +makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT +makeguids : LIBS=dl +makeguids : $(MAKEGUIDS_SOURCES) -fakeguid.o : guid.c - $(CC) $(cflags) -DEFIVAR_BUILD_ENVIRONMENT -c -o $@ $< +guids.o : guids.S | guids.bin names.bin -makeguids.o : makeguids.c - $(CC) $(cflags) -DEFIVAR_BUILD_ENVIRONMENT -c -o $@ $< +$(LIBEFIVAR_OBJECTS) $(LIBEFIBOOT_OBJECTS) : | $(GENERATED_SOURCES) -makeguids : makeguids.o fakeguid.o - $(CC) $(cflags) -o $@ $^ -ldl +libefivar.a : | $(GENERATED_SOURCES) +libefivar.a : $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS)) -include/efivar/efivar-guids.h : makeguids guids.txt - ./makeguids guids.txt guids.bin names.bin guid-symbols.S $@ +libefivar.so : $(LIBEFIVAR_OBJECTS) +libefivar.so : | $(GENERATED_SOURCES) +libefivar.so : LIBS=dl -guidlist.o : guids.S include/efivar/efivar-guids.h - $(CC) $(cflags) -c -o guidlist.o guids.S +efivar : efivar.c | libefivar.so +efivar : LIBS=efivar dl +efivar : PKGS=popt -guid-symbols.o : guid-symbols.S - $(CC) $(cflags) -c -o $@ $< +efivar-static : efivar.c $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS)) +efivar-static : | $(GENERATED_SOURCES) +efivar-static : LIBS=dl +efivar-static : PKGS=popt -.INTERMEDIATE: guids.bin names.bin guid-symbols.S +libefiboot.a : $(patsubst %.o,%.static.o,$(LIBEFIBOOT_OBJECTS)) -deps : $(EFIVAR_DEPS) $(EFIBOOT_DEPS) $(MAKEGUIDS_DEPS) +libefiboot.so : $(LIBEFIBOOT_OBJECTS) --include $(EFIVAR_DEPS) --include $(EFIBOOT_DEPS) --include $(MAKEGUIDS_DEPS) +deps :: $(ALL_SOURCES) + $(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)" clean : - @rm -rfv *~ *.o *.a *.so *.so.$(MAJOR_VERSION) *.so.$(VERSION) .*.c.P .*.h.P $(PCTARGETS) $(BINTARGETS) $(INCTARGETS) *.bin guid-symbols.S makeguids include/efivar/.*.h.P $(LIBTARGETS) - @$(MAKE) -C test TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/src/ $@ + @rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d \ + makeguids guid-symbols.c include/efivar/efivar-guids.h \ + $(BINTARGETS) + @# remove the deps files we used to create, as well. + @rm -rfv .*.P .*.h.P *.S.P include/efivar/.*.h.P install : all $(INSTALL) -d -m 755 $(DESTDIR)$(libdir) - $(foreach x, $(LIBTARGETS), $(INSTALL) -m 755 $(x) $(DESTDIR)$(libdir);) + $(foreach x,$(LIBTARGETS), \ + $(INSTALL) -m 755 $(x) $(DESTDIR)$(libdir)/$(x).$(VERSION) ;\ + ln -fs $(x).$(VERSION) $(DESTDIR)$(libdir)/$(x).$(MAJOR_VERSION);\ + ln -fs $(x).$(VERSION) $(DESTDIR)$(libdir)/$(x); ) $(INSTALL) -d -m 755 $(DESTDIR)$(PCDIR) $(foreach x, $(PCTARGETS), $(INSTALL) -m 644 $(x) $(DESTDIR)$(PCDIR) ;) $(INSTALL) -d -m 755 $(DESTDIR)$(includedir)/efivar $(foreach x, $(wildcard $(TOPDIR)/src/include/efivar/*.h), $(INSTALL) -m 644 $(x) $(DESTDIR)$(includedir)/efivar/$(notdir $(x));) $(INSTALL) -d -m 755 $(DESTDIR)$(bindir) $(foreach x, $(BINTARGETS), $(INSTALL) -m 755 $(x) $(DESTDIR)$(bindir);) - $(foreach x, $(wildcard *.so.$(VERSION)), ln -fs $(x) $(patsubst %.so.$(VERSION),%.so,$(DESTDIR)$(libdir)/$(x));) - $(foreach x, $(wildcard *.so.$(VERSION)), ln -fs $(x) $(patsubst %.so.$(VERSION),%.so.$(MAJOR_VERSION),$(DESTDIR)$(libdir)/$(x));) -test :all - $(MAKE) -C test TOPDIR=$(TOPDIR) SRCDIR=$(TOPDIR)/src/ $@ +test : all + $(MAKE) -C test $@ -.PHONY: all deps clean install test - -include $(TOPDIR)/Make.rules +.PHONY: test +.SECONDARY : libefivar.so.$(VERSION) libefivar.so.$(MAJOR_VERSION) +.SECONDARY : libefiboot.so.$(VERSION) libefiboot.so.$(MAJOR_VERSION) +.SECONDARY : include/efivar/efivar-guids.h guid-symbols.c +.INTERMEDIATE : guids.bin names.bin +.PRECIOUS : guid-symbols.o makeguids diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/creator.c new/efivar-0.23/src/creator.c --- old/efivar-0.21/src/creator.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/creator.c 2016-02-15 20:38:42.000000000 +0100 @@ -49,11 +49,6 @@ char linkbuf[PATH_MAX+1] = ""; ssize_t linklen = 0; - if (!filepath || !devicep || !relpathp) { - errno = EINVAL; - return -1; - } - linklen = strlen(filepath); if (linklen > PATH_MAX) { errno = ENAMETOOLONG; @@ -116,6 +111,8 @@ errno = ENAMETOOLONG; goto err; } + if (strncmp(linkbuf, me->mnt_dir, mntlen)) + continue; *devicep = strdup(me->mnt_fsname); if (!*devicep) goto err; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/dp-acpi.c new/efivar-0.23/src/dp-acpi.c --- old/efivar-0.21/src/dp-acpi.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/dp-acpi.c 2016-02-15 20:38:42.000000000 +0100 @@ -28,7 +28,7 @@ { ssize_t o = 0; o += format(buf, size, o, "AcpiAdr("); - o += format_array(buf, size, o, "%"PRIu32, + o += format_array(buf, size, o, "0x%"PRIx32, typeof(dp->acpi_adr.adr[0]), dp->acpi_adr.adr, (efidp_node_size(dp)-4)/sizeof (dp->acpi_adr.adr[0])); @@ -189,11 +189,6 @@ ssize_t req; ssize_t sz; - if (!hidstr || !uidstr || !cidstr) { - errno = EINVAL; - return -1; - } - req = sizeof (*acpi_hid) + 3 + strlen(hidstr) + strlen(uidstr) + strlen(cidstr); sz = efidp_make_generic(buf, size, EFIDP_ACPI_TYPE, EFIDP_ACPI_HID_EX, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/dp-message.c new/efivar-0.23/src/dp-message.c --- old/efivar-0.21/src/dp-message.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/dp-message.c 2016-02-15 20:38:42.000000000 +0100 @@ -22,7 +22,7 @@ #include <stddef.h> #include <efivar.h> -#include "endian.h" +#include "efivar_endian.h" #include "dp.h" static ssize_t @@ -408,6 +408,7 @@ - sizeof (efidp_header) - sizeof (efi_guid_t)); } + off += format(buf, size, off, ")"); break; } case EFIDP_MSG_IPv6: { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/dp.c new/efivar-0.23/src/dp.c --- old/efivar-0.21/src/dp.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/dp.c 2016-02-15 20:38:42.000000000 +0100 @@ -28,11 +28,6 @@ .subtype = EFIDP_END_ENTIRE, .length = 4 }; -static const efidp_header end_instance = { - .type = EFIDP_END_TYPE, - .subtype = EFIDP_END_INSTANCE, - .length = 4 -}; static inline void * efidp_data_address(const_efidp dp) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/dp.h new/efivar-0.23/src/dp.h --- old/efivar-0.21/src/dp.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/dp.h 2016-02-15 20:38:42.000000000 +0100 @@ -127,7 +127,7 @@ _off += format(buf, size, off+_off, fmt, \ ((type *)addr)[_i]); \ } \ - _off+off; \ + _off; \ }) extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/efivar.c new/efivar-0.23/src/efivar.c --- old/efivar-0.21/src/efivar.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/efivar.c 2016-02-15 20:38:42.000000000 +0100 @@ -329,21 +329,26 @@ prepare_data(file, &data, &data_size); append_variable(name, data, data_size, attributes); case ACTION_LIST_GUIDS: { + efi_guid_t sentinal = {0xffffffff,0xffff,0xffff,0xffff, + {0xff,0xff,0xff,0xff,0xff,0xff}}; extern struct guidname efi_well_known_guids; extern struct guidname efi_well_known_guids_end; + intptr_t start = (intptr_t)&efi_well_known_guids; + intptr_t end = (intptr_t)&efi_well_known_guids_end; + unsigned int i; - for (struct guidname *guid = &efi_well_known_guids; - guid != &efi_well_known_guids_end; - guid++) - { + struct guidname *guid = &efi_well_known_guids; + for (i = 0; i < (end-start) / sizeof(*guid); i++) { + if (!efi_guid_cmp(&sentinal, &guid[i].guid)) + break; printf("{"GUID_FORMAT"} {%s} %s %s\n", - guid->guid.a, guid->guid.b, - guid->guid.c, bswap_16(guid->guid.d), - guid->guid.e[0], guid->guid.e[1], - guid->guid.e[2], guid->guid.e[3], - guid->guid.e[4], guid->guid.e[5], - guid->symbol + strlen("efi_guid_"), - guid->symbol, guid->name); + guid[i].guid.a, guid[i].guid.b, + guid[i].guid.c, bswap_16(guid[i].guid.d), + guid[i].guid.e[0], guid[i].guid.e[1], + guid[i].guid.e[2], guid[i].guid.e[3], + guid[i].guid.e[4], guid[i].guid.e[5], + guid[i].symbol + strlen("efi_guid_"), + guid[i].symbol, guid[i].name); } } }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/efivar_endian.h new/efivar-0.23/src/efivar_endian.h --- old/efivar-0.21/src/efivar_endian.h 1970-01-01 01:00:00.000000000 +0100 +++ new/efivar-0.23/src/efivar_endian.h 2016-02-15 20:38:42.000000000 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright 2009-2015 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Author: Peter Jones <[email protected]> + */ +#ifndef _EFIVAR_ENDIAN_H +#define _EFIVAR_ENDIAN_H + +#include <endian.h> + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define cpu_to_le16(x) (x) +#define cpu_to_le32(x) (x) +#define cpu_to_le64(x) (x) +#define le16_to_cpu(x) (x) +#define le32_to_cpu(x) (x) +#define le64_to_cpu(x) (x) +#define cpu_to_be16(x) __bswap_16(x) +#define cpu_to_be32(x) __bswap_32(x) +#define cpu_to_be64(x) __bswap_64(x) +#define be16_to_cpu(x) __bswap_16(x) +#define be32_to_cpu(x) __bswap_32(x) +#define be64_to_cpu(x) __bswap_64(x) +#else +#define cpu_to_be16(x) (x) +#define cpu_to_be32(x) (x) +#define cpu_to_be64(x) (x) +#define be16_to_cpu(x) (x) +#define be32_to_cpu(x) (x) +#define be64_to_cpu(x) (x) +#define cpu_to_le16(x) __bswap_16(x) +#define cpu_to_le32(x) __bswap_32(x) +#define cpu_to_le64(x) __bswap_64(x) +#define le16_to_cpu(x) __bswap_16(x) +#define le32_to_cpu(x) __bswap_32(x) +#define le64_to_cpu(x) __bswap_64(x) +#endif + +#endif /* _EFIVAR_ENDIAN_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/efivarfs.c new/efivar-0.23/src/efivarfs.c --- old/efivar-0.21/src/efivarfs.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/efivarfs.c 2016-02-15 20:38:42.000000000 +0100 @@ -33,6 +33,8 @@ #include "generics.h" #include "util.h" +#include <linux/fs.h> + #define EFIVARS_PATH "/sys/firmware/efi/efivars/" #ifndef EFIVARFS_MAGIC @@ -67,6 +69,46 @@ }) static int +efivarfs_set_immutable(char *path, int immutable) +{ + unsigned int flags; + typeof(errno) error = 0; + int fd; + int rc = 0; + + fd = open(path, O_RDONLY); + if (fd < 0) { + if (errno == ENOTTY) + return 0; + else + return fd; + } + + rc = ioctl(fd, FS_IOC_GETFLAGS, &flags); + if (rc < 0) { + if (errno == ENOTTY) { + rc = 0; + } else { + error = errno; + } + } else if ((immutable && !(flags & FS_IMMUTABLE_FL)) || + (!immutable && (flags & FS_IMMUTABLE_FL))) { + if (immutable) + flags |= FS_IMMUTABLE_FL; + else + flags &= ~FS_IMMUTABLE_FL; + + rc = ioctl(fd, FS_IOC_SETFLAGS, &flags); + if (rc < 0) + error = errno; + } + + close(fd); + errno = error; + return rc; +} + +static int efivarfs_get_variable_size(efi_guid_t guid, const char *name, size_t *size) { char *path = NULL; @@ -169,7 +211,9 @@ if (rc < 0) return -1; - rc = unlink(path); + rc = efivarfs_set_immutable(path, 0); + if (rc >= 0) + rc = unlink(path); typeof(errno) errno_value = errno; free(path); @@ -216,6 +260,7 @@ } else { unlink(path); } + efivarfs_set_immutable(path, 1); err: errno_value = errno; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/endian.h new/efivar-0.23/src/endian.h --- old/efivar-0.21/src/endian.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/endian.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,51 +0,0 @@ -/* - * Copyright 2009-2015 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Author: Peter Jones <[email protected]> - */ -#ifndef _EFIVAR_ENDIAN_H -#define _EFIVAR_ENDIAN_H - -#include <endian.h> - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define cpu_to_le16(x) (x) -#define cpu_to_le32(x) (x) -#define cpu_to_le64(x) (x) -#define le16_to_cpu(x) (x) -#define le32_to_cpu(x) (x) -#define le64_to_cpu(x) (x) -#define cpu_to_be16(x) __bswap_16(x) -#define cpu_to_be32(x) __bswap_32(x) -#define cpu_to_be64(x) __bswap_64(x) -#define be16_to_cpu(x) __bswap_16(x) -#define be32_to_cpu(x) __bswap_32(x) -#define be64_to_cpu(x) __bswap_64(x) -#else -#define cpu_to_be16(x) (x) -#define cpu_to_be32(x) (x) -#define cpu_to_be64(x) (x) -#define be16_to_cpu(x) (x) -#define be32_to_cpu(x) (x) -#define be64_to_cpu(x) (x) -#define cpu_to_le16(x) __bswap_16(x) -#define cpu_to_le32(x) __bswap_32(x) -#define cpu_to_le64(x) __bswap_64(x) -#define le16_to_cpu(x) __bswap_16(x) -#define le32_to_cpu(x) __bswap_32(x) -#define le64_to_cpu(x) __bswap_64(x) -#endif - -#endif /* _EFIVAR_ENDIAN_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/export.c new/efivar-0.23/src/export.c --- old/efivar-0.21/src/export.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/export.c 2016-02-15 20:38:42.000000000 +0100 @@ -68,9 +68,6 @@ if (size <= min) return -1; - if (!var_out) - return -1; - uint8_t *ptr = data; uint32_t magic = EFIVAR_MAGIC; if (memcmp(data, &magic, sizeof (uint32_t)) || @@ -149,10 +146,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size) { - if (!var) { - errno = EINVAL; - return -1; - } size_t name_len = strlen(var->name); size_t needed = sizeof (uint32_t) /* magic */ @@ -248,11 +241,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_set_name(efi_variable_t *var, char *name) { - if (!var || !name) { - errno = EINVAL; - return -1; - } - var->name = name; return 0; } @@ -267,11 +255,6 @@ #endif efi_variable_get_name(efi_variable_t *var) { - if (!var) { - errno = EINVAL; - return NULL; - } - if (!var->name) { errno = ENOENT; } else { @@ -285,11 +268,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_set_guid(efi_variable_t *var, efi_guid_t *guid) { - if (!var || !guid) { - errno = EINVAL; - return -1; - } - var->guid = guid; return 0; } @@ -299,11 +277,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_get_guid(efi_variable_t *var, efi_guid_t **guid) { - if (!var || !guid) { - errno = EINVAL; - return -1; - } - if (!var->guid) { errno = ENOENT; return -1; @@ -318,7 +291,7 @@ __attribute__((__visibility__ ("default"))) efi_variable_set_data(efi_variable_t *var, uint8_t *data, size_t size) { - if (!var || !data || !size) { + if (!size) { errno = EINVAL; return -1; } @@ -333,11 +306,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_get_data(efi_variable_t *var, uint8_t **data, size_t *size) { - if (!var || !data || !size) { - errno = EINVAL; - return -1; - } - if (var->data || !var->data_size) { errno = ENOENT; return -1; @@ -353,11 +321,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_set_attributes(efi_variable_t *var, uint64_t attrs) { - if (!var) { - errno = -EINVAL; - return -1; - } - var->attrs = attrs; return 0; } @@ -367,11 +330,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_get_attributes(efi_variable_t *var, uint64_t *attrs) { - if (!var || !attrs) { - errno = -EINVAL; - return -1; - } - if (var->attrs == ATTRS_UNSET) { errno = ENOENT; return -1; @@ -386,11 +344,6 @@ __attribute__((__visibility__ ("default"))) efi_variable_realize(efi_variable_t *var) { - if (!var) { - errno = -EINVAL; - return -1; - } - if (!var->name || !var->data || !var->data_size || var->attrs == ATTRS_UNSET) { errno = -EINVAL; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/guid.c new/efivar-0.23/src/guid.c --- old/efivar-0.21/src/guid.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/guid.c 2016-02-15 20:38:42.000000000 +0100 @@ -43,17 +43,26 @@ if (!sp) { return snprintf(NULL, 0, GUID_FORMAT, - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); } else if (sp && *sp) { return snprintf(*sp, GUID_LENGTH_WITH_NUL, GUID_FORMAT, - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); } else { rc = asprintf(&ret, GUID_FORMAT, - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); if (rc >= 0) @@ -62,8 +71,14 @@ return rc; } -extern struct guidname efi_well_known_guids[], efi_well_known_names[]; -extern char efi_well_known_guids_end, efi_well_known_names_end; +extern struct guidname efi_well_known_guids + __attribute__((__visibility__ ("default"))); +extern struct guidname efi_well_known_names + __attribute__((__visibility__ ("default"))); +extern struct guidname efi_well_known_guids_end + __attribute__((__visibility__ ("default"))); +extern struct guidname efi_well_known_names_end + __attribute__((__visibility__ ("default"))); static int __attribute__((__nonnull__ (1, 2))) @@ -91,15 +106,15 @@ { intptr_t end = (intptr_t)&efi_well_known_guids_end; intptr_t start = (intptr_t)&efi_well_known_guids; - size_t nmemb = (end - start) / sizeof (efi_well_known_guids[0]); + size_t nmemb = (end - start) / sizeof (efi_well_known_guids); struct guidname key; memset(&key, '\0', sizeof (key)); memcpy(&key.guid, guid, sizeof (*guid)); struct guidname *tmp; - tmp = bsearch(&key, efi_well_known_guids, nmemb, - sizeof (efi_well_known_guids[0]), cmpguidp); + tmp = bsearch(&key, &efi_well_known_guids, nmemb, + sizeof (efi_well_known_guids), cmpguidp); if (!tmp) { *result = NULL; errno = ENOENT; @@ -166,17 +181,26 @@ } if (!sp) { return snprintf(NULL, 0, "{"GUID_FORMAT"}", - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); } else if (sp && *sp) { return snprintf(*sp, GUID_LENGTH_WITH_NUL+2, "{"GUID_FORMAT"}", - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); } rc = asprintf(&ret, "{"GUID_FORMAT"}", - guid->a, guid->b, guid->c, bswap_16(guid->d), + le32_to_cpu(guid->a), + le16_to_cpu(guid->b), + le16_to_cpu(guid->c), + be16_to_cpu(guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5]); if (rc >= 0) @@ -209,12 +233,9 @@ { intptr_t end = (intptr_t)&efi_well_known_names_end; intptr_t start = (intptr_t)&efi_well_known_names; - size_t nmemb = (end - start) / sizeof (efi_well_known_names[0]); + size_t nmemb = (end - start) / sizeof (efi_well_known_names); size_t namelen; - if (!name || !guid) - return -1; - namelen = strnlen(name, 39); struct guidname key; memset(&key, '\0', sizeof (key)); @@ -229,8 +250,8 @@ key.name[sizeof(key.name) - 1] = '\0'; struct guidname *result; - result = bsearch(&key, efi_well_known_names, nmemb, - sizeof (efi_well_known_names[0]), cmpnamep); + result = bsearch(&key, &efi_well_known_names, nmemb, + sizeof (efi_well_known_names), cmpnamep); if (result != NULL) { memcpy(guid, &result->guid, sizeof (*guid)); return 0; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/guid.h new/efivar-0.23/src/guid.h --- old/efivar-0.21/src/guid.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/guid.h 2016-02-15 20:38:42.000000000 +0100 @@ -24,6 +24,7 @@ #include <limits.h> #include <stdlib.h> #include <string.h> +#include "efivar_endian.h" #define GUID_FORMAT "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x" @@ -105,6 +106,7 @@ if (check_segment_sanity(eightbytes, 8) < 0) return -1; guid->a = (uint32_t)strtoul(eightbytes, NULL, 16); + guid->a = cpu_to_le32(guid->a); /* 84be9c3e-8a32-42c0-891c-4cd3b072becc * ^ */ @@ -112,6 +114,7 @@ if (check_segment_sanity(fourbytes, 4) < 0) return -1; guid->b = (uint16_t)strtoul(fourbytes, NULL, 16); + guid->b = cpu_to_le16(guid->b); /* 84be9c3e-8a32-42c0-891c-4cd3b072becc * ^ */ @@ -119,13 +122,15 @@ if (check_segment_sanity(fourbytes, 4) < 0) return -1; guid->c = (uint16_t)strtoul(fourbytes, NULL, 16); + guid->c = cpu_to_le16(guid->c); /* 84be9c3e-8a32-42c0-891c-4cd3b072becc * ^ */ strncpy(fourbytes, text+19, 4); if (check_segment_sanity(fourbytes, 4) < 0) return -1; - guid->d = bswap_16((uint16_t)strtoul(fourbytes, NULL, 16)); + guid->d = (uint16_t)strtoul(fourbytes, NULL, 16); + guid->d = cpu_to_be16(guid->d); /* 84be9c3e-8a32-42c0-891c-4cd3b072becc * ^ */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/guids.txt new/efivar-0.23/src/guids.txt --- old/efivar-0.21/src/guids.txt 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/guids.txt 2016-02-15 20:38:42.000000000 +0100 @@ -30,3 +30,4 @@ e2b36190-879b-4a3d-ad8d-f2e7bba32784 rsa2048_sha256 RSA 2048 with SHA-256 ff3e5307-9fd0-48c9-85f1-8ad56c701e01 sha384 SHA-384 f46ee6f4-4785-43a3-923d-7f786c3c8479 lenovo_startup_interrupt Lenovo Startup Interrupt Menu +ffffffff-ffff-ffff-ffff-ffffffffffff zzignore-this-guid zzignore-this-guid diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/include/efivar/efivar-dp.h new/efivar-0.23/src/include/efivar/efivar-dp.h --- old/efivar-0.21/src/include/efivar/efivar-dp.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/include/efivar/efivar-dp.h 2016-02-15 20:38:42.000000000 +0100 @@ -770,6 +770,7 @@ int rc = efidp_next_node(dn, &next); if (rc < 0) break; + dn = next; } if (efidp_type(dn) == EFIDP_END_TYPE && @@ -851,7 +852,7 @@ break; int rc = efidp_next_node(dpi, &next); - if (rc < 1) + if (rc < 0) return -1; dpi = next; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/include/efivar/efivar.h new/efivar-0.23/src/include/efivar/efivar.h --- old/efivar-0.21/src/include/efivar/efivar.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/include/efivar/efivar.h 2016-02-15 20:38:42.000000000 +0100 @@ -18,6 +18,7 @@ #ifndef EFIVAR_H #define EFIVAR_H 1 +#include <endian.h> #include <errno.h> #include <stdarg.h> #include <stdint.h> @@ -39,8 +40,13 @@ #include <efivar-guids.h> #endif +#if BYTE_ORDER == LITTLE_ENDIAN #define EFI_GUID(a,b,c,d,e0,e1,e2,e3,e4,e5) \ ((efi_guid_t) {(a), (b), (c), bswap_16(d), { (e0), (e1), (e2), (e3), (e4), (e5) }}) +#else +#define EFI_GUID(a,b,c,d,e0,e1,e2,e3,e4,e5) \ +((efi_guid_t) {(a), (b), (c), (d), { (e0), (e1), (e2), (e3), (e4), (e5) }}) +#endif #define EFI_GLOBAL_GUID EFI_GUID(0x8be4df61,0x93ca,0x11d2,0xaa0d,0x00,0xe0,0x98,0x03,0x2b,0x8c) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/linux.c new/efivar-0.23/src/linux.c --- old/efivar-0.21/src/linux.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/linux.c 2016-02-15 20:38:42.000000000 +0100 @@ -59,7 +59,7 @@ char *linkbuf; ssize_t rc; - rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%"PRIu64":%hhd", + rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%"PRIu64":%hhu", info->major, info->minor); if (rc < 0) return -1; @@ -81,6 +81,10 @@ } penultimate++; + /* + * If there's a better way to figure this out, it'd be good, because + * I don't want to have to change this for every new disk type... + */ if (!strcmp(penultimate, "block")) { if (!info->disk_name) { info->disk_name = strdup(ultimate); @@ -93,6 +97,18 @@ if (rc < 0) return -1; } + } else if (!strncmp(penultimate, "nvme", 4)) { + if (!info->disk_name) { + info->disk_name = strdup(ultimate); + if (!info->disk_name) + return -1; + } + if (!info->part_name) { + rc = asprintf(&info->part_name, "%sp%d", + info->disk_name, info->part); + if (rc < 0) + return -1; + } } else { if (!info->disk_name) { info->disk_name = strdup(penultimate); @@ -117,7 +133,7 @@ int rc; unsigned int maj, min; char *linkbuf; - char *partbuf; + uint8_t *partbuf; int ret = -1; rc = stat(devpath, &statbuf); @@ -129,8 +145,8 @@ return -1; } - maj = gnu_dev_major(statbuf.st_rdev); - min = gnu_dev_minor(statbuf.st_rdev); + maj = major(statbuf.st_rdev); + min = minor(statbuf.st_rdev); rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%u:%u", maj, min); if (rc < 0) @@ -140,7 +156,7 @@ if (rc < 0) return -1; - rc = sscanf(partbuf, "%d\n", &ret); + rc = sscanf((char *)partbuf, "%d\n", &ret); if (rc != 1) return -1; return ret; @@ -185,7 +201,6 @@ { DIR *d; struct dirent *de; - int saved_errno; uint8_t *buf = NULL; int rc; @@ -204,19 +219,18 @@ int rc; rc = sscanf(de->d_name, "dev%d.%d.%d", &found_print_id, &found_pmp, &found_devno); - if (rc == 2) { - found_devno = found_pmp; - found_pmp=0; - } else if (rc != 3) { - saved_errno = errno; - closedir(d); - errno = saved_errno; - return -1; - } - if (found_print_id == print_id) { - info->sata_info.ata_devno = found_devno; + if (rc == 3) { + info->sata_info.ata_devno = 0; info->sata_info.ata_pmp = found_pmp; break; + } else if (rc == 2) { + info->sata_info.ata_devno = 0; + info->sata_info.ata_pmp = 0x8000; + break; + } else { + closedir(d); + errno = EINVAL; + return -1; } } closedir(d); @@ -230,7 +244,6 @@ if (rc != 1) return -1; - info->sata_info.ata_port -= 1; return 0; } @@ -340,7 +353,7 @@ { int rc; int psz = 0; - char *filebuf = NULL; + uint8_t *filebuf = NULL; uint64_t sas_address; *poff = 0; @@ -434,7 +447,7 @@ if (rc < 0) return -1; - rc = sscanf(filebuf, "%"PRIx64, &sas_address); + rc = sscanf((char *)filebuf, "%"PRIx64, &sas_address); if (rc != 1) return -1; @@ -477,7 +490,7 @@ return -1; poff += psz; - char *fbuf = NULL; + uint8_t *fbuf = NULL; rc = read_sysfs_file(&fbuf, "/sys/devices/pci%04x:%02x/firmware_node/hid", root_domain, root_bus); @@ -847,12 +860,13 @@ __attribute__((__visibility__ ("hidden"))) make_mac_path(uint8_t *buf, ssize_t size, const char * const ifname) { - struct ifreq ifr = { 0, }; + struct ifreq ifr; struct ethtool_drvinfo drvinfo = { 0, }; int fd, rc; ssize_t ret = -1, sz, off=0; char busname[PATH_MAX+1] = ""; + memset(&ifr, 0, sizeof (ifr)); strncpy(ifr.ifr_name, ifname, IF_NAMESIZE); drvinfo.cmd = ETHTOOL_GDRVINFO; ifr.ifr_data = (caddr_t)&drvinfo; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/loadopt.c new/efivar-0.23/src/loadopt.c --- old/efivar-0.21/src/loadopt.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/loadopt.c 2016-02-15 20:38:42.000000000 +0100 @@ -36,11 +36,6 @@ efidp dp, ssize_t dp_size, unsigned char *description, uint8_t *optional_data, size_t optional_data_size) { - if (!description) { - errno = EINVAL; - return -1; - } - ssize_t desc_len = utf8len((uint8_t *)description, 1024) * 2 + 2; ssize_t sz = sizeof (attributes) + sizeof (uint16_t) + desc_len @@ -90,9 +85,6 @@ size_t sz; uint8_t *p; - if (!opt) - return -1; - if (size < sizeof(*opt)) return -1; size -= sizeof(*opt); @@ -162,10 +154,6 @@ efi_loadopt_path(efi_load_option *opt) { char *p = (char *)opt; - if (!opt) { - errno = EINVAL; - return NULL; - } efidp dp = (efidp)(p + sizeof (opt->attributes) + sizeof (opt->file_path_list_length) + ucs2size(opt->description, -1)); @@ -179,10 +167,6 @@ unsigned char **datap, size_t *len) { unsigned char *p = (unsigned char *)opt; - if (!opt || !datap) { - errno = EINVAL; - return -1; - } *datap = (unsigned char *)(p + sizeof (opt->attributes) + sizeof (opt->file_path_list_length) + ucs2size(opt->description, -1) @@ -203,7 +187,7 @@ int saved_errno; FILE *f; - if (!filename || (!buf && size > 0)) { + if (!buf && size > 0) { errno = -EINVAL; return -1; } @@ -241,7 +225,7 @@ efi_loadopt_args_as_utf8(uint8_t *buf, ssize_t size, char *utf8) { ssize_t req; - if (!utf8 || (!buf && size > 0)) { + if (!buf && size > 0) { errno = EINVAL; return -1; } @@ -268,7 +252,7 @@ efi_loadopt_args_as_ucs2(uint16_t *buf, ssize_t size, uint8_t *utf8) { ssize_t req; - if (!utf8 || (!buf && size > 0)) { + if (!buf && size > 0) { errno = EINVAL; return -1; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/makeguids.c new/efivar-0.23/src/makeguids.c --- old/efivar-0.21/src/makeguids.c 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/makeguids.c 2016-02-15 20:38:42.000000000 +0100 @@ -30,13 +30,10 @@ efi_guid_t const efi_guid_zero = {0}; efi_guid_t const efi_guid_empty = {0}; -struct guidname efi_well_known_guids[] = { -}; -char efi_well_known_guids_end; - -struct guidname efi_well_known_names[] = { -}; -char efi_well_known_names_end; +struct guidname efi_well_known_guids; +struct guidname efi_well_known_guids_end; +struct guidname efi_well_known_names; +struct guidname efi_well_known_names_end; static int cmpguidp(const void *p1, const void *p2) @@ -150,46 +147,54 @@ fprintf(header, "#ifndef EFIVAR_GUIDS_H\n#define EFIVAR_GUIDS_H 1\n\n"); - for (unsigned int i = 0; i < line-1; i++) { - if (!strcmp(outbuf[i].symbol, "efi_guid_zero")) - fprintf(symout, "\t.globl %s\n" - "\t.data\n" - "\t.balign 1\n" - "\t.type %s, %%object\n" - "\t.size %s, %s_end - %s\n", - "efi_guid_empty", "efi_guid_empty", - "efi_guid_empty", "efi_guid_empty", - "efi_guid_empty"); - fprintf(symout, "\t.globl %s\n" - "\t.data\n" - "\t.balign 1\n" - "\t.type %s, %%object\n" - "\t.size %s, %s_end - %s\n" - "%s:\n", - outbuf[i].symbol, - outbuf[i].symbol, - outbuf[i].symbol, - outbuf[i].symbol, - outbuf[i].symbol, - outbuf[i].symbol); - if (!strcmp(outbuf[i].symbol, "efi_guid_zero")) - fprintf(symout, "efi_guid_empty:\n"); + fprintf(symout, "#include <efivar.h>\n"); + fprintf(symout, "#include <endian.h>\n"); + fprintf(symout, """\n\ +#if BYTE_ORDER == BIG_ENDIAN\n\ +#define cpu_to_be32(n) (n)\n\ +#define cpu_to_be16(n) (n)\n\ +#define cpu_to_le32(n) (__bswap_constant_32(n))\n\ +#define cpu_to_le16(n) (__bswap_constant_16(n))\n\ +#else\n\ +#define cpu_to_le32(n) (n)\n\ +#define cpu_to_le16(n) (n)\n\ +#define cpu_to_be32(n) (__bswap_constant_32(n))\n\ +#define cpu_to_be16(n) (__bswap_constant_16(n))\n\ +#endif\n\ +"""); + for (unsigned int i = 0; i < line-1; i++) { uint8_t *guid_data = (uint8_t *) &outbuf[i].guid; - for (unsigned int j = 0; j < sizeof (efi_guid_t); j++) - fprintf(symout,"\t.byte 0x%02x\n", guid_data[j]); - fprintf(symout, "%s_end:\n", outbuf[i].symbol); + if (!strcmp(outbuf[i].symbol, "efi_guid_zzignore-this-guid")) + break; + + if (!strcmp(outbuf[i].symbol, "efi_guid_zero")) { + fprintf(symout, "const efi_guid_t\n" + "__attribute__((__visibility__ (\"default\")))\n" + "efi_guid_empty = {0x0,0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0}};\n\n"); + } if (!strcmp(outbuf[i].symbol, "efi_guid_zero")) { - fprintf(symout, "efi_guid_empty_end:\n"); - fprintf(header, "extern const efi_guid_t efi_guid_empty;\n"); + fprintf(header, "extern const efi_guid_t efi_guid_empty __attribute__((__visibility__ (\"default\")));\n"); } - fprintf(header, "extern const efi_guid_t %s;\n", outbuf[i].symbol); + fprintf(header, "extern const efi_guid_t %s __attribute__((__visibility__ (\"default\")));\n", outbuf[i].symbol); + + fprintf(symout, "const \n" + "__attribute__((__visibility__ (\"default\")))\n" + "efi_guid_t %s = {cpu_to_le32(0x%02x%02x%02x%02x),cpu_to_le16(0x%02x%02x),cpu_to_le16(0x%02x%02x),cpu_to_be16(0x%02x%02x),{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}};\n\n", + outbuf[i].symbol, + guid_data[3], guid_data[2], + guid_data[1], guid_data[0], + guid_data[5], guid_data[4], + guid_data[7], guid_data[6], + guid_data[8], guid_data[9], + guid_data[10], guid_data[11], + guid_data[12], guid_data[13], + guid_data[14], guid_data[15]); } fprintf(header, "\n#endif /* EFIVAR_GUIDS_H */\n"); - fprintf(symout, "#if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,\"\",%%progbits\n#endif"); fclose(header); fclose(symout); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/efivar-0.21/src/ucs2.h new/efivar-0.23/src/ucs2.h --- old/efivar-0.21/src/ucs2.h 2015-07-13 22:00:06.000000000 +0200 +++ new/efivar-0.23/src/ucs2.h 2016-02-15 20:38:42.000000000 +0100 @@ -9,7 +9,7 @@ ucs2len(const uint16_t * const s, ssize_t limit) { ssize_t i; - for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != L'\0'; i++) + for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++) ; return i; } @@ -120,7 +120,7 @@ ssize_t req; ssize_t i, j; - if (!utf8 || (!ucs2 && size > 0)) { + if (!ucs2 && size > 0) { errno = EINVAL; return -1; } @@ -156,7 +156,7 @@ ucs2[j] = val; } if (terminate) - ucs2[j++] = L'\0'; + ucs2[j++] = (uint16_t)0; return j; }; ++++++ efivar-no-static.patch ++++++ >From d084645fdc9bf805b39b0fb3ff7ec315661884be Mon Sep 17 00:00:00 2001 From: Gary Lin <[email protected]> Date: Wed, 9 Mar 2016 12:19:26 +0800 Subject: [PATCH] Remove efivar-static since it requires static libs Signed-off-by: Gary Lin <[email protected]> --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 5fc7887..e1c1ccd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/Make.defaults LIBTARGETS=libefivar.so libefiboot.so STATICLIBTARGETS=libefivar.a libefiboot.a -BINTARGETS=efivar efivar-static +BINTARGETS=efivar PCTARGETS=efivar.pc efiboot.pc TARGETS=$(LIBTARGETS) $(STATICLIBTARGETS) $(BINTARGETS) $(PCTARGETS) -- 2.7.2 ++++++ efivar-nvme-no-kernel-header.patch ++++++ >From 8910f45c27fadba0904f707e7c40ad80bf828f7e Mon Sep 17 00:00:00 2001 From: Peter Jones <[email protected]> Date: Fri, 19 Feb 2016 18:53:00 -0500 Subject: [PATCH] libefiboot: rework NVME so we get EUI right and don't need kernel headers The headers are broken enough on various distros that it's better to avoid them entirely. Signed-off-by: Peter Jones <[email protected]> --- src/linux.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++-------------- src/linux.h | 8 ++++ 2 files changed, 106 insertions(+), 29 deletions(-) diff --git a/src/linux.c b/src/linux.c index 0063476..084e9c2 100644 --- a/src/linux.c +++ b/src/linux.c @@ -23,11 +23,6 @@ #include <limits.h> #include <linux/ethtool.h> #include <linux/version.h> -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) -#include <linux/nvme_ioctl.h> -#else -#include <linux/nvme.h> -#endif #include <linux/sockios.h> #include <net/if.h> #include <scsi/scsi.h> @@ -48,17 +43,6 @@ int __attribute__((__visibility__ ("hidden"))) -eb_nvme_ns_id(int fd, uint32_t *ns_id) -{ - uint64_t ret = ioctl(fd, NVME_IOCTL_ID, NULL); - if ((int)ret < 0) - return ret; - *ns_id = (uint32_t)ret; - return 0; -} - -int -__attribute__((__visibility__ ("hidden"))) set_disk_and_part_name(struct disk_info *info) { char *linkbuf; @@ -168,6 +152,23 @@ get_partition_number(const char *devpath) } static int +sysfs_test_nvme(const char *buf, ssize_t size) +{ + int rc; + + int32_t tosser0; + int32_t ctrl_id; + int32_t ns_id; + + errno = 0; + rc = sscanf(buf, "nvme/nvme%d/nvme%dn%d", &tosser0, &ctrl_id, &ns_id); + if (rc < 1) + return (errno == 0) ? 0 : -1; + + return 1; +} + +static int sysfs_test_sata(const char *buf, ssize_t size) { if (!strncmp(buf, "ata", MIN(size,3))) @@ -259,6 +260,69 @@ sysfs_sata_get_port_info(uint32_t print_id, struct disk_info *info) } static ssize_t +sysfs_parse_nvme(uint8_t *buf, ssize_t size, ssize_t *off, + const char *pbuf, ssize_t psize, ssize_t *poff, + struct disk_info *info) +{ + int rc; + int psz = 0; + char *filebuf = NULL; + + *poff = 0; + *off = 0; + + int32_t tosser0; + int32_t ctrl_id; + int32_t ns_id; + + /* buf is: + * nvme/nvme0/nvme0n1 + */ + rc = sscanf(pbuf+*poff, "nvme/nvme%d/nvme%dn%d%n", &tosser0, + &ctrl_id, &ns_id, &psz); + if (rc != 3) + return -1; + *poff += psz; + + info->nvme_info.ctrl_id = ctrl_id; + info->nvme_info.ns_id = ns_id; + info->nvme_info.has_eui = 0; + info->interface_type = nvme; + + /* + * now fish the eui out of sysfs is there is one... + */ + rc = read_sysfs_file(&filebuf, + "/sys/class/block/nvme%dn%d/device/eui", + ctrl_id, ns_id); + if (rc >= 0) { + uint8_t eui[8]; + if (rc < 23) { + errno = EINVAL; + return -1; + } + rc = sscanf(filebuf, + "%02hhx-%02hhx-%02hhx-%02hhx-" + "%02hhx-%02hhx-%02hhx-%02hhx", + &eui[0], &eui[1], &eui[2], &eui[3], + &eui[4], &eui[5], &eui[6], &eui[7]); + if (rc < 8) { + errno = EINVAL; + return -1; + } + info->nvme_info.has_eui = 1; + memcpy(info->nvme_info.eui, eui, sizeof(eui)); + } + + *off = efidp_make_nvme(buf, size, + info->nvme_info.ns_id, + info->nvme_info.has_eui ? info->nvme_info.eui + : NULL); + return *off; +} + + +static ssize_t sysfs_parse_sata(uint8_t *buf, ssize_t size, ssize_t *off, const char *pbuf, ssize_t psize, ssize_t *poff, struct disk_info *info) @@ -665,20 +729,25 @@ make_blockdev_path(uint8_t *buf, ssize_t size, int fd, struct disk_info *info) loff += tmpoff; found = 1; } + } - if (!found) { - uint32_t ns_id=0; - int rc = eb_nvme_ns_id(fd, &ns_id); - if (rc >= 0) { - sz = efidp_make_nvme(buf+off, size?size-off:0, - ns_id, NULL); - if (sz < 0) - return -1; - - info->interface_type = nvme; - off += sz; - found = 1; - } + /* /dev/nvme0n1 looks like: + * /sys/dev/block/259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 + */ + if (!found) { + rc = sysfs_test_nvme(linkbuf+loff, PATH_MAX-off); + if (rc < 0) + return -1; + else if (rc > 0) { + ssize_t linksz; + rc = sysfs_parse_nvme(buf+off, size?size-off:0, &sz, + linkbuf+loff, PATH_MAX-off, + &linksz, info); + if (rc < 0) + return -1; + loff += linksz; + off += sz; + found = 1; } } diff --git a/src/linux.h b/src/linux.h index 5e8d003..539fb23 100644 --- a/src/linux.h +++ b/src/linux.h @@ -60,6 +60,13 @@ struct sata_info { uint32_t ata_pmp; }; +struct nvme_info { + int32_t ctrl_id; + int32_t ns_id; + int has_eui; + uint8_t eui[8]; +}; + struct disk_info { int interface_type; unsigned int controllernum; @@ -76,6 +83,7 @@ struct disk_info { struct scsi_info scsi_info; struct sas_info sas_info; struct sata_info sata_info; + struct nvme_info nvme_info; }; char *disk_name; -- 2.7.2 ++++++ efivar-nvme-rename.patch ++++++ >From 3a0ae7189fe96355d64dc2daf91cf85282773c66 Mon Sep 17 00:00:00 2001 From: Mike Gilbert <[email protected]> Date: Thu, 14 Jan 2016 17:02:31 -0500 Subject: [PATCH] Workaround rename of linux/nvme.h Bug: https://bugs.gentoo.org/571548 --- src/linux.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/linux.c b/src/linux.c index b618cfd..9388cd3 100644 --- a/src/linux.c +++ b/src/linux.c @@ -22,7 +22,12 @@ #include <inttypes.h> #include <limits.h> #include <linux/ethtool.h> +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) +#include <linux/nvme_ioctl.h> +#else #include <linux/nvme.h> +#endif #include <linux/sockios.h> #include <net/if.h> #include <scsi/scsi.h> -- 2.7.2
