From 057264410bdec3ae63acd5f3ec9899604b449926 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Thu, 4 Nov 2021 00:50:02 -0400 Subject: [PATCH] import efivar-37-17.el9 --- .efivar.metadata | 1 + .gitignore | 1 + ...utput-for-missing-variadic-arguments.patch | 90 + ...x-sys-block-sysfs-parsing-for-eMMC-s.patch | 55 + ...til.h-add-unlikely-and-likely-macros.patch | 33 + ..._guid-handle-misaligned-guid-pointer.patch | 59 + ...pci-root-remove-an-unused-assignment.patch | 27 + ...es-Werror-address-of-packed-member-c.patch | 172 + ...-of-the-arrows-in-our-debug-messages.patch | 372 ++ ...-Define-strdupa-if-it-is-not-defined.patch | 38 + ...-Android-inital-porting-of-libefivar.patch | 82 + SOURCES/0008-Remove-an-unused-function.patch | 40 + ...r-of-Werror-address-of-packed-member.patch | 54 + .../0010-ucs2.h-remove-unused-variable.patch | 34 + ...-that-checks-for-UCS-2-string-termin.patch | 32 + ...ix-efidp_ipv4_addr-fields-assignment.patch | 44 + ...MBR-and-GPT-fixed-values-as-magic-no.patch | 129 + ...4-Add-more-hexdump-logging-functions.patch | 87 + ...or_pop-and-pop-some-errors-sometimes.patch | 147 + ...og-to-a-memfd-regardless-of-loglevel.patch | 215 + ...e-any-variable-we-use-with-sscanf-s-.patch | 82 + ...fivar_version-and-efi_get_libefiboot.patch | 126 + ...Fix-dbglog_seek-to-update-the-offset.patch | 32 + ...7-.abixml-for-new-libabigail-version.patch | 5854 +++++++++++++++++ ...cmp-s-alignment-problem-a-different-.patch | 70 + ...-to-always-return-the-status-of-writ.patch | 27 + ...of-making-sure-DLIBEFIVAR_VERSION-ha.patch | 36 + ...efi_stash_loglevel_-efi_set_loglevel.patch | 102 + ...0025-guids-add-grub-guid-for-grubenv.patch | 38 + ...6-gcc.specs-add-grecord-gcc-switches.patch | 30 + ...n-t-echo-our-deps-submake-invocation.patch | 26 + ...ome-more-stuff-to-the-toplevel-clean.patch | 26 + ...-build-rules-slightly-more-intuitive.patch | 31 + ...0030-Local-header-whitespace-cleanup.patch | 1511 +++++ ...1-Exported-header-whitespace-cleanup.patch | 97 + .../0032-Main-code-whitespace-cleanup.patch | 5136 +++++++++++++++ SOURCES/0033-efivar-rework-usage.patch | 142 + ...-some-signof-char-signof-uint8_t-mad.patch | 431 ++ ...ucs2-document-things-a-little-better.patch | 219 + ...t-add-mul-sub-for-more-integer-types.patch | 370 ++ ...0037-Implement-efivar-export-foo.var.patch | 1194 ++++ ...-test-cases-for-efivar-export-import.patch | 187 + ...-analyzer-found-where-we-may-try-to-.patch | 119 + ...ids-helper-is-compiled-for-the-host-.patch | 37 + ...-wildcard-output-for-reproducibility.patch | 49 + ...0042-guids.txt-correct-sentinal-typo.patch | 22 + ...or-efivar-such-that-it-reflects-the-.patch | 73 + ...2-bit-size_t-format-specifier-errors.patch | 53 + ...e-top-level-makefile-not-parallelize.patch | 34 + ...6-guids-add-auto_created_boot_option.patch | 25 + ...tructure-makefiles-out-of-the-topdir.patch | 260 + ...D-and-CCLD_FOR_BUILD-override-HOSTCC.patch | 33 + ...file-bits-to-make-overriding-some-op.patch | 299 + ...e-add-Wno-missing-field-initializers.patch | 55 + ...-debug-don-t-write-newlines-to-memfd.patch | 86 + ...rsing-add-some-more-debugging-output.patch | 402 ++ SOURCES/0053-gitignore-ignore-.strace.patch | 25 + ...error-path-in-set_disk_and_part_name.patch | 71 + ...ke-all-the-sys-block-link-parsers-wo.patch | 1084 +++ ...-Improve-consistency-of-debug-prints.patch | 306 + ...to-find-disk-device-symlinks-in-sysf.patch | 212 + ...es-virtual-nvme-fabrics-nvme-subsyst.patch | 313 + ...-EFI-device-paths-into-the-debug-log.patch | 72 + SOURCES/0060-Update-abixml.patch | 99 + ...les-and-work-around-some-inconsequen.patch | 3314 ++++++++++ .../0062-Don-t-use-march-native-on-ia64.patch | 43 + ...round-autoconf-existing-in-the-world.patch | 56 + SOURCES/0064-Fix-efivar-w-and-efivar-a.patch | 37 + ...5-Android-fix-incorrect-include-path.patch | 28 + ...droid-fix-missing-field-initializers.patch | 35 + ...-Fix-variable-sz-uninitialized-error.patch | 39 + .../0068-Fix-an-argument-mismatch-error.patch | 45 + .../0069-Android-fix-building-errors.patch | 66 + ...MBR_MAGIC-type-not-the-format-string.patch | 49 + ...e-scan-build-and-CC-clang-work-again.patch | 174 + SOURCES/0072-Remove-a-dead-store.patch | 42 + ...-makeguids-confuse-ccc-analyzer-less.patch | 38 + ...all-the-license-text-in-source-files.patch | 1629 +++++ SOURCES/0075-Makefile-minor-typo-fix.patch | 25 + ...0076-util.h-minor-whitespace-cleanup.patch | 135 + ...upa-and-strndupa-pass-NULL-straight-.patch | 54 + ...-Update-travis-to-use-a-newer-distro.patch | 26 + SOURCES/efivar.patches | 78 + SPECS/efivar.spec | 357 + 84 files changed, 27478 insertions(+) create mode 100644 .efivar.metadata create mode 100644 .gitignore create mode 100644 SOURCES/0001-Fix-abidw-output-for-missing-variadic-arguments.patch create mode 100644 SOURCES/0001-Fix-sys-block-sysfs-parsing-for-eMMC-s.patch create mode 100644 SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch create mode 100644 SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch create mode 100644 SOURCES/0003-linux-pci-root-remove-an-unused-assignment.patch create mode 100644 SOURCES/0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch create mode 100644 SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch create mode 100644 SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch create mode 100644 SOURCES/0007-Android-inital-porting-of-libefivar.patch create mode 100644 SOURCES/0008-Remove-an-unused-function.patch create mode 100644 SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch create mode 100644 SOURCES/0010-ucs2.h-remove-unused-variable.patch create mode 100644 SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch create mode 100644 SOURCES/0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch create mode 100644 SOURCES/0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch create mode 100644 SOURCES/0014-Add-more-hexdump-logging-functions.patch create mode 100644 SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch create mode 100644 SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch create mode 100644 SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch create mode 100644 SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch create mode 100644 SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch create mode 100644 SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch create mode 100644 SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch create mode 100644 SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch create mode 100644 SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch create mode 100644 SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch create mode 100644 SOURCES/0025-guids-add-grub-guid-for-grubenv.patch create mode 100644 SOURCES/0026-gcc.specs-add-grecord-gcc-switches.patch create mode 100644 SOURCES/0027-Makefile-don-t-echo-our-deps-submake-invocation.patch create mode 100644 SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch create mode 100644 SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch create mode 100644 SOURCES/0030-Local-header-whitespace-cleanup.patch create mode 100644 SOURCES/0031-Exported-header-whitespace-cleanup.patch create mode 100644 SOURCES/0032-Main-code-whitespace-cleanup.patch create mode 100644 SOURCES/0033-efivar-rework-usage.patch create mode 100644 SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch create mode 100644 SOURCES/0035-ucs2-document-things-a-little-better.patch create mode 100644 SOURCES/0036-util.h-implement-add-mul-sub-for-more-integer-types.patch create mode 100644 SOURCES/0037-Implement-efivar-export-foo.var.patch create mode 100644 SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch create mode 100644 SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch create mode 100644 SOURCES/0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch create mode 100644 SOURCES/0041-Makefile-sort-wildcard-output-for-reproducibility.patch create mode 100644 SOURCES/0042-guids.txt-correct-sentinal-typo.patch create mode 100644 SOURCES/0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch create mode 100644 SOURCES/0044-Fix-some-32-bit-size_t-format-specifier-errors.patch create mode 100644 SOURCES/0045-Make-the-top-level-makefile-not-parallelize.patch create mode 100644 SOURCES/0046-guids-add-auto_created_boot_option.patch create mode 100644 SOURCES/0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch create mode 100644 SOURCES/0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch create mode 100644 SOURCES/0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch create mode 100644 SOURCES/0050-Make-add-Wno-missing-field-initializers.patch create mode 100644 SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch create mode 100644 SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch create mode 100644 SOURCES/0053-gitignore-ignore-.strace.patch create mode 100644 SOURCES/0054-Fix-the-error-path-in-set_disk_and_part_name.patch create mode 100644 SOURCES/0055-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch create mode 100644 SOURCES/0056-Improve-consistency-of-debug-prints.patch create mode 100644 SOURCES/0057-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch create mode 100644 SOURCES/0058-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch create mode 100644 SOURCES/0059-Put-some-EFI-device-paths-into-the-debug-log.patch create mode 100644 SOURCES/0060-Update-abixml.patch create mode 100644 SOURCES/0061-Update-abixml-files-and-work-around-some-inconsequen.patch create mode 100644 SOURCES/0062-Don-t-use-march-native-on-ia64.patch create mode 100644 SOURCES/0063-Work-around-autoconf-existing-in-the-world.patch create mode 100644 SOURCES/0064-Fix-efivar-w-and-efivar-a.patch create mode 100644 SOURCES/0065-Android-fix-incorrect-include-path.patch create mode 100644 SOURCES/0066-Android-fix-missing-field-initializers.patch create mode 100644 SOURCES/0067-Fix-variable-sz-uninitialized-error.patch create mode 100644 SOURCES/0068-Fix-an-argument-mismatch-error.patch create mode 100644 SOURCES/0069-Android-fix-building-errors.patch create mode 100644 SOURCES/0070-Fix-the-MSDOS_MBR_MAGIC-type-not-the-format-string.patch create mode 100644 SOURCES/0071-Make-scan-build-and-CC-clang-work-again.patch create mode 100644 SOURCES/0072-Remove-a-dead-store.patch create mode 100644 SOURCES/0073-makeguids-confuse-ccc-analyzer-less.patch create mode 100644 SOURCES/0074-SPDX-ify-all-the-license-text-in-source-files.patch create mode 100644 SOURCES/0075-Makefile-minor-typo-fix.patch create mode 100644 SOURCES/0076-util.h-minor-whitespace-cleanup.patch create mode 100644 SOURCES/0077-util.h-make-strdupa-and-strndupa-pass-NULL-straight-.patch create mode 100644 SOURCES/0078-Update-travis-to-use-a-newer-distro.patch create mode 100644 SOURCES/efivar.patches create mode 100644 SPECS/efivar.spec diff --git a/.efivar.metadata b/.efivar.metadata new file mode 100644 index 0000000..aab069b --- /dev/null +++ b/.efivar.metadata @@ -0,0 +1 @@ +1ef24e0a06e1a42d7a93ba7a76b2970659c7c0c0 SOURCES/efivar-37.tar.bz2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54aaf3c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/efivar-37.tar.bz2 diff --git a/SOURCES/0001-Fix-abidw-output-for-missing-variadic-arguments.patch b/SOURCES/0001-Fix-abidw-output-for-missing-variadic-arguments.patch new file mode 100644 index 0000000..45d4769 --- /dev/null +++ b/SOURCES/0001-Fix-abidw-output-for-missing-variadic-arguments.patch @@ -0,0 +1,90 @@ +From e9b282cbd147eac515c53aa500720de3a43366f3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Tue, 27 Oct 2020 13:06:15 +0100 +Subject: [PATCH] Fix abidw output for missing variadic arguments +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +GCC forgets to add the varidic arguments into debugging data if the +compilation unit is built with -flto option. As a result, the prebuilt +XML ABI dumps were missing the last argument at 4 functions (e.g. +efi_error_set()). + +This was unnoticed until Fedora enabled LTO globally and had to +disable LTO in efivar explicitly because efivar uses symbol versioning +with top-level assembler statements which is not compatible with LTO. + +Since then the abicheck failed: + +make[2]: Leaving directory '/builddir/build/BUILD/efivar-37/src' +abidiff \ + --suppr abignore \ + --headers-dir2 /builddir/build/BUILD/efivar-37/src/include/efivar/ \ + libefivar.abixml \ + libefivar.so +Functions changes summary: 0 Removed, 2 Changed (8 filtered out), 0 Added functions +Variables changes summary: 0 Removed, 0 Changed, 0 Added variable +2 functions with some indirect sub-type change: + [C]'function int _efi_set_variable_variadic(efi_guid_t, const char*, uint8_t*, size_t, uint32_t)' at lib.c:44:1 has some indirect sub-type changes: + parameter 6 of type '...' was added + [C]'function int efi_error_set(const char*, const char*, int, int, const char*)' at error.c:86:1 has some indirect sub-type changes: + parameter 6 of type '...' was added +make[1]: *** [/builddir/build/BUILD/efivar-37/src/include/rules.mk:41: libefivar.abicheck] Error 4 +make[1]: Leaving directory '/builddir/build/BUILD/efivar-37/src' + +This patch corrects the pregenerated abixml files that were probably +generated with the faulty GCC. + + + + +Signed-off-by: Petr Písař +--- + src/libefiboot.abixml | 2 ++ + src/libefivar.abixml | 2 ++ + 2 files changed, 4 insertions(+) + +diff --git a/src/libefiboot.abixml b/src/libefiboot.abixml +index 4a0253b..ab75cbb 100644 +--- a/src/libefiboot.abixml ++++ b/src/libefiboot.abixml +@@ -1800,6 +1800,7 @@ + + + ++ + + + +@@ -1809,6 +1810,7 @@ + + + ++ + + + +diff --git a/src/libefivar.abixml b/src/libefivar.abixml +index a719b8b..2dbb838 100644 +--- a/src/libefivar.abixml ++++ b/src/libefivar.abixml +@@ -393,6 +393,7 @@ + + + ++ + + + +@@ -467,6 +468,7 @@ + + + ++ + + + +-- +2.25.4 + diff --git a/SOURCES/0001-Fix-sys-block-sysfs-parsing-for-eMMC-s.patch b/SOURCES/0001-Fix-sys-block-sysfs-parsing-for-eMMC-s.patch new file mode 100644 index 0000000..0b7c070 --- /dev/null +++ b/SOURCES/0001-Fix-sys-block-sysfs-parsing-for-eMMC-s.patch @@ -0,0 +1,55 @@ +From 54dad567c41b57c4843329856ca5047e63325a9f Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 22 Apr 2020 19:33:01 +0200 +Subject: [PATCH] Fix /sys/block sysfs parsing for eMMC-s + +Commit 471869409464 ("sysfs parsers: make all the /sys/block link +parsers work the same way") has broken sysfs parsing for eMMC-s when +the passed in path points to the whole block device. + +In that case pos2 will stay at its -1 initializaton value, because we +only do 4 conversions; and when we then do: + +current += pos2 + +We end up moving current one char position backwards and we end up +returning -1. + +The correct positing to use is always pos1 independent if we got +passed the whole disk; or a parition, as we always want to return +only the part which points to whole disk which ends at pos1. + +Note that it seems that before commit 471869409464, the case where +path points to the partition was likely broken as the old code then +would return the entire path including the partition element. + +BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1826864 +Signed-off-by: Hans de Goede +--- + src/linux-emmc.c | 9 +++------ + 1 file changed, 3 insertions(+), 6 deletions(-) + +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index 800dc14..65557b4 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -56,13 +56,10 @@ parse_emmc(struct device *dev, const char *path, const char *root UNUSED) + dev->emmc_info.slot_id = slot_id; + dev->interface_type = emmc; + +- if (rc == 6) { +- if (dev->part == -1) +- dev->part = partition; ++ if (rc == 6 && dev->part == -1) ++ dev->part = partition; + +- pos2 = pos1; +- } +- current += pos2; ++ current += pos1; + + debug("current:'%s' sz:%zd", current, current - path); + return current - path; +-- +2.26.0 + diff --git a/SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch b/SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch new file mode 100644 index 0000000..75e973b --- /dev/null +++ b/SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch @@ -0,0 +1,33 @@ +From cb0b1c30103abc17dbbed14210bbc59a73802206 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 10:30:23 -0500 +Subject: [PATCH 01/86] util.h: add unlikely() and likely() macros + +Signed-off-by: Peter Jones +--- + src/util.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/src/util.h b/src/util.h +index f63a8907611..ba8fee35ae9 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -52,6 +52,15 @@ + #define PACKED __attribute__((__packed__)) + #define VERSION(sym, ver) __asm__(".symver " # sym "," # ver) + ++#define __branch_check__(x, expect, is_constant) \ ++ __builtin_expect(!!(x), expect) ++#ifndef likely ++#define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x))) ++#endif ++#ifndef unlikely ++#define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x))) ++#endif ++ + /* + * I'm not actually sure when these appear, but they're present in the + * version in front of me. +-- +2.24.1 + diff --git a/SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch b/SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch new file mode 100644 index 0000000..4ef899c --- /dev/null +++ b/SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch @@ -0,0 +1,59 @@ +From b98ba8921010d03f46704a476c69861515deb1ca Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 10:30:59 -0500 +Subject: [PATCH 02/86] dp.h: make format_guid() handle misaligned guid + pointers safely. + +GCC 9 adds -Werror=address-of-packed-member, which causes us to see the +build error reported at + https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 . + +That bug report shows us the following: + +In file included from dp.c:26: +dp.h: In function 'format_vendor_helper': +dp.h:120:37: error: taking address of packed member of 'struct ' may result in an unaligned pointer value [-Werror=address-of-packed-member] + 120 | format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +dp.h:74:25: note: in definition of macro 'format_guid' + 74 | _rc = efi_guid_to_str(guid, &_guidstr); \ + | ^~~~ +cc1: all warnings being treated as errors + +This patch makes format_guid() use a local variable as a bounce buffer +in the case that the guid we're passed is aligned as chaotic neutral. + +Note that this only fixes this instance and there may be others that bz +didn't show because it exited too soon, and I don't have a gcc 9 build +in front of me right now. + +Signed-off-by: Peter Jones +--- + src/dp.h | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/src/dp.h b/src/dp.h +index aa4e3902992..20cb608d05f 100644 +--- a/src/dp.h ++++ b/src/dp.h +@@ -70,8 +70,15 @@ + #define format_guid(buf, size, off, dp_type, guid) ({ \ + int _rc; \ + char *_guidstr = NULL; \ +- \ +- _rc = efi_guid_to_str(guid, &_guidstr); \ ++ efi_guid_t _guid; \ ++ const efi_guid_t * const _guid_p = \ ++ likely(__alignof__(guid) == sizeof(guid)) \ ++ ? guid \ ++ : &_guid; \ ++ \ ++ if (unlikely(__alignof__(guid) == sizeof(guid))) \ ++ memmove(&_guid, guid, sizeof(_guid)); \ ++ _rc = efi_guid_to_str(_guid_p, &_guidstr); \ + if (_rc < 0) { \ + efi_error("could not build %s GUID DP string", \ + dp_type); \ +-- +2.24.1 + diff --git a/SOURCES/0003-linux-pci-root-remove-an-unused-assignment.patch b/SOURCES/0003-linux-pci-root-remove-an-unused-assignment.patch new file mode 100644 index 0000000..292589e --- /dev/null +++ b/SOURCES/0003-linux-pci-root-remove-an-unused-assignment.patch @@ -0,0 +1,27 @@ +From 8f803791a1c97a4d1bce049264218a94c46d7838 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 11:32:41 -0500 +Subject: [PATCH 03/86] linux-pci-root: remove an unused assignment + +scan-build gripes about this, and it's pointless, so it can go. + +Signed-off-by: Peter Jones +--- + src/linux-pci-root.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index a2d9fb04a11..5d1df06119d 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -115,7 +115,6 @@ dp_create_pci_root(struct device *dev UNUSED, + return new; + } + } +- off += new; + sz += new; + + debug("returning %zd", sz); +-- +2.24.1 + diff --git a/SOURCES/0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch b/SOURCES/0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch new file mode 100644 index 0000000..cf3b363 --- /dev/null +++ b/SOURCES/0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch @@ -0,0 +1,172 @@ +From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Feb 2019 15:20:12 -0500 +Subject: [PATCH 04/86] Fix all the places -Werror=address-of-packed-member + catches. + +This gets rid of all the places GCC 9's -Werror=address-of-packed-member +flags as problematic. + +Fixes github issue #123 + +Signed-off-by: Peter Jones +--- + src/dp-message.c | 6 ++++-- + src/dp.h | 12 ++++-------- + src/guid.c | 2 +- + src/include/efivar/efivar.h | 2 +- + src/ucs2.h | 27 +++++++++++++++++++-------- + 5 files changed, 29 insertions(+), 20 deletions(-) + +diff --git a/src/dp-message.c b/src/dp-message.c +index 3724e5f57bd..9f964663de8 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) + ) / sizeof(efi_ip_addr_t); + format(buf, size, off, "Dns", "Dns("); + for (int i=0; i < end; i++) { +- const efi_ip_addr_t *addr = &dp->dns.addrs[i]; ++ efi_ip_addr_t addr; ++ ++ memcpy(&addr, &dp->dns.addrs[i], sizeof(addr)); + if (i != 0) + format(buf, size, off, "Dns", ","); + format_ip_addr(buf, size, off, "Dns", +- dp->dns.is_ipv6, addr); ++ dp->dns.is_ipv6, &addr); + } + format(buf, size, off, "Dns", ")"); + break; +diff --git a/src/dp.h b/src/dp.h +index 20cb608d05f..1f921d524aa 100644 +--- a/src/dp.h ++++ b/src/dp.h +@@ -71,13 +71,9 @@ + int _rc; \ + char *_guidstr = NULL; \ + efi_guid_t _guid; \ +- const efi_guid_t * const _guid_p = \ +- likely(__alignof__(guid) == sizeof(guid)) \ +- ? guid \ +- : &_guid; \ +- \ +- if (unlikely(__alignof__(guid) == sizeof(guid))) \ +- memmove(&_guid, guid, sizeof(_guid)); \ ++ const efi_guid_t * const _guid_p = &_guid; \ ++ \ ++ memmove(&_guid, guid, sizeof(_guid)); \ + _rc = efi_guid_to_str(_guid_p, &_guidstr); \ + if (_rc < 0) { \ + efi_error("could not build %s GUID DP string", \ +@@ -86,7 +82,7 @@ + _guidstr = onstack(_guidstr, \ + strlen(_guidstr)+1); \ + _rc = format(buf, size, off, dp_type, "%s", \ +- _guidstr); \ ++ _guidstr); \ + } \ + _rc; \ + }) +diff --git a/src/guid.c b/src/guid.c +index 306c9ff8287..3156b3b7c60 100644 +--- a/src/guid.c ++++ b/src/guid.c +@@ -31,7 +31,7 @@ + extern const efi_guid_t efi_guid_zero; + + int NONNULL(1, 2) PUBLIC +-efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b) ++efi_guid_cmp(const void * const a, const void * const b) + { + return memcmp(a, b, sizeof (efi_guid_t)); + } +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 316891ccae9..ad6449d9d93 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid) + + extern int efi_guid_is_zero(const efi_guid_t *guid); + extern int efi_guid_is_empty(const efi_guid_t *guid); +-extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b); ++extern int efi_guid_cmp(const void * const a, const void * const b); + + /* import / export functions */ + typedef struct efi_variable efi_variable_t; +diff --git a/src/ucs2.h b/src/ucs2.h +index dbb59004b7c..edd8367b4bc 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -23,16 +23,21 @@ + (((val) & ((mask) << (shift))) >> (shift)) + + static inline size_t UNUSED +-ucs2len(const uint16_t * const s, ssize_t limit) ++ucs2len(const void *vs, ssize_t limit) + { + ssize_t i; +- for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++) ++ const uint16_t *s = vs; ++ const uint8_t *s8 = vs; ++ ++ for (i = 0; ++ i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; ++ i++, s8 += 2, s++) + ; + return i; + } + + static inline size_t UNUSED +-ucs2size(const uint16_t * const s, ssize_t limit) ++ucs2size(const void *s, ssize_t limit) + { + size_t rc = ucs2len(s, limit); + rc *= sizeof (uint16_t); +@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit) + } + + static inline unsigned char * UNUSED +-ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) ++ucs2_to_utf8(const void * const voidchars, ssize_t limit) + { + ssize_t i, j; + unsigned char *ret; ++ const uint16_t * const chars = voidchars; + + if (limit < 0) + limit = ucs2len(chars, -1); +@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) + } + + static inline ssize_t UNUSED NONNULL(4) +-utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) ++utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8) + { + ssize_t req; + ssize_t i, j; ++ uint16_t *ucs2 = ucs2void; ++ uint16_t val16; + + if (!ucs2 && size > 0) { + errno = EINVAL; +@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) + val = utf8[i] & 0x7f; + i += 1; + } +- ucs2[j] = val; ++ val16 = val; ++ ucs2[j] = val16; ++ } ++ if (terminate) { ++ val16 = 0; ++ ucs2[j++] = val16; + } +- if (terminate) +- ucs2[j++] = (uint16_t)0; + return j; + }; + +-- +2.24.1 + diff --git a/SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch b/SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch new file mode 100644 index 0000000..e5f3f45 --- /dev/null +++ b/SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch @@ -0,0 +1,372 @@ +From e39fb5b9e590c6616459c15b5d95fbc09fb077d6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Feb 2019 15:26:23 -0500 +Subject: [PATCH 05/86] Get rid of the arrows in our debug messages. + +They're not *that* useful, and the code is clever and problematic. + +Resolves github issue #124 + +Signed-off-by: Peter Jones +--- + src/linux-acpi-root.c | 7 ------- + src/linux-emmc.c | 9 --------- + src/linux-md.c | 8 -------- + src/linux-nvme.c | 9 --------- + src/linux-pci-root.c | 7 ------- + src/linux-pci.c | 8 -------- + src/linux-sata.c | 11 ----------- + src/linux-scsi.c | 24 ------------------------ + src/linux-soc-root.c | 7 ------- + src/linux-virtblk.c | 8 -------- + src/util.h | 1 - + 11 files changed, 99 deletions(-) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 06e69eebe78..30728ded671 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -51,13 +51,6 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + char *colon; + + const char *devpart = current; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index 87e92477554..b290ed0a2bd 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -50,13 +50,6 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + int rc; + int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition; + int pos0 = 0, pos1 = 0; +- char *spaces; +- +- pos0 = strlen(current); +- spaces = alloca(pos0+1); +- memset(spaces, ' ', pos0+1); +- spaces[pos0] = '\0'; +- pos0 = 0; + + debug("entry"); + +@@ -65,8 +58,6 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + &tosser0, &tosser1, &tosser2, &slot_id, + &pos0, &tosser3, &partition, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 4); +- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 6); + /* + * If it isn't of that form, it's not one of our emmc devices. + */ +diff --git a/src/linux-md.c b/src/linux-md.c +index 0a5c1cdb435..cb584c96c4b 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -44,13 +44,6 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED) + int rc; + int32_t md, tosser0, part; + int pos0 = 0, pos1 = 0; +- char *spaces; +- +- pos0 = strlen(current); +- spaces = alloca(pos0+1); +- memset(spaces, ' ', pos0+1); +- spaces[pos0] = '\0'; +- pos0 = 0; + + debug("entry"); + +@@ -58,7 +51,6 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED) + rc = sscanf(current, "md%d/%nmd%dp%d%n", + &md, &pos0, &tosser0, &part, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); + /* + * If it isn't of that form, it's not one of our partitioned md devices. + */ +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index d68d11a3409..1d8fc654f76 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -54,13 +54,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; + uint8_t *filebuf = NULL; + int pos0 = 0, pos1 = 0; +- char *spaces; +- +- pos0 = strlen(current); +- spaces = alloca(pos0+1); +- memset(spaces, ' ', pos0+1); +- spaces[pos0] = '\0'; +- pos0 = 0; + + debug("entry"); + +@@ -69,8 +62,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + &tosser0, &ctrl_id, &ns_id, &pos0, + &tosser1, &tosser2, &partition, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); +- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 6); + /* + * If it isn't of that form, it's not one of our nvme devices. + */ +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index 5d1df06119d..0605acfc7cb 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -48,13 +48,6 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + uint16_t root_domain; + uint8_t root_bus; + const char *devpart = current; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + +diff --git a/src/linux-pci.c b/src/linux-pci.c +index f63f5914d9f..64aaefb461c 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -48,13 +48,6 @@ parse_pci(struct device *dev, const char *current, const char *root) + int rc; + int pos; + const char *devpart = current; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + +@@ -75,7 +68,6 @@ parse_pci(struct device *dev, const char *current, const char *root) + rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", + &domain, &bus, &device, &function, &pos); + debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3); + if (rc != 4) + break; + devpart += pos; +diff --git a/src/linux-sata.c b/src/linux-sata.c +index 85265022f89..356411724bb 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -148,13 +148,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + uint64_t scsi_lun, tosser3; + int pos = 0; + int rc; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + if (is_pata(dev)) { +@@ -169,7 +162,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + debug("searching for ata1/"); + rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1); + /* + * If we don't find this one, it isn't an ata device, so return 0 not + * error. Later errors mean it is an ata device, but we can't parse +@@ -183,7 +175,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + debug("searching for host0/"); + rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1); + if (rc != 1) + return -1; + current += pos; +@@ -193,7 +184,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", + &scsi_device, &scsi_target, &scsi_lun, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3); + if (rc != 3) + return -1; + current += pos; +@@ -203,7 +193,6 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", + &tosser0, &tosser1, &tosser2, &tosser3, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 4); + if (rc != 4) + return -1; + current += pos; +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index a5e81cf9cb6..04892f02b4e 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -45,13 +45,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + int rc; + int sz = 0; + int pos0 = 0, pos1 = 0; +- char *spaces; +- +- sz = strlen(current); +- spaces = alloca(sz+1); +- memset(spaces, ' ', sz+1); +- spaces[sz] = '\0'; +- sz = 0; + + debug("entry"); + /* +@@ -108,7 +101,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for host4/"); + rc = sscanf(current, "host%d/%n", scsi_host, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 1); + if (rc != 1) + return -1; + sz += pos0; +@@ -126,8 +118,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0, + &tosser1, &pos0, &tosser2, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); +- arrow(LOG_DEBUG, spaces, 9, pos1, rc, 3); + if (rc == 2 || rc == 3) { + sz += pos0; + pos0 = 0; +@@ -153,7 +143,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for expander-4:0/"); + rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); + if (rc == 2) { + if (!remote_target_id) { + efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); +@@ -169,7 +158,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for port-2:0:2/"); + rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); + if (rc != 3) { + efi_error("Couldn't parse port expander port string"); + return -1; +@@ -192,8 +180,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + + pos1 = 0; + rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc + 2, 2); +- arrow(LOG_DEBUG, spaces, 9, pos0 + pos1, rc + 2, 3); + if (rc != 0 && rc != 1) + return -1; + if (remote_port_id && rc == 1) +@@ -217,7 +203,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, + &tosser3, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); + if (rc != 3) + return -1; + sz += pos0; +@@ -230,7 +215,6 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", + scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 4); + if (rc != 4) + return -1; + sz += pos0; +@@ -247,13 +231,6 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + ssize_t sz; + int pos; + int rc; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + +@@ -265,7 +242,6 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + &dev->scsi_info.scsi_lun, + &pos); + debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 3); + if (rc != 4) + return 0; + +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index 394f496a453..373cd59521a 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -43,13 +43,6 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root + int rc; + int pos; + const char *devpart = current; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index c54a813a947..2e9889def2f 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -50,20 +50,12 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + uint32_t tosser; + int pos; + int rc; +- char *spaces; +- +- pos = strlen(current); +- spaces = alloca(pos+1); +- memset(spaces, ' ', pos+1); +- spaces[pos] = '\0'; +- pos = 0; + + debug("entry"); + + debug("searching for virtio0/"); + rc = sscanf(current, "virtio%x/%n", &tosser, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- arrow(LOG_DEBUG, spaces, 9, pos, rc, 1); + /* + * If we couldn't find virtioX/ then it isn't a virtio device. + */ +diff --git a/src/util.h b/src/util.h +index ba8fee35ae9..6d3c10e946e 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -388,7 +388,6 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + #undef log + #endif + #define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args) +-#define arrow(l,b,o,p,n,m) ({if(n==m){char c_=b[p+1]; b[o]='^'; b[p+o]='^';b[p+o+1]='\0';log(l,"%s",b);b[o]=' ';b[p+o]=' ';b[p+o+1]=c_;}}) + #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args) + + #endif /* EFIVAR_UTIL_H */ +-- +2.24.1 + diff --git a/SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch b/SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch new file mode 100644 index 0000000..17c27bd --- /dev/null +++ b/SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch @@ -0,0 +1,38 @@ +From 25d73605b36933004b0266183de8051af30612ca Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Thu, 10 Jan 2019 16:44:38 +0800 +Subject: [PATCH 06/86] Define strdupa if it is not defined + +Android does not include strdupa in . Define strdupa if it has +not already been defined. + +Signed-off-by: Chih-Wei Huang +--- + src/util.h | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/src/util.h b/src/util.h +index 6d3c10e946e..d98bfa1beed 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -252,6 +252,17 @@ lcm(uint64_t x, uint64_t y) + return (x / n) * y; + } + ++#ifndef strdupa ++#define strdupa(s) \ ++ (__extension__ ({ \ ++ const char *__in = (s); \ ++ size_t __len = strlen (__in); \ ++ char *__out = (char *) alloca (__len + 1); \ ++ strcpy(__out, __in); \ ++ __out; \ ++ })) ++#endif ++ + #ifndef strndupa + #define strndupa(s, l) \ + (__extension__ ({ \ +-- +2.24.1 + diff --git a/SOURCES/0007-Android-inital-porting-of-libefivar.patch b/SOURCES/0007-Android-inital-porting-of-libefivar.patch new file mode 100644 index 0000000..5b56a26 --- /dev/null +++ b/SOURCES/0007-Android-inital-porting-of-libefivar.patch @@ -0,0 +1,82 @@ +From 1a0ea5da82d8be7d05338bb42e8e71cdba7866f4 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Thu, 10 Jan 2019 16:48:30 +0800 +Subject: [PATCH 07/86] Android: inital porting of libefivar + +The static library is linked by efibootmgr. + +Signed-off-by: Chih-Wei Huang +--- + src/Android.mk | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 60 insertions(+) + create mode 100644 src/Android.mk + +diff --git a/src/Android.mk b/src/Android.mk +new file mode 100644 +index 00000000000..b3410e1f3e7 +--- /dev/null ++++ b/src/Android.mk +@@ -0,0 +1,60 @@ ++# ++# Copyright (C) 2019 The Android-x86 Open Source Project ++# ++# Licensed under the GNU Lesser General Public License Version 2.1. ++# You may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# https://www.gnu.org/licenses/lgpl-2.1.html ++# ++ ++LOCAL_PATH := $(call my-dir) ++ ++include $(CLEAR_VARS) ++ ++LOCAL_MODULE := makeguids ++LOCAL_C_INCLUDES := $(LOCAL_PATH)/include ++LOCAL_CFLAGS := -DEFIVAR_BUILD_ENVIRONMENT ++LOCAL_SRC_FILES := guid.c makeguids.c ++LOCAL_LDLIBS := -ldl ++include $(BUILD_HOST_EXECUTABLE) ++ ++include $(CLEAR_VARS) ++ ++LOCAL_MODULE := libefivar ++LOCAL_MODULE_CLASS := STATIC_LIBRARIES ++LIBEFIBOOT_SOURCES := \ ++ crc32.c \ ++ creator.c \ ++ disk.c \ ++ gpt.c \ ++ loadopt.c \ ++ path-helpers.c \ ++ $(notdir $(wildcard $(LOCAL_PATH)/linux*.c)) ++ ++LIBEFIVAR_SOURCES := \ ++ dp.c \ ++ dp-acpi.c \ ++ dp-hw.c \ ++ dp-media.c \ ++ dp-message.c \ ++ efivarfs.c \ ++ error.c \ ++ export.c \ ++ guid.c \ ++ guids.S \ ++ lib.c \ ++ vars.c ++ ++LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) ++LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 ++LOCAL_C_INCLUDES := $(LOCAL_PATH)/include ++LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES)/efivar $(local-generated-sources-dir) ++LIBEFIVAR_GUIDS_H := $(local-generated-sources-dir)/efivar/efivar-guids.h ++LOCAL_GENERATED_SOURCES := $(LIBEFIVAR_GUIDS_H) $(local-generated-sources-dir)/guid-symbols.c ++$(LIBEFIVAR_GUIDS_H): PRIVATE_CUSTOM_TOOL = $^ $(addprefix $(dir $(@D)),guids.bin names.bin guid-symbols.c efivar/efivar-guids.h) ++$(LIBEFIVAR_GUIDS_H): $(BUILD_OUT_EXECUTABLES)/makeguids $(LOCAL_PATH)/guids.txt ++ $(transform-generated-source) ++$(lastword $(LOCAL_GENERATED_SOURCES)): $(LIBEFIVAR_GUIDS_H) ++ ++include $(BUILD_STATIC_LIBRARY) +-- +2.24.1 + diff --git a/SOURCES/0008-Remove-an-unused-function.patch b/SOURCES/0008-Remove-an-unused-function.patch new file mode 100644 index 0000000..affe9c2 --- /dev/null +++ b/SOURCES/0008-Remove-an-unused-function.patch @@ -0,0 +1,40 @@ +From 22da79a45a0c3a1437255c813b0b86a7b7925ae3 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Tue, 26 Feb 2019 14:57:00 +0800 +Subject: [PATCH 08/86] Remove an unused function + +This gets rid of an error from Android 9 clang: + +external/efivar/src/linux.c:256:1: error: unused function 'supports_iface' [-Werror,-Wunused-function] +supports_iface(struct dev_probe *probe, enum interface_type iftype) +^ +1 error generated. + +Signed-off-by: Chih-Wei Huang +--- + src/linux.c | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/src/linux.c b/src/linux.c +index 6d405af8a76..4bb453be834 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -252,15 +252,6 @@ static struct dev_probe *dev_probes[] = { + NULL + }; + +-static inline bool +-supports_iface(struct dev_probe *probe, enum interface_type iftype) +-{ +- for (unsigned int i = 0; probe->iftypes[i] != unknown; i++) +- if (probe->iftypes[i] == iftype) +- return true; +- return false; +-} +- + void HIDDEN + device_free(struct device *dev) + { +-- +2.24.1 + diff --git a/SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch b/SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch new file mode 100644 index 0000000..428212e --- /dev/null +++ b/SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch @@ -0,0 +1,54 @@ +From 0dad6d78a7fb5f6c5fb4a1d646040539db6cf865 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Tue, 26 Feb 2019 18:42:20 +0800 +Subject: [PATCH 09/86] Fix another error of -Werror=address-of-packed-member + +Android 9 clang complains: + +external/efivar/src/dp-message.c:367:24: error: taking address of packed member '' of class or structure 'efidp_infiniband' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] + (efi_guid_t *)&dp->infiniband.ioc_guid); + ^~~~~~~~~~~~~~~~~~~~~~~ +external/efivar/src/dp.h:76:19: note: expanded from macro 'format_guid' + memmove(&_guid, guid, sizeof(_guid)); \ + ^~~~ +1 error generated. + +Since commit c3c553d the fifth parameter of format_guid() is treated as +a const void *. The casting is unnecessary. + +Signed-off-by: Chih-Wei Huang +--- + src/dp-media.c | 3 +-- + src/dp-message.c | 2 +- + 2 files changed, 2 insertions(+), 3 deletions(-) + +diff --git a/src/dp-media.c b/src/dp-media.c +index 96a576fdc2a..be691c44326 100644 +--- a/src/dp-media.c ++++ b/src/dp-media.c +@@ -46,8 +46,7 @@ _format_media_dn(char *buf, size_t size, const_efidp dp) + break; + case EFIDP_HD_SIGNATURE_GUID: + format(buf, size, off, "HD", "GPT,"); +- format_guid(buf, size, off, "HD", +- (efi_guid_t *)dp->hd.signature); ++ format_guid(buf, size, off, "HD", dp->hd.signature); + format(buf, size, off, "HD", + ",0x%"PRIx64",0x%"PRIx64")", + dp->hd.start, dp->hd.size); +diff --git a/src/dp-message.c b/src/dp-message.c +index 9f964663de8..6b8e9072594 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -364,7 +364,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) + dp->infiniband.port_gid[1], + dp->infiniband.port_gid[0]); + format_guid(buf, size, off, "Infiniband", +- (efi_guid_t *)&dp->infiniband.ioc_guid); ++ &dp->infiniband.ioc_guid); + format(buf, size, off, "Infiniband", + ",%"PRIu64",%"PRIu64")", + dp->infiniband.target_port_id, +-- +2.24.1 + diff --git a/SOURCES/0010-ucs2.h-remove-unused-variable.patch b/SOURCES/0010-ucs2.h-remove-unused-variable.patch new file mode 100644 index 0000000..6fd8f52 --- /dev/null +++ b/SOURCES/0010-ucs2.h-remove-unused-variable.patch @@ -0,0 +1,34 @@ +From fdb803402fb32fa6d020bac57a40c7efe4aabb7d Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:24 +0100 +Subject: [PATCH 10/86] ucs2.h: remove unused variable + +The const uint16_t pointer is not used since now the two bytes of the +UCS-2 chars are checked to know if is the termination of the string. + +Signed-off-by: Javier Martinez Canillas +--- + src/ucs2.h | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/src/ucs2.h b/src/ucs2.h +index edd8367b4bc..e0390c34985 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -26,12 +26,11 @@ static inline size_t UNUSED + ucs2len(const void *vs, ssize_t limit) + { + ssize_t i; +- const uint16_t *s = vs; + const uint8_t *s8 = vs; + + for (i = 0; + i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; +- i++, s8 += 2, s++) ++ i++, s8 += 2) + ; + return i; + } +-- +2.24.1 + diff --git a/SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch b/SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch new file mode 100644 index 0000000..ca9b93c --- /dev/null +++ b/SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch @@ -0,0 +1,32 @@ +From 4e04afc2df9bbc26e5ab524b53a6f4f1e61d7c9e Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:32 +0100 +Subject: [PATCH 11/86] ucs2.h: fix logic that checks for UCS-2 string + termination + +Currently the loop to count the lenght of the UCS-2 string ends if either +of the two bytes are 0, but 0 is a valid value for UCS-2 character codes. + +So only break the loop when 0 is the value for both UCS-2 char bytes. + +Signed-off-by: Javier Martinez Canillas +--- + src/ucs2.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/ucs2.h b/src/ucs2.h +index e0390c34985..fd8b056ad25 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -29,7 +29,7 @@ ucs2len(const void *vs, ssize_t limit) + const uint8_t *s8 = vs; + + for (i = 0; +- i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; ++ i < (limit >= 0 ? limit : i+1) && !(s8[0] == 0 && s8[1] == 0); + i++, s8 += 2) + ; + return i; +-- +2.24.1 + diff --git a/SOURCES/0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch b/SOURCES/0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch new file mode 100644 index 0000000..57cd35d --- /dev/null +++ b/SOURCES/0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch @@ -0,0 +1,44 @@ +From 836461e480e2249de134efeaef79588cab045d5c Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:36 +0100 +Subject: [PATCH 12/86] dp-message: fix efidp_ipv4_addr fields assignment + +The efidp_ipv4_addr structure has some 4-byte array fields to store IPv4 +addresses and network mask. But the efidp_make_ipv4() function wrongly +casts these as a char * before dereferencing them to store a value. + +Instead, cast it to a uint32_t * so the 32-bit value is correctly stored. + +Signed-off-by: Javier Martinez Canillas +--- + src/dp-message.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/dp-message.c b/src/dp-message.c +index 6b8e9072594..55fa7810439 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -678,16 +678,16 @@ efidp_make_ipv4(uint8_t *buf, ssize_t size, uint32_t local, uint32_t remote, + EFIDP_MSG_IPv4, sizeof (*ipv4)); + ssize_t req = sizeof (*ipv4); + if (size && sz == req) { +- *((char *)ipv4->local_ipv4_addr) = htonl(local); +- *((char *)ipv4->remote_ipv4_addr) = htonl(remote); ++ *((uint32_t *)ipv4->local_ipv4_addr) = htonl(local); ++ *((uint32_t *)ipv4->remote_ipv4_addr) = htonl(remote); + ipv4->local_port = htons(local_port); + ipv4->remote_port = htons(remote_port); + ipv4->protocol = htons(protocol); + ipv4->static_ip_addr = 0; + if (is_static) + ipv4->static_ip_addr = 1; +- *((char *)ipv4->gateway) = htonl(gateway); +- *((char *)ipv4->netmask) = htonl(netmask); ++ *((uint32_t *)ipv4->gateway) = htonl(gateway); ++ *((uint32_t *)ipv4->netmask) = htonl(netmask); + } + + if (sz < 0) +-- +2.24.1 + diff --git a/SOURCES/0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch b/SOURCES/0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch new file mode 100644 index 0000000..0a914f8 --- /dev/null +++ b/SOURCES/0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch @@ -0,0 +1,129 @@ +From 038afd7a792df5d882d4ca29cc6f9723f3c3fc0f Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2019 11:01:34 -0400 +Subject: [PATCH 13/86] Always refer to MBR and GPT fixed values as 'magic' not + 'signature' + +Signed-off-by: Peter Jones +--- + src/disk.c | 5 +++-- + src/gpt.c | 22 +++++++++++----------- + src/gpt.h | 8 ++++---- + 3 files changed, 18 insertions(+), 17 deletions(-) + +diff --git a/src/disk.c b/src/disk.c +index 3efee03b804..519c2a19325 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -52,10 +52,11 @@ is_mbr_valid(legacy_mbr *mbr) + int ret; + if (!mbr) + return 0; +- ret = (mbr->signature == MSDOS_MBR_SIGNATURE); ++ ret = (mbr->magic == MSDOS_MBR_MAGIC); + if (!ret) { + errno = ENOTTY; +- efi_error("mbr signature is not MSDOS_MBR_SIGNATURE"); ++ efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04hx)", ++ mbr->magic, MSDOS_MBR_MAGIC); + } + return ret; + } +diff --git a/src/gpt.c b/src/gpt.c +index ce8e638ab83..7bdb8ad1575 100644 +--- a/src/gpt.c ++++ b/src/gpt.c +@@ -72,24 +72,24 @@ efi_crc32(const void *buf, unsigned long len) + * + * Description: Returns 1 if PMBR is valid, 0 otherwise. + * Validity depends on two things: +- * 1) MSDOS signature is in the last two bytes of the MBR ++ * 1) MSDOS magic is in the last two bytes of the MBR + * 2) One partition of type 0xEE is found + */ + static int + is_pmbr_valid(legacy_mbr *mbr) + { +- int i, found = 0, signature = 0; ++ int i, found = 0, magic = 0; + if (!mbr) + return 0; +- signature = (le16_to_cpu(mbr->signature) == MSDOS_MBR_SIGNATURE); +- for (i = 0; signature && i < 4; i++) { ++ magic = (le16_to_cpu(mbr->magic) == MSDOS_MBR_MAGIC); ++ for (i = 0; magic && i < 4; i++) { + if (mbr->partition[i].os_type == + EFI_PMBR_OSTYPE_EFI_GPT) { + found = 1; + break; + } + } +- return (signature && found); ++ return (magic && found); + } + + /** +@@ -389,11 +389,11 @@ is_gpt_valid(int fd, uint64_t lba, + if (!(*gpt = alloc_read_gpt_header(fd, lba))) + return 0; + +- /* Check the GUID Partition Table signature */ +- if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) { +- efi_error("GUID Partition Table Header signature is wrong: %"PRIx64" != %"PRIx64, +- (uint64_t)le64_to_cpu((*gpt)->signature), +- GPT_HEADER_SIGNATURE); ++ /* Check the GUID Partition Table magic */ ++ if (le64_to_cpu((*gpt)->magic) != GPT_HEADER_MAGIC) { ++ efi_error("GUID Partition Table Header magic is wrong: %"PRIx64" != %"PRIx64, ++ (uint64_t)le64_to_cpu((*gpt)->magic), ++ GPT_HEADER_MAGIC); + free(*gpt); + *gpt = NULL; + return rc; +@@ -673,7 +673,7 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes, + + /* Would fail due to bad PMBR, but force GPT anyhow */ + if ((good_pgpt || good_agpt) && !good_pmbr && ignore_pmbr_err) { +- efi_error(" Warning: Disk has a valid GPT signature but invalid PMBR.\n" ++ efi_error(" Warning: Disk has a valid GPT magic but invalid PMBR.\n" + " Use GNU Parted to correct disk.\n" + " gpt option taken, disk treated as GPT."); + } +diff --git a/src/gpt.h b/src/gpt.h +index 5eb5d1a732c..0d7d5e8a649 100644 +--- a/src/gpt.h ++++ b/src/gpt.h +@@ -29,10 +29,10 @@ + + #define EFI_PMBR_OSTYPE_EFI 0xEF + #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE +-#define MSDOS_MBR_SIGNATURE 0xaa55 ++#define MSDOS_MBR_MAGIC 0xaa55 + #define GPT_BLOCK_SIZE 512 + +-#define GPT_HEADER_SIGNATURE ((uint64_t)(0x5452415020494645ULL)) ++#define GPT_HEADER_MAGIC ((uint64_t)(0x5452415020494645ULL)) + #define GPT_HEADER_REVISION_V1_02 0x00010200 + #define GPT_HEADER_REVISION_V1_00 0x00010000 + #define GPT_HEADER_REVISION_V0_99 0x00009900 +@@ -61,7 +61,7 @@ + 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28) + + typedef struct _gpt_header { +- uint64_t signature; ++ uint64_t magic; + uint32_t revision; + uint32_t header_size; + uint32_t header_crc32; +@@ -133,7 +133,7 @@ typedef struct _legacy_mbr { + uint32_t unique_mbr_signature; + uint16_t unknown; + partition_record partition[4]; +- uint16_t signature; ++ uint16_t magic; + } PACKED legacy_mbr; + + #define EFI_GPT_PRIMARY_PARTITION_TABLE_LBA 1 +-- +2.24.1 + diff --git a/SOURCES/0014-Add-more-hexdump-logging-functions.patch b/SOURCES/0014-Add-more-hexdump-logging-functions.patch new file mode 100644 index 0000000..243b566 --- /dev/null +++ b/SOURCES/0014-Add-more-hexdump-logging-functions.patch @@ -0,0 +1,87 @@ +From 48910a0cd39d7c08dab555fb464f9765163ad37b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2019 11:02:01 -0400 +Subject: [PATCH 14/86] Add more hexdump logging functions. + +Signed-off-by: Peter Jones +--- + src/hexdump.h | 30 ++++++++++++++++++++++++++++-- + src/util.h | 10 ++++++++++ + 2 files changed, 38 insertions(+), 2 deletions(-) + +diff --git a/src/hexdump.h b/src/hexdump.h +index 4c45cb3732d..f8c32faa9e1 100644 +--- a/src/hexdump.h ++++ b/src/hexdump.h +@@ -63,8 +63,12 @@ prepare_text(uint8_t *data, unsigned long size, char *buf) + buf[offset] = '\0'; + } + ++/* ++ * variadic fhexdump formatted ++ * think of it as: fprintf(f, %s%s\n", vformat(fmt, ap), hexdump(data,size)); ++ */ + static inline void UNUSED +-hexdump(uint8_t *data, unsigned long size) ++vfhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, va_list ap) + { + unsigned long display_offset = (unsigned long)data & 0xffffffff; + unsigned long offset = 0; +@@ -80,11 +84,33 @@ hexdump(uint8_t *data, unsigned long size) + return; + + prepare_text(data+offset, size-offset, txtbuf); +- printf("%016lx %s %s\n", display_offset, hexbuf, txtbuf); ++ vfprintf(f, fmt, ap); ++ fprintf(f, "%016lx %s %s\n", display_offset, hexbuf, txtbuf); + + display_offset += sz; + offset += sz; + } ++ fflush(f); ++} ++ ++/* ++ * fhexdump formatted ++ * think of it as: fprintf(f, %s%s\n", format(fmt, ...), hexdump(data,size)); ++ */ ++static inline void UNUSED ++fhexdumpf(FILE *f, const char * const fmt, uint8_t *data, unsigned long size, ...) ++{ ++ va_list ap; ++ ++ va_start(ap, size); ++ vfhexdumpf(f, fmt, data, size, ap); ++ va_end(ap); ++} ++ ++static inline void UNUSED ++hexdump(uint8_t *data, unsigned long size) ++{ ++ fhexdumpf(stdout, "", data, size); + } + + #endif /* STATIC_HEXDUMP_H */ +diff --git a/src/util.h b/src/util.h +index d98bfa1beed..a6a80e754ec 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -400,5 +400,15 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + #endif + #define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args) + #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args) ++#define log_hex_(file, line, func, level, buf, size) \ ++ ({ \ ++ if (efi_get_verbose() >= level) { \ ++ fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ ++ (uint8_t *)buf, size, \ ++ file, line, func); \ ++ } \ ++ }) ++#define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size) ++#define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size) + + #endif /* EFIVAR_UTIL_H */ +-- +2.24.1 + diff --git a/SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch b/SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch new file mode 100644 index 0000000..9c25efd --- /dev/null +++ b/SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch @@ -0,0 +1,147 @@ +From 2b34ea97db8e42e2461981d812dd5e71b12f09c1 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 14:02:12 -0400 +Subject: [PATCH 15/86] Add efi_error_pop() and pop some errors sometimes. + +Signed-off-by: Peter Jones +--- + src/error.c | 37 +++++++++++++++++++++++++++++-------- + src/include/efivar/efivar.h | 9 +++++++++ + src/libefivar.map.in | 7 +++++++ + src/linux.c | 4 ++++ + 4 files changed, 49 insertions(+), 8 deletions(-) + +diff --git a/src/error.c b/src/error.c +index d1008a3d676..df03d7f45e0 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -78,6 +78,22 @@ efi_error_get(unsigned int n, + return 1; + } + ++static inline UNUSED void ++clear_error_entry(error_table_entry *et) ++{ ++ if (!et) ++ return; ++ ++ if (et->filename) ++ free(et->filename); ++ if (et->function) ++ free(et->function); ++ if (et->message) ++ free(et->message); ++ ++ memset(et, '\0', sizeof(*et)); ++} ++ + int PUBLIC NONNULL(1, 2, 5) PRINTF(5, 6) + efi_error_set(const char *filename, + const char *function, +@@ -136,6 +152,16 @@ err: + return -1; + } + ++void PUBLIC ++efi_error_pop(void) ++{ ++ if (current <= 0) ++ return; ++ ++ current -= 1; ++ clear_error_entry(&error_table[current]); ++} ++ + void PUBLIC DESTRUCTOR + efi_error_clear(void) + { +@@ -143,14 +169,7 @@ efi_error_clear(void) + for (unsigned int i = 0; i < current; i++) { + error_table_entry *et = &error_table[i]; + +- if (et->filename) +- free(et->filename); +- if (et->function) +- free(et->function); +- if (et->message) +- free(et->message); +- +- memset(et, '\0', sizeof(*et)); ++ clear_error_entry(et); + } + free(error_table); + } +@@ -182,3 +201,5 @@ efi_get_verbose(void) + { + return efi_verbose; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index ad6449d9d93..dabf41789e5 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -187,6 +187,7 @@ extern int efi_error_set(const char *filename, + __attribute__((__nonnull__ (1, 2, 5))) + __attribute__((__format__ (printf, 5, 6))); + extern void efi_error_clear(void); ++extern void efi_error_pop(void); + #else + static inline int + __attribute__((__nonnull__ (2, 3, 4, 5, 6))) +@@ -218,6 +219,12 @@ efi_error_clear(void) + { + return; + } ++ ++static inline void ++efi_error_pop(void) ++{ ++ return; ++} + #endif + + #define efi_error_real__(errval, file, function, line, fmt, args...) \ +@@ -238,3 +245,5 @@ extern FILE * efi_get_logfile(void) + #include + + #endif /* EFIVAR_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/libefivar.map.in b/src/libefivar.map.in +index b5ee1ce334a..8e50d574f10 100644 +--- a/src/libefivar.map.in ++++ b/src/libefivar.map.in +@@ -127,3 +127,10 @@ LIBEFIVAR_1.36 { + efi_get_verbose; + efi_get_logfile; + } LIBEFIVAR_1.35; ++ ++LIBEFIVAR_1.37 { ++} LIBEFIVAR_1.36; ++ ++LIBEFIVAR_1.38 { ++ global: efi_error_pop; ++} LIBEFIVAR_1.37; +diff --git a/src/linux.c b/src/linux.c +index 4bb453be834..4e102da5e24 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -405,6 +405,8 @@ struct device HIDDEN + rc = sysfs_readlink(&tmpbuf, + "block/%s/device/device/driver", + dev->disk_name); ++ if (rc >= 0 && tmpbuf) ++ efi_error_pop(); + } + if (rc < 0 || !tmpbuf) { + efi_error("readlink of /sys/block/%s/device/driver failed", +@@ -626,3 +628,5 @@ get_sector_size(int filedes) + sector_size = 512; + return sector_size; + } ++ ++// vim:fenc=utf-8:tw=75:et +-- +2.24.1 + diff --git a/SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch b/SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch new file mode 100644 index 0000000..622e5ec --- /dev/null +++ b/SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch @@ -0,0 +1,215 @@ +From 2bd7a0b4f54e74ac976c14d631643676bea70819 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 15:42:37 -0400 +Subject: [PATCH 16/86] Always log to a memfd regardless of loglevel. + +This writes all debug logs to a memfd, so that they'll always show up in +strace. + +Signed-off-by: Peter Jones +--- + src/error.c | 88 ++++++++++++++++++++++++++++++++++--- + src/include/efivar/efivar.h | 7 +++ + src/libefivar.map.in | 1 + + src/util.h | 26 +++++------ + 4 files changed, 102 insertions(+), 20 deletions(-) + +diff --git a/src/error.c b/src/error.c +index df03d7f45e0..5dc43197c50 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -162,7 +163,58 @@ efi_error_pop(void) + clear_error_entry(&error_table[current]); + } + +-void PUBLIC DESTRUCTOR ++static int efi_verbose; ++static FILE *efi_errlog, *efi_dbglog; ++static int efi_dbglog_fd = -1; ++static int stashed_log_level; ++static char efi_dbglog_buf[4096]; ++ ++void PUBLIC ++efi_stash_loglevel_(int level) ++{ ++ stashed_log_level = level; ++} ++ ++static ssize_t ++dbglog_write(void *cookie UNUSED, const char *buf, size_t size) ++{ ++ FILE *log = efi_errlog ? efi_errlog : stderr; ++ ssize_t ret = size; ++ ++ if (efi_get_verbose() >= stashed_log_level) { ++ ret = fwrite(buf, 1, size, log); ++ } else if (efi_dbglog_fd >= 0) { ++ lseek(efi_dbglog_fd, 0, SEEK_SET); ++ write(efi_dbglog_fd, buf, size); ++ } ++ return ret; ++} ++ ++static int ++dbglog_seek(void *cookie UNUSED, off64_t *offset, int whence) ++{ ++ FILE *log = efi_errlog ? efi_errlog : stderr; ++ return fseek(log, *offset, whence); ++} ++ ++static int ++dbglog_close(void *cookie UNUSED) ++{ ++ if (efi_dbglog_fd >= 0) { ++ close(efi_dbglog_fd); ++ efi_dbglog_fd = -1; ++ } ++ if (efi_errlog) { ++ int ret = fclose(efi_errlog); ++ efi_errlog = NULL; ++ return ret; ++ } ++ ++ errno = EBADF; ++ return -1; ++} ++ ++void PUBLIC + efi_error_clear(void) + { + if (error_table) { +@@ -177,15 +229,39 @@ efi_error_clear(void) + current = 0; + } + +-static int efi_verbose; +-static FILE *efi_errlog; ++void DESTRUCTOR ++efi_error_fini(void) ++{ ++ efi_error_clear(); ++ if (efi_dbglog) { ++ fclose(efi_dbglog); ++ efi_dbglog = NULL; ++ } ++} ++ ++static void CONSTRUCTOR ++efi_error_init(void) ++{ ++ cookie_io_functions_t io_funcs = { ++ .write = dbglog_write, ++ .seek = dbglog_seek, ++ .close = dbglog_close, ++ }; ++ ++ efi_dbglog_fd = memfd_create("efivar-debug.log", MFD_CLOEXEC); ++ if (efi_dbglog_fd == -1) ++ return; ++ ++ efi_dbglog = fopencookie(NULL, "a", io_funcs); ++ if (efi_dbglog) ++ setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF, ++ sizeof(efi_dbglog_buf)); ++} + + FILE PUBLIC * + efi_get_logfile(void) + { +- if (efi_errlog) +- return efi_errlog; +- return stderr; ++ return efi_dbglog; + } + + void PUBLIC +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index dabf41789e5..343d1c557da 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -188,6 +188,7 @@ extern int efi_error_set(const char *filename, + __attribute__((__format__ (printf, 5, 6))); + extern void efi_error_clear(void); + extern void efi_error_pop(void); ++extern void efi_stash_loglevel_(int level); + #else + static inline int + __attribute__((__nonnull__ (2, 3, 4, 5, 6))) +@@ -225,6 +226,12 @@ efi_error_pop(void) + { + return; + } ++ ++static inline void ++efi_stash_loglevel_(int level __attribute__((__unused__))) ++{ ++ return; ++} + #endif + + #define efi_error_real__(errval, file, function, line, fmt, args...) \ +diff --git a/src/libefivar.map.in b/src/libefivar.map.in +index 8e50d574f10..8965b729917 100644 +--- a/src/libefivar.map.in ++++ b/src/libefivar.map.in +@@ -133,4 +133,5 @@ LIBEFIVAR_1.37 { + + LIBEFIVAR_1.38 { + global: efi_error_pop; ++ efi_stash_loglevel_; + } LIBEFIVAR_1.37; +diff --git a/src/util.h b/src/util.h +index a6a80e754ec..337762c9902 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -382,15 +382,14 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + + #define log_(file, line, func, level, fmt, args...) \ + ({ \ +- if (efi_get_verbose() >= level) { \ +- FILE *logfile_ = efi_get_logfile(); \ +- int len_ = strlen(fmt); \ +- fprintf(logfile_, "%s:%d %s(): ", \ +- file, line, func); \ +- fprintf(logfile_, fmt, ## args); \ +- if (!len_ || fmt[len_ - 1] != '\n') \ +- fprintf(logfile_, "\n"); \ +- } \ ++ efi_stash_loglevel_(level); \ ++ FILE *logfile_ = efi_get_logfile(); \ ++ int len_ = strlen(fmt); \ ++ fprintf(logfile_, "%s:%d %s(): ", \ ++ file, line, func); \ ++ fprintf(logfile_, fmt, ## args); \ ++ if (!len_ || fmt[len_ - 1] != '\n') \ ++ fprintf(logfile_, "\n"); \ + }) + + #define LOG_VERBOSE 0 +@@ -402,11 +401,10 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args) + #define log_hex_(file, line, func, level, buf, size) \ + ({ \ +- if (efi_get_verbose() >= level) { \ +- fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ +- (uint8_t *)buf, size, \ +- file, line, func); \ +- } \ ++ efi_stash_loglevel_(level); \ ++ fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ ++ (uint8_t *)buf, size, \ ++ file, line, func); \ + }) + #define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size) + #define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size) +-- +2.24.1 + diff --git a/SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch b/SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch new file mode 100644 index 0000000..b8d29e0 --- /dev/null +++ b/SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch @@ -0,0 +1,82 @@ +From 5dc12cc56c79d293cf68d12a0b84373a785745e7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 16:27:31 -0400 +Subject: [PATCH 17/86] Always initialize any variable we use with sscanf's %n + +Signed-off-by: Peter Jones +--- + src/linux-acpi-root.c | 2 +- + src/linux-pci-root.c | 2 +- + src/linux-pci.c | 2 +- + src/linux-soc-root.c | 2 +- + src/linux-virtblk.c | 2 +- + 5 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 30728ded671..b237039685e 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -44,7 +44,7 @@ static ssize_t + parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED) + { + int rc; +- int pos; ++ int pos = 0; + uint16_t pad0; + uint8_t pad1; + char *acpi_header = NULL; +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index 0605acfc7cb..0b5ad48d6db 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -44,7 +44,7 @@ static ssize_t + parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + { + int rc; +- int pos; ++ int pos = 0; + uint16_t root_domain; + uint8_t root_bus; + const char *devpart = current; +diff --git a/src/linux-pci.c b/src/linux-pci.c +index 64aaefb461c..c3b9fcf9092 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -46,7 +46,7 @@ static ssize_t + parse_pci(struct device *dev, const char *current, const char *root) + { + int rc; +- int pos; ++ int pos = 0; + const char *devpart = current; + + debug("entry"); +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index 373cd59521a..cbb4779b6fb 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -41,7 +41,7 @@ static ssize_t + parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED) + { + int rc; +- int pos; ++ int pos = 0; + const char *devpart = current; + + debug("entry"); +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index 2e9889def2f..fe6eb873a37 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -48,7 +48,7 @@ static ssize_t + parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + { + uint32_t tosser; +- int pos; ++ int pos = 0; + int rc; + + debug("entry"); +-- +2.24.1 + diff --git a/SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch b/SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch new file mode 100644 index 0000000..a7599f6 --- /dev/null +++ b/SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch @@ -0,0 +1,126 @@ +From 2763ad732781c9e8b36bdab25d04ca632c9b77fe Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 16:08:25 -0400 +Subject: [PATCH 18/86] Add efi_get_libefivar_version() and + efi_get_libefiboot_version() + +Signed-off-by: Peter Jones +--- + Make.defaults | 2 +- + src/Android.mk | 4 +++- + src/creator.c | 6 ++++++ + src/include/efivar/efiboot.h | 3 +++ + src/include/efivar/efivar.h | 3 +++ + src/lib.c | 6 ++++++ + src/libefiboot.map.in | 4 ++++ + src/libefivar.map.in | 1 + + 8 files changed, 27 insertions(+), 2 deletions(-) + +diff --git a/Make.defaults b/Make.defaults +index 57cee6e82b5..6c575846687 100644 +--- a/Make.defaults ++++ b/Make.defaults +@@ -18,7 +18,7 @@ CCLD_FOR_BUILD ?= $(CC_FOR_BUILD) + CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD)) + OPTIMIZE ?= -O2 -flto + CFLAGS ?= $(OPTIMIZE) -g3 +-CFLAGS := $(CFLAGS) ++CFLAGS := $(CFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) + LDFLAGS ?= + LDFLAGS := $(LDFLAGS) + AR := $(CROSS_COMPILE)$(COMPILER)-ar +diff --git a/src/Android.mk b/src/Android.mk +index b3410e1f3e7..bf6cfb2e91b 100644 +--- a/src/Android.mk ++++ b/src/Android.mk +@@ -46,8 +46,10 @@ LIBEFIVAR_SOURCES := \ + lib.c \ + vars.c + ++include $(LOCAL_PATH)/../Make.version ++ + LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) +-LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 ++LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION) + LOCAL_C_INCLUDES := $(LOCAL_PATH)/include + LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES)/efivar $(local-generated-sources-dir) + LIBEFIVAR_GUIDS_H := $(local-generated-sources-dir)/efivar/efivar-guids.h +diff --git a/src/creator.c b/src/creator.c +index 987fa033e5b..f4bb01bc4a6 100644 +--- a/src/creator.c ++++ b/src/creator.c +@@ -511,3 +511,9 @@ efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size, + + return off; + } ++ ++uint32_t PUBLIC ++efi_get_libefiboot_version(void) ++{ ++ return LIBEFIVAR_VERSION; ++} +diff --git a/src/include/efivar/efiboot.h b/src/include/efivar/efiboot.h +index c2af55fbf45..2aee86d661e 100644 +--- a/src/include/efivar/efiboot.h ++++ b/src/include/efivar/efiboot.h +@@ -35,4 +35,7 @@ + #include + #include + ++extern uint32_t efi_get_libefiboot_version(void) ++ __attribute__((__visibility__("default"))); ++ + #endif /* EFIBOOT_H */ +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 343d1c557da..ff95cb10791 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -249,6 +249,9 @@ extern int efi_get_verbose(void) + extern FILE * efi_get_logfile(void) + __attribute__((__visibility__("default"))); + ++extern uint32_t efi_get_libefivar_version(void) ++ __attribute__((__visibility__("default"))); ++ + #include + + #endif /* EFIVAR_H */ +diff --git a/src/lib.c b/src/lib.c +index dc06fdb3c15..457a8604d5d 100644 +--- a/src/lib.c ++++ b/src/lib.c +@@ -265,3 +265,9 @@ libefivar_init(void) + } + } + } ++ ++uint32_t PUBLIC ++efi_get_libefivar_version(void) ++{ ++ return LIBEFIVAR_VERSION; ++} +diff --git a/src/libefiboot.map.in b/src/libefiboot.map.in +index cb19d65d0e4..0771eac5639 100644 +--- a/src/libefiboot.map.in ++++ b/src/libefiboot.map.in +@@ -33,3 +33,7 @@ LIBEFIBOOT_1.29 { + + LIBEFIBOOT_1.30 { + } LIBEFIBOOT_1.29; ++ ++LIBEFIBOOT_1.31 { ++ global: efi_get_libefiboot_version; ++} LIBEFIBOOT_1.30; +diff --git a/src/libefivar.map.in b/src/libefivar.map.in +index 8965b729917..33196fefc64 100644 +--- a/src/libefivar.map.in ++++ b/src/libefivar.map.in +@@ -134,4 +134,5 @@ LIBEFIVAR_1.37 { + LIBEFIVAR_1.38 { + global: efi_error_pop; + efi_stash_loglevel_; ++ efi_get_libefivar_version; + } LIBEFIVAR_1.37; +-- +2.24.1 + diff --git a/SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch b/SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch new file mode 100644 index 0000000..9002cf1 --- /dev/null +++ b/SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch @@ -0,0 +1,32 @@ +From ee17f35cc79a865d700c78f783a7aa886a89dc1d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 09:28:50 -0400 +Subject: [PATCH 19/86] Fix dbglog_seek() to update the offset. + +Signed-off-by: Peter Jones +--- + src/error.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/error.c b/src/error.c +index 5dc43197c50..5eaee84599a 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -194,7 +194,13 @@ static int + dbglog_seek(void *cookie UNUSED, off64_t *offset, int whence) + { + FILE *log = efi_errlog ? efi_errlog : stderr; +- return fseek(log, *offset, whence); ++ int rc; ++ ++ rc = fseek(log, *offset, whence); ++ if (rc < 0) ++ return rc; ++ *offset = ftell(log); ++ return 0; + } + + static int +-- +2.24.1 + diff --git a/SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch b/SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch new file mode 100644 index 0000000..7e48052 --- /dev/null +++ b/SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch @@ -0,0 +1,5854 @@ +From 578ad7c2293ad0c439adf8677713a615d88964b6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 09:33:36 -0400 +Subject: [PATCH 20/86] Update efivar-37 .abixml for new libabigail version + +Signed-off-by: Peter Jones +--- + src/libefiboot.abixml | 2151 ++++++++++++++++++++----------------- + src/libefivar.abixml | 2326 +++++++++++++++++++++-------------------- + 2 files changed, 2361 insertions(+), 2116 deletions(-) + +diff --git a/src/libefiboot.abixml b/src/libefiboot.abixml +index 29a57c5a4c5..ffdae048021 100644 +--- a/src/libefiboot.abixml ++++ b/src/libefiboot.abixml +@@ -21,1583 +21,1812 @@ + + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- + +- +- +- ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ + + +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ + +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +- +- ++ ++ + + +- +- ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- +- ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- ++ + +- ++ + + +- +- ++ ++ + +- ++ + + +- +- ++ ++ + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ + +- +- +- +- +- +- ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ + + +- +- +- +- +- ++ ++ + +- +- ++ ++ + + +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +diff --git a/src/libefivar.abixml b/src/libefivar.abixml +index 1a075f262ec..4aadf5079a7 100644 +--- a/src/libefivar.abixml ++++ b/src/libefivar.abixml +@@ -52,6 +52,7 @@ + + + ++ + + + +@@ -107,1879 +108,1894 @@ + + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ ++ ++ ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- +- ++ ++ ++ ++ ++ + +- +- ++ ++ + + +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + +- +- ++ ++ ++ ++ ++ + + +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +- +- ++ ++ + + +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- +- +- +- ++ ++ ++ ++ + + +- +- +- +- +- +- +- ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- +- ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- ++ + +- ++ + + +- +- ++ ++ + +- ++ + + +- +- ++ ++ + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- ++ ++ ++ ++ + +- +- +- +- ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ + +- +- +- +- +- ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ + + +- +- +- +- +- +- +- ++ ++ ++ ++ + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +-- +2.24.1 + diff --git a/SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch b/SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch new file mode 100644 index 0000000..0809a19 --- /dev/null +++ b/SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch @@ -0,0 +1,70 @@ +From 8a003f0c495da3719338881286bc2976b2d086aa Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:11:24 -0400 +Subject: [PATCH 21/86] Fix up efi_guid_cmp()'s alignment problem a different + way + +With the prior fix for efi_guid_cmp()'s alignment issue, abicheck shows: + +1 function with some indirect sub-type change: + + [C]'function int efi_guid_cmp(void* const, void* const)' at :34:1 has some indirect sub-type changes: + parameter 1 of type 'void* const' changed: + entity changed from 'void* const' to 'const efi_guid_t*' + type size hasn't changed + parameter 2 of type 'void* const' changed: + entity changed from 'void* const' to 'const efi_guid_t*' + type size hasn't changed + +While this isn't a meaningful ABI difference in terms of linking, it is +definitely worse than having the type actually specified. + +This patch changes the type back to the previous type, but also changes +the typedef to require a 1-byte alignment. This will guarantee that all +new builds of efi_guid_cmp() and related code have code generated in a +way that's compatible with any alignment, thus alleviating the issue. + +Signed-off-by: Peter Jones +--- + src/guid.c | 2 +- + src/include/efivar/efivar.h | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/guid.c b/src/guid.c +index 3156b3b7c60..306c9ff8287 100644 +--- a/src/guid.c ++++ b/src/guid.c +@@ -31,7 +31,7 @@ + extern const efi_guid_t efi_guid_zero; + + int NONNULL(1, 2) PUBLIC +-efi_guid_cmp(const void * const a, const void * const b) ++efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b) + { + return memcmp(a, b, sizeof (efi_guid_t)); + } +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index ff95cb10791..11d9a9d7b78 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -37,7 +37,7 @@ typedef struct { + uint16_t c; + uint16_t d; + uint8_t e[6]; +-} efi_guid_t; ++} efi_guid_t __attribute__((__aligned__(1))); + + typedef struct { + uint8_t addr[4]; +@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid) + + extern int efi_guid_is_zero(const efi_guid_t *guid); + extern int efi_guid_is_empty(const efi_guid_t *guid); +-extern int efi_guid_cmp(const void * const a, const void * const b); ++extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b); + + /* import / export functions */ + typedef struct efi_variable efi_variable_t; +-- +2.24.1 + diff --git a/SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch b/SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch new file mode 100644 index 0000000..31e9f50 --- /dev/null +++ b/SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch @@ -0,0 +1,27 @@ +From 2ed65b6801e0c7eb24d32b338f035c5b5d684205 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:18:56 -0400 +Subject: [PATCH 22/86] Fix dbglog_write() to always return the status of + write() + +Signed-off-by: Peter Jones +--- + src/error.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/error.c b/src/error.c +index 5eaee84599a..a77b0df1feb 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -185,7 +185,7 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size) + ret = fwrite(buf, 1, size, log); + } else if (efi_dbglog_fd >= 0) { + lseek(efi_dbglog_fd, 0, SEEK_SET); +- write(efi_dbglog_fd, buf, size); ++ ret = write(efi_dbglog_fd, buf, size); + } + return ret; + } +-- +2.24.1 + diff --git a/SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch b/SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch new file mode 100644 index 0000000..20b5a54 --- /dev/null +++ b/SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch @@ -0,0 +1,36 @@ +From 15a379e4764ae5a3f5d8fdf224410c7eaa74c66a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:21:32 -0400 +Subject: [PATCH 23/86] Do a better job of making sure -DLIBEFIVAR_VERSION + happens... + +Signed-off-by: Peter Jones +--- + Make.defaults | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/Make.defaults b/Make.defaults +index 6c575846687..80fd99eba71 100644 +--- a/Make.defaults ++++ b/Make.defaults +@@ -18,7 +18,7 @@ CCLD_FOR_BUILD ?= $(CC_FOR_BUILD) + CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD)) + OPTIMIZE ?= -O2 -flto + CFLAGS ?= $(OPTIMIZE) -g3 +-CFLAGS := $(CFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) ++CFLAGS := $(CFLAGS) + LDFLAGS ?= + LDFLAGS := $(LDFLAGS) + AR := $(CROSS_COMPILE)$(COMPILER)-ar +@@ -29,6 +29,8 @@ ABIDIFF := abidiff + + PKGS = + ++CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION) ++ + clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member + gcc_cflags = -specs=$(TOPDIR)/gcc.specs + cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \ +-- +2.24.1 + diff --git a/SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch b/SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch new file mode 100644 index 0000000..57f3e8c --- /dev/null +++ b/SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch @@ -0,0 +1,102 @@ +From e0ded4593e57657837dfcf110985eabaa37bc492 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:28:41 -0400 +Subject: [PATCH 24/86] efi_stash_loglevel_() -> efi_set_loglevel() + +Signed-off-by: Peter Jones +--- + src/error.c | 8 ++++---- + src/include/efivar/efivar.h | 4 ++-- + src/libefivar.map.in | 2 +- + src/util.h | 4 ++-- + 4 files changed, 9 insertions(+), 9 deletions(-) + +diff --git a/src/error.c b/src/error.c +index a77b0df1feb..083de15e984 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -166,13 +166,13 @@ efi_error_pop(void) + static int efi_verbose; + static FILE *efi_errlog, *efi_dbglog; + static int efi_dbglog_fd = -1; +-static int stashed_log_level; ++static int log_level; + static char efi_dbglog_buf[4096]; + + void PUBLIC +-efi_stash_loglevel_(int level) ++efi_set_loglevel(int level) + { +- stashed_log_level = level; ++ log_level = level; + } + + static ssize_t +@@ -181,7 +181,7 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size) + FILE *log = efi_errlog ? efi_errlog : stderr; + ssize_t ret = size; + +- if (efi_get_verbose() >= stashed_log_level) { ++ if (efi_get_verbose() >= log_level) { + ret = fwrite(buf, 1, size, log); + } else if (efi_dbglog_fd >= 0) { + lseek(efi_dbglog_fd, 0, SEEK_SET); +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 11d9a9d7b78..2fdf5b93b29 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -188,7 +188,7 @@ extern int efi_error_set(const char *filename, + __attribute__((__format__ (printf, 5, 6))); + extern void efi_error_clear(void); + extern void efi_error_pop(void); +-extern void efi_stash_loglevel_(int level); ++extern void efi_set_loglevel(int level); + #else + static inline int + __attribute__((__nonnull__ (2, 3, 4, 5, 6))) +@@ -228,7 +228,7 @@ efi_error_pop(void) + } + + static inline void +-efi_stash_loglevel_(int level __attribute__((__unused__))) ++efi_set_loglevel(int level __attribute__((__unused__))) + { + return; + } +diff --git a/src/libefivar.map.in b/src/libefivar.map.in +index 33196fefc64..682e622c302 100644 +--- a/src/libefivar.map.in ++++ b/src/libefivar.map.in +@@ -133,6 +133,6 @@ LIBEFIVAR_1.37 { + + LIBEFIVAR_1.38 { + global: efi_error_pop; +- efi_stash_loglevel_; ++ efi_set_loglevel; + efi_get_libefivar_version; + } LIBEFIVAR_1.37; +diff --git a/src/util.h b/src/util.h +index 337762c9902..ec1c5f1a69a 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -382,7 +382,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + + #define log_(file, line, func, level, fmt, args...) \ + ({ \ +- efi_stash_loglevel_(level); \ ++ efi_set_loglevel(level); \ + FILE *logfile_ = efi_get_logfile(); \ + int len_ = strlen(fmt); \ + fprintf(logfile_, "%s:%d %s(): ", \ +@@ -401,7 +401,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args) + #define log_hex_(file, line, func, level, buf, size) \ + ({ \ +- efi_stash_loglevel_(level); \ ++ efi_set_loglevel(level); \ + fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ + (uint8_t *)buf, size, \ + file, line, func); \ +-- +2.24.1 + diff --git a/SOURCES/0025-guids-add-grub-guid-for-grubenv.patch b/SOURCES/0025-guids-add-grub-guid-for-grubenv.patch new file mode 100644 index 0000000..b2f8335 --- /dev/null +++ b/SOURCES/0025-guids-add-grub-guid-for-grubenv.patch @@ -0,0 +1,38 @@ +From fdf91db0e35bcc48164c8778fcd0f3ace7ab9403 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 13:59:29 -0400 +Subject: [PATCH 25/86] guids: add 'grub' guid for grubenv. + +Signed-off-by: Peter Jones +--- + src/guids.txt | 1 + + src/libefivar.map.in | 3 +++ + 2 files changed, 4 insertions(+) + +diff --git a/src/guids.txt b/src/guids.txt +index 0d48ddbad30..2486255b26c 100644 +--- a/src/guids.txt ++++ b/src/guids.txt +@@ -21,6 +21,7 @@ + 826ca512-cf10-4ac9-b187-be01496631bd sha1 SHA-1 + 82988420-7467-4490-9059-feb448dd1963 lenovo_me_config Lenovo ME Configuration Menu + 8be4df61-93ca-11d2-aa0d-00e098032b8c global EFI Global Variable ++91376aff-cba6-42be-949d-06fde81128e8 grub GRUB + a5c059a1-94e4-4aa7-87b5-ab155c2bf072 x509_cert X.509 Certificate + a7717414-c616-4977-9420-844712a735bf rsa2048_sha256_cert RSA 2048 with SHA-256 Certificate + a7d8d9a6-6ab0-4aeb-ad9d-163e59a7a380 lenovo_diag_splash Lenovo Diagnostic Splash Screen +diff --git a/src/libefivar.map.in b/src/libefivar.map.in +index 682e622c302..54bfb765998 100644 +--- a/src/libefivar.map.in ++++ b/src/libefivar.map.in +@@ -135,4 +135,7 @@ LIBEFIVAR_1.38 { + global: efi_error_pop; + efi_set_loglevel; + efi_get_libefivar_version; ++ efi_guid_grub; ++ efi_variable_alloc; ++ efi_variable_export_dmpstore; + } LIBEFIVAR_1.37; +-- +2.24.1 + diff --git a/SOURCES/0026-gcc.specs-add-grecord-gcc-switches.patch b/SOURCES/0026-gcc.specs-add-grecord-gcc-switches.patch new file mode 100644 index 0000000..7469b0d --- /dev/null +++ b/SOURCES/0026-gcc.specs-add-grecord-gcc-switches.patch @@ -0,0 +1,30 @@ +From 4c419d91d9b81c6223a1d44b4ed759197fd2aab5 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:00:05 -0400 +Subject: [PATCH 26/86] gcc.specs: add -grecord-gcc-switches + +Signed-off-by: Peter Jones +--- + gcc.specs | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/gcc.specs b/gcc.specs +index 45d43d11294..d06a8e096fc 100644 +--- a/gcc.specs ++++ b/gcc.specs +@@ -8,10 +8,10 @@ + + %(efivar_cpp_options) + + *cc1_options: +-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} +++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches + + *self_spec: +-+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} +++ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches + + *link: + + %{!static:--fatal-warnings} --no-undefined-version --no-allow-shlib-undefined --add-needed -z now --build-id %{!static:%{!shared:-pie}} %{shared:-z relro} %{static:% +Date: Tue, 18 Jun 2019 10:05:11 -0400 +Subject: [PATCH 27/86] Makefile: don't echo our deps submake invocation + +Signed-off-by: Peter Jones +--- + src/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/Makefile b/src/Makefile +index 76bc4748eb1..ecbbc02e1f7 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -84,7 +84,7 @@ libefiboot.so : LIBS=efivar + libefiboot.so : MAP=libefiboot.map + + deps : $(ALL_SOURCES) +- $(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)" ++ @$(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)" + + clean : + @rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \ +-- +2.24.1 + diff --git a/SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch b/SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch new file mode 100644 index 0000000..720ffc6 --- /dev/null +++ b/SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch @@ -0,0 +1,26 @@ +From 1ab255ac8be670c55c7c0dbf329801093c206f3e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 11:06:09 -0400 +Subject: [PATCH 28/86] Make: Add some more stuff to the toplevel 'clean' + +Signed-off-by: Peter Jones +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 8c67b9d2654..9c2620cb485 100644 +--- a/Makefile ++++ b/Makefile +@@ -49,7 +49,7 @@ clean : + @set -e ; for x in $(SUBDIRS) ; do \ + $(MAKE) -C $$x $@ ; \ + done +- @rm -vf efivar.spec ++ @rm -vf efivar.spec vgcore.* core.* + + test-archive: abicheck efivar.spec + @rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp +-- +2.24.1 + diff --git a/SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch b/SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch new file mode 100644 index 0000000..3b9025c --- /dev/null +++ b/SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch @@ -0,0 +1,31 @@ +From 47351ed986d8cb2c04c0447e62419b3ef5eebc78 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 19 Jun 2019 11:35:28 -0400 +Subject: [PATCH 29/86] Make scan build rules slightly more intuitive. + +Signed-off-by: Peter Jones +--- + Make.scan-build | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/Make.scan-build b/Make.scan-build +index 7d684f7539f..f508e30be16 100644 +--- a/Make.scan-build ++++ b/Make.scan-build +@@ -12,10 +12,9 @@ scan-build : | scan-test + scan-build : clean + scan-build -o scan-results make $(DASHJ) CC=clang all + +-scan-build-all : | scan-test +-scan-build-all : clean +- scan-build -o scan-results make $(DASHJ) CC=clang all ++scan-build-all: | scan-build ++scan : | scan-build + +-.PHONY : scan-build scan-clean ++.PHONY : scan-build scan-clean scan-build-all scan + + # vim:ft=make +-- +2.24.1 + diff --git a/SOURCES/0030-Local-header-whitespace-cleanup.patch b/SOURCES/0030-Local-header-whitespace-cleanup.patch new file mode 100644 index 0000000..609946a --- /dev/null +++ b/SOURCES/0030-Local-header-whitespace-cleanup.patch @@ -0,0 +1,1511 @@ +From b65f2aceaaa6e71803e112e7c0cd29bbc9f2fade Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:25:21 -0400 +Subject: [PATCH 30/86] Local header whitespace cleanup. + +Signed-off-by: Peter Jones +--- + src/crc32.h | 2 + + src/disk.h | 4 +- + src/dp.h | 2 + + src/efiboot.h | 3 +- + src/efivar.h | 3 +- + src/efivar_endian.h | 2 + + src/fix_coverity.h | 28 ++- + src/generics.h | 2 + + src/gpt.h | 97 ++++---- + src/guid.h | 20 +- + src/hexdump.h | 2 + + src/lib.h | 2 + + src/linux.h | 370 +++++++++++++++--------------- + src/path-helpers.h | 37 +-- + src/ucs2.h | 2 + + src/util.h | 532 ++++++++++++++++++++++---------------------- + 16 files changed, 572 insertions(+), 536 deletions(-) + +diff --git a/src/crc32.h b/src/crc32.h +index 405d23c86ec..b5b975a5768 100644 +--- a/src/crc32.h ++++ b/src/crc32.h +@@ -30,3 +30,5 @@ + extern uint32_t crc32 (const void *buf, unsigned long len, uint32_t seed); + + #endif /* _CRC32_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/disk.h b/src/disk.h +index f0fa7f9f42d..8ba0f4602f4 100644 +--- a/src/disk.h ++++ b/src/disk.h +@@ -24,6 +24,8 @@ + extern bool HIDDEN is_partitioned(int fd); + + extern HIDDEN ssize_t make_hd_dn(uint8_t *buf, ssize_t size, int fd, +- int32_t partition, uint32_t options); ++ int32_t partition, uint32_t options); + + #endif /* _EFIBOOT_DISK_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp.h b/src/dp.h +index 1f921d524aa..33a29db0d5d 100644 +--- a/src/dp.h ++++ b/src/dp.h +@@ -187,3 +187,5 @@ extern ssize_t _format_bios_boot_dn(char *buf, size_t size, const_efidp dp); + format_helper_2(_format_bios_boot_dn, buf, size, off, dp) + + #endif /* _EFIVAR_INTERNAL_DP_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/efiboot.h b/src/efiboot.h +index f60f2cf5c2a..23275ed82bf 100644 +--- a/src/efiboot.h ++++ b/src/efiboot.h +@@ -24,4 +24,5 @@ + #include + + #endif /* !PRIVATE_EFIBOOT_H_ */ +-// vim:fenc=utf-8:tw=75:et ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/efivar.h b/src/efivar.h +index ce6beb6850b..3d4b429631e 100644 +--- a/src/efivar.h ++++ b/src/efivar.h +@@ -36,4 +36,5 @@ + #include "path-helpers.h" + + #endif /* !PRIVATE_EFIVAR_H_ */ +-// vim:fenc=utf-8:tw=75:et ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/efivar_endian.h b/src/efivar_endian.h +index b8e6a314838..bed4603ad71 100644 +--- a/src/efivar_endian.h ++++ b/src/efivar_endian.h +@@ -51,3 +51,5 @@ + #endif + + #endif /* _EFIVAR_ENDIAN_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/fix_coverity.h b/src/fix_coverity.h +index 95a5c9282c9..acb4cc65eff 100644 +--- a/src/fix_coverity.h ++++ b/src/fix_coverity.h +@@ -22,8 +22,8 @@ + * + * In glibc's headers, bits/floatn.h has: + * +- * #if (defined __x86_64__ \ +- * ? __GNUC_PREREQ (4, 3) \ ++ * #if (defined __x86_64__ \ ++ * ? __GNUC_PREREQ (4, 3) \ + * : (defined __GNU__ ? __GNUC_PREREQ (4, 5) : __GNUC_PREREQ (4, 4))) + * # define __HAVE_FLOAT128 1 + * #else +@@ -35,24 +35,21 @@ + * #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) + * slash* Likewise for the '_Float128' format *slash + * extern _Float128 strtof128 (const char *__restrict __nptr, +- * char **__restrict __endptr) +- * __THROW __nonnull ((1)); ++ * char **__restrict __endptr) ++ * __THROW __nonnull ((1)); + * #endif + * + * Which then causes cov-emit to lose its shit: + * +- * "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is +- * undefined ++ * "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is undefined + * extern _Float128 strtof128 (const char *__restrict __nptr, +- * ^ +- * "/usr/include/stdlib.h", line 190: error #20: identifier "_Float128" is +- * undefined +- * _Float128 __f) +- * ^ +- * "/usr/include/stdlib.h", line 236: error #20: identifier "_Float128" is +- * undefined ++ * ^ ++ * "/usr/include/stdlib.h", line 190: error #20: identifier "_Float128" is undefined ++ * _Float128 __f) ++ * ^ ++ * "/usr/include/stdlib.h", line 236: error #20: identifier "_Float128" is undefined + * extern _Float128 strtof128_l (const char *__restrict __nptr, +- * ^ ++ * ^ + * + * And then you'll notice something like this later on: + * [WARNING] Emitted 0 C/C++ compilation units (0%) successfully +@@ -91,4 +88,5 @@ typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__))); + #endif + + #endif /* !FIX_COVERITY_H */ +-// vim:fenc=utf-8:tw=75 ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/generics.h b/src/generics.h +index 66be4bd76ab..8ade54ee96b 100644 +--- a/src/generics.h ++++ b/src/generics.h +@@ -184,3 +184,5 @@ generic_append_variable(efi_guid_t guid, const char *name, + + #endif /* LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H */ + #endif /* EFIVAR_BUILD_ENVIRONMENT */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/gpt.h b/src/gpt.h +index 0d7d5e8a649..66fbc21106c 100644 +--- a/src/gpt.h ++++ b/src/gpt.h +@@ -38,27 +38,27 @@ + #define GPT_HEADER_REVISION_V0_99 0x00009900 + #define GPT_PRIMARY_PARTITION_TABLE_LBA 1 + +-#define PARTITION_SYSTEM_GUID \ +- EFI_GUID(0xC12A7328, 0xF81F, 0x11d2, 0xBA4B, \ +- 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B) +-#define LEGACY_MBR_PARTITION_GUID \ +- EFI_GUID(0x024DEE41, 0x33E7, 0x11d3, 0x9D69, \ +- 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F) +-#define PARTITION_MSFT_RESERVED_GUID \ +- EFI_GUID(0xE3C9E316, 0x0B5C, 0x4DB8, 0x817D, \ +- 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE) +-#define PARTITION_BASIC_DATA_GUID \ +- EFI_GUID(0xEBD0A0A2, 0xB9E5, 0x4433, 0x87C0, \ +- 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7) +-#define PARTITION_LINUX_RAID_GUID \ +- EFI_GUID(0xa19d880f, 0x05fc, 0x4d3b, 0xA006, \ +- 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e) +-#define PARTITION_LINUX_SWAP_GUID \ +- EFI_GUID(0x0657fd6d, 0xa4ab, 0x43c4, 0x84E5, \ +- 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f) +-#define PARTITION_LINUX_LVM_GUID \ +- EFI_GUID(0xe6d6d379, 0xf507, 0x44c2, 0xa23c, \ +- 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28) ++#define PARTITION_SYSTEM_GUID \ ++ EFI_GUID(0xC12A7328, 0xF81F, 0x11d2, 0xBA4B, \ ++ 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B) ++#define LEGACY_MBR_PARTITION_GUID \ ++ EFI_GUID(0x024DEE41, 0x33E7, 0x11d3, 0x9D69, \ ++ 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F) ++#define PARTITION_MSFT_RESERVED_GUID \ ++ EFI_GUID(0xE3C9E316, 0x0B5C, 0x4DB8, 0x817D, \ ++ 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE) ++#define PARTITION_BASIC_DATA_GUID \ ++ EFI_GUID(0xEBD0A0A2, 0xB9E5, 0x4433, 0x87C0, \ ++ 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7) ++#define PARTITION_LINUX_RAID_GUID \ ++ EFI_GUID(0xa19d880f, 0x05fc, 0x4d3b, 0xA006, \ ++ 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e) ++#define PARTITION_LINUX_SWAP_GUID \ ++ EFI_GUID(0x0657fd6d, 0xa4ab, 0x43c4, 0x84E5, \ ++ 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f) ++#define PARTITION_LINUX_LVM_GUID \ ++ EFI_GUID(0xe6d6d379, 0xf507, 0x44c2, 0xa23c, \ ++ 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28) + + typedef struct _gpt_header { + uint64_t magic; +@@ -81,7 +81,7 @@ typedef struct _gpt_header { + typedef struct _gpt_entry_attributes { + uint64_t required_to_function:1; + uint64_t reserved:47; +- uint64_t type_guid_specific:16; ++ uint64_t type_guid_specific:16; + } PACKED gpt_entry_attributes; + + typedef struct _gpt_entry { +@@ -103,25 +103,36 @@ typedef struct _gpt_entry { + * Number of actual partition entries should be calculated as: + */ + #define GPT_DEFAULT_RESERVED_PARTITION_ENTRIES \ +- (GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE / \ +- sizeof(gpt_entry)) ++ (GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE / \ ++ sizeof(gpt_entry)) + + typedef struct _partition_record { +- uint8_t boot_indicator; /* Not used by EFI firmware. Set to 0x80 to indicate that this +- is the bootable legacy partition. */ +- uint8_t start_head; /* Start of partition in CHS address, not used by EFI firmware. */ +- uint8_t start_sector; /* Start of partition in CHS address, not used by EFI firmware. */ +- uint8_t start_track; /* Start of partition in CHS address, not used by EFI firmware. */ +- uint8_t os_type; /* OS type. A value of 0xEF defines an EFI system partition. +- Other values are reserved for legacy operating systems, and +- allocated independently of the EFI specification. */ +- uint8_t end_head; /* End of partition in CHS address, not used by EFI firmware. */ +- uint8_t end_sector; /* End of partition in CHS address, not used by EFI firmware. */ +- uint8_t end_track; /* End of partition in CHS address, not used by EFI firmware. */ +- uint32_t starting_lba; /* Starting LBA address of the partition on the disk. Used by +- EFI firmware to define the start of the partition. */ +- uint32_t size_in_lba; /* Size of partition in LBA. Used by EFI firmware to determine +- the size of the partition. */ ++ uint8_t boot_indicator; /* Not used by EFI firmware. Set to 0x80 to ++ indicate that this is the bootable ++ legacy partition. */ ++ uint8_t start_head; /* Start of partition in CHS address, not ++ used by EFI firmware. */ ++ uint8_t start_sector; /* Start of partition in CHS address, not ++ used by EFI firmware. */ ++ uint8_t start_track; /* Start of partition in CHS address, not ++ used by EFI firmware. */ ++ uint8_t os_type; /* OS type. A value of 0xEF defines an EFI ++ system partition. ++ Other values are reserved for legacy ++ operating systems, and allocated ++ independently of the EFI specification. */ ++ uint8_t end_head; /* End of partition in CHS address, not ++ used by EFI firmware. */ ++ uint8_t end_sector; /* End of partition in CHS address, not ++ used by EFI firmware. */ ++ uint8_t end_track; /* End of partition in CHS address, not ++ used by EFI firmware. */ ++ uint32_t starting_lba; /* Starting LBA address of the partition on ++ the disk. Used by EFI firmware to define ++ the start of the partition. */ ++ uint32_t size_in_lba; /* Size of partition in LBA. Used by EFI ++ firmware to determine the size of the ++ partition. */ + } PACKED partition_record; + + /* +@@ -141,8 +152,10 @@ typedef struct _legacy_mbr { + /* Functions */ + extern int NONNULL(3, 4, 5, 6, 7) HIDDEN + gpt_disk_get_partition_info (int fd, uint32_t num, uint64_t *start, +- uint64_t *size, uint8_t *signature, +- uint8_t *mbr_type, uint8_t *signature_type, +- int ignore_pmbr_error, int logical_sector_size); ++ uint64_t *size, uint8_t *signature, ++ uint8_t *mbr_type, uint8_t *signature_type, ++ int ignore_pmbr_error, int logical_sector_size); + + #endif /* _EFIBOOT_GPT_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/guid.h b/src/guid.h +index d4a06f957a5..3229621a3f1 100644 +--- a/src/guid.h ++++ b/src/guid.h +@@ -110,7 +110,7 @@ text_to_guid(const char *text, efi_guid_t *guid) + guid->a = cpu_to_le32(guid->a); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(fourbytes, text+9, 4); + if (check_segment_sanity(fourbytes, 4) < 0) + return -1; +@@ -118,7 +118,7 @@ text_to_guid(const char *text, efi_guid_t *guid) + guid->b = cpu_to_le16(guid->b); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(fourbytes, text+14, 4); + if (check_segment_sanity(fourbytes, 4) < 0) + return -1; +@@ -126,7 +126,7 @@ text_to_guid(const char *text, efi_guid_t *guid) + 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; +@@ -134,42 +134,42 @@ text_to_guid(const char *text, efi_guid_t *guid) + guid->d = cpu_to_be16(guid->d); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+24, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; + guid->e[0] = (uint8_t)strtoul(twobytes, NULL, 16); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+26, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; + guid->e[1] = (uint8_t)strtoul(twobytes, NULL, 16); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+28, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; + guid->e[2] = (uint8_t)strtoul(twobytes, NULL, 16); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+30, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; + guid->e[3] = (uint8_t)strtoul(twobytes, NULL, 16); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+32, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; + guid->e[4] = (uint8_t)strtoul(twobytes, NULL, 16); + + /* 84be9c3e-8a32-42c0-891c-4cd3b072becc +- * ^ */ ++ * ^ */ + strncpy(twobytes, text+34, 2); + if (check_segment_sanity(twobytes, 2) < 0) + return -1; +@@ -185,3 +185,5 @@ struct guidname { + }; + + #endif /* LIBEFIVAR_GUID */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/hexdump.h b/src/hexdump.h +index f8c32faa9e1..d88aa507b8d 100644 +--- a/src/hexdump.h ++++ b/src/hexdump.h +@@ -114,3 +114,5 @@ hexdump(uint8_t *data, unsigned long size) + } + + #endif /* STATIC_HEXDUMP_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/lib.h b/src/lib.h +index 5024128c42c..3cc29a01fb4 100644 +--- a/src/lib.h ++++ b/src/lib.h +@@ -51,3 +51,5 @@ extern struct efi_var_operations vars_ops; + extern struct efi_var_operations efivarfs_ops; + + #endif /* LIBEFIVAR_LIB_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux.h b/src/linux.h +index 43a9b7899f5..5ae64ffaacf 100644 +--- a/src/linux.h ++++ b/src/linux.h +@@ -22,75 +22,75 @@ + #define _EFIBOOT_LINUX_H + + struct acpi_root_info { +- uint32_t acpi_hid; +- uint64_t acpi_uid; +- uint32_t acpi_cid; +- char *acpi_hid_str; +- char *acpi_uid_str; +- char *acpi_cid_str; ++ uint32_t acpi_hid; ++ uint64_t acpi_uid; ++ uint32_t acpi_cid; ++ char *acpi_hid_str; ++ char *acpi_uid_str; ++ char *acpi_cid_str; + }; + + struct pci_root_info { +- uint16_t pci_domain; +- uint8_t pci_bus; ++ uint16_t pci_domain; ++ uint8_t pci_bus; + }; + + struct pci_dev_info { +- uint16_t pci_domain; +- uint8_t pci_bus; +- uint8_t pci_device; +- uint8_t pci_function; +- char *driverlink; ++ uint16_t pci_domain; ++ uint8_t pci_bus; ++ uint8_t pci_device; ++ uint8_t pci_function; ++ char *driverlink; + }; + + struct scsi_info { +- uint32_t scsi_bus; +- uint32_t scsi_device; +- uint32_t scsi_target; +- uint64_t scsi_lun; ++ uint32_t scsi_bus; ++ uint32_t scsi_device; ++ uint32_t scsi_target; ++ uint64_t scsi_lun; + }; + + struct sas_info { +- uint32_t scsi_bus; +- uint32_t scsi_device; +- uint32_t scsi_target; +- uint64_t scsi_lun; ++ uint32_t scsi_bus; ++ uint32_t scsi_device; ++ uint32_t scsi_target; ++ uint64_t scsi_lun; + +- uint64_t sas_address; ++ uint64_t sas_address; + }; + + struct sata_info { +- uint32_t scsi_bus; +- uint32_t scsi_device; +- uint32_t scsi_target; +- uint64_t scsi_lun; ++ uint32_t scsi_bus; ++ uint32_t scsi_device; ++ uint32_t scsi_target; ++ uint64_t scsi_lun; + +- uint32_t ata_devno; +- uint32_t ata_port; +- uint32_t ata_pmp; ++ uint32_t ata_devno; ++ uint32_t ata_port; ++ uint32_t ata_pmp; + +- uint32_t ata_print_id; ++ uint32_t ata_print_id; + }; + + struct ata_info { +- uint32_t scsi_bus; +- uint32_t scsi_device; +- uint32_t scsi_target; +- uint64_t scsi_lun; ++ uint32_t scsi_bus; ++ uint32_t scsi_device; ++ uint32_t scsi_target; ++ uint64_t scsi_lun; + +- uint32_t scsi_host; ++ uint32_t scsi_host; + }; + + struct nvme_info { +- int32_t ctrl_id; +- int32_t ns_id; +- int has_eui; +- uint8_t eui[8]; ++ int32_t ctrl_id; ++ int32_t ns_id; ++ int has_eui; ++ uint8_t eui[8]; + }; + + struct nvdimm_info { +- efi_guid_t namespace_label; +- efi_guid_t nvdimm_label; ++ efi_guid_t namespace_label; ++ efi_guid_t nvdimm_label; + }; + + struct emmc_info { +@@ -98,58 +98,58 @@ struct emmc_info { + }; + + enum interface_type { +- unknown, +- isa, acpi_root, pci_root, soc_root, pci, network, +- ata, atapi, scsi, sata, sas, +- usb, i1394, fibre, i2o, +- md, virtblk, +- nvme, nd_pmem, +- emmc, ++ unknown, ++ isa, acpi_root, pci_root, soc_root, pci, network, ++ ata, atapi, scsi, sata, sas, ++ usb, i1394, fibre, i2o, ++ md, virtblk, ++ nvme, nd_pmem, ++ emmc, + }; + + struct dev_probe; + + struct device { +- enum interface_type interface_type; +- uint32_t flags; +- char *link; +- char *device; +- char *driver; +- +- struct dev_probe **probes; +- unsigned int n_probes; +- +- union { +- struct { +- struct stat stat; +- +- unsigned int controllernum; +- unsigned int disknum; +- int part; +- uint64_t major; +- uint32_t minor; +- uint32_t edd10_devicenum; +- +- char *disk_name; +- char *part_name; +- +- struct acpi_root_info acpi_root; +- struct pci_root_info pci_root; +- unsigned int n_pci_devs; +- struct pci_dev_info *pci_dev; +- +- union { +- struct scsi_info scsi_info; +- struct sas_info sas_info; +- struct sata_info sata_info; +- struct ata_info ata_info; +- struct nvme_info nvme_info; +- struct emmc_info emmc_info; +- struct nvdimm_info nvdimm_info; +- }; +- }; +- char *ifname; +- }; ++ enum interface_type interface_type; ++ uint32_t flags; ++ char *link; ++ char *device; ++ char *driver; ++ ++ struct dev_probe **probes; ++ unsigned int n_probes; ++ ++ union { ++ struct { ++ struct stat stat; ++ ++ unsigned int controllernum; ++ unsigned int disknum; ++ int part; ++ uint64_t major; ++ uint32_t minor; ++ uint32_t edd10_devicenum; ++ ++ char *disk_name; ++ char *part_name; ++ ++ struct acpi_root_info acpi_root; ++ struct pci_root_info pci_root; ++ unsigned int n_pci_devs; ++ struct pci_dev_info *pci_dev; ++ ++ union { ++ struct scsi_info scsi_info; ++ struct sas_info sas_info; ++ struct sata_info sata_info; ++ struct ata_info ata_info; ++ struct nvme_info nvme_info; ++ struct emmc_info emmc_info; ++ struct nvdimm_info nvdimm_info; ++ }; ++ }; ++ char *ifname; ++ }; + }; + + extern struct device HIDDEN *device_get(int fd, int partition); +@@ -160,117 +160,117 @@ extern int HIDDEN set_part_name(struct device *dev, const char * const fmt, ...) + extern int HIDDEN set_disk_name(struct device *dev, const char * const fmt, ...); + extern bool HIDDEN is_pata(struct device *dev); + extern int HIDDEN make_blockdev_path(uint8_t *buf, ssize_t size, +- struct device *dev); ++ struct device *dev); + extern int HIDDEN parse_acpi_hid_uid(struct device *dev, const char *fmt, ...); + extern int HIDDEN eb_nvme_ns_id(int fd, uint32_t *ns_id); + + int HIDDEN get_sector_size(int filedes); + + extern int HIDDEN find_parent_devpath(const char * const child, +- char **parent); ++ char **parent); + + extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size, +- const char * const ifname); +- +-#define read_sysfs_file(buf, fmt, args...) \ +- ({ \ +- uint8_t *buf_ = NULL; \ +- ssize_t bufsize_ = -1; \ +- int error_; \ +- \ +- bufsize_ = get_file(&buf_, "/sys/" fmt, ## args); \ +- if (bufsize_ > 0) { \ +- uint8_t *buf2_ = alloca(bufsize_); \ +- error_ = errno; \ +- if (buf2_) \ +- memcpy(buf2_, buf_, bufsize_); \ +- free(buf_); \ +- *(buf) = (__typeof__(*(buf)))buf2_; \ +- errno = error_; \ +- } else if (buf_) { \ +- /* covscan is _sure_ we leak buf_ if bufsize_ */\ +- /* is <= 0, which is wrong, but appease it. */\ +- free(buf_); \ +- buf_ = NULL; \ +- } \ +- bufsize_; \ +- }) +- +-#define sysfs_readlink(linkbuf, fmt, args...) \ +- ({ \ +- char *_lb = alloca(PATH_MAX+1); \ +- char *_pn; \ +- int _rc; \ +- \ +- *(linkbuf) = NULL; \ +- _rc = asprintfa(&_pn, "/sys/" fmt, ## args); \ +- if (_rc >= 0) { \ +- ssize_t _linksz; \ +- _rc = _linksz = readlink(_pn, _lb, PATH_MAX); \ +- if (_linksz >= 0) \ +- _lb[_linksz] = '\0'; \ +- else \ +- efi_error("readlink of %s failed", _pn);\ +- *(linkbuf) = _lb; \ +- } else { \ +- efi_error("could not allocate memory"); \ +- } \ +- _rc; \ +- }) +- +-#define sysfs_stat(statbuf, fmt, args...) \ +- ({ \ +- int rc_; \ +- char *pn_; \ +- \ +- rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \ +- if (rc_ >= 0) { \ +- rc_ = stat(pn_, statbuf); \ +- if (rc_ < 0) \ +- efi_error("could not stat %s", pn_); \ +- } else { \ +- efi_error("could not allocate memory"); \ +- } \ +- rc_; \ +- }) +- +-#define sysfs_opendir(fmt, args...) \ +- ({ \ +- int rc_; \ +- char *pn_; \ +- DIR *dir_ = NULL; \ +- \ +- rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \ +- if (rc_ >= 0) { \ +- dir_ = opendir(pn_); \ +- if (dir_ == NULL) \ +- efi_error("could not open %s", pn_); \ +- } else { \ +- efi_error("could not allocate memory"); \ +- } \ +- dir_; \ +- }) ++ const char * const ifname); ++ ++#define read_sysfs_file(buf, fmt, args...) \ ++ ({ \ ++ uint8_t *buf_ = NULL; \ ++ ssize_t bufsize_ = -1; \ ++ int error_; \ ++ \ ++ bufsize_ = get_file(&buf_, "/sys/" fmt, ## args); \ ++ if (bufsize_ > 0) { \ ++ uint8_t *buf2_ = alloca(bufsize_); \ ++ error_ = errno; \ ++ if (buf2_) \ ++ memcpy(buf2_, buf_, bufsize_); \ ++ free(buf_); \ ++ *(buf) = (__typeof__(*(buf)))buf2_; \ ++ errno = error_; \ ++ } else if (buf_) { \ ++ /* covscan is _sure_ we leak buf_ if bufsize_ */\ ++ /* is <= 0, which is wrong, but appease it. */\ ++ free(buf_); \ ++ buf_ = NULL; \ ++ } \ ++ bufsize_; \ ++ }) ++ ++#define sysfs_readlink(linkbuf, fmt, args...) \ ++ ({ \ ++ char *_lb = alloca(PATH_MAX+1); \ ++ char *_pn; \ ++ int _rc; \ ++ \ ++ *(linkbuf) = NULL; \ ++ _rc = asprintfa(&_pn, "/sys/" fmt, ## args); \ ++ if (_rc >= 0) { \ ++ ssize_t _linksz; \ ++ _rc = _linksz = readlink(_pn, _lb, PATH_MAX); \ ++ if (_linksz >= 0) \ ++ _lb[_linksz] = '\0'; \ ++ else \ ++ efi_error("readlink of %s failed", _pn);\ ++ *(linkbuf) = _lb; \ ++ } else { \ ++ efi_error("could not allocate memory"); \ ++ } \ ++ _rc; \ ++ }) ++ ++#define sysfs_stat(statbuf, fmt, args...) \ ++ ({ \ ++ int rc_; \ ++ char *pn_; \ ++ \ ++ rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \ ++ if (rc_ >= 0) { \ ++ rc_ = stat(pn_, statbuf); \ ++ if (rc_ < 0) \ ++ efi_error("could not stat %s", pn_); \ ++ } else { \ ++ efi_error("could not allocate memory"); \ ++ } \ ++ rc_; \ ++ }) ++ ++#define sysfs_opendir(fmt, args...) \ ++ ({ \ ++ int rc_; \ ++ char *pn_; \ ++ DIR *dir_ = NULL; \ ++ \ ++ rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \ ++ if (rc_ >= 0) { \ ++ dir_ = opendir(pn_); \ ++ if (dir_ == NULL) \ ++ efi_error("could not open %s", pn_); \ ++ } else { \ ++ efi_error("could not allocate memory"); \ ++ } \ ++ dir_; \ ++ }) + + #define DEV_PROVIDES_ROOT 1 +-#define DEV_PROVIDES_HD 2 +-#define DEV_ABBREV_ONLY 4 ++#define DEV_PROVIDES_HD 2 ++#define DEV_ABBREV_ONLY 4 + + struct dev_probe { +- char *name; +- enum interface_type *iftypes; +- uint32_t flags; +- ssize_t (*parse)(struct device *dev, +- const char * const current, const char * const root); +- ssize_t (*create)(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off); +- char *(*make_part_name)(struct device *dev); ++ char *name; ++ enum interface_type *iftypes; ++ uint32_t flags; ++ ssize_t (*parse)(struct device *dev, ++ const char * const current, const char * const root); ++ ssize_t (*create)(struct device *dev, ++ uint8_t *buf, ssize_t size, ssize_t off); ++ char *(*make_part_name)(struct device *dev); + }; + + extern ssize_t parse_scsi_link(const char *current, uint32_t *host, +- uint32_t *bus, uint32_t *device, +- uint32_t *target, uint64_t *lun, +- uint32_t *local_port_id, uint32_t *remote_port_id, +- uint32_t *remote_target_id); ++ uint32_t *bus, uint32_t *device, ++ uint32_t *target, uint64_t *lun, ++ uint32_t *local_port_id, uint32_t *remote_port_id, ++ uint32_t *remote_target_id); + + /* device support implementations */ + extern struct dev_probe pmem_parser; +@@ -288,3 +288,5 @@ extern struct dev_probe ata_parser; + extern struct dev_probe emmc_parser; + + #endif /* _EFIBOOT_LINUX_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/path-helpers.h b/src/path-helpers.h +index 355f4be56af..7dec05b6297 100644 +--- a/src/path-helpers.h ++++ b/src/path-helpers.h +@@ -24,25 +24,26 @@ void HIDDEN fill_spans(const char *str, const char *reject, void *spanbuf); + unsigned int HIDDEN count_spans(const char *str, const char *reject, unsigned int *chars); + int HIDDEN find_path_segment(const char *path, int segment, const char **pos, size_t *len); + +-#define pathseg(path, seg) \ +- ({ \ +- const char *pos_ = NULL; \ +- char *ret_ = NULL; \ +- size_t len_ = 0; \ +- int rc_; \ +- \ +- rc_ = find_path_segment(path, seg, &pos_, &len_); \ +- if (rc_ >= 0) { \ +- ret_ = alloca(len_ + 1); \ +- if (ret_) { \ +- memcpy(ret_, pos_, len_); \ +- ret_[len_] = '\0'; \ +- } \ +- } \ +- ret_; \ +- }) ++#define pathseg(path, seg) \ ++ ({ \ ++ const char *pos_ = NULL; \ ++ char *ret_ = NULL; \ ++ size_t len_ = 0; \ ++ int rc_; \ ++ \ ++ rc_ = find_path_segment(path, seg, &pos_, &len_); \ ++ if (rc_ >= 0) { \ ++ ret_ = alloca(len_ + 1); \ ++ if (ret_) { \ ++ memcpy(ret_, pos_, len_); \ ++ ret_[len_] = '\0'; \ ++ } \ ++ } \ ++ ret_; \ ++ }) + + + + #endif /* !PATH_HELPER_H_ */ +-// vim:fenc=utf-8:tw=75:et ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/ucs2.h b/src/ucs2.h +index fd8b056ad25..176f9ccac57 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -180,3 +180,5 @@ utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8) + }; + + #endif /* _EFIVAR_UCS2_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/util.h b/src/util.h +index ec1c5f1a69a..712abea2d42 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -75,322 +75,322 @@ + #endif + #endif + #ifndef int_add +-#define int_add(a, b, c) ({ \ +- const int _limit = INT_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) ++#define int_add(a, b, c) ({ \ ++ const int _limit = INT_MAX; \ ++ int _ret; \ ++ _ret = _limit - ((unsigned long long)a) > \ ++ ((unsigned long long)b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ _ret; \ ++ }) + #endif + #ifndef long_add +-#define long_add(a, b, c) ({ \ +- const long _limit = LONG_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) ++#define long_add(a, b, c) ({ \ ++ const long _limit = LONG_MAX; \ ++ int _ret; \ ++ _ret = _limit - ((unsigned long long)a) > \ ++ ((unsigned long long)b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ _ret; \ ++ }) + #endif + #ifndef long_mult +-#define long_mult(a, b, c) ({ \ +- const long _limit = LONG_MAX; \ +- int _ret = 1; \ +- if ((a) == 0 || (b) == 0) \ +- _ret = 0; \ +- else \ +- _ret = _limit / (a) < (b); \ +- if (!_ret) \ +- *(c) = ((a) * (b)); \ +- _ret; \ +- }) ++#define long_mult(a, b, c) ({ \ ++ const long _limit = LONG_MAX; \ ++ int _ret = 1; \ ++ if ((a) == 0 || (b) == 0) \ ++ _ret = 0; \ ++ else \ ++ _ret = _limit / (a) < (b); \ ++ if (!_ret) \ ++ *(c) = ((a) * (b)); \ ++ _ret; \ ++ }) + #endif + #ifndef ulong_add +-#define ulong_add(a, b, c) ({ \ +- const unsigned long _limit = ULONG_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) ++#define ulong_add(a, b, c) ({ \ ++ const unsigned long _limit = ULONG_MAX; \ ++ int _ret; \ ++ _ret = _limit - ((unsigned long long)a) > \ ++ ((unsigned long long)b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ _ret; \ ++ }) + #endif + #ifndef ulong_mult +-#define ulong_mult(a, b, c) ({ \ +- const unsigned long _limit = ULONG_MAX; \ +- int _ret = 1; \ +- if ((a) == 0 || (b) == 0) \ +- _ret = 0; \ +- else \ +- _ret = _limit / (a) < (b); \ +- if (!_ret) \ +- *(c) = ((a) * (b)); \ +- _ret; \ +- }) ++#define ulong_mult(a, b, c) ({ \ ++ const unsigned long _limit = ULONG_MAX; \ ++ int _ret = 1; \ ++ if ((a) == 0 || (b) == 0) \ ++ _ret = 0; \ ++ else \ ++ _ret = _limit / (a) < (b); \ ++ if (!_ret) \ ++ *(c) = ((a) * (b)); \ ++ _ret; \ ++ }) + #endif + + #if defined(__GNUC__) && defined(__GNUC_MINOR__) + #if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1 +-#define add(a, b, c) _Generic((c), \ +- int *: int_add(a,b,c), \ +- long *: long_add(a,b,c), \ +- unsigned long *: ulong_add(a,b,c)) +-#define mult(a, b, c) _Generic((c), \ +- long *: long_mult(a,b,c), \ +- unsigned long *: ulong_mult(a,b,c)) ++#define add(a, b, c) _Generic((c), \ ++ int *: int_add(a,b,c), \ ++ long *: long_add(a,b,c), \ ++ unsigned long *: ulong_add(a,b,c)) ++#define mult(a, b, c) _Generic((c), \ ++ long *: long_mult(a,b,c), \ ++ unsigned long *: ulong_mult(a,b,c)) + #endif + #endif + + #ifndef add +-#define add(a, b, c) ({ \ +- (*(c)) = ((a) + (b)); \ +- }) ++#define add(a, b, c) ({ \ ++ (*(c)) = ((a) + (b)); \ ++ }) + #endif + #ifndef mult +-#define mult(a, b, c) ({ \ +- (*(c)) = ((a) * (b)); \ +- }) ++#define mult(a, b, c) ({ \ ++ (*(c)) = ((a) * (b)); \ ++ }) + #endif + + static inline int UNUSED + read_file(int fd, uint8_t **result, size_t *bufsize) + { +- uint8_t *p; +- size_t size = 4096; +- size_t filesize = 0; +- ssize_t s = 0; +- uint8_t *buf, *newbuf; ++ uint8_t *p; ++ size_t size = 4096; ++ size_t filesize = 0; ++ ssize_t s = 0; ++ uint8_t *buf, *newbuf; + +- if (!(newbuf = calloc(size, sizeof (uint8_t)))) { +- efi_error("could not allocate memory"); +- *result = buf = NULL; +- *bufsize = 0; +- return -1; +- } +- buf = newbuf; ++ if (!(newbuf = calloc(size, sizeof (uint8_t)))) { ++ efi_error("could not allocate memory"); ++ *result = buf = NULL; ++ *bufsize = 0; ++ return -1; ++ } ++ buf = newbuf; + +- do { +- p = buf + filesize; +- /* size - filesize shouldn't exceed SSIZE_MAX because we're +- * only allocating 4096 bytes at a time and we're checking that +- * before doing so. */ +- s = read(fd, p, size - filesize); +- if (s < 0 && errno == EAGAIN) { +- /* +- * if we got EAGAIN, there's a good chance we've hit +- * the kernel rate limiter. Doing more reads is just +- * going to make it worse, so instead, give it a rest. +- */ +- sched_yield(); +- continue; +- } else if (s < 0) { +- int saved_errno = errno; +- free(buf); +- *result = buf = NULL; +- *bufsize = 0; +- errno = saved_errno; +- efi_error("could not read from file"); +- return -1; +- } +- filesize += s; +- /* only exit for empty reads */ +- if (s == 0) +- break; +- if (filesize >= size) { +- /* See if we're going to overrun and return an error +- * instead. */ +- if (size > (size_t)-1 - 4096) { +- free(buf); +- *result = buf = NULL; +- *bufsize = 0; +- errno = ENOMEM; +- efi_error("could not read from file"); +- return -1; +- } +- newbuf = realloc(buf, size + 4096); +- if (newbuf == NULL) { +- int saved_errno = errno; +- free(buf); +- *result = buf = NULL; +- *bufsize = 0; +- errno = saved_errno; +- efi_error("could not allocate memory"); +- return -1; +- } +- buf = newbuf; +- memset(buf + size, '\0', 4096); +- size += 4096; +- } +- } while (1); ++ do { ++ p = buf + filesize; ++ /* size - filesize shouldn't exceed SSIZE_MAX because we're ++ * only allocating 4096 bytes at a time and we're checking that ++ * before doing so. */ ++ s = read(fd, p, size - filesize); ++ if (s < 0 && errno == EAGAIN) { ++ /* ++ * if we got EAGAIN, there's a good chance we've hit ++ * the kernel rate limiter. Doing more reads is just ++ * going to make it worse, so instead, give it a rest. ++ */ ++ sched_yield(); ++ continue; ++ } else if (s < 0) { ++ int saved_errno = errno; ++ free(buf); ++ *result = buf = NULL; ++ *bufsize = 0; ++ errno = saved_errno; ++ efi_error("could not read from file"); ++ return -1; ++ } ++ filesize += s; ++ /* only exit for empty reads */ ++ if (s == 0) ++ break; ++ if (filesize >= size) { ++ /* See if we're going to overrun and return an error ++ * instead. */ ++ if (size > (size_t)-1 - 4096) { ++ free(buf); ++ *result = buf = NULL; ++ *bufsize = 0; ++ errno = ENOMEM; ++ efi_error("could not read from file"); ++ return -1; ++ } ++ newbuf = realloc(buf, size + 4096); ++ if (newbuf == NULL) { ++ int saved_errno = errno; ++ free(buf); ++ *result = buf = NULL; ++ *bufsize = 0; ++ errno = saved_errno; ++ efi_error("could not allocate memory"); ++ return -1; ++ } ++ buf = newbuf; ++ memset(buf + size, '\0', 4096); ++ size += 4096; ++ } ++ } while (1); + +- newbuf = realloc(buf, filesize+1); +- if (!newbuf) { +- free(buf); +- *result = buf = NULL; +- efi_error("could not allocate memory"); +- return -1; +- } +- newbuf[filesize] = '\0'; +- *result = newbuf; +- *bufsize = filesize+1; +- return 0; ++ newbuf = realloc(buf, filesize+1); ++ if (!newbuf) { ++ free(buf); ++ *result = buf = NULL; ++ efi_error("could not allocate memory"); ++ return -1; ++ } ++ newbuf[filesize] = '\0'; ++ *result = newbuf; ++ *bufsize = filesize+1; ++ return 0; + } + + static inline uint64_t UNUSED + lcm(uint64_t x, uint64_t y) + { +- uint64_t m = x, n = y, o; +- while ((o = m % n)) { +- m = n; +- n = o; +- } +- return (x / n) * y; ++ uint64_t m = x, n = y, o; ++ while ((o = m % n)) { ++ m = n; ++ n = o; ++ } ++ return (x / n) * y; + } + + #ifndef strdupa +-#define strdupa(s) \ +- (__extension__ ({ \ +- const char *__in = (s); \ +- size_t __len = strlen (__in); \ +- char *__out = (char *) alloca (__len + 1); \ +- strcpy(__out, __in); \ +- __out; \ +- })) ++#define strdupa(s) \ ++ (__extension__ ({ \ ++ const char *__in = (s); \ ++ size_t __len = strlen (__in); \ ++ char *__out = (char *) alloca (__len + 1); \ ++ strcpy(__out, __in); \ ++ __out; \ ++ })) + #endif + + #ifndef strndupa +-#define strndupa(s, l) \ +- (__extension__ ({ \ +- const char *__in = (s); \ +- size_t __len = strnlen (__in, (l)); \ +- char *__out = (char *) alloca (__len + 1); \ +- strncpy(__out, __in, __len); \ +- __out[__len] = '\0'; \ +- __out; \ +- })) ++#define strndupa(s, l) \ ++ (__extension__ ({ \ ++ const char *__in = (s); \ ++ size_t __len = strnlen (__in, (l)); \ ++ char *__out = (char *) alloca (__len + 1); \ ++ strncpy(__out, __in, __len); \ ++ __out[__len] = '\0'; \ ++ __out; \ ++ })) + #endif + +-#define asprintfa(str, fmt, args...) \ +- ({ \ +- char *_tmp = NULL; \ +- int _rc; \ +- *(str) = NULL; \ +- _rc = asprintf((str), (fmt), ## args); \ +- if (_rc > 0) { \ +- _tmp = strdupa(*(str)); \ +- if (!_tmp) { \ +- _rc = -1; \ +- } else { \ +- free(*(str)); \ +- *(str) = _tmp; \ +- } \ +- } else { \ +- _rc = -1; \ +- } \ +- _rc; \ +- }) ++#define asprintfa(str, fmt, args...) \ ++ ({ \ ++ char *_tmp = NULL; \ ++ int _rc; \ ++ *(str) = NULL; \ ++ _rc = asprintf((str), (fmt), ## args); \ ++ if (_rc > 0) { \ ++ _tmp = strdupa(*(str)); \ ++ if (!_tmp) { \ ++ _rc = -1; \ ++ } else { \ ++ free(*(str)); \ ++ *(str) = _tmp; \ ++ } \ ++ } else { \ ++ _rc = -1; \ ++ } \ ++ _rc; \ ++ }) + +-#define vasprintfa(str, fmt, ap) \ +- ({ \ +- char *_tmp = NULL; \ +- int _rc; \ +- *(str) = NULL; \ +- _rc = vasprintf((str), (fmt), (ap)); \ +- if (_rc > 0) { \ +- _tmp = strdupa(*(str)); \ +- if (!_tmp) { \ +- _rc = -1; \ +- } else { \ +- free(*(str)); \ +- *(str) = _tmp; \ +- } \ +- } else { \ +- _rc = -1; \ +- } \ +- _rc; \ +- }) ++#define vasprintfa(str, fmt, ap) \ ++ ({ \ ++ char *_tmp = NULL; \ ++ int _rc; \ ++ *(str) = NULL; \ ++ _rc = vasprintf((str), (fmt), (ap)); \ ++ if (_rc > 0) { \ ++ _tmp = strdupa(*(str)); \ ++ if (!_tmp) { \ ++ _rc = -1; \ ++ } else { \ ++ free(*(str)); \ ++ *(str) = _tmp; \ ++ } \ ++ } else { \ ++ _rc = -1; \ ++ } \ ++ _rc; \ ++ }) + + static inline ssize_t + get_file(uint8_t **result, const char * const fmt, ...) + { +- char *path; +- uint8_t *buf = NULL; +- size_t bufsize = 0; +- ssize_t rc; +- va_list ap; +- int error; +- int fd; ++ char *path; ++ uint8_t *buf = NULL; ++ size_t bufsize = 0; ++ ssize_t rc; ++ va_list ap; ++ int error; ++ int fd; + +- if (result == NULL) { +- efi_error("invalid parameter 'result'"); +- return -1; +- } ++ if (result == NULL) { ++ efi_error("invalid parameter 'result'"); ++ return -1; ++ } + +- va_start(ap, fmt); +- rc = vasprintfa(&path, fmt, ap); +- va_end(ap); +- if (rc < 0) { +- efi_error("could not allocate memory"); +- return -1; +- } ++ va_start(ap, fmt); ++ rc = vasprintfa(&path, fmt, ap); ++ va_end(ap); ++ if (rc < 0) { ++ efi_error("could not allocate memory"); ++ return -1; ++ } + +- fd = open(path, O_RDONLY); +- if (fd < 0) { +- efi_error("could not open file \"%s\" for reading", +- path); +- return -1; +- } ++ fd = open(path, O_RDONLY); ++ if (fd < 0) { ++ efi_error("could not open file \"%s\" for reading", ++ path); ++ return -1; ++ } + +- rc = read_file(fd, &buf, &bufsize); +- error = errno; +- close(fd); +- errno = error; ++ rc = read_file(fd, &buf, &bufsize); ++ error = errno; ++ close(fd); ++ errno = error; + +- if (rc < 0 || bufsize < 1) { +- /* +- * I don't think this can happen, but I can't convince +- * cov-scan +- */ +- if (buf) +- free(buf); +- *result = NULL; +- efi_error("could not read file \"%s\"", path); +- return -1; +- } ++ if (rc < 0 || bufsize < 1) { ++ /* ++ * I don't think this can happen, but I can't convince ++ * cov-scan ++ */ ++ if (buf) ++ free(buf); ++ *result = NULL; ++ efi_error("could not read file \"%s\"", path); ++ return -1; ++ } + +- *result = buf; +- return bufsize; ++ *result = buf; ++ return bufsize; + } + + static inline void UNUSED + swizzle_guid_to_uuid(efi_guid_t *guid) + { +- uint32_t *u32; +- uint16_t *u16; ++ uint32_t *u32; ++ uint16_t *u16; + +- u32 = (uint32_t *)guid; +- u32[0] = __builtin_bswap32(u32[0]); +- u16 = (uint16_t *)&u32[1]; +- u16[0] = __builtin_bswap16(u16[0]); +- u16[1] = __builtin_bswap16(u16[1]); ++ u32 = (uint32_t *)guid; ++ u32[0] = __builtin_bswap32(u32[0]); ++ u16 = (uint16_t *)&u32[1]; ++ u16[0] = __builtin_bswap16(u16[0]); ++ u16[1] = __builtin_bswap16(u16[1]); + } + +-#define log_(file, line, func, level, fmt, args...) \ +- ({ \ +- efi_set_loglevel(level); \ +- FILE *logfile_ = efi_get_logfile(); \ +- int len_ = strlen(fmt); \ +- fprintf(logfile_, "%s:%d %s(): ", \ +- file, line, func); \ +- fprintf(logfile_, fmt, ## args); \ +- if (!len_ || fmt[len_ - 1] != '\n') \ +- fprintf(logfile_, "\n"); \ +- }) ++#define log_(file, line, func, level, fmt, args...) \ ++ ({ \ ++ efi_set_loglevel(level); \ ++ FILE *logfile_ = efi_get_logfile(); \ ++ int len_ = strlen(fmt); \ ++ fprintf(logfile_, "%s:%d %s(): ", \ ++ file, line, func); \ ++ fprintf(logfile_, fmt, ## args); \ ++ if (!len_ || fmt[len_ - 1] != '\n') \ ++ fprintf(logfile_, "\n"); \ ++ }) + + #define LOG_VERBOSE 0 + #define LOG_DEBUG 1 +@@ -399,14 +399,16 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + #endif + #define log(level, fmt, args...) log_(__FILE__, __LINE__, __func__, level, fmt, ## args) + #define debug(fmt, args...) log(LOG_DEBUG, fmt, ## args) +-#define log_hex_(file, line, func, level, buf, size) \ +- ({ \ +- efi_set_loglevel(level); \ +- fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ +- (uint8_t *)buf, size, \ +- file, line, func); \ +- }) ++#define log_hex_(file, line, func, level, buf, size) \ ++ ({ \ ++ efi_set_loglevel(level); \ ++ fhexdumpf(efi_get_logfile(), "%s:%d %s(): ", \ ++ (uint8_t *)buf, size, \ ++ file, line, func); \ ++ }) + #define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size) + #define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size) + + #endif /* EFIVAR_UTIL_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +-- +2.24.1 + diff --git a/SOURCES/0031-Exported-header-whitespace-cleanup.patch b/SOURCES/0031-Exported-header-whitespace-cleanup.patch new file mode 100644 index 0000000..af1c82e --- /dev/null +++ b/SOURCES/0031-Exported-header-whitespace-cleanup.patch @@ -0,0 +1,97 @@ +From 68dfc9ec98de261401deb88686cd35600d69b8a6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:27:08 -0400 +Subject: [PATCH 31/86] Exported header whitespace cleanup. + +Signed-off-by: Peter Jones +--- + src/include/efivar/efiboot-creator.h | 2 ++ + src/include/efivar/efiboot-loadopt.h | 2 ++ + src/include/efivar/efiboot.h | 4 +++- + src/include/efivar/efivar-dp.h | 8 +++++--- + src/include/efivar/efivar.h | 8 ++++---- + 5 files changed, 16 insertions(+), 8 deletions(-) + +diff --git a/src/include/efivar/efiboot-creator.h b/src/include/efivar/efiboot-creator.h +index b56e836d2e5..b6e094c637c 100644 +--- a/src/include/efivar/efiboot-creator.h ++++ b/src/include/efivar/efiboot-creator.h +@@ -58,3 +58,5 @@ extern ssize_t efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size, + __attribute__((__visibility__ ("default"))); + + #endif /* _EFIBOOT_CREATOR_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/include/efivar/efiboot-loadopt.h b/src/include/efivar/efiboot-loadopt.h +index efc29c69d47..97b7892f4b8 100644 +--- a/src/include/efivar/efiboot-loadopt.h ++++ b/src/include/efivar/efiboot-loadopt.h +@@ -74,3 +74,5 @@ extern int efi_loadopt_is_valid(efi_load_option *opt, size_t size) + __attribute__((__visibility__ ("default"))); + + #endif /* _EFIBOOT_LOADOPT_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/include/efivar/efiboot.h b/src/include/efivar/efiboot.h +index 2aee86d661e..8ae51ffa2a7 100644 +--- a/src/include/efivar/efiboot.h ++++ b/src/include/efivar/efiboot.h +@@ -36,6 +36,8 @@ + #include + + extern uint32_t efi_get_libefiboot_version(void) +- __attribute__((__visibility__("default"))); ++ __attribute__((__visibility__("default"))); + + #endif /* EFIBOOT_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h +index eab04f2dfac..57453548701 100644 +--- a/src/include/efivar/efivar-dp.h ++++ b/src/include/efivar/efivar-dp.h +@@ -135,9 +135,9 @@ typedef struct { + } EFIVAR_PACKED efidp_acpi_hid_ex; + extern ssize_t + efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size, +- uint32_t hid, uint32_t uid, uint32_t cid, +- const char *hidstr, const char *uidstr, +- const char *cidstr); ++ uint32_t hid, uint32_t uid, uint32_t cid, ++ const char *hidstr, const char *uidstr, ++ const char *cidstr); + + #define EFIDP_PNP_EISA_ID_CONST 0x41d0 + #define EFIDP_PNP_ACPI_ID_CONST 0x8e09 +@@ -1257,3 +1257,5 @@ extern ssize_t efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type, + EFIDP_END_INSTANCE, sizeof (efidp_header)); + + #endif /* _EFIVAR_DP_H */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 2fdf5b93b29..caa4adf056c 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -243,14 +243,14 @@ efi_set_loglevel(int level __attribute__((__unused__))) + efi_error_real__(errval, __FILE__, __func__, __LINE__, (fmt), ## args) + + extern void efi_set_verbose(int verbosity, FILE *errlog) +- __attribute__((__visibility__("default"))); ++ __attribute__((__visibility__("default"))); + extern int efi_get_verbose(void) +- __attribute__((__visibility__("default"))); ++ __attribute__((__visibility__("default"))); + extern FILE * efi_get_logfile(void) +- __attribute__((__visibility__("default"))); ++ __attribute__((__visibility__("default"))); + + extern uint32_t efi_get_libefivar_version(void) +- __attribute__((__visibility__("default"))); ++ __attribute__((__visibility__("default"))); + + #include + +-- +2.24.1 + diff --git a/SOURCES/0032-Main-code-whitespace-cleanup.patch b/SOURCES/0032-Main-code-whitespace-cleanup.patch new file mode 100644 index 0000000..65bb360 --- /dev/null +++ b/SOURCES/0032-Main-code-whitespace-cleanup.patch @@ -0,0 +1,5136 @@ +From b049a3267bdddde8c75e5451d6af38c3421a55a6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:42:46 -0400 +Subject: [PATCH 32/86] Main code whitespace cleanup. + +Signed-off-by: Peter Jones +--- + src/crc32.c | 207 +++++---- + src/creator.c | 22 +- + src/disk.c | 24 +- + src/dp-acpi.c | 2 + + src/dp-hw.c | 2 + + src/dp-media.c | 2 + + src/dp-message.c | 2 + + src/dp.c | 5 +- + src/efivar.c | 14 +- + src/efivarfs.c | 19 +- + src/export.c | 2 + + src/gpt.c | 2 + + src/guid.c | 6 +- + src/lib.c | 16 +- + src/linux-acpi-root.c | 280 ++++++------ + src/linux-acpi.c | 150 +++--- + src/linux-ata.c | 202 ++++---- + src/linux-emmc.c | 102 +++-- + src/linux-i2o.c | 42 +- + src/linux-md.c | 66 +-- + src/linux-nvme.c | 171 +++---- + src/linux-pci-root.c | 128 +++--- + src/linux-pci.c | 194 ++++---- + src/linux-pmem.c | 200 ++++---- + src/linux-sas.c | 314 ++++++------- + src/linux-sata.c | 340 +++++++------- + src/linux-scsi.c | 492 ++++++++++---------- + src/linux-soc-root.c | 30 +- + src/linux-virtblk.c | 39 +- + src/linux.c | 1016 ++++++++++++++++++++--------------------- + src/loadopt.c | 2 + + src/makeguids.c | 2 + + src/path-helpers.c | 222 ++++----- + src/vars.c | 2 + + 34 files changed, 2192 insertions(+), 2127 deletions(-) + +diff --git a/src/crc32.c b/src/crc32.c +index e9086b10e2c..533d2c0f551 100644 +--- a/src/crc32.c ++++ b/src/crc32.c +@@ -1,4 +1,4 @@ +-/* ++/* + * Dec 5, 2000 Matt Domsch + * - Copied crc32.c from the linux/drivers/net/cipe directory. + * - Now pass seed as an arg +@@ -7,118 +7,117 @@ + * - License remains unchanged! It's still GPL-compatable! + */ + +- /* ============================================================= */ +- /* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */ +- /* code or tables extracted from it, as desired without restriction. */ +- /* */ +- /* First, the polynomial itself and its table of feedback terms. The */ +- /* polynomial is */ +- /* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ +- /* */ +- /* Note that we take it "backwards" and put the highest-order term in */ +- /* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ +- /* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ +- /* the MSB being 1. */ +- /* */ +- /* Note that the usual hardware shift register implementation, which */ +- /* is what we're using (we're merely optimizing it by doing eight-bit */ +- /* chunks at a time) shifts bits into the lowest-order term. In our */ +- /* implementation, that means shifting towards the right. Why do we */ +- /* do it this way? Because the calculated CRC must be transmitted in */ +- /* order from highest-order term to lowest-order term. UARTs transmit */ +- /* characters in order from LSB to MSB. By storing the CRC this way, */ +- /* we hand it to the UART in the order low-byte to high-byte; the UART */ +- /* sends each low-bit to hight-bit; and the result is transmission bit */ +- /* by bit from highest- to lowest-order term without requiring any bit */ +- /* shuffling on our part. Reception works similarly. */ +- /* */ +- /* The feedback terms table consists of 256, 32-bit entries. Notes: */ +- /* */ +- /* The table can be generated at runtime if desired; code to do so */ +- /* is shown later. It might not be obvious, but the feedback */ +- /* terms simply represent the results of eight shift/xor opera- */ +- /* tions for all combinations of data and CRC register values. */ +- /* */ +- /* The values must be right-shifted by eight bits by the "updcrc" */ +- /* logic; the shift must be unsigned (bring in zeroes). On some */ +- /* hardware you could probably optimize the shift in assembler by */ +- /* using byte-swap instructions. */ +- /* polynomial $edb88320 */ +- /* */ +- /* -------------------------------------------------------------------- */ ++/* ============================================================= */ ++/* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or */ ++/* code or tables extracted from it, as desired without restriction. */ ++/* */ ++/* First, the polynomial itself and its table of feedback terms. The */ ++/* polynomial is */ ++/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ ++/* */ ++/* Note that we take it "backwards" and put the highest-order term in */ ++/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ ++/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ ++/* the MSB being 1. */ ++/* */ ++/* Note that the usual hardware shift register implementation, which */ ++/* is what we're using (we're merely optimizing it by doing eight-bit */ ++/* chunks at a time) shifts bits into the lowest-order term. In our */ ++/* implementation, that means shifting towards the right. Why do we */ ++/* do it this way? Because the calculated CRC must be transmitted in */ ++/* order from highest-order term to lowest-order term. UARTs transmit */ ++/* characters in order from LSB to MSB. By storing the CRC this way, */ ++/* we hand it to the UART in the order low-byte to high-byte; the UART */ ++/* sends each low-bit to hight-bit; and the result is transmission bit */ ++/* by bit from highest- to lowest-order term without requiring any bit */ ++/* shuffling on our part. Reception works similarly. */ ++/* */ ++/* The feedback terms table consists of 256, 32-bit entries. Notes: */ ++/* */ ++/* The table can be generated at runtime if desired; code to do so */ ++/* is shown later. It might not be obvious, but the feedback */ ++/* terms simply represent the results of eight shift/xor opera- */ ++/* tions for all combinations of data and CRC register values. */ ++/* */ ++/* The values must be right-shifted by eight bits by the "updcrc" */ ++/* logic; the shift must be unsigned (bring in zeroes). On some */ ++/* hardware you could probably optimize the shift in assembler by */ ++/* using byte-swap instructions. */ ++/* polynomial $edb88320 */ ++/* */ ++/* -------------------------------------------------------------------- */ + + #include + + static uint32_t crc32_tab[] = { +- 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, +- 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, +- 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, +- 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, +- 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, +- 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, +- 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, +- 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, +- 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, +- 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, +- 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, +- 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, +- 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, +- 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, +- 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, +- 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, +- 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, +- 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, +- 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, +- 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, +- 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, +- 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, +- 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, +- 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, +- 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, +- 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, +- 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, +- 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, +- 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, +- 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, +- 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, +- 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, +- 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, +- 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, +- 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, +- 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, +- 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, +- 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, +- 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, +- 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, +- 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, +- 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, +- 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, +- 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, +- 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, +- 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, +- 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, +- 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, +- 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, +- 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, +- 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, +- 0x2d02ef8dL +- }; ++ 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, ++ 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, ++ 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, ++ 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, ++ 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, ++ 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, ++ 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, ++ 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, ++ 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, ++ 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, ++ 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, ++ 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, ++ 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, ++ 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, ++ 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, ++ 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, ++ 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, ++ 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, ++ 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, ++ 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, ++ 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, ++ 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, ++ 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, ++ 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, ++ 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, ++ 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, ++ 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, ++ 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, ++ 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, ++ 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, ++ 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, ++ 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, ++ 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, ++ 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, ++ 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, ++ 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, ++ 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, ++ 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, ++ 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, ++ 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, ++ 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, ++ 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, ++ 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, ++ 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, ++ 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, ++ 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, ++ 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, ++ 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, ++ 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, ++ 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, ++ 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, ++ 0x2d02ef8dL ++}; + + /* Return a 32-bit CRC of the contents of the buffer. */ + + uint32_t + crc32(const void *buf, unsigned long len, uint32_t seed) + { +- unsigned long i; +- register uint32_t crc32val; +- const unsigned char *s = buf; ++ unsigned long i; ++ register uint32_t val; ++ const unsigned char *s = buf; + +- crc32val = seed; +- for (i = 0; i < len; i ++) +- { +- crc32val = +- crc32_tab[(crc32val ^ s[i]) & 0xff] ^ +- (crc32val >> 8); +- } +- return crc32val; ++ val = seed; ++ for (i = 0; i < len; i ++) ++ val = crc32_tab[(val ^ s[i]) & 0xff] ^ (val >> 8); ++ ++ return val; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/creator.c b/src/creator.c +index f4bb01bc4a6..8a2f8e79aca 100644 +--- a/src/creator.c ++++ b/src/creator.c +@@ -243,13 +243,13 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, + va_end(aq); + } + +- if (!(options & (EFIBOOT_ABBREV_FILE|EFIBOOT_ABBREV_HD)) && +- (dev->flags & DEV_ABBREV_ONLY)) { +- efi_error_clear(); +- errno = EINVAL; +- efi_error("Device must use File() or HD() device path"); +- goto err; +- } ++ if (!(options & (EFIBOOT_ABBREV_FILE|EFIBOOT_ABBREV_HD)) ++ && (dev->flags & DEV_ABBREV_ONLY)) { ++ efi_error_clear(); ++ errno = EINVAL; ++ efi_error("Device must use File() or HD() device path"); ++ goto err; ++ } + + if ((options & EFIBOOT_ABBREV_EDD10) + && (!(options & EFIBOOT_ABBREV_FILE) +@@ -290,7 +290,7 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, + } + + sz = make_hd_dn(buf+off, size?size-off:0, +- disk_fd, dev->part, options); ++ disk_fd, dev->part, options); + saved_errno = errno; + close(disk_fd); + errno = saved_errno; +@@ -404,7 +404,7 @@ efi_generate_file_device_path(uint8_t *buf, ssize_t size, + efi_error("could not find parent device for file"); + goto err; + } +- debug("child_devpath:%s", child_devpath); ++ debug("child_devpath:%s", child_devpath); + + debug("parent_devpath:%s", parent_devpath); + debug("child_devpath:%s", child_devpath); +@@ -515,5 +515,7 @@ efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size, + uint32_t PUBLIC + efi_get_libefiboot_version(void) + { +- return LIBEFIVAR_VERSION; ++ return LIBEFIVAR_VERSION; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/disk.c b/src/disk.c +index 519c2a19325..3b5bf8330b1 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -79,11 +79,11 @@ msdos_disk_get_extended_partition_info (int fd UNUSED, + uint64_t *start UNUSED, + uint64_t *size UNUSED) + { +- /* Until I can handle these... */ +- //fprintf(stderr, "Extended partition info not supported.\n"); ++ /* Until I can handle these... */ ++ //fprintf(stderr, "Extended partition info not supported.\n"); + errno = ENOSYS; + efi_error("extended partition info is not supported"); +- return -1; ++ return -1; + } + + /************************************************************ +@@ -162,23 +162,23 @@ msdos_disk_get_partition_info (int fd, int write_signature, + } + *(uint32_t *)signature = mbr->unique_mbr_signature; + +- if (num > 4) { ++ if (num > 4) { + /* Extended partition */ +- rc = msdos_disk_get_extended_partition_info(fd, mbr, num, ++ rc = msdos_disk_get_extended_partition_info(fd, mbr, num, + start, size); + if (rc < 0) { + efi_error("could not get extended partition info"); + return rc; + } +- } else if (num == 0) { ++ } else if (num == 0) { + /* Whole disk */ +- *start = 0; ++ *start = 0; + ioctl(fd, BLKGETSIZE, &disk_size); +- *size = disk_size; ++ *size = disk_size; + } else if (num >= 1 && num <= 4) { + /* Primary partition */ +- *start = mbr->partition[num-1].starting_lba; +- *size = mbr->partition[num-1].size_in_lba; ++ *start = mbr->partition[num-1].starting_lba; ++ *size = mbr->partition[num-1].size_in_lba; + } + return 0; + } +@@ -259,7 +259,7 @@ is_partitioned(int fd) + + ssize_t HIDDEN + make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition, +- uint32_t options) ++ uint32_t options) + { + uint64_t part_start=0, part_size = 0; + uint8_t signature[16]="", format=0, signature_type=0; +@@ -284,3 +284,5 @@ make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition, + efi_error("could not make HD DP node"); + return rc; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp-acpi.c b/src/dp-acpi.c +index 3a80ba9e006..2525fdfd073 100644 +--- a/src/dp-acpi.c ++++ b/src/dp-acpi.c +@@ -333,3 +333,5 @@ efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size, + + return sz; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp-hw.c b/src/dp-hw.c +index 0dcf991d5c3..1fe0f66e871 100644 +--- a/src/dp-hw.c ++++ b/src/dp-hw.c +@@ -120,3 +120,5 @@ efidp_make_edd10(uint8_t *buf, ssize_t size, uint32_t hardware_device) + + return sz; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp-media.c b/src/dp-media.c +index be691c44326..4728c326100 100644 +--- a/src/dp-media.c ++++ b/src/dp-media.c +@@ -207,3 +207,5 @@ efidp_make_hd(uint8_t *buf, ssize_t size, uint32_t num, uint64_t part_start, + + return sz; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp-message.c b/src/dp-message.c +index 55fa7810439..b88f17fb712 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -846,3 +846,5 @@ efidp_make_emmc(uint8_t *buf, ssize_t size, uint32_t slot_id) + + return sz; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/dp.c b/src/dp.c +index 82d60b4f9be..b6eea74878c 100644 +--- a/src/dp.c ++++ b/src/dp.c +@@ -402,8 +402,7 @@ efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit) + } + + ssize_t PUBLIC +-efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, +- size_t size UNUSED) ++efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED) + { + efi_error("not implented"); + errno = -ENOSYS; +@@ -462,3 +461,5 @@ efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type, uint8_t subtype, + head->length = total_size; + return head->length; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/efivar.c b/src/efivar.c +index 228bdb745a7..df075809db5 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -281,7 +281,7 @@ edit_variable(const char *guid_name, void *data, size_t data_size, + } + + rc = efi_get_variable(guid, name, &old_data, &old_data_size, +- &old_attributes); ++ &old_attributes); + if (rc < 0 && edit_type != EDIT_WRITE) { + fprintf(stderr, "efivar: %m\n"); + show_errors(); +@@ -293,12 +293,14 @@ edit_variable(const char *guid_name, void *data, size_t data_size, + + switch (edit_type){ + case EDIT_APPEND: +- rc = efi_append_variable(guid, name, data, data_size, +- old_attributes); ++ rc = efi_append_variable(guid, name, ++ data, data_size, ++ old_attributes); + break; + case EDIT_WRITE: +- rc = efi_set_variable(guid, name, data, data_size, +- old_attributes, 0644); ++ rc = efi_set_variable(guid, name, ++ data, data_size, ++ old_attributes, 0644); + break; + } + +@@ -509,3 +511,5 @@ int main(int argc, char *argv[]) + + return 0; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/efivarfs.c b/src/efivarfs.c +index f47524a75c4..ec2585a6648 100644 +--- a/src/efivarfs.c ++++ b/src/efivarfs.c +@@ -130,14 +130,19 @@ efivarfs_make_fd_mutable(int fd, unsigned long *orig_attrs) + { + unsigned long mutable_attrs = 0; + +- *orig_attrs = 0; ++ *orig_attrs = 0; ++ + if (ioctl(fd, FS_IOC_GETFLAGS, orig_attrs) == -1) + return -1; ++ + if ((*orig_attrs & FS_IMMUTABLE_FL) == 0) + return 0; +- mutable_attrs = *orig_attrs & ~(unsigned long)FS_IMMUTABLE_FL; ++ ++ mutable_attrs = *orig_attrs & ~(unsigned long)FS_IMMUTABLE_FL; ++ + if (ioctl(fd, FS_IOC_SETFLAGS, &mutable_attrs) == -1) + return -1; ++ + return 0; + } + +@@ -448,10 +453,10 @@ err: + + ioctl(restore_immutable_fd, FS_IOC_SETFLAGS, &orig_attrs); + +- if (wfd >= 0) +- close(wfd); +- if (rfd >= 0) +- close(rfd); ++ if (wfd >= 0) ++ close(wfd); ++ if (rfd >= 0) ++ close(rfd); + + free(buf); + free(path); +@@ -513,3 +518,5 @@ struct efi_var_operations efivarfs_ops = { + .get_next_variable_name = efivarfs_get_next_variable_name, + .chmod_variable = efivarfs_chmod_variable, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/export.c b/src/export.c +index 8321bd3f8ba..5b11ae883cf 100644 +--- a/src/export.c ++++ b/src/export.c +@@ -335,3 +335,5 @@ efi_variable_realize(efi_variable_t *var) + return efi_set_variable(*var->guid, var->name, var->data, + var->data_size, attrs, 0600); + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/gpt.c b/src/gpt.c +index 7bdb8ad1575..aa4055b9812 100644 +--- a/src/gpt.c ++++ b/src/gpt.c +@@ -781,3 +781,5 @@ gpt_disk_get_partition_info(int fd, uint32_t num, uint64_t * start, + * tab-width: 8 + * End: + */ ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/guid.c b/src/guid.c +index 306c9ff8287..34efb132d51 100644 +--- a/src/guid.c ++++ b/src/guid.c +@@ -44,7 +44,7 @@ efi_guid_is_zero(const efi_guid_t *guid) + + int + efi_guid_is_empty(const efi_guid_t *guid) +- NONNULL(1) PUBLIC ALIAS(efi_guid_is_zero); ++ NONNULL(1) PUBLIC ALIAS(efi_guid_is_zero); + + int NONNULL(1, 2) PUBLIC + efi_str_to_guid(const char *s, efi_guid_t *guid) +@@ -286,4 +286,6 @@ efi_name_to_guid(const char *name, efi_guid_t *guid) + + int + efi_id_guid_to_guid(const char *name, efi_guid_t *guid) +- NONNULL(1, 2) PUBLIC ALIAS(efi_name_to_guid); ++ NONNULL(1, 2) PUBLIC ALIAS(efi_name_to_guid); ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/lib.c b/src/lib.c +index 457a8604d5d..b2eea6c2569 100644 +--- a/src/lib.c ++++ b/src/lib.c +@@ -83,7 +83,7 @@ VERSION(_efi_set_variable_mode,efi_set_variable@@LIBEFIVAR_0.24); + int NONNULL(2, 3) PUBLIC + efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data, + size_t data_size, uint32_t attributes, mode_t mode) +- ALIAS(_efi_set_variable_mode); ++ ALIAS(_efi_set_variable_mode); + + int NONNULL(2, 3) PUBLIC + efi_append_variable(efi_guid_t guid, const char *name, uint8_t *data, +@@ -238,12 +238,12 @@ libefivar_init(void) + NULL + }; + char *ops_name = getenv("LIBEFIVAR_OPS"); +- if (ops_name && strcasestr(ops_name, "help")) { +- printf("LIBEFIVAR_OPS operations available:\n"); +- for (int i = 0; ops_list[i] != NULL; i++) +- printf("\t%s\n", ops_list[i]->name); +- exit(0); +- } ++ if (ops_name && strcasestr(ops_name, "help")) { ++ printf("LIBEFIVAR_OPS operations available:\n"); ++ for (int i = 0; ops_list[i] != NULL; i++) ++ printf("\t%s\n", ops_list[i]->name); ++ exit(0); ++ } + + for (int i = 0; ops_list[i] != NULL; i++) + { +@@ -271,3 +271,5 @@ efi_get_libefivar_version(void) + { + return LIBEFIVAR_VERSION; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index b237039685e..f48d4be9ac6 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -33,159 +33,161 @@ + * + * various devices /sys/dev/block/$major:$minor start with: + * maj:min -> ../../devices/ACPI0000:00/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART +- * i.e.: APMC0D0D:00/ata1/host0/target0:0:0/0:0:0:0/block/sda +- * ^ root hub ^blockdev stuff ++ * i.e.: APMC0D0D:00/ata1/host0/target0:0:0/0:0:0:0/block/sda ++ * ^ root hub ^blockdev stuff + * or: + * maj:min -> ../../devices/ACPI0000:00/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART +- * i.e.: APMC0D0D:00/0000:00:1d.0/0000:05:00.0/ata1/host0/target0:0:0/0:0:0:0/block/sda +- * ^ root hub ^pci dev ^pci dev ^ blockdev stuff ++ * i.e.: APMC0D0D:00/0000:00:1d.0/0000:05:00.0/ata1/host0/target0:0:0/0:0:0:0/block/sda ++ * ^ root hub ^pci dev ^pci dev ^ blockdev stuff + */ + static ssize_t + parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED) + { +- int rc; +- int pos = 0; +- uint16_t pad0; +- uint8_t pad1; +- char *acpi_header = NULL; +- char *colon; +- +- const char *devpart = current; +- +- debug("entry"); +- +- /* +- * find the ACPI root dunno0 and dunno1; they basically look like: +- * ABCD0000:00/ +- * ^d0 ^d1 +- * This is annoying because "/%04ms%h:%hhx/" won't bind from the right +- * side in sscanf. +- */ +- rc = sscanf(devpart, "../../devices/platform/%n", &pos); +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- if (rc != 0 || pos < 1) +- return 0; +- devpart += pos; +- +- /* +- * If it's too short to be A0000:00, it's not an ACPI string +- */ +- if (strlen(devpart) < 8) +- return 0; +- +- colon = strchr(devpart, ':'); +- if (!colon) +- return 0; +- pos = colon - devpart; +- +- /* +- * If colon doesn't point at something between one of these: +- * A0000:00 ACPI0000:00 +- * ^ 5 ^ 8 +- * Then it's not an ACPI string. +- */ +- if (pos < 5 || pos > 8) +- return 0; +- +- dev->acpi_root.acpi_hid_str = strndup(devpart, pos + 1); +- if (!dev->acpi_root.acpi_hid_str) { +- efi_error("Could not allocate memory"); +- return -1; +- } +- dev->acpi_root.acpi_hid_str[pos] = 0; +- debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); +- +- pos -= 4; +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- acpi_header = strndupa(devpart, pos); +- if (!acpi_header) +- return 0; +- acpi_header[pos] = 0; +- debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); +- devpart += pos; +- +- /* +- * If we can't find these numbers, it's not an ACPI string +- */ +- rc = sscanf(devpart, "%hx:%hhx/%n", &pad0, &pad1, &pos); +- if (rc != 2) { +- efi_error("Could not parse ACPI path \"%s\"", devpart); +- return 0; +- } +- debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", +- devpart, pad0, pad1, pos, rc); +- +- devpart += pos; +- +- rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX", +- acpi_header, pad0, pad1); +- debug("rc:%d acpi_header:%s pad0:%04hX pad1:%02hhX", +- rc, acpi_header, pad0, pad1); +- if (rc < 0 && errno == ENOENT) { +- rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hx:%02hhx", +- acpi_header, pad0, pad1); +- debug("rc:%d acpi_header:%s pad0:%04hx pad1:%02hhx", +- rc, acpi_header, pad0, pad1); +- } +- if (rc < 0) { +- efi_error("Could not parse hid/uid"); +- return rc; +- } +- debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"", +- dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, +- dev->acpi_root.acpi_uid_str, +- dev->acpi_root.acpi_cid_str); +- +- return devpart - current; ++ int rc; ++ int pos = 0; ++ uint16_t pad0; ++ uint8_t pad1; ++ char *acpi_header = NULL; ++ char *colon; ++ ++ const char *devpart = current; ++ ++ debug("entry"); ++ ++ /* ++ * find the ACPI root dunno0 and dunno1; they basically look like: ++ * ABCD0000:00/ ++ * ^d0 ^d1 ++ * This is annoying because "/%04ms%h:%hhx/" won't bind from the right ++ * side in sscanf. ++ */ ++ rc = sscanf(devpart, "../../devices/platform/%n", &pos); ++ debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ if (rc != 0 || pos < 1) ++ return 0; ++ devpart += pos; ++ ++ /* ++ * If it's too short to be A0000:00, it's not an ACPI string ++ */ ++ if (strlen(devpart) < 8) ++ return 0; ++ ++ colon = strchr(devpart, ':'); ++ if (!colon) ++ return 0; ++ pos = colon - devpart; ++ ++ /* ++ * If colon doesn't point at something between one of these: ++ * A0000:00 ACPI0000:00 ++ * ^ 5 ^ 8 ++ * Then it's not an ACPI string. ++ */ ++ if (pos < 5 || pos > 8) ++ return 0; ++ ++ dev->acpi_root.acpi_hid_str = strndup(devpart, pos + 1); ++ if (!dev->acpi_root.acpi_hid_str) { ++ efi_error("Could not allocate memory"); ++ return -1; ++ } ++ dev->acpi_root.acpi_hid_str[pos] = 0; ++ debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); ++ ++ pos -= 4; ++ debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ acpi_header = strndupa(devpart, pos); ++ if (!acpi_header) ++ return 0; ++ acpi_header[pos] = 0; ++ debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); ++ devpart += pos; ++ ++ /* ++ * If we can't find these numbers, it's not an ACPI string ++ */ ++ rc = sscanf(devpart, "%hx:%hhx/%n", &pad0, &pad1, &pos); ++ if (rc != 2) { ++ efi_error("Could not parse ACPI path \"%s\"", devpart); ++ return 0; ++ } ++ debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", ++ devpart, pad0, pad1, pos, rc); ++ ++ devpart += pos; ++ ++ rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX", ++ acpi_header, pad0, pad1); ++ debug("rc:%d acpi_header:%s pad0:%04hX pad1:%02hhX", ++ rc, acpi_header, pad0, pad1); ++ if (rc < 0 && errno == ENOENT) { ++ rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hx:%02hhx", ++ acpi_header, pad0, pad1); ++ debug("rc:%d acpi_header:%s pad0:%04hx pad1:%02hhx", ++ rc, acpi_header, pad0, pad1); ++ } ++ if (rc < 0) { ++ efi_error("Could not parse hid/uid"); ++ return rc; ++ } ++ debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"", ++ dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, ++ dev->acpi_root.acpi_uid_str, ++ dev->acpi_root.acpi_cid_str); ++ ++ return devpart - current; + } + + static ssize_t + dp_create_acpi_root(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz = 0, new = 0; +- +- debug("entry buf:%p size:%zd off:%zd", buf, size, off); +- +- if (dev->acpi_root.acpi_uid_str || dev->acpi_root.acpi_cid_str) { +- debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"", +- dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, +- dev->acpi_root.acpi_uid_str, dev->acpi_root.acpi_cid_str); +- new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid, +- dev->acpi_root.acpi_cid, +- dev->acpi_root.acpi_hid_str, +- dev->acpi_root.acpi_uid_str, +- dev->acpi_root.acpi_cid_str); +- if (new < 0) { +- efi_error("efidp_make_acpi_hid_ex() failed"); +- return new; +- } +- } else { +- debug("creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid); +- new = efidp_make_acpi_hid(buf + off, size ? size - off : 0, +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid); +- if (new < 0) { +- efi_error("efidp_make_acpi_hid() failed"); +- return new; +- } +- } +- sz += new; +- +- debug("returning %zd", sz); +- return sz; ++ ssize_t sz = 0, new = 0; ++ ++ debug("entry buf:%p size:%zd off:%zd", buf, size, off); ++ ++ if (dev->acpi_root.acpi_uid_str || dev->acpi_root.acpi_cid_str) { ++ debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"", ++ dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, ++ dev->acpi_root.acpi_uid_str, dev->acpi_root.acpi_cid_str); ++ new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid, ++ dev->acpi_root.acpi_cid, ++ dev->acpi_root.acpi_hid_str, ++ dev->acpi_root.acpi_uid_str, ++ dev->acpi_root.acpi_cid_str); ++ if (new < 0) { ++ efi_error("efidp_make_acpi_hid_ex() failed"); ++ return new; ++ } ++ } else { ++ debug("creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid); ++ new = efidp_make_acpi_hid(buf + off, size ? size - off : 0, ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid); ++ if (new < 0) { ++ efi_error("efidp_make_acpi_hid() failed"); ++ return new; ++ } ++ } ++ sz += new; ++ ++ debug("returning %zd", sz); ++ return sz; + } + + enum interface_type acpi_root_iftypes[] = { acpi_root, unknown }; + + struct dev_probe HIDDEN acpi_root_parser = { +- .name = "acpi_root", +- .iftypes = acpi_root_iftypes, +- .flags = DEV_PROVIDES_ROOT, +- .parse = parse_acpi_root, +- .create = dp_create_acpi_root, ++ .name = "acpi_root", ++ .iftypes = acpi_root_iftypes, ++ .flags = DEV_PROVIDES_ROOT, ++ .parse = parse_acpi_root, ++ .create = dp_create_acpi_root, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-acpi.c b/src/linux-acpi.c +index 346eba09041..919f4654ae3 100644 +--- a/src/linux-acpi.c ++++ b/src/linux-acpi.c +@@ -31,89 +31,91 @@ + int HIDDEN + parse_acpi_hid_uid(struct device *dev, const char *fmt, ...) + { +- int rc; +- char *path = NULL; +- va_list ap; +- char *fbuf = NULL; +- uint16_t tmp16; +- uint32_t acpi_hid = 0; +- uint64_t acpi_uid_int = 0; ++ int rc; ++ char *path = NULL; ++ va_list ap; ++ char *fbuf = NULL; ++ uint16_t tmp16; ++ uint32_t acpi_hid = 0; ++ uint64_t acpi_uid_int = 0; + +- debug("entry"); ++ debug("entry"); + +- va_start(ap, fmt); +- rc = vasprintfa(&path, fmt, ap); +- va_end(ap); +- debug("path:%s rc:%d", path, rc); +- if (rc < 0 || path == NULL) +- return -1; ++ va_start(ap, fmt); ++ rc = vasprintfa(&path, fmt, ap); ++ va_end(ap); ++ debug("path:%s rc:%d", path, rc); ++ if (rc < 0 || path == NULL) ++ return -1; + +- rc = read_sysfs_file(&fbuf, "%s/firmware_node/path", path); +- if (rc > 0 && fbuf) { +- size_t l = strlen(fbuf); +- if (l > 1) { +- fbuf[l-1] = 0; +- dev->acpi_root.acpi_cid_str = strdup(fbuf); +- debug("Setting ACPI root path to \"%s\"", fbuf); +- } +- } ++ rc = read_sysfs_file(&fbuf, "%s/firmware_node/path", path); ++ if (rc > 0 && fbuf) { ++ size_t l = strlen(fbuf); ++ if (l > 1) { ++ fbuf[l-1] = 0; ++ dev->acpi_root.acpi_cid_str = strdup(fbuf); ++ debug("Setting ACPI root path to \"%s\"", fbuf); ++ } ++ } + +- rc = read_sysfs_file(&fbuf, "%s/firmware_node/hid", path); +- if (rc < 0 || fbuf == NULL) { +- efi_error("could not read %s/firmware_node/hid", path); +- return -1; +- } ++ rc = read_sysfs_file(&fbuf, "%s/firmware_node/hid", path); ++ if (rc < 0 || fbuf == NULL) { ++ efi_error("could not read %s/firmware_node/hid", path); ++ return -1; ++ } + +- rc = strlen(fbuf); +- if (rc < 4) { ++ rc = strlen(fbuf); ++ if (rc < 4) { + hid_err: +- efi_error("could not parse %s/firmware_node/hid", path); +- return -1; +- } +- rc -= 4; ++ efi_error("could not parse %s/firmware_node/hid", path); ++ return -1; ++ } ++ rc -= 4; + +- rc = sscanf((char *)fbuf + rc, "%04hx", &tmp16); +- debug("rc:%d hid:0x%08x\n", rc, tmp16); +- if (rc != 1) +- goto hid_err; ++ rc = sscanf((char *)fbuf + rc, "%04hx", &tmp16); ++ debug("rc:%d hid:0x%08x\n", rc, tmp16); ++ if (rc != 1) ++ goto hid_err; + +- acpi_hid = EFIDP_EFI_PNP_ID(tmp16); ++ acpi_hid = EFIDP_EFI_PNP_ID(tmp16); + +- /* +- * Apparently basically nothing can look up a PcieRoot() node, +- * because they just check _CID. So since _CID for the root pretty +- * much always has to be PNP0A03 anyway, just use that no matter +- * what. +- */ +- if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID) +- acpi_hid = EFIDP_ACPI_PCI_ROOT_HID; +- dev->acpi_root.acpi_hid = acpi_hid; +- debug("acpi root HID:0x%08x", acpi_hid); ++ /* ++ * Apparently basically nothing can look up a PcieRoot() node, ++ * because they just check _CID. So since _CID for the root pretty ++ * much always has to be PNP0A03 anyway, just use that no matter ++ * what. ++ */ ++ if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID) ++ acpi_hid = EFIDP_ACPI_PCI_ROOT_HID; ++ dev->acpi_root.acpi_hid = acpi_hid; ++ debug("acpi root HID:0x%08x", acpi_hid); + +- errno = 0; +- fbuf = NULL; +- rc = read_sysfs_file(&fbuf, "%s/firmware_node/uid", path); +- if ((rc < 0 && errno != ENOENT) || (rc > 0 && fbuf == NULL)) { +- efi_error("could not read %s/firmware_node/uid", path); +- return -1; +- } +- if (rc > 0) { +- rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int); +- if (rc == 1) { +- dev->acpi_root.acpi_uid = acpi_uid_int; +- } else { +- /* kernel uses "%s\n" to print it, so there +- * should always be some value and a newline... */ +- int l = strlen((char *)fbuf); +- if (l >= 1) { +- fbuf[l-1] = '\0'; +- dev->acpi_root.acpi_uid_str = strdup(fbuf); +- } +- } +- } +- debug("acpi root UID:0x%"PRIx64" uidstr:\"%s\"", +- dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str); ++ errno = 0; ++ fbuf = NULL; ++ rc = read_sysfs_file(&fbuf, "%s/firmware_node/uid", path); ++ if ((rc < 0 && errno != ENOENT) || (rc > 0 && fbuf == NULL)) { ++ efi_error("could not read %s/firmware_node/uid", path); ++ return -1; ++ } ++ if (rc > 0) { ++ rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int); ++ if (rc == 1) { ++ dev->acpi_root.acpi_uid = acpi_uid_int; ++ } else { ++ /* kernel uses "%s\n" to print it, so there ++ * should always be some value and a newline... */ ++ int l = strlen((char *)fbuf); ++ if (l >= 1) { ++ fbuf[l-1] = '\0'; ++ dev->acpi_root.acpi_uid_str = strdup(fbuf); ++ } ++ } ++ } ++ debug("acpi root UID:0x%"PRIx64" uidstr:\"%s\"", ++ dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str); + +- errno = 0; +- return 0; ++ errno = 0; ++ return 0; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-ata.c b/src/linux-ata.c +index 43e5f4c5d23..b6a7c2dcf8a 100644 +--- a/src/linux-ata.c ++++ b/src/linux-ata.c +@@ -31,22 +31,22 @@ + bool HIDDEN + is_pata(struct device *dev) + { +- if (!strncmp(dev->driver, "pata_", 5) || +- !strncmp(dev->driver, "ata_", 4)) +- return true; +- +- if (dev->n_pci_devs > 0 && +- dev->pci_dev[dev->n_pci_devs - 1].driverlink) { +- char *slash = dev->pci_dev[dev->n_pci_devs - 1].driverlink; +- +- slash = strrchr(slash, '/'); +- if (slash && +- (!strncmp(slash, "/ata_", 5) || +- !strncmp(slash, "/pata_", 6))) +- return true; +- } +- +- return false; ++ if (!strncmp(dev->driver, "pata_", 5) || ++ !strncmp(dev->driver, "ata_", 4)) ++ return true; ++ ++ if (dev->n_pci_devs > 0 && ++ dev->pci_dev[dev->n_pci_devs - 1].driverlink) { ++ char *slash = dev->pci_dev[dev->n_pci_devs - 1].driverlink; ++ ++ slash = strrchr(slash, '/'); ++ if (slash && ++ (!strncmp(slash, "/ata_", 5) || ++ !strncmp(slash, "/pata_", 6))) ++ return true; ++ } ++ ++ return false; + } + + /* +@@ -60,101 +60,103 @@ is_pata(struct device *dev) + static ssize_t + parse_ata(struct device *dev, const char *current, const char *root UNUSED) + { +- uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; +- uint64_t scsi_lun; +- int pos; +- +- debug("entry"); +- /* IDE disks can have up to 64 partitions, or 6 bits worth, +- * and have one bit for the disk number. +- * This leaves an extra bit at the top. +- */ +- if (dev->major == 3) { +- dev->disknum = (dev->minor >> 6) & 1; +- dev->controllernum = (dev->major - 3 + 0) + dev->disknum; +- dev->interface_type = ata; +- set_part(dev, dev->minor & 0x3F); +- } else if (dev->major == 22) { +- dev->disknum = (dev->minor >> 6) & 1; +- dev->controllernum = (dev->major - 22 + 2) + dev->disknum; +- dev->interface_type = ata; +- set_part(dev, dev->minor & 0x3F); +- } else if (dev->major >= 33 && dev->major <= 34) { +- dev->disknum = (dev->minor >> 6) & 1; +- dev->controllernum = (dev->major - 33 + 4) + dev->disknum; +- dev->interface_type = ata; +- set_part(dev, dev->minor & 0x3F); +- } else if (dev->major >= 56 && dev->major <= 57) { +- dev->disknum = (dev->minor >> 6) & 1; +- dev->controllernum = (dev->major - 56 + 8) + dev->disknum; +- dev->interface_type = ata; +- set_part(dev, dev->minor & 0x3F); +- } else if (dev->major >= 88 && dev->major <= 91) { +- dev->disknum = (dev->minor >> 6) & 1; +- dev->controllernum = (dev->major - 88 + 12) + dev->disknum; +- dev->interface_type = ata; +- set_part(dev, dev->minor & 0x3F); +- } else { +- debug("If this is ATA, it isn't using a traditional IDE inode."); +- } +- +- if (is_pata(dev)) { +- dev->interface_type = ata; +- } else { +- /* +- * If it isn't one of the pata drivers or ata_piix, it isn't a +- * PATA device. +- */ +- return 0; +- } +- +- char *host = strstr(current, "/host"); +- if (!host) +- return -1; +- +- pos = parse_scsi_link(host + 1, &scsi_host, +- &scsi_bus, &scsi_device, +- &scsi_target, &scsi_lun, +- NULL, NULL, NULL); +- if (pos < 0) +- return -1; +- +- dev->ata_info.scsi_host = scsi_host; +- dev->ata_info.scsi_bus = scsi_bus; +- dev->ata_info.scsi_device = scsi_device; +- dev->ata_info.scsi_target = scsi_target; +- dev->ata_info.scsi_lun = scsi_lun; +- +- char *block = strstr(current, "/block/"); +- if (!block) +- return -1; +- return block + 1 - current; ++ uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; ++ uint64_t scsi_lun; ++ int pos; ++ ++ debug("entry"); ++ /* IDE disks can have up to 64 partitions, or 6 bits worth, ++ * and have one bit for the disk number. ++ * This leaves an extra bit at the top. ++ */ ++ if (dev->major == 3) { ++ dev->disknum = (dev->minor >> 6) & 1; ++ dev->controllernum = (dev->major - 3 + 0) + dev->disknum; ++ dev->interface_type = ata; ++ set_part(dev, dev->minor & 0x3F); ++ } else if (dev->major == 22) { ++ dev->disknum = (dev->minor >> 6) & 1; ++ dev->controllernum = (dev->major - 22 + 2) + dev->disknum; ++ dev->interface_type = ata; ++ set_part(dev, dev->minor & 0x3F); ++ } else if (dev->major >= 33 && dev->major <= 34) { ++ dev->disknum = (dev->minor >> 6) & 1; ++ dev->controllernum = (dev->major - 33 + 4) + dev->disknum; ++ dev->interface_type = ata; ++ set_part(dev, dev->minor & 0x3F); ++ } else if (dev->major >= 56 && dev->major <= 57) { ++ dev->disknum = (dev->minor >> 6) & 1; ++ dev->controllernum = (dev->major - 56 + 8) + dev->disknum; ++ dev->interface_type = ata; ++ set_part(dev, dev->minor & 0x3F); ++ } else if (dev->major >= 88 && dev->major <= 91) { ++ dev->disknum = (dev->minor >> 6) & 1; ++ dev->controllernum = (dev->major - 88 + 12) + dev->disknum; ++ dev->interface_type = ata; ++ set_part(dev, dev->minor & 0x3F); ++ } else { ++ debug("If this is ATA, it isn't using a traditional IDE inode."); ++ } ++ ++ if (is_pata(dev)) { ++ dev->interface_type = ata; ++ } else { ++ /* ++ * If it isn't one of the pata drivers or ata_piix, it isn't a ++ * PATA device. ++ */ ++ return 0; ++ } ++ ++ char *host = strstr(current, "/host"); ++ if (!host) ++ return -1; ++ ++ pos = parse_scsi_link(host + 1, &scsi_host, ++ &scsi_bus, &scsi_device, ++ &scsi_target, &scsi_lun, ++ NULL, NULL, NULL); ++ if (pos < 0) ++ return -1; ++ ++ dev->ata_info.scsi_host = scsi_host; ++ dev->ata_info.scsi_bus = scsi_bus; ++ dev->ata_info.scsi_device = scsi_device; ++ dev->ata_info.scsi_target = scsi_target; ++ dev->ata_info.scsi_lun = scsi_lun; ++ ++ char *block = strstr(current, "/block/"); ++ if (!block) ++ return -1; ++ return block + 1 - current; + } + + static ssize_t + dp_create_ata(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz; ++ ssize_t sz; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_atapi(buf + off, size ? size - off : 0, +- dev->ata_info.scsi_device, +- dev->ata_info.scsi_target - 1, +- dev->ata_info.scsi_lun); +- if (sz < 0) +- efi_error("efidp_make_atapi() failed"); ++ sz = efidp_make_atapi(buf + off, size ? size - off : 0, ++ dev->ata_info.scsi_device, ++ dev->ata_info.scsi_target - 1, ++ dev->ata_info.scsi_lun); ++ if (sz < 0) ++ efi_error("efidp_make_atapi() failed"); + +- return sz; ++ return sz; + } + + enum interface_type ata_iftypes[] = { ata, atapi, unknown }; + + struct dev_probe ata_parser = { +- .name = "ata", +- .iftypes = ata_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_ata, +- .create = dp_create_ata, ++ .name = "ata", ++ .iftypes = ata_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_ata, ++ .create = dp_create_ata, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index b290ed0a2bd..8af316a1723 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -47,74 +47,76 @@ + static ssize_t + parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + { +- int rc; +- int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition; +- int pos0 = 0, pos1 = 0; +- +- debug("entry"); +- +- debug("searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1"); +- rc = sscanf(current, "mmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n", +- &tosser0, &tosser1, &tosser2, &slot_id, +- &pos0, &tosser3, &partition, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- /* +- * If it isn't of that form, it's not one of our emmc devices. +- */ +- if (rc != 4 && rc != 6) +- return 0; +- +- dev->emmc_info.slot_id = slot_id; +- dev->interface_type = emmc; +- +- if (rc == 6) { +- if (dev->part == -1) +- dev->part = partition; +- +- pos0 = pos1; +- } +- +- return pos0; ++ int rc; ++ int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition; ++ int pos0 = 0, pos1 = 0; ++ ++ debug("entry"); ++ ++ debug("searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1"); ++ rc = sscanf(current, "mmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n", ++ &tosser0, &tosser1, &tosser2, &slot_id, ++ &pos0, &tosser3, &partition, &pos1); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ /* ++ * If it isn't of that form, it's not one of our emmc devices. ++ */ ++ if (rc != 4 && rc != 6) ++ return 0; ++ ++ dev->emmc_info.slot_id = slot_id; ++ dev->interface_type = emmc; ++ ++ if (rc == 6) { ++ if (dev->part == -1) ++ dev->part = partition; ++ ++ pos0 = pos1; ++ } ++ ++ return pos0; + } + + static ssize_t + dp_create_emmc(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz; ++ ssize_t sz; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_emmc(buf + off, size ? size - off : 0, +- dev->emmc_info.slot_id); +- return sz; ++ sz = efidp_make_emmc(buf + off, size ? size - off : 0, ++ dev->emmc_info.slot_id); ++ return sz; + } + + static char * + make_part_name(struct device *dev) + { +- char *ret = NULL; +- ssize_t rc; ++ char *ret = NULL; ++ ssize_t rc; + +- if (dev->part < 1) +- return NULL; ++ if (dev->part < 1) ++ return NULL; + +- rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); +- if (rc < 0) { +- efi_error("could not allocate memory"); +- return NULL; +- } ++ rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); ++ if (rc < 0) { ++ efi_error("could not allocate memory"); ++ return NULL; ++ } + +- return ret; ++ return ret; + } + + static enum interface_type emmc_iftypes[] = { emmc, unknown }; + + struct dev_probe HIDDEN emmc_parser = { +- .name = "emmc", +- .iftypes = emmc_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_emmc, +- .create = dp_create_emmc, +- .make_part_name = make_part_name, ++ .name = "emmc", ++ .iftypes = emmc_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_emmc, ++ .create = dp_create_emmc, ++ .make_part_name = make_part_name, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-i2o.c b/src/linux-i2o.c +index 3ce25b957bf..ebd92aeeb53 100644 +--- a/src/linux-i2o.c ++++ b/src/linux-i2o.c +@@ -35,29 +35,31 @@ + static ssize_t + parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED) + { +- debug("entry"); +- /* I2O disks can have up to 16 partitions, or 4 bits worth. */ +- if (dev->major >= 80 && dev->major <= 87) { +- dev->interface_type = i2o; +- dev->disknum = 16*(dev->major-80) + (dev->minor >> 4); +- set_part(dev, dev->minor & 0xF); +- } else { +- /* If it isn't those majors, it's not an i2o dev */ +- return 0; +- } +- +- char *block = strstr(current, "/block/"); +- if (!block) +- return -1; +- return block + 1 - current; ++ debug("entry"); ++ /* I2O disks can have up to 16 partitions, or 4 bits worth. */ ++ if (dev->major >= 80 && dev->major <= 87) { ++ dev->interface_type = i2o; ++ dev->disknum = 16*(dev->major-80) + (dev->minor >> 4); ++ set_part(dev, dev->minor & 0xF); ++ } else { ++ /* If it isn't those majors, it's not an i2o dev */ ++ return 0; ++ } ++ ++ char *block = strstr(current, "/block/"); ++ if (!block) ++ return -1; ++ return block + 1 - current; + } + + enum interface_type i2o_iftypes[] = { i2o, unknown }; + + struct dev_probe HIDDEN i2o_parser = { +- .name = "i2o", +- .iftypes = i2o_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_i2o, +- .create = NULL, ++ .name = "i2o", ++ .iftypes = i2o_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_i2o, ++ .create = NULL, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-md.c b/src/linux-md.c +index cb584c96c4b..3d5975d8195 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -41,55 +41,57 @@ + static ssize_t + parse_md(struct device *dev, const char *current, const char *root UNUSED) + { +- int rc; +- int32_t md, tosser0, part; +- int pos0 = 0, pos1 = 0; ++ int rc; ++ int32_t md, tosser0, part; ++ int pos0 = 0, pos1 = 0; + +- debug("entry"); ++ debug("entry"); + +- debug("searching for mdM/mdMpN"); +- rc = sscanf(current, "md%d/%nmd%dp%d%n", +- &md, &pos0, &tosser0, &part, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- /* +- * If it isn't of that form, it's not one of our partitioned md devices. +- */ +- if (rc != 3) +- return 0; ++ debug("searching for mdM/mdMpN"); ++ rc = sscanf(current, "md%d/%nmd%dp%d%n", ++ &md, &pos0, &tosser0, &part, &pos1); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ /* ++ * If it isn't of that form, it's not one of our partitioned md devices. ++ */ ++ if (rc != 3) ++ return 0; + +- dev->interface_type = md; ++ dev->interface_type = md; + +- if (dev->part == -1) +- dev->part = part; ++ if (dev->part == -1) ++ dev->part = part; + +- return pos1; ++ return pos1; + } + + + static char * + make_part_name(struct device *dev) + { +- char *ret = NULL; +- ssize_t rc; ++ char *ret = NULL; ++ ssize_t rc; + +- if (dev->part < 1) +- return NULL; ++ if (dev->part < 1) ++ return NULL; + +- rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); +- if (rc < 0) { +- efi_error("could not allocate memory"); +- return NULL; +- } ++ rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); ++ if (rc < 0) { ++ efi_error("could not allocate memory"); ++ return NULL; ++ } + +- return ret; ++ return ret; + } + + static enum interface_type md_iftypes[] = { md, unknown }; + + struct dev_probe HIDDEN md_parser = { +- .name = "md", +- .iftypes = md_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_md, +- .make_part_name = make_part_name, ++ .name = "md", ++ .iftypes = md_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_md, ++ .make_part_name = make_part_name, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 1d8fc654f76..e6e42c7a3fc 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -50,110 +50,111 @@ + static ssize_t + parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + { +- int rc; +- int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; +- uint8_t *filebuf = NULL; +- int pos0 = 0, pos1 = 0; +- +- debug("entry"); +- +- debug("searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1"); +- rc = sscanf(current, "nvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", +- &tosser0, &ctrl_id, &ns_id, &pos0, +- &tosser1, &tosser2, &partition, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- /* +- * If it isn't of that form, it's not one of our nvme devices. +- */ +- if (rc != 3 && rc != 6) +- return 0; +- +- dev->nvme_info.ctrl_id = ctrl_id; +- dev->nvme_info.ns_id = ns_id; +- dev->nvme_info.has_eui = 0; +- dev->interface_type = nvme; +- +- if (rc == 6) { +- if (dev->part == -1) +- dev->part = partition; +- +- pos0 = pos1; +- } +- +- /* +- * now fish the eui out of sysfs is there is one... +- */ +- rc = read_sysfs_file(&filebuf, +- "class/block/nvme%dn%d/eui", +- ctrl_id, ns_id); +- if ((rc < 0 && errno == ENOENT) || filebuf == NULL) { +- rc = read_sysfs_file(&filebuf, +- "class/block/nvme%dn%d/device/eui", +- ctrl_id, ns_id); +- } +- if (rc >= 0 && filebuf != NULL) { +- uint8_t eui[8]; +- if (rc < 23) { +- errno = EINVAL; +- return -1; +- } +- rc = sscanf((char *)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; +- } +- dev->nvme_info.has_eui = 1; +- memcpy(dev->nvme_info.eui, eui, sizeof(eui)); +- } +- +- return pos0; ++ int rc; ++ int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; ++ uint8_t *filebuf = NULL; ++ int pos0 = 0, pos1 = 0; ++ ++ debug("entry"); ++ ++ debug("searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1"); ++ rc = sscanf(current, "nvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", ++ &tosser0, &ctrl_id, &ns_id, &pos0, ++ &tosser1, &tosser2, &partition, &pos1); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ /* ++ * If it isn't of that form, it's not one of our nvme devices. ++ */ ++ if (rc != 3 && rc != 6) ++ return 0; ++ ++ dev->nvme_info.ctrl_id = ctrl_id; ++ dev->nvme_info.ns_id = ns_id; ++ dev->nvme_info.has_eui = 0; ++ dev->interface_type = nvme; ++ ++ if (rc == 6) { ++ if (dev->part == -1) ++ dev->part = partition; ++ ++ pos0 = pos1; ++ } ++ ++ /* ++ * now fish the eui out of sysfs is there is one... ++ */ ++ rc = read_sysfs_file(&filebuf, ++ "class/block/nvme%dn%d/eui", ++ ctrl_id, ns_id); ++ if ((rc < 0 && errno == ENOENT) || filebuf == NULL) { ++ rc = read_sysfs_file(&filebuf, ++ "class/block/nvme%dn%d/device/eui", ++ ctrl_id, ns_id); ++ } ++ if (rc >= 0 && filebuf != NULL) { ++ uint8_t eui[8]; ++ if (rc < 23) { ++ errno = EINVAL; ++ return -1; ++ } ++ rc = sscanf((char *)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; ++ } ++ dev->nvme_info.has_eui = 1; ++ memcpy(dev->nvme_info.eui, eui, sizeof(eui)); ++ } ++ ++ return pos0; + } + + static ssize_t + dp_create_nvme(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz; ++ ssize_t sz; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_nvme(buf + off, size ? size - off : 0, +- dev->nvme_info.ns_id, +- dev->nvme_info.has_eui ? dev->nvme_info.eui +- : NULL); +- return sz; ++ sz = efidp_make_nvme(buf + off, size ? size - off : 0, ++ dev->nvme_info.ns_id, ++ dev->nvme_info.has_eui ? dev->nvme_info.eui ++ : NULL); ++ return sz; + } + + static char * + make_part_name(struct device *dev) + { +- char *ret = NULL; +- ssize_t rc; ++ char *ret = NULL; ++ ssize_t rc; + +- if (dev->part < 1) +- return NULL; ++ if (dev->part < 1) ++ return NULL; + +- rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); +- if (rc < 0) { +- efi_error("could not allocate memory"); +- return NULL; +- } ++ rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part); ++ if (rc < 0) { ++ efi_error("could not allocate memory"); ++ return NULL; ++ } + +- return ret; ++ return ret; + } + + static enum interface_type nvme_iftypes[] = { nvme, unknown }; + + struct dev_probe HIDDEN nvme_parser = { +- .name = "nvme", +- .iftypes = nvme_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_nvme, +- .create = dp_create_nvme, +- .make_part_name = make_part_name, ++ .name = "nvme", ++ .iftypes = nvme_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_nvme, ++ .create = dp_create_nvme, ++ .make_part_name = make_part_name, + }; + ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index 0b5ad48d6db..ede9321395c 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -43,83 +43,85 @@ + static ssize_t + parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + { +- int rc; +- int pos = 0; +- uint16_t root_domain; +- uint8_t root_bus; +- const char *devpart = current; ++ int rc; ++ int pos = 0; ++ uint16_t root_domain; ++ uint8_t root_bus; ++ const char *devpart = current; + +- debug("entry"); ++ debug("entry"); + +- /* +- * find the pci root domain and port; they basically look like: +- * pci0000:00/ +- * ^d ^p +- */ +- rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos); +- /* +- * If we can't find that, it's not a PCI device. +- */ +- if (rc != 2) +- return 0; +- devpart += pos; ++ /* ++ * find the pci root domain and port; they basically look like: ++ * pci0000:00/ ++ * ^d ^p ++ */ ++ rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos); ++ /* ++ * If we can't find that, it's not a PCI device. ++ */ ++ if (rc != 2) ++ return 0; ++ devpart += pos; + +- dev->pci_root.pci_domain = root_domain; +- dev->pci_root.pci_bus = root_bus; ++ dev->pci_root.pci_domain = root_domain; ++ dev->pci_root.pci_bus = root_bus; + +- rc = parse_acpi_hid_uid(dev, "devices/pci%04hx:%02hhx", +- root_domain, root_bus); +- if (rc < 0) +- return -1; ++ rc = parse_acpi_hid_uid(dev, "devices/pci%04hx:%02hhx", ++ root_domain, root_bus); ++ if (rc < 0) ++ return -1; + +- errno = 0; +- return devpart - current; ++ errno = 0; ++ return devpart - current; + } + + static ssize_t + dp_create_pci_root(struct device *dev UNUSED, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t new = 0, sz = 0; +- debug("entry buf:%p size:%zd off:%zd", buf, size, off); +- debug("returning 0"); +- if (dev->acpi_root.acpi_uid_str) { +- debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"", +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid_str); +- new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, +- dev->acpi_root.acpi_hid, +- 0, 0, "", +- dev->acpi_root.acpi_uid_str, +- ""); +- if (new < 0) { +- efi_error("efidp_make_acpi_hid_ex() failed"); +- return new; +- } +- } else { +- debug("creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid); +- new = efidp_make_acpi_hid(buf + off, size ? size - off : 0, +- dev->acpi_root.acpi_hid, +- dev->acpi_root.acpi_uid); +- if (new < 0) { +- efi_error("efidp_make_acpi_hid() failed"); +- return new; +- } +- } +- sz += new; ++ ssize_t new = 0, sz = 0; ++ debug("entry buf:%p size:%zd off:%zd", buf, size, off); ++ debug("returning 0"); ++ if (dev->acpi_root.acpi_uid_str) { ++ debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"", ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid_str); ++ new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, ++ dev->acpi_root.acpi_hid, ++ 0, 0, "", ++ dev->acpi_root.acpi_uid_str, ++ ""); ++ if (new < 0) { ++ efi_error("efidp_make_acpi_hid_ex() failed"); ++ return new; ++ } ++ } else { ++ debug("creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid); ++ new = efidp_make_acpi_hid(buf + off, size ? size - off : 0, ++ dev->acpi_root.acpi_hid, ++ dev->acpi_root.acpi_uid); ++ if (new < 0) { ++ efi_error("efidp_make_acpi_hid() failed"); ++ return new; ++ } ++ } ++ sz += new; + +- debug("returning %zd", sz); +- return sz; ++ debug("returning %zd", sz); ++ return sz; + } + + enum interface_type pci_root_iftypes[] = { pci_root, unknown }; + + struct dev_probe HIDDEN pci_root_parser = { +- .name = "pci_root", +- .iftypes = pci_root_iftypes, +- .flags = DEV_PROVIDES_ROOT, +- .parse = parse_pci_root, +- .create = dp_create_pci_root, ++ .name = "pci_root", ++ .iftypes = pci_root_iftypes, ++ .flags = DEV_PROVIDES_ROOT, ++ .parse = parse_pci_root, ++ .create = dp_create_pci_root, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-pci.c b/src/linux-pci.c +index c3b9fcf9092..4c715df3d6e 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -45,110 +45,112 @@ + static ssize_t + parse_pci(struct device *dev, const char *current, const char *root) + { +- int rc; +- int pos = 0; +- const char *devpart = current; +- +- debug("entry"); +- +- /* find the pci domain/bus/device/function: +- * 0000:00:01.0/0000:01:00.0/ +- * ^d ^b ^d ^f (of the last one in the series) +- */ +- while (*devpart) { +- uint16_t domain; +- uint8_t bus, device, function; +- struct pci_dev_info *pci_dev; +- unsigned int i = dev->n_pci_devs; +- struct stat statbuf; +- +- debug("devpart is \"%s\"", devpart); +- pos = 0; +- debug("searching for 0000:00:00.0/"); +- rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", +- &domain, &bus, &device, &function, &pos); +- debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- if (rc != 4) +- break; +- devpart += pos; +- +- debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", +- domain, bus, device, function); +- pci_dev = realloc(dev->pci_dev, +- sizeof(*pci_dev) * (i + 1)); +- if (!pci_dev) { +- efi_error("realloc(%p, %zd * (%d + 1)) failed", +- dev->pci_dev, sizeof(*pci_dev), i); +- return -1; +- } +- dev->pci_dev = pci_dev; +- +- dev->pci_dev[i].pci_domain = domain; +- dev->pci_dev[i].pci_bus = bus; +- dev->pci_dev[i].pci_device = device; +- dev->pci_dev[i].pci_function = function; +- char *tmp = strndup(root, devpart-root+1); +- char *linkbuf = NULL; +- if (!tmp) { +- efi_error("could not allocate memory"); +- return -1; +- } +- tmp[devpart - root] = '\0'; +- rc = sysfs_stat(&statbuf, "class/block/%s/driver", tmp); +- if (rc < 0 && errno == ENOENT) { +- debug("No driver link for /sys/class/block/%s", tmp); +- debug("Assuming this is just a buggy platform core driver"); +- dev->pci_dev[i].driverlink = NULL; +- } else { +- rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp); +- if (rc < 0 || !linkbuf) { +- efi_error("Could not find driver for pci device %s", tmp); +- free(tmp); +- return -1; +- } else { +- dev->pci_dev[i].driverlink = strdup(linkbuf); +- debug("driver:%s\n", linkbuf); +- } +- } +- free(tmp); +- dev->n_pci_devs += 1; +- } +- +- debug("next:\"%s\"", devpart); +- return devpart - current; ++ int rc; ++ int pos = 0; ++ const char *devpart = current; ++ ++ debug("entry"); ++ ++ /* find the pci domain/bus/device/function: ++ * 0000:00:01.0/0000:01:00.0/ ++ * ^d ^b ^d ^f (of the last one in the series) ++ */ ++ while (*devpart) { ++ uint16_t domain; ++ uint8_t bus, device, function; ++ struct pci_dev_info *pci_dev; ++ unsigned int i = dev->n_pci_devs; ++ struct stat statbuf; ++ ++ debug("devpart is \"%s\"", devpart); ++ pos = 0; ++ debug("searching for 0000:00:00.0/"); ++ rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", ++ &domain, &bus, &device, &function, &pos); ++ debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ if (rc != 4) ++ break; ++ devpart += pos; ++ ++ debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", ++ domain, bus, device, function); ++ pci_dev = realloc(dev->pci_dev, ++ sizeof(*pci_dev) * (i + 1)); ++ if (!pci_dev) { ++ efi_error("realloc(%p, %zd * (%d + 1)) failed", ++ dev->pci_dev, sizeof(*pci_dev), i); ++ return -1; ++ } ++ dev->pci_dev = pci_dev; ++ ++ dev->pci_dev[i].pci_domain = domain; ++ dev->pci_dev[i].pci_bus = bus; ++ dev->pci_dev[i].pci_device = device; ++ dev->pci_dev[i].pci_function = function; ++ char *tmp = strndup(root, devpart-root+1); ++ char *linkbuf = NULL; ++ if (!tmp) { ++ efi_error("could not allocate memory"); ++ return -1; ++ } ++ tmp[devpart - root] = '\0'; ++ rc = sysfs_stat(&statbuf, "class/block/%s/driver", tmp); ++ if (rc < 0 && errno == ENOENT) { ++ debug("No driver link for /sys/class/block/%s", tmp); ++ debug("Assuming this is just a buggy platform core driver"); ++ dev->pci_dev[i].driverlink = NULL; ++ } else { ++ rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp); ++ if (rc < 0 || !linkbuf) { ++ efi_error("Could not find driver for pci device %s", tmp); ++ free(tmp); ++ return -1; ++ } else { ++ dev->pci_dev[i].driverlink = strdup(linkbuf); ++ debug("driver:%s\n", linkbuf); ++ } ++ } ++ free(tmp); ++ dev->n_pci_devs += 1; ++ } ++ ++ debug("next:\"%s\"", devpart); ++ return devpart - current; + } + + static ssize_t + dp_create_pci(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz = 0, new = 0; +- +- debug("entry buf:%p size:%zd off:%zd", buf, size, off); +- +- debug("creating PCI device path nodes"); +- for (unsigned int i = 0; i < dev->n_pci_devs; i++) { +- debug("creating PCI device path node %u", i); +- new = efidp_make_pci(buf + off, size ? size - off : 0, +- dev->pci_dev[i].pci_device, +- dev->pci_dev[i].pci_function); +- if (new < 0) { +- efi_error("efidp_make_pci() failed"); +- return new; +- } +- sz += new; +- off += new; +- } +- +- debug("returning %zd", sz); +- return sz; ++ ssize_t sz = 0, new = 0; ++ ++ debug("entry buf:%p size:%zd off:%zd", buf, size, off); ++ ++ debug("creating PCI device path nodes"); ++ for (unsigned int i = 0; i < dev->n_pci_devs; i++) { ++ debug("creating PCI device path node %u", i); ++ new = efidp_make_pci(buf + off, size ? size - off : 0, ++ dev->pci_dev[i].pci_device, ++ dev->pci_dev[i].pci_function); ++ if (new < 0) { ++ efi_error("efidp_make_pci() failed"); ++ return new; ++ } ++ sz += new; ++ off += new; ++ } ++ ++ debug("returning %zd", sz); ++ return sz; + } + + enum interface_type pci_iftypes[] = { pci, unknown }; + + struct dev_probe HIDDEN pci_parser = { +- .name = "pci", +- .iftypes = pci_iftypes, +- .parse = parse_pci, +- .create = dp_create_pci, ++ .name = "pci", ++ .iftypes = pci_iftypes, ++ .parse = parse_pci, ++ .create = dp_create_pci, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index 4d981fc8ad3..099ac8aef8c 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -72,120 +72,122 @@ + static ssize_t + parse_pmem(struct device *dev, const char *current, const char *root UNUSED) + { +- uint8_t *filebuf = NULL; +- uint8_t system, sysbus, acpi_id; +- uint16_t pnp_id; +- int ndbus, region, btt_region_id, btt_id, rc, pos; +- char *namespace = NULL; ++ uint8_t *filebuf = NULL; ++ uint8_t system, sysbus, acpi_id; ++ uint16_t pnp_id; ++ int ndbus, region, btt_region_id, btt_id, rc, pos; ++ char *namespace = NULL; + +- debug("entry"); ++ debug("entry"); + +- if (!strcmp(dev->driver, "nd_pmem")) { +- ; ++ if (!strcmp(dev->driver, "nd_pmem")) { ++ ; + #if 0 /* dunno */ +- } else if (!strcmp(dev->driver, "nd_blk")) { +- /* dunno */ +- dev->inteface_type = scsi; ++ } else if (!strcmp(dev->driver, "nd_blk")) { ++ /* dunno */ ++ dev->inteface_type = scsi; + #endif +- } else { +- /* +- * not a pmem device +- */ +- return 0; +- } +- +- /* +- * We're not actually using any of the values here except pos (our +- * return value), but rather just being paranoid that this is the sort +- * of device we care about. +- * +- * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s +- */ +- rc = sscanf(current, +- "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", +- &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ®ion, +- &btt_region_id, &btt_id, &pos); +- if (rc < 8) +- return 0; +- +- /* +- * but the UUID we really do need to have. +- */ +- rc = read_sysfs_file(&filebuf, +- "class/block/%s/device/namespace", dev->disk_name); +- if ((rc < 0 && errno == ENOENT) || filebuf == NULL) +- return -1; +- +- rc = sscanf((char *)filebuf, "%ms[^\n]\n", &namespace); +- if (rc != 1 || namespace == NULL) +- return -1; +- +- filebuf = NULL; +- debug("nvdimm namespace is \"%s\"", namespace); +- rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace); +- free(namespace); +- if (rc < 0 || filebuf == NULL) +- return -1; +- +- rc = efi_str_to_guid((char *)filebuf, +- &dev->nvdimm_info.namespace_label); +- if (rc < 0) +- return -1; +- +- filebuf = NULL; +- rc = read_sysfs_file(&filebuf, "class/block/%s/device/uuid", +- dev->disk_name); +- if (rc < 0 || filebuf == NULL) +- return -1; +- +- rc = efi_str_to_guid((char *)filebuf, +- &dev->nvdimm_info.nvdimm_label); +- if (rc < 0) +- return -1; +- +- /* +- * Right now it's not clear what encoding NVDIMM($uuid) gets in the +- * binary format, so this will be in the mixed endian format EFI GUIDs +- * are in (33221100-1100-1100-0011-223344556677) unless you set this +- * variable. +- */ +- if (getenv("LIBEFIBOOT_SWIZZLE_PMEM_UUID") != NULL) { +- swizzle_guid_to_uuid(&dev->nvdimm_info.namespace_label); +- swizzle_guid_to_uuid(&dev->nvdimm_info.nvdimm_label); +- } +- +- dev->interface_type = nd_pmem; +- +- return pos; ++ } else { ++ /* ++ * not a pmem device ++ */ ++ return 0; ++ } ++ ++ /* ++ * We're not actually using any of the values here except pos (our ++ * return value), but rather just being paranoid that this is the sort ++ * of device we care about. ++ * ++ * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s ++ */ ++ rc = sscanf(current, ++ "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", ++ &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ®ion, ++ &btt_region_id, &btt_id, &pos); ++ if (rc < 8) ++ return 0; ++ ++ /* ++ * but the UUID we really do need to have. ++ */ ++ rc = read_sysfs_file(&filebuf, ++ "class/block/%s/device/namespace", dev->disk_name); ++ if ((rc < 0 && errno == ENOENT) || filebuf == NULL) ++ return -1; ++ ++ rc = sscanf((char *)filebuf, "%ms[^\n]\n", &namespace); ++ if (rc != 1 || namespace == NULL) ++ return -1; ++ ++ filebuf = NULL; ++ debug("nvdimm namespace is \"%s\"", namespace); ++ rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace); ++ free(namespace); ++ if (rc < 0 || filebuf == NULL) ++ return -1; ++ ++ rc = efi_str_to_guid((char *)filebuf, ++ &dev->nvdimm_info.namespace_label); ++ if (rc < 0) ++ return -1; ++ ++ filebuf = NULL; ++ rc = read_sysfs_file(&filebuf, "class/block/%s/device/uuid", ++ dev->disk_name); ++ if (rc < 0 || filebuf == NULL) ++ return -1; ++ ++ rc = efi_str_to_guid((char *)filebuf, ++ &dev->nvdimm_info.nvdimm_label); ++ if (rc < 0) ++ return -1; ++ ++ /* ++ * Right now it's not clear what encoding NVDIMM($uuid) gets in the ++ * binary format, so this will be in the mixed endian format EFI GUIDs ++ * are in (33221100-1100-1100-0011-223344556677) unless you set this ++ * variable. ++ */ ++ if (getenv("LIBEFIBOOT_SWIZZLE_PMEM_UUID") != NULL) { ++ swizzle_guid_to_uuid(&dev->nvdimm_info.namespace_label); ++ swizzle_guid_to_uuid(&dev->nvdimm_info.nvdimm_label); ++ } ++ ++ dev->interface_type = nd_pmem; ++ ++ return pos; + } + + static ssize_t + dp_create_pmem(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz, sz1; ++ ssize_t sz, sz1; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_nvdimm(buf + off, size ? size - off : 0, +- &dev->nvdimm_info.namespace_label); +- if (sz < 0) +- return sz; +- off += sz; +- sz1 = efidp_make_nvdimm(buf + off, size ? size - off : 0, +- &dev->nvdimm_info.nvdimm_label); +- if (sz1 < 0) +- return sz1; ++ sz = efidp_make_nvdimm(buf + off, size ? size - off : 0, ++ &dev->nvdimm_info.namespace_label); ++ if (sz < 0) ++ return sz; ++ off += sz; ++ sz1 = efidp_make_nvdimm(buf + off, size ? size - off : 0, ++ &dev->nvdimm_info.nvdimm_label); ++ if (sz1 < 0) ++ return sz1; + +- return sz + sz1; ++ return sz + sz1; + } + + enum interface_type pmem_iftypes[] = { nd_pmem, unknown }; + + struct dev_probe HIDDEN pmem_parser = { +- .name = "pmem", +- .iftypes = pmem_iftypes, +- .flags = DEV_PROVIDES_ROOT|DEV_PROVIDES_HD, +- .parse = parse_pmem, +- .create = dp_create_pmem, ++ .name = "pmem", ++ .iftypes = pmem_iftypes, ++ .flags = DEV_PROVIDES_ROOT|DEV_PROVIDES_HD, ++ .parse = parse_pmem, ++ .create = dp_create_pmem, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-sas.c b/src/linux-sas.c +index bb04fe83064..f985deeaa3f 100644 +--- a/src/linux-sas.c ++++ b/src/linux-sas.c +@@ -30,87 +30,87 @@ + + static int + get_port_expander_sas_address(uint64_t *sas_address, uint32_t scsi_host, +- uint32_t local_port_id, +- uint32_t remote_port_id, uint32_t remote_scsi_target) ++ uint32_t local_port_id, ++ uint32_t remote_port_id, uint32_t remote_scsi_target) + { +- uint8_t *filebuf = NULL; +- int rc; ++ uint8_t *filebuf = NULL; ++ int rc; + +- /* +- * We find sas_address via this insanity: +- * /sys/class/scsi_host/host2 -> ../../devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2 +- * /sys/devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2/device -> ../../../host2 +- * /sys/devices/pci0000:74/0000:74:02.0/host2/device -> ../../../host2 +- * /sys/devices/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address +- * +- * But since host2 is always host2, we can skip most of that and just +- * go for: +- * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address +- */ ++ /* ++ * We find sas_address via this insanity: ++ * /sys/class/scsi_host/host2 -> ../../devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2 ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/scsi_host/host2/device -> ../../../host2 ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/device -> ../../../host2 ++ * /sys/devices/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address ++ * ++ * But since host2 is always host2, we can skip most of that and just ++ * go for: ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address ++ */ + + #if 0 /* previously thought this was right, but it's the expander's address, not the target's address */ +- /* +- * /sys/class/scsi_host/host2/device/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address +- * ... I think. I would have expected that to be port-2:0:0 and I +- * don't understand why it isn't. (I do now; this is the expander not +- * the port.) +- */ ++ /* ++ * /sys/class/scsi_host/host2/device/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address ++ * ... I think. I would have expected that to be port-2:0:0 and I ++ * don't understand why it isn't. (I do now; this is the expander not ++ * the port.) ++ */ + +- debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address", +- scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target); +- rc = read_sysfs_file(&filebuf, +- "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address", +- scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target); +- if (rc < 0 || filebuf == NULL) { +- debug("didn't find it."); +- return -1; +- } ++ debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address", ++ scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target); ++ rc = read_sysfs_file(&filebuf, ++ "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/sas_device/expander-%d:%d/sas_address", ++ scsi_host, scsi_host, port_id, scsi_host, remote_scsi_target, scsi_host, remote_scsi_target); ++ if (rc < 0 || filebuf == NULL) { ++ debug("didn't find it."); ++ return -1; ++ } + #else +- debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address", +- scsi_host, +- scsi_host, local_port_id, +- scsi_host, remote_scsi_target, +- scsi_host, remote_scsi_target, remote_port_id, +- scsi_host, remote_scsi_target, remote_port_id, +- scsi_host, remote_scsi_target, remote_port_id); +- rc = read_sysfs_file(&filebuf, +- "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address", +- scsi_host, +- scsi_host, local_port_id, +- scsi_host, remote_scsi_target, +- scsi_host, remote_scsi_target, remote_port_id, +- scsi_host, remote_scsi_target, remote_port_id, +- scsi_host, remote_scsi_target, remote_port_id); +- if (rc < 0 || filebuf == NULL) { +- debug("didn't find it."); +- return -1; +- } ++ debug("looking for /sys/class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address", ++ scsi_host, ++ scsi_host, local_port_id, ++ scsi_host, remote_scsi_target, ++ scsi_host, remote_scsi_target, remote_port_id, ++ scsi_host, remote_scsi_target, remote_port_id, ++ scsi_host, remote_scsi_target, remote_port_id); ++ rc = read_sysfs_file(&filebuf, ++ "class/scsi_host/host%d/device/port-%d:%d/expander-%d:%d/port-%d:%d:%d/end_device-%d:%d:%d/sas_device/end_device-%d:%d:%d/sas_address", ++ scsi_host, ++ scsi_host, local_port_id, ++ scsi_host, remote_scsi_target, ++ scsi_host, remote_scsi_target, remote_port_id, ++ scsi_host, remote_scsi_target, remote_port_id, ++ scsi_host, remote_scsi_target, remote_port_id); ++ if (rc < 0 || filebuf == NULL) { ++ debug("didn't find it."); ++ return -1; ++ } + #endif + +- rc = sscanf((char *)filebuf, "%"PRIx64, sas_address); +- if (rc != 1) +- return -1; ++ rc = sscanf((char *)filebuf, "%"PRIx64, sas_address); ++ if (rc != 1) ++ return -1; + +- return 0; ++ return 0; + } + + static int + get_local_sas_address(uint64_t *sas_address, struct device *dev) + { +- int rc; +- char *filebuf = NULL; ++ int rc; ++ char *filebuf = NULL; + +- rc = read_sysfs_file(&filebuf, +- "class/block/%s/device/sas_address", +- dev->disk_name); +- if (rc < 0 || filebuf == NULL) +- return -1; ++ rc = read_sysfs_file(&filebuf, ++ "class/block/%s/device/sas_address", ++ dev->disk_name); ++ if (rc < 0 || filebuf == NULL) ++ return -1; + +- rc = sscanf((char *)filebuf, "%"PRIx64, sas_address); +- if (rc != 1) +- return -1; ++ rc = sscanf((char *)filebuf, "%"PRIx64, sas_address); ++ if (rc != 1) ++ return -1; + +- return 0; ++ return 0; + } + + /* +@@ -150,115 +150,117 @@ get_local_sas_address(uint64_t *sas_address, struct device *dev) + static ssize_t + parse_sas(struct device *dev, const char *current, const char *root UNUSED) + { +- struct stat statbuf = { 0, }; +- int rc; +- uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; +- uint32_t local_port_id = 0, remote_port_id = 0; +- uint32_t remote_scsi_target = 0; +- uint64_t scsi_lun; +- ssize_t pos; +- uint64_t sas_address = 0; ++ struct stat statbuf = { 0, }; ++ int rc; ++ uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; ++ uint32_t local_port_id = 0, remote_port_id = 0; ++ uint32_t remote_scsi_target = 0; ++ uint64_t scsi_lun; ++ ssize_t pos; ++ uint64_t sas_address = 0; + +- debug("entry"); ++ debug("entry"); + +- pos = parse_scsi_link(current, &scsi_host, +- &scsi_bus, &scsi_device, +- &scsi_target, &scsi_lun, +- &local_port_id, &remote_port_id, +- &remote_scsi_target); +- /* +- * If we can't parse the scsi data, it isn't a sas device, so return 0 +- * not error. +- */ +- if (pos < 0) +- return 0; ++ pos = parse_scsi_link(current, &scsi_host, ++ &scsi_bus, &scsi_device, ++ &scsi_target, &scsi_lun, ++ &local_port_id, &remote_port_id, ++ &remote_scsi_target); ++ /* ++ * If we can't parse the scsi data, it isn't a sas device, so return 0 ++ * not error. ++ */ ++ if (pos < 0) ++ return 0; + +- /* +- * Make sure it has the actual /SAS/ bits before we continue +- * validating all this junk. +- */ +- debug("looking for /sys/class/scsi_host/host%d/host_sas_address", scsi_host); +- rc = sysfs_stat(&statbuf, +- "class/scsi_host/host%d/host_sas_address", +- scsi_host); +- /* +- * If we can't parse the scsi data, it isn't a /SAS/ device, so return +- * 0 not error. Later errors mean it is an ata device, but we can't +- * parse it right, so they return -1. +- */ +- if (rc < 0) { +- debug("didn't find it."); +- /* +- * If it's on a port expander, it won't have the +- * host_sas_address, so we need to check if it's a sas_host +- * instead. +- * It may work to just check this to begin with, but I don't +- * have such a device in front of me right now. +- */ +- debug("looking for /sys/class/sas_host/host%d", scsi_host); +- rc = sysfs_stat(&statbuf, +- "class/sas_host/host%d", scsi_host); +- if (rc < 0) { +- debug("didn't find it."); +- return 0; +- } +- debug("found it."); ++ /* ++ * Make sure it has the actual /SAS/ bits before we continue ++ * validating all this junk. ++ */ ++ debug("looking for /sys/class/scsi_host/host%d/host_sas_address", scsi_host); ++ rc = sysfs_stat(&statbuf, ++ "class/scsi_host/host%d/host_sas_address", ++ scsi_host); ++ /* ++ * If we can't parse the scsi data, it isn't a /SAS/ device, so return ++ * 0 not error. Later errors mean it is an ata device, but we can't ++ * parse it right, so they return -1. ++ */ ++ if (rc < 0) { ++ debug("didn't find it."); ++ /* ++ * If it's on a port expander, it won't have the ++ * host_sas_address, so we need to check if it's a sas_host ++ * instead. ++ * It may work to just check this to begin with, but I don't ++ * have such a device in front of me right now. ++ */ ++ debug("looking for /sys/class/sas_host/host%d", scsi_host); ++ rc = sysfs_stat(&statbuf, ++ "class/sas_host/host%d", scsi_host); ++ if (rc < 0) { ++ debug("didn't find it."); ++ return 0; ++ } ++ debug("found it."); + +- /* +- * So it *is* a sas_host, and we have to fish the sas_address +- * from the remote port +- */ +- rc = get_port_expander_sas_address(&sas_address, scsi_host, +- local_port_id, +- remote_port_id, +- remote_scsi_target); +- if (rc < 0) { +- debug("Couldn't find port expander sas address"); +- return 0; +- } +- } else { +- /* +- * we also need to get the actual sas_address from someplace... +- */ +- debug("found it."); +- rc = get_local_sas_address(&sas_address, dev); +- if (rc < 0) { +- debug("Couldn't find sas address"); +- return 0; +- } +- } +- debug("sas address is 0x%"PRIx64, sas_address); ++ /* ++ * So it *is* a sas_host, and we have to fish the sas_address ++ * from the remote port ++ */ ++ rc = get_port_expander_sas_address(&sas_address, scsi_host, ++ local_port_id, ++ remote_port_id, ++ remote_scsi_target); ++ if (rc < 0) { ++ debug("Couldn't find port expander sas address"); ++ return 0; ++ } ++ } else { ++ /* ++ * we also need to get the actual sas_address from someplace... ++ */ ++ debug("found it."); ++ rc = get_local_sas_address(&sas_address, dev); ++ if (rc < 0) { ++ debug("Couldn't find sas address"); ++ return 0; ++ } ++ } ++ debug("sas address is 0x%"PRIx64, sas_address); + +- dev->sas_info.sas_address = sas_address; ++ dev->sas_info.sas_address = sas_address; + +- dev->scsi_info.scsi_bus = scsi_bus; +- dev->scsi_info.scsi_device = scsi_device; +- dev->scsi_info.scsi_target = scsi_target; +- dev->scsi_info.scsi_lun = scsi_lun; +- dev->interface_type = sas; +- return pos; ++ dev->scsi_info.scsi_bus = scsi_bus; ++ dev->scsi_info.scsi_device = scsi_device; ++ dev->scsi_info.scsi_target = scsi_target; ++ dev->scsi_info.scsi_lun = scsi_lun; ++ dev->interface_type = sas; ++ return pos; + } + + static ssize_t + dp_create_sas(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz; ++ ssize_t sz; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_sas(buf + off, size ? size - off : 0, +- dev->sas_info.sas_address); ++ sz = efidp_make_sas(buf + off, size ? size - off : 0, ++ dev->sas_info.sas_address); + +- return sz; ++ return sz; + } + + enum interface_type sas_iftypes[] = { sas, unknown }; + + struct dev_probe HIDDEN sas_parser = { +- .name = "sas", +- .iftypes = sas_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_sas, +- .create = dp_create_sas, ++ .name = "sas", ++ .iftypes = sas_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_sas, ++ .create = dp_create_sas, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-sata.c b/src/linux-sata.c +index 356411724bb..ee285d84a76 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -65,188 +65,190 @@ + static ssize_t + sysfs_sata_get_port_info(uint32_t print_id, struct device *dev) + { +- DIR *d; +- struct dirent *de; +- uint8_t *buf = NULL; +- int rc; +- +- d = sysfs_opendir("class/ata_device/"); +- if (!d) { +- efi_error("could not open /sys/class/ata_device/"); +- return -1; +- } +- +- while ((de = readdir(d)) != NULL) { +- uint32_t found_print_id; +- uint32_t found_pmp; +- uint32_t found_devno = 0; +- +- if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) +- continue; +- +- rc = sscanf(de->d_name, "dev%d.%d.%d", &found_print_id, +- &found_pmp, &found_devno); +- if (rc < 2 || rc > 3) { +- closedir(d); +- errno = EINVAL; +- return -1; +- } else if (found_print_id != print_id) { +- continue; +- } else if (rc == 3) { +- /* +- * the kernel doesn't ever tell us the SATA PMPN +- * sentinal value, it'll give us devM.N instead of +- * devM.N.O in that case instead. +- */ +- if (found_pmp > 0x7fff) { +- closedir(d); +- errno = EINVAL; +- return -1; +- } +- dev->sata_info.ata_devno = 0; +- dev->sata_info.ata_pmp = found_pmp; +- break; +- } else if (rc == 2) { +- dev->sata_info.ata_devno = 0; +- dev->sata_info.ata_pmp = 0xffff; +- break; +- } +- } +- closedir(d); +- +- rc = read_sysfs_file(&buf, "class/ata_port/ata%d/port_no", +- print_id); +- if (rc <= 0 || buf == NULL) +- return -1; +- +- rc = sscanf((char *)buf, "%d", &dev->sata_info.ata_port); +- if (rc != 1) +- return -1; +- +- /* +- * ata_port numbers are 1-indexed from libata in the kernel, but +- * they're 0-indexed in the spec. For maximal confusion. +- */ +- if (dev->sata_info.ata_port == 0) { +- errno = EINVAL; +- return -1; +- } else { +- dev->sata_info.ata_port -= 1; +- } +- +- return 0; ++ DIR *d; ++ struct dirent *de; ++ uint8_t *buf = NULL; ++ int rc; ++ ++ d = sysfs_opendir("class/ata_device/"); ++ if (!d) { ++ efi_error("could not open /sys/class/ata_device/"); ++ return -1; ++ } ++ ++ while ((de = readdir(d)) != NULL) { ++ uint32_t found_print_id; ++ uint32_t found_pmp; ++ uint32_t found_devno = 0; ++ ++ if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) ++ continue; ++ ++ rc = sscanf(de->d_name, "dev%d.%d.%d", &found_print_id, ++ &found_pmp, &found_devno); ++ if (rc < 2 || rc > 3) { ++ closedir(d); ++ errno = EINVAL; ++ return -1; ++ } else if (found_print_id != print_id) { ++ continue; ++ } else if (rc == 3) { ++ /* ++ * the kernel doesn't ever tell us the SATA PMPN ++ * sentinal value, it'll give us devM.N instead of ++ * devM.N.O in that case instead. ++ */ ++ if (found_pmp > 0x7fff) { ++ closedir(d); ++ errno = EINVAL; ++ return -1; ++ } ++ dev->sata_info.ata_devno = 0; ++ dev->sata_info.ata_pmp = found_pmp; ++ break; ++ } else if (rc == 2) { ++ dev->sata_info.ata_devno = 0; ++ dev->sata_info.ata_pmp = 0xffff; ++ break; ++ } ++ } ++ closedir(d); ++ ++ rc = read_sysfs_file(&buf, "class/ata_port/ata%d/port_no", ++ print_id); ++ if (rc <= 0 || buf == NULL) ++ return -1; ++ ++ rc = sscanf((char *)buf, "%d", &dev->sata_info.ata_port); ++ if (rc != 1) ++ return -1; ++ ++ /* ++ * ata_port numbers are 1-indexed from libata in the kernel, but ++ * they're 0-indexed in the spec. For maximal confusion. ++ */ ++ if (dev->sata_info.ata_port == 0) { ++ errno = EINVAL; ++ return -1; ++ } else { ++ dev->sata_info.ata_port -= 1; ++ } ++ ++ return 0; + } + + static ssize_t + parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + { +- const char *current = devlink; +- uint32_t print_id; +- uint32_t scsi_bus, tosser0; +- uint32_t scsi_device, tosser1; +- uint32_t scsi_target, tosser2; +- uint64_t scsi_lun, tosser3; +- int pos = 0; +- int rc; +- +- debug("entry"); +- if (is_pata(dev)) { +- debug("This is a PATA device; skipping."); +- return 0; +- } +- +- /* find the ata info: +- * ata1/host0/target0:0:0/0:0:0:0 +- * ^dev ^host x y z +- */ +- debug("searching for ata1/"); +- rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- /* +- * If we don't find this one, it isn't an ata device, so return 0 not +- * error. Later errors mean it is an ata device, but we can't parse +- * it right, so they return -1. +- */ +- if (rc != 1) +- return 0; +- current += pos; +- pos = 0; +- +- debug("searching for host0/"); +- rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- if (rc != 1) +- return -1; +- current += pos; +- pos = 0; +- +- debug("searching for target0:0:0:0/"); +- rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", +- &scsi_device, &scsi_target, &scsi_lun, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- if (rc != 3) +- return -1; +- current += pos; +- pos = 0; +- +- debug("searching for 0:0:0:0/"); +- rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", +- &tosser0, &tosser1, &tosser2, &tosser3, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- if (rc != 4) +- return -1; +- current += pos; +- +- rc = sysfs_sata_get_port_info(print_id, dev); +- if (rc < 0) +- return -1; +- +- dev->sata_info.scsi_bus = scsi_bus; +- dev->sata_info.scsi_device = scsi_device; +- dev->sata_info.scsi_target = scsi_target; +- dev->sata_info.scsi_lun = scsi_lun; +- +- if (dev->interface_type == unknown) +- dev->interface_type = sata; +- +- return current - devlink; ++ const char *current = devlink; ++ uint32_t print_id; ++ uint32_t scsi_bus, tosser0; ++ uint32_t scsi_device, tosser1; ++ uint32_t scsi_target, tosser2; ++ uint64_t scsi_lun, tosser3; ++ int pos = 0; ++ int rc; ++ ++ debug("entry"); ++ if (is_pata(dev)) { ++ debug("This is a PATA device; skipping."); ++ return 0; ++ } ++ ++ /* find the ata info: ++ * ata1/host0/target0:0:0/0:0:0:0 ++ * ^dev ^host x y z ++ */ ++ debug("searching for ata1/"); ++ rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ /* ++ * If we don't find this one, it isn't an ata device, so return 0 not ++ * error. Later errors mean it is an ata device, but we can't parse ++ * it right, so they return -1. ++ */ ++ if (rc != 1) ++ return 0; ++ current += pos; ++ pos = 0; ++ ++ debug("searching for host0/"); ++ rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ if (rc != 1) ++ return -1; ++ current += pos; ++ pos = 0; ++ ++ debug("searching for target0:0:0:0/"); ++ rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", ++ &scsi_device, &scsi_target, &scsi_lun, &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ if (rc != 3) ++ return -1; ++ current += pos; ++ pos = 0; ++ ++ debug("searching for 0:0:0:0/"); ++ rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", ++ &tosser0, &tosser1, &tosser2, &tosser3, &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ if (rc != 4) ++ return -1; ++ current += pos; ++ ++ rc = sysfs_sata_get_port_info(print_id, dev); ++ if (rc < 0) ++ return -1; ++ ++ dev->sata_info.scsi_bus = scsi_bus; ++ dev->sata_info.scsi_device = scsi_device; ++ dev->sata_info.scsi_target = scsi_target; ++ dev->sata_info.scsi_lun = scsi_lun; ++ ++ if (dev->interface_type == unknown) ++ dev->interface_type = sata; ++ ++ return current - devlink; + } + + static ssize_t + dp_create_sata(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz = -1; +- +- debug("entry buf:%p size:%zd off:%zd", buf, size, off); +- +- if (dev->interface_type == ata || dev->interface_type == atapi) { +- sz = efidp_make_atapi(buf + off, size ? size - off : 0, +- dev->sata_info.ata_port, +- dev->sata_info.ata_pmp, +- dev->sata_info.ata_devno); +- if (sz < 0) +- efi_error("efidp_make_atapi() failed"); +- } else if (dev->interface_type == sata) { +- sz = efidp_make_sata(buf + off, size ? size - off : 0, +- dev->sata_info.ata_port, +- dev->sata_info.ata_pmp, +- dev->sata_info.ata_devno); +- if (sz < 0) +- efi_error("efidp_make_sata() failed"); +- } else { +- return -EINVAL; +- } +- +- return sz; ++ ssize_t sz = -1; ++ ++ debug("entry buf:%p size:%zd off:%zd", buf, size, off); ++ ++ if (dev->interface_type == ata || dev->interface_type == atapi) { ++ sz = efidp_make_atapi(buf + off, size ? size - off : 0, ++ dev->sata_info.ata_port, ++ dev->sata_info.ata_pmp, ++ dev->sata_info.ata_devno); ++ if (sz < 0) ++ efi_error("efidp_make_atapi() failed"); ++ } else if (dev->interface_type == sata) { ++ sz = efidp_make_sata(buf + off, size ? size - off : 0, ++ dev->sata_info.ata_port, ++ dev->sata_info.ata_pmp, ++ dev->sata_info.ata_devno); ++ if (sz < 0) ++ efi_error("efidp_make_sata() failed"); ++ } else { ++ return -EINVAL; ++ } ++ ++ return sz; + } + + enum interface_type sata_iftypes[] = { sata, unknown }; + + struct dev_probe HIDDEN sata_parser = { +- .name = "sata", +- .iftypes = sata_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_sata, +- .create = dp_create_sata, ++ .name = "sata", ++ .iftypes = sata_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_sata, ++ .create = dp_create_sata, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 04892f02b4e..90a85836b1c 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -37,268 +37,270 @@ + */ + ssize_t HIDDEN + parse_scsi_link(const char *current, uint32_t *scsi_host, +- uint32_t *scsi_bus, uint32_t *scsi_device, +- uint32_t *scsi_target, uint64_t *scsi_lun, +- uint32_t *local_port_id, uint32_t *remote_port_id, +- uint32_t *remote_target_id) ++ uint32_t *scsi_bus, uint32_t *scsi_device, ++ uint32_t *scsi_target, uint64_t *scsi_lun, ++ uint32_t *local_port_id, uint32_t *remote_port_id, ++ uint32_t *remote_target_id) + { +- int rc; +- int sz = 0; +- int pos0 = 0, pos1 = 0; +- +- debug("entry"); +- /* +- * This structure is completely ridiculous. +- * +- * /dev/sdc as SAS looks like: +- * /sys/dev/block/8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc +- * /dev/sdc1 looks like: +- * /sys/dev/block/8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 +- * +- * OR +- * +- * /dev/sdc as SAS looks like: +- * /sys/dev/block/8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:2:0/end_device-4:2:0/target4:2:0/4:2:0:0/block/sdc +- * /dev/sdc1 looks like: +- * /sys/dev/block/8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:2:0/end_device-4:2:0/target4:2:0/4:2:0:0/block/sdc/sdc1 +- * +- * /sys/block/sdc/device looks like: +- * device-> ../../../4:2:0:0 +- * +- * OR +- * +- * 8:0 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda +- * 8:1 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- * +- * /sys/block/sda/device looks like: +- * device -> ../../../2:0:0:0 * +- * +- * sas_address exists, but it's hard to find: +- * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address +- * but sas_host_address is nowhere to be found, and sas_address +- * doesn't directly exist under /sys/class/ anywhere. So you actually +- * have to go to +- * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address +- * and chop that off to +- * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/ +- * and then add a bunch of port and end device crap to it to get: +- * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address +- +- */ +- +- /* +- * So we start when current is: +- * host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 +- * or +- * host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- */ +- uint32_t tosser0, tosser1, tosser2; +- +- /* ignore a bunch of stuff +- * host4/port-4:0 +- * or host4/port-4:0:0 +- */ +- debug("searching for host4/"); +- rc = sscanf(current, "host%d/%n", scsi_host, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 1) +- return -1; +- sz += pos0; +- pos0 = 0; +- +- /* +- * We might have this next: +- * port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- * or: +- * port-2:0/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- * or maybe (not sure): +- * port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- */ +- debug("searching for port-4:0 or port-4:0:0"); +- rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0, +- &tosser1, &pos0, &tosser2, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); +- if (rc == 2 || rc == 3) { +- sz += pos0; +- pos0 = 0; +- if (local_port_id && rc == 2) +- *local_port_id = tosser1; +- if (remote_port_id && rc == 3) +- *remote_port_id = tosser2; +- +- if (current[sz] == '/') +- sz += 1; +- +- /* +- * We might have this next: +- * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- * ^ port id +- * ^ scsi target id +- * ^ host number +- * ^ host number +- * We don't actually care about either number in expander-.../, +- * because they're replicated in all the other places. We just need +- * to get past it. +- */ +- debug("searching for expander-4:0/"); +- rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc == 2) { +- if (!remote_target_id) { +- efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); +- return -1; +- } +- *remote_target_id = tosser1; +- sz += pos0; +- pos0 = 0; +- +- /* +- * if we have that, we should have a 3-part port next +- */ +- debug("searching for port-2:0:2/"); +- rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 3) { +- efi_error("Couldn't parse port expander port string"); +- return -1; +- } +- sz += pos0; +- } +- pos0 = 0; +- +- /* next: +- * /end_device-4:0 +- * or /end_device-4:0:0 +- * awesomely these are the exact same fields that go into port-blah, +- * but we don't care for now about any of them anyway. +- */ +- debug("searching for end_device-4:0/ or end_device-4:0:0/"); +- rc = sscanf(current + sz, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 2) +- return -1; +- +- pos1 = 0; +- rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); +- if (rc != 0 && rc != 1) +- return -1; +- if (remote_port_id && rc == 1) +- *remote_port_id = tosser2; +- if (local_port_id && rc == 0) +- *local_port_id = tosser1; +- sz += pos0 + pos1; +- pos0 = pos1 = 0; +- +- if (current[sz] == '/') +- sz += 1; +- } else if (rc != 0) { +- return -1; +- } +- +- /* now: +- * /target4:0:0/ +- */ +- uint64_t tosser3; +- debug("searching for target4:0:0/"); +- rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, +- &tosser3, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 3) +- return -1; +- sz += pos0; +- pos0 = 0; +- +- /* now: +- * %d:%d:%d:%llu/ +- */ +- debug("searching for 4:0:0:0/"); +- rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", +- scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 4) +- return -1; +- sz += pos0; +- +- debug("returning %d", sz); +- return sz; ++ int rc; ++ int sz = 0; ++ int pos0 = 0, pos1 = 0; ++ ++ debug("entry"); ++ /* ++ * This structure is completely ridiculous. ++ * ++ * /dev/sdc as SAS looks like: ++ * /sys/dev/block/8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc ++ * /dev/sdc1 looks like: ++ * /sys/dev/block/8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 ++ * ++ * OR ++ * ++ * /dev/sdc as SAS looks like: ++ * /sys/dev/block/8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:2:0/end_device-4:2:0/target4:2:0/4:2:0:0/block/sdc ++ * /dev/sdc1 looks like: ++ * /sys/dev/block/8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:2:0/end_device-4:2:0/target4:2:0/4:2:0:0/block/sdc/sdc1 ++ * ++ * /sys/block/sdc/device looks like: ++ * device-> ../../../4:2:0:0 ++ * ++ * OR ++ * ++ * 8:0 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda ++ * 8:1 -> ../../devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ * ++ * /sys/block/sda/device looks like: ++ * device -> ../../../2:0:0:0 * ++ * ++ * sas_address exists, but it's hard to find: ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address ++ * but sas_host_address is nowhere to be found, and sas_address ++ * doesn't directly exist under /sys/class/ anywhere. So you actually ++ * have to go to ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address ++ * and chop that off to ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/ ++ * and then add a bunch of port and end device crap to it to get: ++ * /sys/devices/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/sas_device/end_device-2:0:2/sas_address ++ ++ */ ++ ++ /* ++ * So we start when current is: ++ * host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 ++ * or ++ * host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ */ ++ uint32_t tosser0, tosser1, tosser2; ++ ++ /* ignore a bunch of stuff ++ * host4/port-4:0 ++ * or host4/port-4:0:0 ++ */ ++ debug("searching for host4/"); ++ rc = sscanf(current, "host%d/%n", scsi_host, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc != 1) ++ return -1; ++ sz += pos0; ++ pos0 = 0; ++ ++ /* ++ * We might have this next: ++ * port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ * or: ++ * port-2:0/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ * or maybe (not sure): ++ * port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ */ ++ debug("searching for port-4:0 or port-4:0:0"); ++ rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0, ++ &tosser1, &pos0, &tosser2, &pos1); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); ++ if (rc == 2 || rc == 3) { ++ sz += pos0; ++ pos0 = 0; ++ if (local_port_id && rc == 2) ++ *local_port_id = tosser1; ++ if (remote_port_id && rc == 3) ++ *remote_port_id = tosser2; ++ ++ if (current[sz] == '/') ++ sz += 1; ++ ++ /* ++ * We might have this next: ++ * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ * ^ port id ++ * ^ scsi target id ++ * ^ host number ++ * ^ host number ++ * We don't actually care about either number in expander-.../, ++ * because they're replicated in all the other places. We just need ++ * to get past it. ++ */ ++ debug("searching for expander-4:0/"); ++ rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc == 2) { ++ if (!remote_target_id) { ++ efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); ++ return -1; ++ } ++ *remote_target_id = tosser1; ++ sz += pos0; ++ pos0 = 0; ++ ++ /* ++ * if we have that, we should have a 3-part port next ++ */ ++ debug("searching for port-2:0:2/"); ++ rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc != 3) { ++ efi_error("Couldn't parse port expander port string"); ++ return -1; ++ } ++ sz += pos0; ++ } ++ pos0 = 0; ++ ++ /* next: ++ * /end_device-4:0 ++ * or /end_device-4:0:0 ++ * awesomely these are the exact same fields that go into port-blah, ++ * but we don't care for now about any of them anyway. ++ */ ++ debug("searching for end_device-4:0/ or end_device-4:0:0/"); ++ rc = sscanf(current + sz, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc != 2) ++ return -1; ++ ++ pos1 = 0; ++ rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); ++ if (rc != 0 && rc != 1) ++ return -1; ++ if (remote_port_id && rc == 1) ++ *remote_port_id = tosser2; ++ if (local_port_id && rc == 0) ++ *local_port_id = tosser1; ++ sz += pos0 + pos1; ++ pos0 = pos1 = 0; ++ ++ if (current[sz] == '/') ++ sz += 1; ++ } else if (rc != 0) { ++ return -1; ++ } ++ ++ /* now: ++ * /target4:0:0/ ++ */ ++ uint64_t tosser3; ++ debug("searching for target4:0:0/"); ++ rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, ++ &tosser3, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc != 3) ++ return -1; ++ sz += pos0; ++ pos0 = 0; ++ ++ /* now: ++ * %d:%d:%d:%llu/ ++ */ ++ debug("searching for 4:0:0:0/"); ++ rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", ++ scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); ++ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ if (rc != 4) ++ return -1; ++ sz += pos0; ++ ++ debug("returning %d", sz); ++ return sz; + } + + static ssize_t + parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + { +- uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; +- uint64_t scsi_lun; +- ssize_t sz; +- int pos; +- int rc; +- +- debug("entry"); +- +- debug("searching for ../../../0:0:0:0"); +- rc = sscanf(dev->device, "../../../%d:%d:%d:%"PRIu64"%n", +- &dev->scsi_info.scsi_bus, +- &dev->scsi_info.scsi_device, +- &dev->scsi_info.scsi_target, +- &dev->scsi_info.scsi_lun, +- &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); +- if (rc != 4) +- return 0; +- +- sz = parse_scsi_link(current, &scsi_host, +- &scsi_bus, &scsi_device, +- &scsi_target, &scsi_lun, +- NULL, NULL, NULL); +- if (sz < 0) +- return 0; +- +- /* +- * SCSI disks can have up to 16 partitions, or 4 bits worth +- * and have one bit for the disk number. +- */ +- if (dev->major == 8) { +- dev->interface_type = scsi; +- dev->disknum = (dev->minor >> 4); +- set_part(dev, dev->minor & 0xF); +- } else if (dev->major >= 65 && dev->major <= 71) { +- dev->interface_type = scsi; +- dev->disknum = 16*(dev->major-64) + (dev->minor >> 4); +- set_part(dev, dev->minor & 0xF); +- } else if (dev->major >= 128 && dev->major <= 135) { +- dev->interface_type = scsi; +- dev->disknum = 16*(dev->major-128) + (dev->minor >> 4); +- set_part(dev, dev->minor & 0xF); +- } else { +- efi_error("couldn't parse scsi major/minor"); +- return -1; +- } +- +- return sz; ++ uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; ++ uint64_t scsi_lun; ++ ssize_t sz; ++ int pos; ++ int rc; ++ ++ debug("entry"); ++ ++ debug("searching for ../../../0:0:0:0"); ++ rc = sscanf(dev->device, "../../../%d:%d:%d:%"PRIu64"%n", ++ &dev->scsi_info.scsi_bus, ++ &dev->scsi_info.scsi_device, ++ &dev->scsi_info.scsi_target, ++ &dev->scsi_info.scsi_lun, ++ &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); ++ if (rc != 4) ++ return 0; ++ ++ sz = parse_scsi_link(current, &scsi_host, ++ &scsi_bus, &scsi_device, ++ &scsi_target, &scsi_lun, ++ NULL, NULL, NULL); ++ if (sz < 0) ++ return 0; ++ ++ /* ++ * SCSI disks can have up to 16 partitions, or 4 bits worth ++ * and have one bit for the disk number. ++ */ ++ if (dev->major == 8) { ++ dev->interface_type = scsi; ++ dev->disknum = (dev->minor >> 4); ++ set_part(dev, dev->minor & 0xF); ++ } else if (dev->major >= 65 && dev->major <= 71) { ++ dev->interface_type = scsi; ++ dev->disknum = 16*(dev->major-64) + (dev->minor >> 4); ++ set_part(dev, dev->minor & 0xF); ++ } else if (dev->major >= 128 && dev->major <= 135) { ++ dev->interface_type = scsi; ++ dev->disknum = 16*(dev->major-128) + (dev->minor >> 4); ++ set_part(dev, dev->minor & 0xF); ++ } else { ++ efi_error("couldn't parse scsi major/minor"); ++ return -1; ++ } ++ ++ return sz; + } + + static ssize_t + dp_create_scsi(struct device *dev, +- uint8_t *buf, ssize_t size, ssize_t off) ++ uint8_t *buf, ssize_t size, ssize_t off) + { +- ssize_t sz = 0; ++ ssize_t sz = 0; + +- debug("entry"); ++ debug("entry"); + +- sz = efidp_make_scsi(buf + off, size ? size - off : 0, +- dev->scsi_info.scsi_target, +- dev->scsi_info.scsi_lun); +- if (sz < 0) +- efi_error("efidp_make_scsi() failed"); ++ sz = efidp_make_scsi(buf + off, size ? size - off : 0, ++ dev->scsi_info.scsi_target, ++ dev->scsi_info.scsi_lun); ++ if (sz < 0) ++ efi_error("efidp_make_scsi() failed"); + +- return sz; ++ return sz; + } + + enum interface_type scsi_iftypes[] = { scsi, unknown }; + + struct dev_probe HIDDEN scsi_parser = { +- .name = "scsi", +- .iftypes = scsi_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_scsi, +- .create = dp_create_scsi, ++ .name = "scsi", ++ .iftypes = scsi_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_scsi, ++ .create = dp_create_scsi, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index cbb4779b6fb..27633d69c97 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -40,26 +40,28 @@ + static ssize_t + parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED) + { +- int rc; +- int pos = 0; +- const char *devpart = current; ++ int rc; ++ int pos = 0; ++ const char *devpart = current; + +- debug("entry"); ++ debug("entry"); + +- rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); +- if (rc != 0) +- return 0; +- devpart += pos; +- debug("new position is \"%s\"", devpart); ++ rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); ++ if (rc != 0) ++ return 0; ++ devpart += pos; ++ debug("new position is \"%s\"", devpart); + +- return devpart - current; ++ return devpart - current; + } + + enum interface_type soc_root_iftypes[] = { soc_root, unknown }; + + struct dev_probe HIDDEN soc_root_parser = { +- .name = "soc_root", +- .iftypes = soc_root_iftypes, +- .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT, +- .parse = parse_soc_root, ++ .name = "soc_root", ++ .iftypes = soc_root_iftypes, ++ .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT, ++ .parse = parse_soc_root, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index fe6eb873a37..891c262fe05 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -47,33 +47,34 @@ + static ssize_t + parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + { +- uint32_t tosser; +- int pos = 0; +- int rc; ++ uint32_t tosser; ++ int pos = 0; ++ int rc; + +- debug("entry"); ++ debug("entry"); + +- debug("searching for virtio0/"); +- rc = sscanf(current, "virtio%x/%n", &tosser, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- /* +- * If we couldn't find virtioX/ then it isn't a virtio device. +- */ +- if (rc < 1) +- return 0; ++ debug("searching for virtio0/"); ++ rc = sscanf(current, "virtio%x/%n", &tosser, &pos); ++ debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ /* ++ * If we couldn't find virtioX/ then it isn't a virtio device. ++ */ ++ if (rc < 1) ++ return 0; + +- dev->interface_type = virtblk; ++ dev->interface_type = virtblk; + +- return pos; ++ return pos; + } + + enum interface_type virtblk_iftypes[] = { virtblk, unknown }; + + struct dev_probe HIDDEN virtblk_parser = { +- .name = "virtio block", +- .iftypes = virtblk_iftypes, +- .flags = DEV_PROVIDES_HD, +- .parse = parse_virtblk, +- .create = NULL, ++ .name = "virtio block", ++ .iftypes = virtblk_iftypes, ++ .flags = DEV_PROVIDES_HD, ++ .parse = parse_virtblk, ++ .create = NULL, + }; + ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux.c b/src/linux.c +index 4e102da5e24..45b1ee2d96f 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -46,568 +46,568 @@ + int HIDDEN + find_parent_devpath(const char * const child, char **parent) + { +- int ret; +- char *node; +- char *linkbuf; +- +- /* strip leading /dev/ */ +- node = strrchr(child, '/'); +- if (!node) +- return -1; +- node++; +- +- /* look up full path symlink */ +- ret = sysfs_readlink(&linkbuf, "class/block/%s", node); +- if (ret < 0 || !linkbuf) +- return ret; +- +- /* strip child */ +- node = strrchr(linkbuf, '/'); +- if (!node) +- return -1; +- *node = '\0'; +- +- /* read parent */ +- node = strrchr(linkbuf, '/'); +- if (!node) +- return -1; +- *node = '\0'; +- node++; +- +- /* write out new path */ +- ret = asprintf(parent, "/dev/%s", node); +- if (ret < 0) +- return ret; +- +- return 0; ++ int ret; ++ char *node; ++ char *linkbuf; ++ ++ /* strip leading /dev/ */ ++ node = strrchr(child, '/'); ++ if (!node) ++ return -1; ++ node++; ++ ++ /* look up full path symlink */ ++ ret = sysfs_readlink(&linkbuf, "class/block/%s", node); ++ if (ret < 0 || !linkbuf) ++ return ret; ++ ++ /* strip child */ ++ node = strrchr(linkbuf, '/'); ++ if (!node) ++ return -1; ++ *node = '\0'; ++ ++ /* read parent */ ++ node = strrchr(linkbuf, '/'); ++ if (!node) ++ return -1; ++ *node = '\0'; ++ node++; ++ ++ /* write out new path */ ++ ret = asprintf(parent, "/dev/%s", node); ++ if (ret < 0) ++ return ret; ++ ++ return 0; + } + + int HIDDEN + set_part_name(struct device *dev, const char * const fmt, ...) + { +- ssize_t rc; +- va_list ap; +- int error; +- +- if (dev->part <= 0) +- return 0; +- +- va_start(ap, fmt); +- rc = vasprintf(&dev->part_name, fmt, ap); +- error = errno; +- va_end(ap); +- errno = error; +- if (rc < 0) +- efi_error("could not allocate memory"); +- +- return rc; ++ ssize_t rc; ++ va_list ap; ++ int error; ++ ++ if (dev->part <= 0) ++ return 0; ++ ++ va_start(ap, fmt); ++ rc = vasprintf(&dev->part_name, fmt, ap); ++ error = errno; ++ va_end(ap); ++ errno = error; ++ if (rc < 0) ++ efi_error("could not allocate memory"); ++ ++ return rc; + } + + int HIDDEN + reset_part_name(struct device *dev) + { +- char *part = NULL; +- int rc; +- +- if (dev->part_name) { +- free(dev->part_name); +- dev->part_name = NULL; +- } +- +- if (dev->part < 1) +- return 0; +- +- if (dev->n_probes > 0 && +- dev->probes[dev->n_probes-1] && +- dev->probes[dev->n_probes-1]->make_part_name) { +- part = dev->probes[dev->n_probes]->make_part_name(dev); +- dev->part_name = part; +- rc = 0; +- } else { +- rc = asprintf(&dev->part_name, "%s%d", +- dev->disk_name, dev->part); +- if (rc < 0) +- efi_error("could not allocate memory"); +- } +- return rc; ++ char *part = NULL; ++ int rc; ++ ++ if (dev->part_name) { ++ free(dev->part_name); ++ dev->part_name = NULL; ++ } ++ ++ if (dev->part < 1) ++ return 0; ++ ++ if (dev->n_probes > 0 && ++ dev->probes[dev->n_probes-1] && ++ dev->probes[dev->n_probes-1]->make_part_name) { ++ part = dev->probes[dev->n_probes]->make_part_name(dev); ++ dev->part_name = part; ++ rc = 0; ++ } else { ++ rc = asprintf(&dev->part_name, "%s%d", ++ dev->disk_name, dev->part); ++ if (rc < 0) ++ efi_error("could not allocate memory"); ++ } ++ return rc; + } + + int HIDDEN + set_part(struct device *dev, int value) + { +- int rc; ++ int rc; + +- if (dev->part == value) +- return 0; ++ if (dev->part == value) ++ return 0; + +- dev->part = value; +- rc = reset_part_name(dev); +- if (rc < 0) +- efi_error("reset_part_name() failed"); ++ dev->part = value; ++ rc = reset_part_name(dev); ++ if (rc < 0) ++ efi_error("reset_part_name() failed"); + +- return rc; ++ return rc; + } + + int HIDDEN + set_disk_name(struct device *dev, const char * const fmt, ...) + { +- ssize_t rc; +- va_list ap; +- int error; +- +- va_start(ap, fmt); +- rc = vasprintf(&dev->disk_name, fmt, ap); +- error = errno; +- va_end(ap); +- errno = error; +- if (rc < 0) +- efi_error("could not allocate memory"); +- +- return rc; ++ ssize_t rc; ++ va_list ap; ++ int error; ++ ++ va_start(ap, fmt); ++ rc = vasprintf(&dev->disk_name, fmt, ap); ++ error = errno; ++ va_end(ap); ++ errno = error; ++ if (rc < 0) ++ efi_error("could not allocate memory"); ++ ++ return rc; + } + + int HIDDEN + set_disk_and_part_name(struct device *dev) + { +- /* +- * results are like such: +- * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART +- */ +- +- char *ultimate = pathseg(dev->link, -1); +- char *penultimate = pathseg(dev->link, -2); +- char *approximate = pathseg(dev->link, -3); +- char *proximate = pathseg(dev->link, -4); +- +- errno = 0; +- debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name); +- debug("dev->part:%d", dev->part); +- debug("ultimate:\"%s\"", ultimate ? : ""); +- debug("penultimate:\"%s\"", penultimate ? : ""); +- debug("approximate:\"%s\"", approximate ? : ""); +- debug("proximate:\"%s\"", proximate ? : ""); +- +- if (ultimate && penultimate && +- ((proximate && !strcmp(proximate, "nvme")) || +- (approximate && !strcmp(approximate, "block")))) { +- /* +- * 259:1 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1/nvme0n1p1 +- * 8:1 -> ../../devices/pci0000:00/0000:00:17.0/ata2/host1/target1:0:0/1:0:0:0/block/sda/sda1 +- * 8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 +- * 252:1 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda/vda1 +- * 259:3 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s/pmem11s1 +- */ +- set_disk_name(dev, "%s", penultimate); +- set_part_name(dev, "%s", ultimate); +- debug("disk:%s part:%s", penultimate, ultimate); +- } else if (ultimate && approximate && !strcmp(approximate, "nvme")) { +- /* +- * 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 +- */ +- set_disk_name(dev, "%s", ultimate); +- set_part_name(dev, "%sp%d", ultimate, dev->part); +- debug("disk:%s part:%sp%d", ultimate, ultimate, dev->part); +- } else if (ultimate && penultimate && !strcmp(penultimate, "block")) { +- /* +- * 253:0 -> ../../devices/virtual/block/dm-0 (... I guess) +- * 8:0 -> ../../devices/pci0000:00/0000:00:17.0/ata2/host1/target1:0:0/1:0:0:0/block/sda +- * 11:0 -> ../../devices/pci0000:00/0000:00:11.5/ata3/host2/target2:0:0/2:0:0:0/block/sr0 +- * 8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc +- * 252:0 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda +- * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region9/btt9.0/block/pmem9s +- * 259:1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s +- */ +- set_disk_name(dev, "%s", ultimate); +- set_part_name(dev, "%s%d", ultimate, dev->part); +- debug("disk:%s part:%s%d", ultimate, ultimate, dev->part); +- } else if (ultimate && approximate && !strcmp(approximate, "mtd")) { +- /* +- * 31:0 -> ../../devices/platform/1e000000.palmbus/1e000b00.spi/spi_master/spi32766/spi32766.0/mtd/mtd0/mtdblock0 +- */ +- set_disk_name(dev, "%s", ultimate); +- debug("disk:%s", ultimate); +- } +- +- return 0; ++ /* ++ * results are like such: ++ * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART ++ */ ++ ++ char *ultimate = pathseg(dev->link, -1); ++ char *penultimate = pathseg(dev->link, -2); ++ char *approximate = pathseg(dev->link, -3); ++ char *proximate = pathseg(dev->link, -4); ++ ++ errno = 0; ++ debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name); ++ debug("dev->part:%d", dev->part); ++ debug("ultimate:\"%s\"", ultimate ? : ""); ++ debug("penultimate:\"%s\"", penultimate ? : ""); ++ debug("approximate:\"%s\"", approximate ? : ""); ++ debug("proximate:\"%s\"", proximate ? : ""); ++ ++ if (ultimate && penultimate && ++ ((proximate && !strcmp(proximate, "nvme")) || ++ (approximate && !strcmp(approximate, "block")))) { ++ /* ++ * 259:1 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1/nvme0n1p1 ++ * 8:1 -> ../../devices/pci0000:00/0000:00:17.0/ata2/host1/target1:0:0/1:0:0:0/block/sda/sda1 ++ * 8:33 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1 ++ * 252:1 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda/vda1 ++ * 259:3 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s/pmem11s1 ++ */ ++ set_disk_name(dev, "%s", penultimate); ++ set_part_name(dev, "%s", ultimate); ++ debug("disk:%s part:%s", penultimate, ultimate); ++ } else if (ultimate && approximate && !strcmp(approximate, "nvme")) { ++ /* ++ * 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 ++ */ ++ set_disk_name(dev, "%s", ultimate); ++ set_part_name(dev, "%sp%d", ultimate, dev->part); ++ debug("disk:%s part:%sp%d", ultimate, ultimate, dev->part); ++ } else if (ultimate && penultimate && !strcmp(penultimate, "block")) { ++ /* ++ * 253:0 -> ../../devices/virtual/block/dm-0 (... I guess) ++ * 8:0 -> ../../devices/pci0000:00/0000:00:17.0/ata2/host1/target1:0:0/1:0:0:0/block/sda ++ * 11:0 -> ../../devices/pci0000:00/0000:00:11.5/ata3/host2/target2:0:0/2:0:0:0/block/sr0 ++ * 8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc ++ * 252:0 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda ++ * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region9/btt9.0/block/pmem9s ++ * 259:1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s ++ */ ++ set_disk_name(dev, "%s", ultimate); ++ set_part_name(dev, "%s%d", ultimate, dev->part); ++ debug("disk:%s part:%s%d", ultimate, ultimate, dev->part); ++ } else if (ultimate && approximate && !strcmp(approximate, "mtd")) { ++ /* ++ * 31:0 -> ../../devices/platform/1e000000.palmbus/1e000b00.spi/spi_master/spi32766/spi32766.0/mtd/mtd0/mtdblock0 ++ */ ++ set_disk_name(dev, "%s", ultimate); ++ debug("disk:%s", ultimate); ++ } ++ ++ return 0; + } + + static struct dev_probe *dev_probes[] = { +- /* +- * pmem needs to be before PCI, so if it provides root it'll +- * be found first. +- */ +- &pmem_parser, +- &acpi_root_parser, +- &pci_root_parser, +- &soc_root_parser, +- &pci_parser, +- &virtblk_parser, +- &sas_parser, +- &sata_parser, +- &nvme_parser, +- &ata_parser, +- &scsi_parser, +- &i2o_parser, +- &emmc_parser, +- NULL ++ /* ++ * pmem needs to be before PCI, so if it provides root it'll ++ * be found first. ++ */ ++ &pmem_parser, ++ &acpi_root_parser, ++ &pci_root_parser, ++ &soc_root_parser, ++ &pci_parser, ++ &virtblk_parser, ++ &sas_parser, ++ &sata_parser, ++ &nvme_parser, ++ &ata_parser, ++ &scsi_parser, ++ &i2o_parser, ++ &emmc_parser, ++ NULL + }; + + void HIDDEN + device_free(struct device *dev) + { +- if (!dev) +- return; +- if (dev->link) +- free(dev->link); +- +- if (dev->device) +- free(dev->device); +- +- if (dev->driver) +- free(dev->driver); +- +- if (dev->probes) +- free(dev->probes); +- +- if (dev->acpi_root.acpi_hid_str) +- free(dev->acpi_root.acpi_hid_str); +- if (dev->acpi_root.acpi_uid_str) +- free(dev->acpi_root.acpi_uid_str); +- if (dev->acpi_root.acpi_cid_str) +- free(dev->acpi_root.acpi_cid_str); +- +- if (dev->interface_type == network) { +- if (dev->ifname) +- free(dev->ifname); +- } else { +- if (dev->disk_name) +- free(dev->disk_name); +- if (dev->part_name) +- free(dev->part_name); +- } +- +- for (unsigned int i = 0; i < dev->n_pci_devs; i++) +- if (dev->pci_dev[i].driverlink) +- free(dev->pci_dev[i].driverlink); +- +- if (dev->pci_dev) +- free(dev->pci_dev); +- +- memset(dev, 0, sizeof(*dev)); +- free(dev); ++ if (!dev) ++ return; ++ if (dev->link) ++ free(dev->link); ++ ++ if (dev->device) ++ free(dev->device); ++ ++ if (dev->driver) ++ free(dev->driver); ++ ++ if (dev->probes) ++ free(dev->probes); ++ ++ if (dev->acpi_root.acpi_hid_str) ++ free(dev->acpi_root.acpi_hid_str); ++ if (dev->acpi_root.acpi_uid_str) ++ free(dev->acpi_root.acpi_uid_str); ++ if (dev->acpi_root.acpi_cid_str) ++ free(dev->acpi_root.acpi_cid_str); ++ ++ if (dev->interface_type == network) { ++ if (dev->ifname) ++ free(dev->ifname); ++ } else { ++ if (dev->disk_name) ++ free(dev->disk_name); ++ if (dev->part_name) ++ free(dev->part_name); ++ } ++ ++ for (unsigned int i = 0; i < dev->n_pci_devs; i++) ++ if (dev->pci_dev[i].driverlink) ++ free(dev->pci_dev[i].driverlink); ++ ++ if (dev->pci_dev) ++ free(dev->pci_dev); ++ ++ memset(dev, 0, sizeof(*dev)); ++ free(dev); + } + + struct device HIDDEN + *device_get(int fd, int partition) + { +- struct device *dev; +- char *linkbuf = NULL, *tmpbuf = NULL; +- int i = 0; +- unsigned int n = 0; +- int rc; +- +- size_t nmemb = (sizeof(dev_probes) +- / sizeof(dev_probes[0])) + 1; +- +- dev = calloc(1, sizeof(*dev)); +- if (!dev) { +- efi_error("could not allocate %zd bytes", sizeof(*dev)); +- return NULL; +- } +- +- dev->part = partition; +- debug("partition:%d dev->part:%d", partition, dev->part); +- dev->probes = calloc(nmemb, sizeof(struct dev_probe *)); +- if (!dev->probes) { +- efi_error("could not allocate %zd bytes", +- nmemb * sizeof(struct dev_probe *)); +- goto err; +- } +- +- rc = fstat(fd, &dev->stat); +- if (rc < 0) { +- efi_error("fstat(%d) failed", fd); +- goto err; +- } +- +- dev->pci_root.pci_domain = 0xffff; +- dev->pci_root.pci_bus = 0xff; +- +- if (S_ISBLK(dev->stat.st_mode)) { +- dev->major = major(dev->stat.st_rdev); +- dev->minor = minor(dev->stat.st_rdev); +- } else if (S_ISREG(dev->stat.st_mode)) { +- dev->major = major(dev->stat.st_dev); +- dev->minor = minor(dev->stat.st_dev); +- } else { +- efi_error("device is not a block device or regular file"); +- goto err; +- } +- +- rc = sysfs_readlink(&linkbuf, "dev/block/%"PRIu64":%"PRIu32, +- dev->major, dev->minor); +- if (rc < 0 || !linkbuf) { +- efi_error("readlink of /sys/dev/block/%"PRIu64":%"PRIu32" failed", +- dev->major, dev->minor); +- goto err; +- } +- +- dev->link = strdup(linkbuf); +- if (!dev->link) { +- efi_error("strdup(\"%s\") failed", linkbuf); +- goto err; +- } +- debug("dev->link: %s", dev->link); +- +- if (dev->part == -1) { +- rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link); +- if (rc < 0 || !tmpbuf) { +- efi_error("device has no /partition node; not a partition"); +- } else { +- rc = sscanf((char *)tmpbuf, "%d\n", &dev->part); +- if (rc != 1) +- efi_error("couldn't parse partition number for %s", tmpbuf); +- } +- } +- +- rc = set_disk_and_part_name(dev); +- if (rc < 0) { +- efi_error("could not set disk and partition names"); +- goto err; +- } +- debug("dev->disk_name: %s", dev->disk_name); +- debug("dev->part_name: %s", dev->part_name); +- +- rc = sysfs_readlink(&tmpbuf, "block/%s/device", dev->disk_name); +- if (rc < 0 || !tmpbuf) { +- debug("readlink of /sys/block/%s/device failed", +- dev->disk_name); +- +- dev->device = strdup(""); +- } else { +- dev->device = strdup(tmpbuf); +- } +- +- if (!dev->device) { +- efi_error("strdup(\"%s\") failed", tmpbuf); +- goto err; +- } +- +- if (dev->device[0] != 0) { +- rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name); +- if (rc < 0 || !tmpbuf) { +- if (errno == ENOENT) { +- /* +- * nvme, for example, will have nvme0n1/device point +- * at nvme0, and we need to look for device/driver +- * there. +- */ +- rc = sysfs_readlink(&tmpbuf, +- "block/%s/device/device/driver", +- dev->disk_name); +- if (rc >= 0 && tmpbuf) +- efi_error_pop(); +- } +- if (rc < 0 || !tmpbuf) { +- efi_error("readlink of /sys/block/%s/device/driver failed", +- dev->disk_name); +- goto err; +- } +- } +- +- linkbuf = pathseg(tmpbuf, -1); +- if (!linkbuf) { +- efi_error("could not get segment -1 of \"%s\"", tmpbuf); +- goto err; +- } +- +- dev->driver = strdup(linkbuf); +- } else { +- dev->driver = strdup(""); +- } +- +- if (!dev->driver) { +- efi_error("strdup(\"%s\") failed", linkbuf); +- goto err; +- } +- +- const char *current = dev->link; +- bool needs_root = true; +- int last_successful_probe = -1; +- +- debug("searching for device nodes in %s", dev->link); +- for (i = 0; +- dev_probes[i] && dev_probes[i]->parse && *current; +- i++) { +- struct dev_probe *probe = dev_probes[i]; +- int pos; +- +- if (!needs_root && +- (probe->flags & DEV_PROVIDES_ROOT)) { +- debug("not testing %s because flags is 0x%x", +- probe->name, probe->flags); +- continue; +- } +- +- debug("trying %s", probe->name); +- pos = probe->parse(dev, current, dev->link); +- if (pos < 0) { +- efi_error("parsing %s failed", probe->name); +- goto err; +- } else if (pos > 0) { +- debug("%s matched %s", probe->name, current); +- dev->flags |= probe->flags; +- +- if (probe->flags & DEV_PROVIDES_HD || +- probe->flags & DEV_PROVIDES_ROOT || +- probe->flags & DEV_ABBREV_ONLY) +- needs_root = false; +- +- dev->probes[n++] = dev_probes[i]; +- current += pos; +- debug("current:%s", current); +- last_successful_probe = i; +- +- if (!*current || !strncmp(current, "block/", 6)) +- break; +- +- continue; +- } +- +- debug("dev_probes[i+1]: %p dev->interface_type: %d\n", +- dev_probes[i+1], dev->interface_type); +- if (dev_probes[i+1] == NULL && dev->interface_type == unknown) { +- pos = 0; +- rc = sscanf(current, "%*[^/]/%n", &pos); +- if (rc < 0) { ++ struct device *dev; ++ char *linkbuf = NULL, *tmpbuf = NULL; ++ int i = 0; ++ unsigned int n = 0; ++ int rc; ++ ++ size_t nmemb = (sizeof(dev_probes) ++ / sizeof(dev_probes[0])) + 1; ++ ++ dev = calloc(1, sizeof(*dev)); ++ if (!dev) { ++ efi_error("could not allocate %zd bytes", sizeof(*dev)); ++ return NULL; ++ } ++ ++ dev->part = partition; ++ debug("partition:%d dev->part:%d", partition, dev->part); ++ dev->probes = calloc(nmemb, sizeof(struct dev_probe *)); ++ if (!dev->probes) { ++ efi_error("could not allocate %zd bytes", ++ nmemb * sizeof(struct dev_probe *)); ++ goto err; ++ } ++ ++ rc = fstat(fd, &dev->stat); ++ if (rc < 0) { ++ efi_error("fstat(%d) failed", fd); ++ goto err; ++ } ++ ++ dev->pci_root.pci_domain = 0xffff; ++ dev->pci_root.pci_bus = 0xff; ++ ++ if (S_ISBLK(dev->stat.st_mode)) { ++ dev->major = major(dev->stat.st_rdev); ++ dev->minor = minor(dev->stat.st_rdev); ++ } else if (S_ISREG(dev->stat.st_mode)) { ++ dev->major = major(dev->stat.st_dev); ++ dev->minor = minor(dev->stat.st_dev); ++ } else { ++ efi_error("device is not a block device or regular file"); ++ goto err; ++ } ++ ++ rc = sysfs_readlink(&linkbuf, "dev/block/%"PRIu64":%"PRIu32, ++ dev->major, dev->minor); ++ if (rc < 0 || !linkbuf) { ++ efi_error("readlink of /sys/dev/block/%"PRIu64":%"PRIu32" failed", ++ dev->major, dev->minor); ++ goto err; ++ } ++ ++ dev->link = strdup(linkbuf); ++ if (!dev->link) { ++ efi_error("strdup(\"%s\") failed", linkbuf); ++ goto err; ++ } ++ debug("dev->link: %s", dev->link); ++ ++ if (dev->part == -1) { ++ rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link); ++ if (rc < 0 || !tmpbuf) { ++ efi_error("device has no /partition node; not a partition"); ++ } else { ++ rc = sscanf((char *)tmpbuf, "%d\n", &dev->part); ++ if (rc != 1) ++ efi_error("couldn't parse partition number for %s", tmpbuf); ++ } ++ } ++ ++ rc = set_disk_and_part_name(dev); ++ if (rc < 0) { ++ efi_error("could not set disk and partition names"); ++ goto err; ++ } ++ debug("dev->disk_name: %s", dev->disk_name); ++ debug("dev->part_name: %s", dev->part_name); ++ ++ rc = sysfs_readlink(&tmpbuf, "block/%s/device", dev->disk_name); ++ if (rc < 0 || !tmpbuf) { ++ debug("readlink of /sys/block/%s/device failed", ++ dev->disk_name); ++ ++ dev->device = strdup(""); ++ } else { ++ dev->device = strdup(tmpbuf); ++ } ++ ++ if (!dev->device) { ++ efi_error("strdup(\"%s\") failed", tmpbuf); ++ goto err; ++ } ++ ++ if (dev->device[0] != 0) { ++ rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name); ++ if (rc < 0 || !tmpbuf) { ++ if (errno == ENOENT) { ++ /* ++ * nvme, for example, will have nvme0n1/device point ++ * at nvme0, and we need to look for device/driver ++ * there. ++ */ ++ rc = sysfs_readlink(&tmpbuf, ++ "block/%s/device/device/driver", ++ dev->disk_name); ++ if (rc >= 0 && tmpbuf) ++ efi_error_pop(); ++ } ++ if (rc < 0 || !tmpbuf) { ++ efi_error("readlink of /sys/block/%s/device/driver failed", ++ dev->disk_name); ++ goto err; ++ } ++ } ++ ++ linkbuf = pathseg(tmpbuf, -1); ++ if (!linkbuf) { ++ efi_error("could not get segment -1 of \"%s\"", tmpbuf); ++ goto err; ++ } ++ ++ dev->driver = strdup(linkbuf); ++ } else { ++ dev->driver = strdup(""); ++ } ++ ++ if (!dev->driver) { ++ efi_error("strdup(\"%s\") failed", linkbuf); ++ goto err; ++ } ++ ++ const char *current = dev->link; ++ bool needs_root = true; ++ int last_successful_probe = -1; ++ ++ debug("searching for device nodes in %s", dev->link); ++ for (i = 0; ++ dev_probes[i] && dev_probes[i]->parse && *current; ++ i++) { ++ struct dev_probe *probe = dev_probes[i]; ++ int pos; ++ ++ if (!needs_root && ++ (probe->flags & DEV_PROVIDES_ROOT)) { ++ debug("not testing %s because flags is 0x%x", ++ probe->name, probe->flags); ++ continue; ++ } ++ ++ debug("trying %s", probe->name); ++ pos = probe->parse(dev, current, dev->link); ++ if (pos < 0) { ++ efi_error("parsing %s failed", probe->name); ++ goto err; ++ } else if (pos > 0) { ++ debug("%s matched %s", probe->name, current); ++ dev->flags |= probe->flags; ++ ++ if (probe->flags & DEV_PROVIDES_HD || ++ probe->flags & DEV_PROVIDES_ROOT || ++ probe->flags & DEV_ABBREV_ONLY) ++ needs_root = false; ++ ++ dev->probes[n++] = dev_probes[i]; ++ current += pos; ++ debug("current:%s", current); ++ last_successful_probe = i; ++ ++ if (!*current || !strncmp(current, "block/", 6)) ++ break; ++ ++ continue; ++ } ++ ++ debug("dev_probes[i+1]: %p dev->interface_type: %d\n", ++ dev_probes[i+1], dev->interface_type); ++ if (dev_probes[i+1] == NULL && dev->interface_type == unknown) { ++ pos = 0; ++ rc = sscanf(current, "%*[^/]/%n", &pos); ++ if (rc < 0) { + slash_err: +- efi_error("Cannot parse device link segment \"%s\"", current); +- goto err; +- } +- +- while (current[pos] == '/') +- pos += 1; +- +- if (!current[pos]) +- goto slash_err; +- +- debug("Cannot parse device link segment \"%s\"", current); +- debug("Skipping to \"%s\"", current + pos); +- debug("This means we can only create abbreviated paths"); +- dev->flags |= DEV_ABBREV_ONLY; +- i = last_successful_probe; +- current += pos; +- +- if (!*current || !strncmp(current, "block/", 6)) +- break; +- } +- } +- +- if (dev->interface_type == unknown && +- !(dev->flags & DEV_ABBREV_ONLY) && +- !strcmp(current, "block/")) { +- efi_error("unknown storage interface"); +- errno = ENOSYS; +- goto err; +- } +- +- return dev; ++ efi_error("Cannot parse device link segment \"%s\"", current); ++ goto err; ++ } ++ ++ while (current[pos] == '/') ++ pos += 1; ++ ++ if (!current[pos]) ++ goto slash_err; ++ ++ debug("Cannot parse device link segment \"%s\"", current); ++ debug("Skipping to \"%s\"", current + pos); ++ debug("This means we can only create abbreviated paths"); ++ dev->flags |= DEV_ABBREV_ONLY; ++ i = last_successful_probe; ++ current += pos; ++ ++ if (!*current || !strncmp(current, "block/", 6)) ++ break; ++ } ++ } ++ ++ if (dev->interface_type == unknown && ++ !(dev->flags & DEV_ABBREV_ONLY) && ++ !strcmp(current, "block/")) { ++ efi_error("unknown storage interface"); ++ errno = ENOSYS; ++ goto err; ++ } ++ ++ return dev; + err: +- device_free(dev); +- return NULL; ++ device_free(dev); ++ return NULL; + } + + int HIDDEN + make_blockdev_path(uint8_t *buf, ssize_t size, struct device *dev) + { +- ssize_t off = 0; ++ ssize_t off = 0; + +- debug("entry buf:%p size:%zd", buf, size); ++ debug("entry buf:%p size:%zd", buf, size); + +- for (unsigned int i = 0; dev->probes[i] && +- dev->probes[i]->parse; i++) { +- struct dev_probe *probe = dev->probes[i]; +- ssize_t sz; ++ for (unsigned int i = 0; dev->probes[i] && ++ dev->probes[i]->parse; i++) { ++ struct dev_probe *probe = dev->probes[i]; ++ ssize_t sz; + +- if (!probe->create) +- continue; ++ if (!probe->create) ++ continue; + +- sz = probe->create(dev, buf + off, size ? size - off : 0, 0); +- if (sz < 0) { +- efi_error("could not create %s device path", +- probe->name); +- return sz; +- } +- off += sz; +- } ++ sz = probe->create(dev, buf + off, size ? size - off : 0, 0); ++ if (sz < 0) { ++ efi_error("could not create %s device path", ++ probe->name); ++ return sz; ++ } ++ off += sz; ++ } + +- debug("= %zd", off); ++ debug("= %zd", off); + +- return off; ++ return off; + } + + ssize_t HIDDEN + make_mac_path(uint8_t *buf, ssize_t size, const char * const ifname) + { +- struct ifreq ifr; +- struct ethtool_drvinfo drvinfo = { 0, }; +- int fd = -1, rc; +- ssize_t ret = -1, sz, off = 0; +- char busname[PATH_MAX+1] = ""; +- struct device dev; +- +- memset(&dev, 0, sizeof (dev)); +- dev.interface_type = network; +- dev.ifname = strdupa(ifname); +- if (!dev.ifname) +- return -1; +- +- /* +- * find the device link, which looks like: +- * ../../devices/$PCI_STUFF/net/$IFACE +- */ +- rc = sysfs_readlink(&dev.link, "class/net/%s", ifname); +- if (rc < 0 || !dev.link) +- goto err; +- +- memset(&ifr, 0, sizeof (ifr)); +- strncpy(ifr.ifr_name, ifname, IF_NAMESIZE); +- ifr.ifr_name[IF_NAMESIZE-1] = '\0'; +- drvinfo.cmd = ETHTOOL_GDRVINFO; +- ifr.ifr_data = (caddr_t)&drvinfo; +- +- fd = socket(AF_INET, SOCK_DGRAM, 0); +- if (fd < 0) +- goto err; +- +- rc = ioctl(fd, SIOCETHTOOL, &ifr); +- if (rc < 0) +- goto err; +- +- strncpy(busname, drvinfo.bus_info, PATH_MAX); +- +- rc = ioctl(fd, SIOCGIFHWADDR, &ifr); +- if (rc < 0) +- goto err; +- +- sz = pci_parser.create(&dev, buf, size, off); +- if (sz < 0) +- goto err; +- off += sz; +- +- sz = efidp_make_mac_addr(buf+off, size?size-off:0, +- ifr.ifr_ifru.ifru_hwaddr.sa_family, +- (uint8_t *)ifr.ifr_ifru.ifru_hwaddr.sa_data, +- sizeof(ifr.ifr_ifru.ifru_hwaddr.sa_data)); +- if (sz < 0) +- goto err; +- +- off += sz; +- ret = off; ++ struct ifreq ifr; ++ struct ethtool_drvinfo drvinfo = { 0, }; ++ int fd = -1, rc; ++ ssize_t ret = -1, sz, off = 0; ++ char busname[PATH_MAX+1] = ""; ++ struct device dev; ++ ++ memset(&dev, 0, sizeof (dev)); ++ dev.interface_type = network; ++ dev.ifname = strdupa(ifname); ++ if (!dev.ifname) ++ return -1; ++ ++ /* ++ * find the device link, which looks like: ++ * ../../devices/$PCI_STUFF/net/$IFACE ++ */ ++ rc = sysfs_readlink(&dev.link, "class/net/%s", ifname); ++ if (rc < 0 || !dev.link) ++ goto err; ++ ++ memset(&ifr, 0, sizeof (ifr)); ++ strncpy(ifr.ifr_name, ifname, IF_NAMESIZE); ++ ifr.ifr_name[IF_NAMESIZE-1] = '\0'; ++ drvinfo.cmd = ETHTOOL_GDRVINFO; ++ ifr.ifr_data = (caddr_t)&drvinfo; ++ ++ fd = socket(AF_INET, SOCK_DGRAM, 0); ++ if (fd < 0) ++ goto err; ++ ++ rc = ioctl(fd, SIOCETHTOOL, &ifr); ++ if (rc < 0) ++ goto err; ++ ++ strncpy(busname, drvinfo.bus_info, PATH_MAX); ++ ++ rc = ioctl(fd, SIOCGIFHWADDR, &ifr); ++ if (rc < 0) ++ goto err; ++ ++ sz = pci_parser.create(&dev, buf, size, off); ++ if (sz < 0) ++ goto err; ++ off += sz; ++ ++ sz = efidp_make_mac_addr(buf+off, size?size-off:0, ++ ifr.ifr_ifru.ifru_hwaddr.sa_family, ++ (uint8_t *)ifr.ifr_ifru.ifru_hwaddr.sa_data, ++ sizeof(ifr.ifr_ifru.ifru_hwaddr.sa_data)); ++ if (sz < 0) ++ goto err; ++ ++ off += sz; ++ ret = off; + err: +- if (fd >= 0) +- close(fd); +- return ret; ++ if (fd >= 0) ++ close(fd); ++ return ret; + } + + /************************************************************ +@@ -621,12 +621,12 @@ err: + int UNUSED + get_sector_size(int filedes) + { +- int rc, sector_size = 512; ++ int rc, sector_size = 512; + +- rc = ioctl(filedes, BLKSSZGET, §or_size); +- if (rc) +- sector_size = 512; +- return sector_size; ++ rc = ioctl(filedes, BLKSSZGET, §or_size); ++ if (rc) ++ sector_size = 512; ++ return sector_size; + } + +-// vim:fenc=utf-8:tw=75:et ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/loadopt.c b/src/loadopt.c +index 85fb646d107..e643d4a4fb8 100644 +--- a/src/loadopt.c ++++ b/src/loadopt.c +@@ -374,3 +374,5 @@ efi_loadopt_desc(efi_load_option *opt, ssize_t limit) + last_desc = ucs2_to_utf8(opt->description, limit); + return last_desc; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/makeguids.c b/src/makeguids.c +index a15356b152e..f12dac3bb15 100644 +--- a/src/makeguids.c ++++ b/src/makeguids.c +@@ -247,3 +247,5 @@ main(int argc, char *argv[]) + + return 0; + } ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/path-helpers.c b/src/path-helpers.c +index 1b328071587..dff8f34dfc8 100644 +--- a/src/path-helpers.c ++++ b/src/path-helpers.c +@@ -23,26 +23,26 @@ + static bool + cinpat(const char c, const char *pat) + { +- for (unsigned int i = 0; pat[i]; i++) +- if (pat[i] == c) +- return true; +- return false; ++ for (unsigned int i = 0; pat[i]; i++) ++ if (pat[i] == c) ++ return true; ++ return false; + } + + static unsigned int + strxcspn(const char *s, const char *pattern) + { +- unsigned int i; +- for (i = 0; s[i]; i++) { +- if (!cinpat(s[i], pattern)) +- break; +- } +- return i; ++ unsigned int i; ++ for (i = 0; s[i]; i++) { ++ if (!cinpat(s[i], pattern)) ++ break; ++ } ++ return i; + } + + struct span { +- const char *pos; +- size_t len; ++ const char *pos; ++ size_t len; + }; + + /* +@@ -59,116 +59,116 @@ struct span { + unsigned int HIDDEN + count_spans(const char *str, const char *reject, unsigned int *chars) + { +- unsigned int s = 0, c = 0, pos = 0; +- +- if (str[0] == '/') { +- s += 1; +- c += 2; +- pos += 1; +- } +- +- while (str[pos]) { +- unsigned int n; +- +- n = strcspn(str + pos, reject); +- if (n) { +- s += 1; +- c += n + 1; +- pos += n; +- } +- +- pos += strxcspn(str + pos, reject); +- } +- +- if (chars) +- *chars = c; +- return s; ++ unsigned int s = 0, c = 0, pos = 0; ++ ++ if (str[0] == '/') { ++ s += 1; ++ c += 2; ++ pos += 1; ++ } ++ ++ while (str[pos]) { ++ unsigned int n; ++ ++ n = strcspn(str + pos, reject); ++ if (n) { ++ s += 1; ++ c += n + 1; ++ pos += n; ++ } ++ ++ pos += strxcspn(str + pos, reject); ++ } ++ ++ if (chars) ++ *chars = c; ++ return s; + } + + void HIDDEN + fill_spans(const char *str, const char *reject, void *spanbuf) + { +- struct span *spans = (struct span *)spanbuf; +- struct span *span = spans; +- unsigned int pos = 0; +- +- if (str[0] == '/') { +- span->pos = str; +- span->len = 1; +- span++; +- pos += 1; +- } +- +- while (str[pos]) { +- unsigned int n; +- +- n = strcspn(str + pos, reject); +- if (n) { +- span->pos = str + pos; +- span->len = n; +- span++; +- pos += n; +- } +- +- pos += strxcspn(str + pos, reject); +- } +- span->pos = NULL; +- span->len = 0; ++ struct span *spans = (struct span *)spanbuf; ++ struct span *span = spans; ++ unsigned int pos = 0; ++ ++ if (str[0] == '/') { ++ span->pos = str; ++ span->len = 1; ++ span++; ++ pos += 1; ++ } ++ ++ while (str[pos]) { ++ unsigned int n; ++ ++ n = strcspn(str + pos, reject); ++ if (n) { ++ span->pos = str + pos; ++ span->len = n; ++ span++; ++ pos += n; ++ } ++ ++ pos += strxcspn(str + pos, reject); ++ } ++ span->pos = NULL; ++ span->len = 0; + } + + #define split_spans(str, reject) \ +- ({ \ +- struct span *ret_ = NULL; \ +- unsigned int s_, c_; \ +- \ +- s_ = count_spans(str, "/", &c_); \ +- if (s_) { \ +- ret_ = alloca(sizeof(struct span[s_+1])); \ +- if (ret_) \ +- fill_spans(str, reject, ret_); \ +- } else { \ +- errno = 0; \ +- } \ +- ret_; \ +- }) ++ ({ \ ++ struct span *ret_ = NULL; \ ++ unsigned int s_, c_; \ ++ \ ++ s_ = count_spans(str, "/", &c_); \ ++ if (s_) { \ ++ ret_ = alloca(sizeof(struct span[s_+1])); \ ++ if (ret_) \ ++ fill_spans(str, reject, ret_); \ ++ } else { \ ++ errno = 0; \ ++ } \ ++ ret_; \ ++ }) + + int HIDDEN + find_path_segment(const char *path, int segment, const char **pos, size_t *len) + { +- struct span *span, *last; +- int nspans = 0; +- +- if (!pos || !len) { +- errno = EINVAL; +- return -1; +- } +- +- span = split_spans(path, "/"); +- if (!span) { +- if (errno) +- return -1; +- *pos = NULL; +- *len = 0; +- return 0; +- } +- +- for (last = span; last->pos; last++) +- nspans += 1; +- +- if (segment < 0) +- segment = nspans + segment; +- +- if (nspans < 1 || segment < 0 || segment >= nspans) { +- errno = ENOENT; +- return -1; +- } +- +- for (int i = 0; i < segment; i++) +- span++; +- +- *pos = span->pos; +- *len = span->len; +- return 0; ++ struct span *span, *last; ++ int nspans = 0; ++ ++ if (!pos || !len) { ++ errno = EINVAL; ++ return -1; ++ } ++ ++ span = split_spans(path, "/"); ++ if (!span) { ++ if (errno) ++ return -1; ++ *pos = NULL; ++ *len = 0; ++ return 0; ++ } ++ ++ for (last = span; last->pos; last++) ++ nspans += 1; ++ ++ if (segment < 0) ++ segment = nspans + segment; ++ ++ if (nspans < 1 || segment < 0 || segment >= nspans) { ++ errno = ENOENT; ++ return -1; ++ } ++ ++ for (int i = 0; i < segment; i++) ++ span++; ++ ++ *pos = span->pos; ++ *len = span->len; ++ return 0; + } + +-// vim:fenc=utf-8:tw=75:et ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/vars.c b/src/vars.c +index 218146028bd..148dd7943bc 100644 +--- a/src/vars.c ++++ b/src/vars.c +@@ -670,3 +670,5 @@ struct efi_var_operations vars_ops = { + .get_next_variable_name = vars_get_next_variable_name, + .chmod_variable = vars_chmod_variable, + }; ++ ++// vim:fenc=utf-8:tw=75:noet +-- +2.24.1 + diff --git a/SOURCES/0033-efivar-rework-usage.patch b/SOURCES/0033-efivar-rework-usage.patch new file mode 100644 index 0000000..ff4eee8 --- /dev/null +++ b/SOURCES/0033-efivar-rework-usage.patch @@ -0,0 +1,142 @@ +From 7ff64fa2dc920659aebab34dc1ef91afaff9b632 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:45:39 -0400 +Subject: [PATCH 33/86] efivar: rework usage() + +Signed-off-by: Peter Jones +--- + src/efivar.c | 74 ++++++++++++++++++++++++++++------------------------ + 1 file changed, 40 insertions(+), 34 deletions(-) + +diff --git a/src/efivar.c b/src/efivar.c +index df075809db5..7f16ab15bab 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -39,10 +39,11 @@ extern int optind, opterr, optopt; + + #include "efivar.h" + +-#define ACTION_LIST 0x1 +-#define ACTION_PRINT 0x2 +-#define ACTION_APPEND 0x4 +-#define ACTION_LIST_GUIDS 0x8 ++#define ACTION_USAGE 0x00 ++#define ACTION_LIST 0x01 ++#define ACTION_PRINT 0x02 ++#define ACTION_APPEND 0x04 ++#define ACTION_LIST_GUIDS 0x08 + #define ACTION_WRITE 0x10 + #define ACTION_PRINT_DEC 0x20 + +@@ -326,7 +327,7 @@ validate_name(const char *name) + } + + static void +-prepare_data(const char *filename, void **data, size_t *data_size) ++prepare_data(const char *filename, uint8_t **data, size_t *data_size) + { + int fd = -1; + void *buf; +@@ -365,25 +366,29 @@ err: + exit(1); + } + +-static void +-usage(const char *progname) ++static void __attribute__((__noreturn__)) ++usage(int ret) + { +- printf("Usage: %s [OPTION...]\n", basename(progname)); +- printf(" -l, --list list current variables\n"); +- printf(" -p, --print print variable specified by --name\n"); +- printf(" -d, --print-decimal print variable in decimal values specified\n"); +- printf(" by --name\n"); +- printf(" -n, --name= variable to manipulate, in the form\n"); +- printf(" 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n"); +- printf(" -a, --append append to variable specified by --name\n"); +- printf(" -f, --fromfile= use data from \n"); +- printf(" -t, --attributes= attributes to use on append\n"); +- printf(" -L, --list-guids show internal guid list\n"); +- printf(" -w, --write write to variable specified by --name\n\n"); +- printf("Help options:\n"); +- printf(" -?, --help Show this help message\n"); +- printf(" --usage Display brief usage message\n"); +- return; ++ FILE *out = ret == 0 ? stdout : stderr; ++ fprintf(out, ++ "Usage: %s [OPTION...]\n" ++ " -l, --list list current variables\n" ++ " -p, --print print variable specified by --name\n" ++ " -d, --print-decimal print variable in decimal values specified\n" ++ " by --name\n" ++ " -n, --name= variable to manipulate, in the form\n" ++ " 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n" ++ " -a, --append append to variable specified by --name\n" ++ " -e, --export= export variable to \n" ++ " -f, --fromfile= use data from \n" ++ " -t, --attributes= attributes to use on append\n" ++ " -L, --list-guids show internal guid list\n" ++ " -w, --write write to variable specified by --name\n\n" ++ "Help options:\n" ++ " -?, --help Show this help message\n" ++ " --usage Display brief usage message\n", ++ program_invocation_short_name); ++ exit(ret); + } + + int main(int argc, char *argv[]) +@@ -391,7 +396,7 @@ int main(int argc, char *argv[]) + int c = 0; + int i = 0; + int action = 0; +- void *data = NULL; ++ uint8_t *data = NULL; + size_t data_size = 0; + char *name = NULL; + char *file = NULL; +@@ -434,10 +439,10 @@ int main(int argc, char *argv[]) + break; + case 't': + attributes = strtoul(optarg, NULL, 10); +- if (errno == ERANGE || errno == EINVAL) { +- fprintf(stderr, "invalid argument for -t: %s: %s\n", optarg, strerror(errno)); +- return EXIT_FAILURE; +- } ++ if (errno == ERANGE || errno == EINVAL) ++ err(1, ++ "invalid argument for -t: %s: %m\n", ++ optarg); + break; + case 'L': + action |= ACTION_LIST_GUIDS; +@@ -446,13 +451,11 @@ int main(int argc, char *argv[]) + action |= ACTION_WRITE; + break; + case '?': +- usage(argv[0]); +- return EXIT_SUCCESS; ++ usage(EXIT_SUCCESS); ++ break; + case 0: +- if (strcmp(lopts[i].name, "usage")) { +- usage(argv[0]); +- return EXIT_SUCCESS; +- } ++ if (strcmp(lopts[i].name, "usage")) ++ usage(EXIT_SUCCESS); + break; + } + } +@@ -506,6 +509,9 @@ int main(int argc, char *argv[]) + guid[i].symbol + strlen("efi_guid_"), + guid[i].symbol, guid[i].name); + } ++ case ACTION_USAGE: ++ default: ++ usage(EXIT_FAILURE); + } + }; + +-- +2.24.1 + diff --git a/SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch b/SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch new file mode 100644 index 0000000..2fada87 --- /dev/null +++ b/SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch @@ -0,0 +1,431 @@ +From ba165d1482558005a16f4b44abaa1df5169727d1 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:47:24 -0400 +Subject: [PATCH 34/86] Try to deal with some signof(char) != signof(uint8_t) + madness. + +The 3-sign "char" type in C is so so painful sometimes. This attempts +to use -funsigned-char to avoid type-casting between (uint8_t *) and +(char *) quite so much. I'm not sure it'll pay off. The fact that +"char" is something that's not ever actually the same type as "unsigned +char" or "signed char" is still the absolute worst thing. + +Why do we need signed char at all again? + +Signed-off-by: Peter Jones +--- + Make.defaults | 4 +++- + gcc.specs | 4 ++-- + src/dp-acpi.c | 11 ++++++----- + src/dp-hw.c | 5 +++-- + src/dp-media.c | 2 +- + src/dp-message.c | 22 +++++++++++----------- + src/dp.c | 8 +++++--- + src/dp.h | 18 ++++++++++-------- + src/export.c | 12 ++++++------ + src/include/efivar/efivar-dp.h | 10 ++++++---- + src/include/efivar/efivar.h | 4 ++-- + src/ucs2.h | 6 +++--- + 12 files changed, 58 insertions(+), 48 deletions(-) + +diff --git a/Make.defaults b/Make.defaults +index 80fd99eba71..36e922f5ba7 100644 +--- a/Make.defaults ++++ b/Make.defaults +@@ -31,7 +31,9 @@ PKGS = + + CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION) + +-clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member ++clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \ ++ -funsigned-char -Wall -Wno-nonnull-compare \ ++ -Werror -Wno-error=cpp + gcc_cflags = -specs=$(TOPDIR)/gcc.specs + cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \ + $(if $(findstring clang,$(CC)),$(clang_cflags),) \ +diff --git a/gcc.specs b/gcc.specs +index d06a8e096fc..9d2b145ee6e 100644 +--- a/gcc.specs ++++ b/gcc.specs +@@ -2,13 +2,13 @@ + + -D_GNU_SOURCE + + *efivar_cpp_options: +- -Werror -Wall -std=gnu11 -Wextra ++ -Wall -Wno-nonnull-compare -Werror -Wno-error=cpp -std=gnu11 -Wextra -funsigned-char + + *cpp_options: + + %(efivar_cpp_options) + + *cc1_options: +-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches +++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -funsigned-char -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches + + *self_spec: + + %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches +diff --git a/src/dp-acpi.c b/src/dp-acpi.c +index 2525fdfd073..02ec70eec7a 100644 +--- a/src/dp-acpi.c ++++ b/src/dp-acpi.c +@@ -28,7 +28,7 @@ + #include "efivar.h" + + static ssize_t +-_format_acpi_adr(char *buf, size_t size, ++_format_acpi_adr(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp) + { +@@ -45,9 +45,10 @@ _format_acpi_adr(char *buf, size_t size, + format_helper(_format_acpi_adr, buf, size, off, "AcpiAdr", dp) + + static ssize_t +-_format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED, +- const_efidp dp, +- const char *hidstr, const char *cidstr, const char *uidstr) ++_format_acpi_hid_ex(unsigned char *buf, size_t size, ++ const char *dp_type UNUSED, const_efidp dp, ++ const char *hidstr, const char *cidstr, ++ const char *uidstr) + { + ssize_t off = 0; + +@@ -98,7 +99,7 @@ _format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED, + hidstr, cidstr, uidstr) + + ssize_t +-_format_acpi_dn(char *buf, size_t size, const_efidp dp) ++_format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp) + { + ssize_t off = 0; + const char *hidstr = NULL; +diff --git a/src/dp-hw.c b/src/dp-hw.c +index 1fe0f66e871..28998316d9d 100644 +--- a/src/dp-hw.c ++++ b/src/dp-hw.c +@@ -26,7 +26,8 @@ + #include "efivar.h" + + ssize_t +-format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp) ++format_edd10_guid(unsigned char *buf, size_t size, ++ const char *dp_type, const_efidp dp) + { + ssize_t off = 0; + efidp_edd10 const *edd_dp = (efidp_edd10 *)dp; +@@ -36,7 +37,7 @@ format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp) + } + + ssize_t +-_format_hw_dn(char *buf, size_t size, const_efidp dp) ++_format_hw_dn(unsigned char *buf, size_t size, const_efidp dp) + { + efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID; + ssize_t off = 0; +diff --git a/src/dp-media.c b/src/dp-media.c +index 4728c326100..7f5d1c678ce 100644 +--- a/src/dp-media.c ++++ b/src/dp-media.c +@@ -28,7 +28,7 @@ + #include "efivar.h" + + ssize_t +-_format_media_dn(char *buf, size_t size, const_efidp dp) ++_format_media_dn(unsigned char *buf, size_t size, const_efidp dp) + { + ssize_t off = 0; + switch (dp->subtype) { +diff --git a/src/dp-message.c b/src/dp-message.c +index b88f17fb712..d00b2ad5d67 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -28,7 +28,7 @@ + #include "efivar.h" + + static ssize_t +-format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type, ++format_ipv4_addr_helper(unsigned char *buf, size_t size, const char *dp_type, + const uint8_t *ipaddr, int32_t port) + { + ssize_t off = 0; +@@ -40,7 +40,7 @@ format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type, + } + + static ssize_t +-format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type, ++format_ipv6_addr_helper(unsigned char *buf, size_t size, const char *dp_type, + const uint8_t *ipaddr, int32_t port) + { + uint16_t *ip = (uint16_t *)ipaddr; +@@ -123,7 +123,7 @@ format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type, + "IPv6", addr, port) + + static ssize_t +-format_ip_addr_helper(char *buf, size_t size, ++format_ip_addr_helper(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + int is_ipv6, const efi_ip_addr_t *addr) + { +@@ -142,7 +142,7 @@ format_ip_addr_helper(char *buf, size_t size, + dp_type, is_ipv6, addr) + + static ssize_t +-format_uart(char *buf, size_t size, ++format_uart(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp) + { +@@ -162,7 +162,7 @@ format_uart(char *buf, size_t size, + } + + static ssize_t +-format_sas(char *buf, size_t size, ++format_sas(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp) + { +@@ -232,7 +232,7 @@ format_sas(char *buf, size_t size, + dp->usb_class.device_protocol) + + static ssize_t +-format_usb_class(char *buf, size_t size, ++format_usb_class(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp) + { +@@ -312,7 +312,7 @@ format_usb_class(char *buf, size_t size, + } + + ssize_t +-_format_message_dn(char *buf, size_t size, const_efidp dp) ++_format_message_dn(unsigned char *buf, size_t size, const_efidp dp) + { + ssize_t off = 0; + switch (dp->subtype) { +@@ -393,7 +393,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) + struct { + efi_guid_t guid; + char label[40]; +- ssize_t (*formatter)(char *buf, size_t size, ++ ssize_t (*formatter)(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp); + } subtypes[] = { +@@ -417,7 +417,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) + .label = "" } + }; + char *label = NULL; +- ssize_t (*formatter)(char *buf, size_t size, ++ ssize_t (*formatter)(unsigned char *buf, size_t size, + const char *dp_type UNUSED, + const_efidp dp) = NULL; + +@@ -455,8 +455,8 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) + } + case EFIDP_MSG_IPv6: { + efidp_ipv6_addr const *a = &dp->ipv6_addr; +- char *addr0 = NULL; +- char *addr1 = NULL; ++ unsigned char *addr0 = NULL; ++ unsigned char *addr1 = NULL; + ssize_t tmpoff = 0; + ssize_t sz; + +diff --git a/src/dp.c b/src/dp.c +index b6eea74878c..f6a4b2ddafa 100644 +--- a/src/dp.c ++++ b/src/dp.c +@@ -298,7 +298,8 @@ efidp_append_instance(const_efidp dp, const_efidp dpi, efidp *out) + } + + ssize_t PUBLIC +-efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit) ++efidp_format_device_path(unsigned char *buf, size_t size, const_efidp dp, ++ ssize_t limit) + { + ssize_t off = 0; + int first = 1; +@@ -402,7 +403,8 @@ efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit) + } + + ssize_t PUBLIC +-efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED) ++efidp_parse_device_node(unsigned char *path UNUSED, ++ efidp out UNUSED, size_t size UNUSED) + { + efi_error("not implented"); + errno = -ENOSYS; +@@ -410,7 +412,7 @@ efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED) + } + + ssize_t PUBLIC +-efidp_parse_device_path(char *path UNUSED, efidp out UNUSED, ++efidp_parse_device_path(unsigned char *path UNUSED, efidp out UNUSED, + size_t size UNUSED) + { + efi_error("not implented"); +diff --git a/src/dp.h b/src/dp.h +index 33a29db0d5d..6609b0d827e 100644 +--- a/src/dp.h ++++ b/src/dp.h +@@ -88,8 +88,9 @@ + }) + + static inline ssize_t UNUSED +-format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator, +- int stride, const void * const addr, const size_t len) ++format_hex_helper(unsigned char *buf, size_t size, const char *dp_type, ++ char *separator, int stride, const void * const addr, ++ const size_t len) + { + ssize_t off = 0; + for (size_t i = 0; i < len; i++) { +@@ -110,7 +111,8 @@ format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator, + addr, len) + + static inline ssize_t UNUSED +-format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp) ++format_vendor_helper(unsigned char *buf, size_t size, char *label, ++ const_efidp dp) + { + ssize_t off = 0; + ssize_t bytes = efidp_node_size(dp) +@@ -157,11 +159,11 @@ format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp) + off; \ + }) + +-extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp); +-extern ssize_t _format_acpi_dn(char *buf, size_t size, const_efidp dp); +-extern ssize_t _format_message_dn(char *buf, size_t size, const_efidp dp); +-extern ssize_t _format_media_dn(char *buf, size_t size, const_efidp dp); +-extern ssize_t _format_bios_boot_dn(char *buf, size_t size, const_efidp dp); ++extern ssize_t _format_hw_dn(unsigned char *buf, size_t size, const_efidp dp); ++extern ssize_t _format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp); ++extern ssize_t _format_message_dn(unsigned char *buf, size_t size, const_efidp dp); ++extern ssize_t _format_media_dn(unsigned char *buf, size_t size, const_efidp dp); ++extern ssize_t _format_bios_boot_dn(unsigned char *buf, size_t size, const_efidp dp); + + #define format_helper_2(name, buf, size, off, dp) ({ \ + ssize_t _sz; \ +diff --git a/src/export.c b/src/export.c +index 5b11ae883cf..6b78412cce1 100644 +--- a/src/export.c ++++ b/src/export.c +@@ -35,7 +35,7 @@ + struct efi_variable { + uint64_t attrs; + efi_guid_t *guid; +- char *name; ++ unsigned char *name; + uint8_t *data; + size_t data_size; + }; +@@ -149,7 +149,7 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out) + ssize_t NONNULL(1) PUBLIC + efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size) + { +- size_t name_len = strlen(var->name); ++ size_t name_len = strlen((char *)var->name); + + size_t needed = sizeof (uint32_t) /* magic */ + + sizeof (uint32_t) /* version */ +@@ -233,13 +233,13 @@ efi_variable_free(efi_variable_t *var, int free_data) + } + + int NONNULL(1, 2) PUBLIC +-efi_variable_set_name(efi_variable_t *var, char *name) ++efi_variable_set_name(efi_variable_t *var, unsigned char *name) + { + var->name = name; + return 0; + } + +-char PUBLIC NONNULL(1) * ++unsigned char PUBLIC NONNULL(1) * + efi_variable_get_name(efi_variable_t *var) + { + if (!var->name) { +@@ -329,10 +329,10 @@ efi_variable_realize(efi_variable_t *var) + } + uint32_t attrs = var->attrs & ATTRS_MASK; + if (attrs & EFI_VARIABLE_APPEND_WRITE) { +- return efi_append_variable(*var->guid, var->name, ++ return efi_append_variable(*var->guid, (char *)var->name, + var->data, var->data_size, attrs); + } +- return efi_set_variable(*var->guid, var->name, var->data, ++ return efi_set_variable(*var->guid, (char *)var->name, var->data, + var->data_size, attrs, 0600); + } + +diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h +index 57453548701..706d25bdebd 100644 +--- a/src/include/efivar/efivar-dp.h ++++ b/src/include/efivar/efivar-dp.h +@@ -1240,10 +1240,12 @@ efidp_is_valid(const_efidp dp, ssize_t limit) + #endif + + /* and now, printing and parsing */ +-extern ssize_t efidp_parse_device_node(char *path, efidp out, size_t size); +-extern ssize_t efidp_parse_device_path(char *path, efidp out, size_t size); +-extern ssize_t efidp_format_device_path(char *buf, size_t size, const_efidp dp, +- ssize_t limit); ++extern ssize_t efidp_parse_device_node(unsigned char *path, ++ efidp out, size_t size); ++extern ssize_t efidp_parse_device_path(unsigned char *path, ++ efidp out, size_t size); ++extern ssize_t efidp_format_device_path(unsigned char *buf, size_t size, ++ const_efidp dp, ssize_t limit); + extern ssize_t efidp_make_vendor(uint8_t *buf, ssize_t size, uint8_t type, + uint8_t subtype, efi_guid_t vendor_guid, + void *data, size_t data_size); +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index caa4adf056c..729b6fe80f7 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -144,9 +144,9 @@ extern efi_variable_t *efi_variable_alloc(void) + __attribute__((__visibility__ ("default"))); + extern void efi_variable_free(efi_variable_t *var, int free_data); + +-extern int efi_variable_set_name(efi_variable_t *var, char *name) ++extern int efi_variable_set_name(efi_variable_t *var, unsigned char *name) + __attribute__((__nonnull__ (1, 2))); +-extern char *efi_variable_get_name(efi_variable_t *var) ++extern unsigned char *efi_variable_get_name(efi_variable_t *var) + __attribute__((__visibility__ ("default"))) + __attribute__((__nonnull__ (1))); + +diff --git a/src/ucs2.h b/src/ucs2.h +index 176f9ccac57..478de23b23f 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -47,7 +47,7 @@ ucs2size(const void *s, ssize_t limit) + } + + static inline size_t UNUSED NONNULL(1) +-utf8len(uint8_t *s, ssize_t limit) ++utf8len(const unsigned char *s, ssize_t limit) + { + ssize_t i, j; + for (i = 0, j = 0; i < (limit >= 0 ? limit : i+1) && s[i] != '\0'; +@@ -64,7 +64,7 @@ utf8len(uint8_t *s, ssize_t limit) + } + + static inline size_t UNUSED NONNULL(1) +-utf8size(uint8_t *s, ssize_t limit) ++utf8size(const unsigned char *s, ssize_t limit) + { + size_t ret = utf8len(s,limit); + if (ret < (limit >= 0 ? (size_t)limit : ret+1)) +@@ -129,7 +129,7 @@ ucs2_to_utf8(const void * const voidchars, ssize_t limit) + } + + static inline ssize_t UNUSED NONNULL(4) +-utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8) ++utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, const unsigned char *utf8) + { + ssize_t req; + ssize_t i, j; +-- +2.24.1 + diff --git a/SOURCES/0035-ucs2-document-things-a-little-better.patch b/SOURCES/0035-ucs2-document-things-a-little-better.patch new file mode 100644 index 0000000..7328d82 --- /dev/null +++ b/SOURCES/0035-ucs2-document-things-a-little-better.patch @@ -0,0 +1,219 @@ +From 6b2b7e8803027b7089a853af0f47b53a7d20e950 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 13:12:39 -0400 +Subject: [PATCH 35/86] ucs2: document things a little better + +Signed-off-by: Peter Jones +--- + src/ucs2.h | 135 +++++++++++++++++++++++++++++++++++++++-------------- + 1 file changed, 100 insertions(+), 35 deletions(-) + +diff --git a/src/ucs2.h b/src/ucs2.h +index 478de23b23f..3f8a41d8ccc 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -22,11 +22,20 @@ + #define ev_bits(val, mask, shift) \ + (((val) & ((mask) << (shift))) >> (shift)) + ++/* ++ * ucs2len(): Count the number of characters in a UCS-2 string. ++ * s: a UCS-2 string ++ * limit: the maximum number of uint16_t bytepairs to examine ++ * ++ * returns the number of characters before NUL is found (i.e., excluding ++ * the NUL character). If limit is non-negative, no character index above ++ * limit will be accessed, and the maximum return value is limit. ++ */ + static inline size_t UNUSED +-ucs2len(const void *vs, ssize_t limit) ++ucs2len(const void *s, ssize_t limit) + { + ssize_t i; +- const uint8_t *s8 = vs; ++ const uint8_t *s8 = s; + + for (i = 0; + i < (limit >= 0 ? limit : i+1) && !(s8[0] == 0 && s8[1] == 0); +@@ -35,6 +44,15 @@ ucs2len(const void *vs, ssize_t limit) + return i; + } + ++/* ++ * ucs2size(): count the number of bytes in use by a UCS-2 string. ++ * s: a UCS-2 string ++ * limit: the maximum number of uint16_t bytepairs to examine ++ * ++ * returns the number of bytes, including NUL, in the UCS-2 string s. If ++ * limit is non-negative, no character index above limit will be accessed, ++ * and the maximum return value is limit. ++ */ + static inline size_t UNUSED + ucs2size(const void *s, ssize_t limit) + { +@@ -46,6 +64,18 @@ ucs2size(const void *s, ssize_t limit) + return rc; + } + ++/* ++ * utf8len(): Count the number of characters in a UTF-8 string. ++ * s: a UTF-8 string ++ * limit: the maximum number of bytes to examine ++ * ++ * returns the number of UTF-8 charters before NUL is found (i.e., ++ * excluding the NUL character). If limit is non-negative, no character ++ * index above limit will be accessed, and the maximum return value is ++ * limit. ++ * ++ * Caveat: only good up to 3-byte sequences. ++ */ + static inline size_t UNUSED NONNULL(1) + utf8len(const unsigned char *s, ssize_t limit) + { +@@ -63,6 +93,15 @@ utf8len(const unsigned char *s, ssize_t limit) + return j; + } + ++/* ++ * utf8size(): count the number of bytes in use by a UTF-8 string. ++ * s: a UTF-8 string ++ * limit: the maximum number of bytes to examine ++ * ++ * returns the number of bytes, including NUL, in the UTF-8 string s. ++ * If limit is non-negative, no character index above limit will be ++ * accessed, and the maximum return value is limit. ++ */ + static inline size_t UNUSED NONNULL(1) + utf8size(const unsigned char *s, ssize_t limit) + { +@@ -72,68 +111,94 @@ utf8size(const unsigned char *s, ssize_t limit) + return ret; + } + ++/* ++ * ucs2_to_utf8(): convert UCS-2 to UTF-8 ++ * s: the UCS-2 string ++ * limit: the maximum number of characters to copy from s, including the ++ * NUL terminator, or -1 for no limit. ++ * ++ * returns an allocated string, into which at most limit - 1 characters of ++ * UTF-8 are translated from UCS-2. The return value is *always* ++ * NUL-terminated. ++ */ + static inline unsigned char * UNUSED +-ucs2_to_utf8(const void * const voidchars, ssize_t limit) ++ucs2_to_utf8(const void * const s, ssize_t limit) + { + ssize_t i, j; +- unsigned char *ret; +- const uint16_t * const chars = voidchars; ++ unsigned char *out, *ret; ++ const uint16_t * const chars = s; + + if (limit < 0) + limit = ucs2len(chars, -1); +- ret = malloc(limit * 6 + 1); +- if (!ret) ++ out = malloc(limit * 6 + 1); ++ if (!out) + return NULL; +- memset(ret, 0, limit * 6 +1); ++ memset(out, 0, limit * 6 +1); + + for (i=0, j=0; chars[i] && i < (limit >= 0 ? limit : i+1); i++,j++) { + if (chars[i] <= 0x7f) { +- ret[j] = chars[i]; ++ out[j] = chars[i]; + } else if (chars[i] > 0x7f && chars[i] <= 0x7ff) { +- ret[j++] = 0xc0 | ev_bits(chars[i], 0x1f, 6); +- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xc0 | ev_bits(chars[i], 0x1f, 6); ++ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); + #if 1 + } else if (chars[i] > 0x7ff) { +- ret[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); +- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); ++ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0); + } + #else + } else if (chars[i] > 0x7ff && chars[i] < 0x10000) { +- ret[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); +- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xe0 | ev_bits(chars[i], 0xf, 12); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); ++ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0); + } else if (chars[i] > 0xffff && chars[i] < 0x200000) { +- ret[j++] = 0xf0 | ev_bits(chars[i], 0x7, 18); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); +- ret[j] = 0x80| ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xf0 | ev_bits(chars[i], 0x7, 18); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); ++ out[j] = 0x80| ev_bits(chars[i], 0x3f, 0); + } else if (chars[i] > 0x1fffff && chars[i] < 0x4000000) { +- ret[j++] = 0xf8 | ev_bits(chars[i], 0x3, 24); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); +- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xf8 | ev_bits(chars[i], 0x3, 24); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); ++ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); + } else if (chars[i] > 0x3ffffff) { +- ret[j++] = 0xfc | ev_bits(chars[i], 0x1, 30); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 24); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); +- ret[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); +- ret[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); ++ out[j++] = 0xfc | ev_bits(chars[i], 0x1, 30); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 24); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 18); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 12); ++ out[j++] = 0x80 | ev_bits(chars[i], 0x3f, 6); ++ out[j] = 0x80 | ev_bits(chars[i], 0x3f, 0); + } + #endif + } +- ret[j] = '\0'; ++ out[j++] = '\0'; ++ ret = realloc(out, j); ++ if (!ret) { ++ free(out); ++ return NULL; ++ } + return ret; + } + ++/* ++ * utf8_to_ucs2(): convert UTF-8 to UCS-2 ++ * s: the destination buffer to write to. ++ * size: the size of the allocation to write to ++ * terminate: whether or not to add a terminator to the string ++ * utf8: the utf8 source ++ * ++ * returns the number of characters written to s, including the NUL ++ * terminator if "terminate" is true, or -1 on error. In the case of an ++ * error, the buffer will not be modified. ++ */ + static inline ssize_t UNUSED NONNULL(4) +-utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, const unsigned char *utf8) ++utf8_to_ucs2(void *s, ssize_t size, bool terminate, const unsigned char *utf8) + { + ssize_t req; + ssize_t i, j; +- uint16_t *ucs2 = ucs2void; ++ uint16_t *ucs2 = s; + uint16_t val16; + + if (!ucs2 && size > 0) { +-- +2.24.1 + diff --git a/SOURCES/0036-util.h-implement-add-mul-sub-for-more-integer-types.patch b/SOURCES/0036-util.h-implement-add-mul-sub-for-more-integer-types.patch new file mode 100644 index 0000000..924ff46 --- /dev/null +++ b/SOURCES/0036-util.h-implement-add-mul-sub-for-more-integer-types.patch @@ -0,0 +1,370 @@ +From 3536ccae29c9079eeee99fd363c7dec8a243ab58 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 16:37:29 -0400 +Subject: [PATCH 36/86] util.h: implement add()/mul()/sub() for more integer + types. + +This adds the following: +uint_add() +uint_mul() +uint_sub() +long_sub() +ulong_sub() + +Additionally it renames ulong_mult() to ulong_mul() and long_mult() to +long_mul(). + +As before, all of these are available without caring about the types, +as if declared: + +bool add(TYPE addend, TYPE addend, TYPE *sum); +bool mul(TYPE factor, TYPE factor, TYPE *product); +bool sub(TYPE minuend, TYPE subtractahend, TYPE *difference); + +If overflow would occur, the pointer target for the result is not +changed and the function returns true, otherwise it returns false. + +Signed-off-by: Peter Jones +--- + src/efivar.h | 1 + + src/safemath.h | 208 +++++++++++++++++++++++++++++++++++++++++++++++++ + src/util.h | 96 ----------------------- + 3 files changed, 209 insertions(+), 96 deletions(-) + create mode 100644 src/safemath.h + +diff --git a/src/efivar.h b/src/efivar.h +index 3d4b429631e..646863d14c5 100644 +--- a/src/efivar.h ++++ b/src/efivar.h +@@ -23,6 +23,7 @@ + #include + + #include "util.h" ++#include "safemath.h" + #include "efivar_endian.h" + #include "lib.h" + #include "guid.h" +diff --git a/src/safemath.h b/src/safemath.h +new file mode 100644 +index 00000000000..08dfef7ec0b +--- /dev/null ++++ b/src/safemath.h +@@ -0,0 +1,208 @@ ++/* ++ * safemath.h ++ * Copyright 2016-2019 Peter Jones ++ * ++ * This library is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public License as ++ * published by the Free Software Foundation; either version 2.1 of the ++ * License, or (at your option) any later version. ++ * ++ * This library 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, see ++ * . ++ * ++ */ ++ ++#ifndef SAFEMATH_H_ ++#define SAFEMATH_H_ ++ ++/* ++ * I'm not actually sure when these appear, but they're present in the ++ * version in front of me. ++ */ ++#if defined(__GNUC__) && defined(__GNUC_MINOR__) ++#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1 ++#define int_add(a, b, c) __builtin_add_overflow(a, b, c) ++#define uint_add(a, b, c) __builtin_add_overflow(a, b, c) ++#define long_add(a, b, c) __builtin_add_overflow(a, b, c) ++#define ulong_add(a, b, c) __builtin_add_overflow(a, b, c) ++ ++#define int_mul(a, b, c) __builtin_mul_overflow(a, b, c) ++#define uint_mul(a, b, c) __builtin_mul_overflow(a, b, c) ++#define long_mul(a, b, c) __builtin_mul_overflow(a, b, c) ++#define ulong_mul(a, b, c) __builtin_mul_overflow(a, b, c) ++ ++#define int_sub(a, b, c) __builtin_sub_overflow(a, b, c) ++#define uint_sub(a, b, c) __builtin_sub_overflow(a, b, c) ++#define long_sub(a, b, c) __builtin_sub_overflow(a, b, c) ++#define ulong_sub(a, b, c) __builtin_sub_overflow(a, b, c) ++#endif ++#endif ++ ++#ifndef int_add ++#define int_add(a, b, c) ({ \ ++ const int _limit = INT_MAX; \ ++ long int _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef uint_add ++#define uint_add(a, b, c) ({ \ ++ const unsigned int _limit = UINT_MAX; \ ++ unsigned int _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef long_add ++#define long_add(a, b, c) ({ \ ++ const long _limit = LONG_MAX; \ ++ long _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef ulong_add ++#define ulong_add(a, b, c) ({ \ ++ const unsigned long _limit = ULONG_MAX; \ ++ unsigned long _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) + (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef int_mul ++#define int_mul(a, b, c) ({ \ ++ int _ret; \ ++ _ret = __builtin_popcount(a) + __builtin_popcount(b); \ ++ _ret = _ret < ((sizeof(a) + sizeof(b)) << 4); \ ++ if (!_ret) \ ++ *(c) = ((a) * (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef uint_mul ++#define uint_mul(a, b, c) int_mul(a, b, c) ++#endif ++ ++#ifndef long_mul ++#define long_mul(a, b, c) int_mul(a, b, c) ++#endif ++ ++#ifndef ulong_mul ++#define ulong_mul(a, b, c) int_mul(a, b, c) ++#endif ++ ++#ifndef int_sub ++#define int_sub(a, b, c) ({ \ ++ const long _min_limit = INT_MIN; \ ++ const long _max_limit = INT_MAX; \ ++ int _ret; \ ++ _ret = _min_limit + (b); \ ++ _ret = !(_ret < (a)); \ ++ if (!_ret) { \ ++ _ret = _max_limit - (a); \ ++ _ret = _ret > (b); \ ++ } \ ++ if (!_ret) \ ++ *(c) = ((a) - (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef uint_sub ++#define uint_sub(a, b, c) ({ \ ++ const unsigned int _limit = UINT_MAX; \ ++ unsigned int _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) - (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef long_sub ++#define long_sub(a, b, c) ({ \ ++ const long _min_limit = LONG_MIN; \ ++ const long _max_limit = LONG_MAX; \ ++ int _ret; \ ++ _ret = _min_limit + (b); \ ++ _ret = !(_ret < (a)); \ ++ if (!_ret) { \ ++ _ret = _max_limit - (a); \ ++ _ret = _ret > (b); \ ++ } \ ++ if (!_ret) \ ++ *(c) = ((a) - (b)); \ ++ (bool)_ret; \ ++ }) ++#endif ++ ++#ifndef ulong_sub ++#define ulong_sub(a, b, c) ({ \ ++ const unsigned long _limit = ULONG_MAX; \ ++ unsigned long _ret = _limit - (a); \ ++ _ret = _ret > (b); \ ++ if (!_ret) \ ++ *(c) = ((a) - (b)); \ ++ _ret; \ ++ }) ++#endif ++ ++#if defined(__GNUC__) && defined(__GNUC_MINOR__) ++#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1 ++#define add(a, b, c) _Generic((c), \ ++ int *: int_add(a, b, c), \ ++ unsigned int *: uint_add(a, b, c), \ ++ long *: long_add(a, b, c), \ ++ unsigned long *: ulong_add(a, b, c)) ++#define sub(a, b, c) _Generic((c), \ ++ int *: int_sub(a, b, c), \ ++ unsigned int *: uint_sub(a, b, c), \ ++ long *: long_sub(a, b, c), \ ++ unsigned long *: ulong_sub(a, b, c)) ++#define mul(a, b, c) _Generic((c), \ ++ int *: int_sub(a, b, c), \ ++ unsigned int *: uint_mul(a, b, c), \ ++ long *: long_mul(a, b, c), \ ++ unsigned long *: ulong_mul(a, b, c)) ++#endif ++#endif ++ ++#ifndef add ++#define add(a, b, c) ({ \ ++ (*(c)) = ((a) + (b)); \ ++ }) ++#endif ++#ifndef mul ++#define mul(a, b, c) ({ \ ++ (*(c)) = ((a) * (b)); \ ++ }) ++#endif ++#ifndef sub ++#define sub(a, b, c) ({ \ ++ (*(c)) = ((a) - (b)); \ ++ }) ++#endif ++ ++ ++#endif /* !SAFEMATH_H_ */ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/util.h b/src/util.h +index 712abea2d42..3f68d812700 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -61,102 +61,6 @@ + #define unlikely(x) (__branch_check__(x, 0, __builtin_constant_p(x))) + #endif + +-/* +- * I'm not actually sure when these appear, but they're present in the +- * version in front of me. +- */ +-#if defined(__GNUC__) && defined(__GNUC_MINOR__) +-#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1 +-#define int_add(a, b, c) __builtin_add_overflow(a, b, c) +-#define long_add(a, b, c) __builtin_add_overflow(a, b, c) +-#define long_mult(a, b, c) __builtin_mul_overflow(a, b, c) +-#define ulong_add(a, b, c) __builtin_add_overflow(a, b, c) +-#define ulong_mult(a, b, c) __builtin_mul_overflow(a, b, c) +-#endif +-#endif +-#ifndef int_add +-#define int_add(a, b, c) ({ \ +- const int _limit = INT_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) +-#endif +-#ifndef long_add +-#define long_add(a, b, c) ({ \ +- const long _limit = LONG_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) +-#endif +-#ifndef long_mult +-#define long_mult(a, b, c) ({ \ +- const long _limit = LONG_MAX; \ +- int _ret = 1; \ +- if ((a) == 0 || (b) == 0) \ +- _ret = 0; \ +- else \ +- _ret = _limit / (a) < (b); \ +- if (!_ret) \ +- *(c) = ((a) * (b)); \ +- _ret; \ +- }) +-#endif +-#ifndef ulong_add +-#define ulong_add(a, b, c) ({ \ +- const unsigned long _limit = ULONG_MAX; \ +- int _ret; \ +- _ret = _limit - ((unsigned long long)a) > \ +- ((unsigned long long)b); \ +- if (!_ret) \ +- *(c) = ((a) + (b)); \ +- _ret; \ +- }) +-#endif +-#ifndef ulong_mult +-#define ulong_mult(a, b, c) ({ \ +- const unsigned long _limit = ULONG_MAX; \ +- int _ret = 1; \ +- if ((a) == 0 || (b) == 0) \ +- _ret = 0; \ +- else \ +- _ret = _limit / (a) < (b); \ +- if (!_ret) \ +- *(c) = ((a) * (b)); \ +- _ret; \ +- }) +-#endif +- +-#if defined(__GNUC__) && defined(__GNUC_MINOR__) +-#if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1 +-#define add(a, b, c) _Generic((c), \ +- int *: int_add(a,b,c), \ +- long *: long_add(a,b,c), \ +- unsigned long *: ulong_add(a,b,c)) +-#define mult(a, b, c) _Generic((c), \ +- long *: long_mult(a,b,c), \ +- unsigned long *: ulong_mult(a,b,c)) +-#endif +-#endif +- +-#ifndef add +-#define add(a, b, c) ({ \ +- (*(c)) = ((a) + (b)); \ +- }) +-#endif +-#ifndef mult +-#define mult(a, b, c) ({ \ +- (*(c)) = ((a) * (b)); \ +- }) +-#endif +- + static inline int UNUSED + read_file(int fd, uint8_t **result, size_t *bufsize) + { +-- +2.24.1 + diff --git a/SOURCES/0037-Implement-efivar-export-foo.var.patch b/SOURCES/0037-Implement-efivar-export-foo.var.patch new file mode 100644 index 0000000..4f740f9 --- /dev/null +++ b/SOURCES/0037-Implement-efivar-export-foo.var.patch @@ -0,0 +1,1194 @@ +From d1679020393532f99d9fb33f2b3e3a7eecdec2fe Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 15:04:11 -0400 +Subject: [PATCH 37/86] Implement 'efivar --export=foo.var' + +Signed-off-by: Peter Jones +--- + .gitignore | 17 +- + src/Makefile | 2 +- + src/crc32.h | 19 ++ + src/efivar.c | 362 ++++++++++++++++++++------ + src/export.c | 502 +++++++++++++++++++++++++++++++++--- + src/gpt.c | 18 -- + src/include/efivar/efivar.h | 3 + + 7 files changed, 783 insertions(+), 140 deletions(-) + +diff --git a/.gitignore b/.gitignore +index 5c3fd0e3f52..947d88eec42 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -1,23 +1,26 @@ ++.*.c.P ++.*.h.P ++.*.d + .*.sw? + *~ + *.a ++*.env + *.E + *.o ++*.map + *.pc + *.S + !src/guids.S + *.so + *.so.* ++*.spec + *.tar.* +-.*.c.P +-.*.h.P +-.*.d ++*.var + core.* +-*.spec ++cov-int ++vgcore.* ++scan-results/ + src/efivar + src/efivar-static + src/makeguids + src/guid-symbols.c +-*.map +-cov-int +-scan-results/ +diff --git a/src/Makefile b/src/Makefile +index ecbbc02e1f7..addfaa03c85 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -17,7 +17,7 @@ STATICTARGETS=$(STATICLIBTARGETS) $(STATICBINTARGETS) + LIBEFIBOOT_SOURCES = crc32.c creator.c disk.c gpt.c loadopt.c path-helpers.c \ + linux.c $(wildcard linux-*.c) + LIBEFIBOOT_OBJECTS = $(patsubst %.c,%.o,$(LIBEFIBOOT_SOURCES)) +-LIBEFIVAR_SOURCES = dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \ ++LIBEFIVAR_SOURCES = crc32.c dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \ + efivarfs.c error.c export.c guid.c guids.S guid-symbols.c \ + lib.c vars.c + LIBEFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(LIBEFIVAR_SOURCES))) +diff --git a/src/crc32.h b/src/crc32.h +index b5b975a5768..4e833aafac0 100644 +--- a/src/crc32.h ++++ b/src/crc32.h +@@ -29,6 +29,25 @@ + + extern uint32_t crc32 (const void *buf, unsigned long len, uint32_t seed); + ++/** ++ * efi_crc32() - EFI version of crc32 function ++ * @buf: buffer to calculate crc32 of ++ * @len - length of buf ++ * ++ * Description: Returns EFI-style CRC32 value for @buf ++ * ++ * This function uses the little endian Ethernet polynomial ++ * but seeds the function with ~0, and xor's with ~0 at the end. ++ * Note, the EFI Specification, v1.02, has a reference to ++ * Dr. Dobbs Journal, May 1994 (actually it's in May 1992). ++ */ ++static inline uint32_t ++efi_crc32(const void *buf, unsigned long len) ++{ ++ return (crc32(buf, len, ~0L) ^ ~0L); ++} ++ ++ + #endif /* _CRC32_H */ + + // vim:fenc=utf-8:tw=75:noet +diff --git a/src/efivar.c b/src/efivar.c +index 7f16ab15bab..885a9af864b 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -46,6 +46,8 @@ extern int optind, opterr, optopt; + #define ACTION_LIST_GUIDS 0x08 + #define ACTION_WRITE 0x10 + #define ACTION_PRINT_DEC 0x20 ++#define ACTION_IMPORT 0x40 ++#define ACTION_EXPORT 0x80 + + #define EDIT_APPEND 0 + #define EDIT_WRITE 1 +@@ -173,31 +175,10 @@ bad_name: + } + + static void +-show_variable(char *guid_name, int display_type) ++show_variable_data(efi_guid_t guid, const char *name, uint32_t attributes, ++ uint8_t *data, size_t data_size, ++ int display_type) + { +- efi_guid_t guid = efi_guid_empty; +- char *name = NULL; +- int rc; +- +- uint8_t *data = NULL; +- size_t data_size = 0; +- uint32_t attributes; +- +- parse_name(guid_name, &name, &guid); +- if (!name || efi_guid_is_empty(&guid)) { +- fprintf(stderr, "efivar: could not parse variable name.\n"); +- show_errors(); +- exit(1); +- } +- +- errno = 0; +- rc = efi_get_variable(guid, name, &data, &data_size, &attributes); +- if (rc < 0) { +- fprintf(stderr, "efivar: show variable: %m\n"); +- show_errors(); +- exit(1); +- } +- + if (display_type == SHOW_VERBOSE) { + printf("GUID: "GUID_FORMAT "\n", + guid.a, guid.b, guid.c, bswap_16(guid.d), +@@ -257,6 +238,117 @@ show_variable(char *guid_name, int display_type) + } + printf("\n"); + } ++} ++ ++static void ++show_variable(char *guid_name, int display_type) ++{ ++ efi_guid_t guid = efi_guid_empty; ++ char *name = NULL; ++ int rc; ++ ++ uint8_t *data = NULL; ++ size_t data_size = 0; ++ uint32_t attributes; ++ ++ parse_name(guid_name, &name, &guid); ++ if (!name || efi_guid_is_empty(&guid)) { ++ fprintf(stderr, "efivar: could not parse variable name.\n"); ++ show_errors(); ++ exit(1); ++ } ++ ++ errno = 0; ++ rc = efi_get_variable(guid, name, &data, &data_size, &attributes); ++ if (rc < 0) { ++ fprintf(stderr, "efivar: show variable: %m\n"); ++ show_errors(); ++ exit(1); ++ } ++ ++ show_variable_data(guid, name, attributes, ++ data, data_size, display_type); ++ ++ free(name); ++ if (data) ++ free(data); ++} ++ ++static void ++save_variable_data(efi_variable_t *var, char *outfile, bool dmpstore) ++{ ++ FILE *out = NULL; ++ ssize_t sz; ++ uint8_t *data = NULL; ++ size_t datasz = 0; ++ ssize_t (*export)(efi_variable_t *var, uint8_t *data, size_t size) = ++ dmpstore ? efi_variable_export_dmpstore : efi_variable_export; ++ ++ out = fopen(outfile, "w"); ++ if (!out) ++ err(1, "Could not open \"%s\" for writing", outfile); ++ ++ sz = export(var, data, datasz); ++ data = calloc(sz, 1); ++ if (!data) ++ err(1, "Could not allocate memory"); ++ datasz = sz; ++ ++ sz = export(var, data, datasz); ++ if (sz < 0) ++ err(1, "Could not format data"); ++ datasz = sz; ++ ++ sz = fwrite(data, 1, datasz, out); ++ if (sz < (ssize_t)datasz) ++ err(1, "Could not write to \"%s\"", outfile); ++ ++ fflush(out); ++ fclose(out); ++} ++ ++static void ++save_variable(char *guid_name, char *outfile, bool dmpstore) ++{ ++ efi_guid_t guid = efi_guid_empty; ++ char *name = NULL; ++ int rc; ++ ++ uint8_t *data = NULL; ++ size_t data_size = 0; ++ uint32_t attributes = 7; ++ efi_variable_t *var; ++ ++ parse_name(guid_name, &name, &guid); ++ if (!name || efi_guid_is_empty(&guid)) { ++ fprintf(stderr, "efivar: could not parse variable name.\n"); ++ show_errors(); ++ exit(1); ++ } ++ ++ errno = 0; ++ rc = efi_get_variable(guid, name, &data, &data_size, &attributes); ++ if (rc < 0) { ++ fprintf(stderr, "efivar: show variable: %m\n"); ++ show_errors(); ++ exit(1); ++ } ++ ++ var = efi_variable_alloc(); ++ if (!var) { ++ fprintf(stderr, "efivar: could not allocate variable storage.\n"); ++ show_errors(); ++ exit(1); ++ } ++ ++ efi_variable_set_name(var, (unsigned char *)name); ++ efi_variable_set_guid(var, &guid); ++ efi_variable_set_attributes(var, attributes); ++ efi_variable_set_data(var, data, data_size); ++ ++ save_variable_data(var, outfile, dmpstore); ++ ++ efi_variable_free(var, false); + + free(name); + if (data) +@@ -372,16 +464,18 @@ usage(int ret) + FILE *out = ret == 0 ? stdout : stderr; + fprintf(out, + "Usage: %s [OPTION...]\n" ++ " -t, --attributes= attributes to use on append\n" + " -l, --list list current variables\n" + " -p, --print print variable specified by --name\n" ++ " -D, --dmpstore use DMPSTORE format when exporting\n" + " -d, --print-decimal print variable in decimal values specified\n" + " by --name\n" + " -n, --name= variable to manipulate, in the form\n" + " 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000\n" + " -a, --append append to variable specified by --name\n" ++ " -f, --datafile= load or save variable contents from \n" + " -e, --export= export variable to \n" +- " -f, --fromfile= use data from \n" +- " -t, --attributes= attributes to use on append\n" ++ " -i, --import= import variable from 0x%"PRIx32", expected 0x%"PRIx32, ++ data, size - sizeof(uint32_t), crc, ++ *(uint32_t*)(data + size - sizeof(uint32_t))); ++ ++ if (memcmp(data + size - sizeof(uint32_t), ++ &crc, sizeof(uint32_t))) { ++ errno = EINVAL; ++ efi_error("crc32 did not match"); ++ return -1; ++ } ++ ++ var.name = ucs2_to_utf8(ptr, -1); ++ if (!var.name) ++ goto oom; ++ ptr += namesz; ++ ++ var.guid = malloc(sizeof (efi_guid_t)); ++ if (!var.guid) ++ goto oom; ++ memcpy(var.guid, ptr, sizeof (efi_guid_t)); ++ ptr += sizeof (efi_guid_t); ++ ++ var.attrs = *(uint32_t *)ptr; ++ ptr += sizeof(uint32_t); ++ ++ var.data_size = datasz; ++ var.data = malloc(datasz); ++ if (!var.data) { ++ efi_error("Could not allocate %"PRIu32" bytes", datasz); ++ goto oom; ++ } ++ memcpy(var.data, ptr, datasz); ++ ++ if (!*var_out) { ++ *var_out =malloc(sizeof (var)); ++ if (!*var_out) ++ goto oom; ++ memcpy(*var_out, &var, sizeof (var)); ++ } else { ++ return -1; ++ } ++ return size; ++oom: ++ saved_errno = errno; ++ ++ if (var.guid) ++ free(var.guid); ++ ++ if (var.name) ++ free(var.name); ++ ++ if (var.data) ++ free(var.data); ++ ++ errno = saved_errno; ++ efi_error("Could not allocate memory"); ++ return -1; ++} ++ ++ssize_t NONNULL(1, 3) ++efi_variable_import_efivar(uint8_t *data, size_t datasz, efi_variable_t **var_out) + { + efi_variable_t var; + size_t min = sizeof (uint32_t) * 2 /* magic */ +@@ -63,47 +217,83 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out) + + sizeof (uint64_t) /* attr */ + + sizeof (efi_guid_t) /* guid */ + + sizeof (uint32_t) * 2 /* name_len and data_len */ +- + sizeof (char16_t) /* two bytes of name */ +- + 1; /* one byte of data */ ++ + sizeof (char16_t) /* two bytes of name */ ++ + 1 /* one byte of data */ ++ + 4; /* crc32 */ ++ uint32_t crc; ++ uint8_t *ptr = data; ++ uint32_t magic = EFIVAR_MAGIC; ++ int test; ++ + errno = EINVAL; +- if (size <= min) ++ if (datasz <= min) + return -1; + +- uint8_t *ptr = data; +- uint32_t magic = EFIVAR_MAGIC; +- if (memcmp(data, &magic, sizeof (uint32_t)) || +- memcmp(data + size - sizeof (uint32_t), &magic, +- sizeof (uint32_t))) ++ test = memcmp(data, &magic, sizeof (uint32_t)); ++ debug("test magic 0: cmp(0x%04x,0x%04x)->%d", *(uint32_t *)data, magic, test); ++ if (test) { ++ errno = EINVAL; ++ efi_error("MAGIC for file format did not match."); + return -1; +- size -= sizeof (uint32_t); ++ } ++ + ptr += sizeof (uint32_t); + ++ debug("test version"); + if (*(uint32_t *)ptr == 1) { + ptr += sizeof (uint32_t); ++ debug("version 1"); ++ + var.attrs = *(uint64_t *)ptr; +- ptr += sizeof (uint32_t); ++ ptr += sizeof (uint64_t); ++ debug("var.attrs:0x%08"PRIx64, var.attrs); + + var.guid = malloc(sizeof (efi_guid_t)); + if (!var.guid) + return -1; + *var.guid = *(efi_guid_t *)ptr; + ptr += sizeof (efi_guid_t); ++ debug("var.guid:"GUID_FORMAT, ++ var.guid->a, var.guid->b, var.guid->c, ++ bswap_16(var.guid->d), ++ var.guid->e[0], var.guid->e[1], var.guid->e[2], ++ var.guid->e[3], var.guid->e[4], var.guid->e[5]); + + uint32_t name_len = *(uint32_t *)ptr; + ptr += sizeof (uint32_t); ++ debug("name_len:%"PRIu32, name_len); ++ + uint32_t data_len = *(uint32_t *)ptr; + ptr += sizeof (uint32_t); ++ debug("data_len:%"PRIu32, data_len); ++ ++ min -= 3; ++ min += name_len; ++ min += data_len; + +- if (name_len < 1 || +- name_len != ((data + size) - ptr - data_len) || ++ if (name_len < 2 || ++ name_len > (datasz - data_len) || + data_len < 1 || +- data_len != ((data + size) - ptr - name_len)) { ++ data_len > (datasz - name_len)) { + int saved_errno = errno; + free(var.guid); + errno = saved_errno; + return -1; + } + ++ crc = efi_crc32(data, datasz - sizeof(uint32_t)); ++ debug("efi_crc32(%p, %lu) -> 0x%"PRIx32", expected 0x%"PRIx32, ++ data, datasz - sizeof(uint32_t), crc, ++ *(uint32_t*)(data + datasz - sizeof(uint32_t))); ++ ++ if (memcmp(data + datasz - sizeof (uint32_t), &crc, ++ sizeof (uint32_t))) { ++ free(var.guid); ++ errno = EINVAL; ++ efi_error("crc32 did not match"); ++ return -1; ++ } ++ + var.name = calloc(1, name_len + 1); + if (!var.name) { + int saved_errno = errno; +@@ -115,7 +305,8 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out) + char16_t *wname = (char16_t *)ptr; + for (uint32_t i = 0; i < name_len; i++) + var.name[i] = wname[i] & 0xff; +- ptr += name_len * 2; ++ ptr += name_len; ++ debug("name:%s", var.name); + + var.data_size = data_len; + var.data = malloc(data_len); +@@ -143,31 +334,228 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out) + } else { + return -1; + } +- return size; ++ return min; ++} ++ ++ssize_t NONNULL(1, 3) PUBLIC ++efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out) ++{ ++ ssize_t rc; ++ ++ rc = efi_variable_import_efivar(data, size, var_out); ++ if (rc >= 0) ++ return rc; ++ ++ rc = efi_variable_import_dmpstore(data, size, var_out); ++ return rc; + } + + ssize_t NONNULL(1) PUBLIC +-efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size) ++efi_variable_export_dmpstore(efi_variable_t *var, uint8_t *data, size_t datasz) + { +- size_t name_len = strlen((char *)var->name); +- +- size_t needed = sizeof (uint32_t) /* magic */ +- + sizeof (uint32_t) /* version */ +- + sizeof (uint64_t) /* attr */ +- + sizeof (efi_guid_t) /* guid */ +- + sizeof (uint32_t) /* name_len */ +- + sizeof (uint32_t) /* data_len */ +- + sizeof (char16_t) * name_len /* name */ +- + var->data_size /* data */ +- + sizeof (uint32_t); /* magic again */ +- +- if (!data || size == 0) { ++ uint32_t tmpu32; ++ ssize_t tmpssz; ++ uint32_t namesz; ++ uint32_t needed = sizeof (uint32_t) /* name_size */ ++ + sizeof (uint32_t) /* data_size */ ++ + 2 /* name */ ++ + sizeof (efi_guid_t) /* guid */ ++ + sizeof (uint32_t) /* attrs */ ++ + 1 /* data */ ++ + 4; /* crc32 */ ++ uint8_t *ptr; ++ uint32_t crc; ++ ++ if (!var) { ++ errno = EINVAL; ++ efi_error("var cannot be NULL"); ++ return -1; ++ } ++ if (!var->name) { ++ errno = EINVAL; ++ efi_error("var->name cannot be NULL"); ++ return -1; ++ } ++ if (!var->data) { ++ errno = EINVAL; ++ efi_error("var->data cannot be NULL"); ++ return -1; ++ } ++ ++ debug("data: %p datasz: %zu", data, datasz); ++ ++ namesz = utf8size(var->name, -1); ++ debug("sizeof(uint16_t):%zd * namesz:%"PRIu32, sizeof(uint16_t), namesz); ++ if (mul(sizeof (uint16_t), namesz, &namesz)) { ++overflow: ++ errno = EOVERFLOW; ++ efi_error("arithmetic overflow computing name size"); ++ return -1; ++ } ++ debug("namesz -> %"PRIu32, namesz); ++ ++ /* ++ * Remove our stand-ins for name size and data size before we add ++ * them back in. ++ */ ++ needed -= 3; ++ ++ debug("needed:%"PRIu32" + namesz:%"PRIu32, needed, namesz); ++ if (add(needed, namesz, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ debug("needed:%"PRIu32" + var->data_size:%zd", needed, var->data_size); ++ if (add(needed, var->data_size, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ if (!data || datasz == 0) { ++ debug("data: %p datasz: %zd -> returning needed size %"PRIu32, ++ data, datasz, needed); + return needed; +- } else if (size < needed) { +- return needed - size; + } + +- uint8_t *ptr = data; ++ debug("datasz:%zu needed: %"PRIu32, datasz, needed); ++ if (datasz < needed) { ++ efi_error("needed: %"PRIu32" datasz: %zd -> returning needed datasz %zu", ++ needed, datasz, needed - datasz); ++ return needed - datasz; ++ } ++ ++ ptr = data; ++ ++ tmpssz = utf8_to_ucs2(ptr + 8, datasz - 8, true, var->name); ++ if (tmpssz < 0) { ++ efi_error("UTF-8 to UCS-2 conversion failed"); ++ return -1; ++ } ++ tmpu32 = tmpssz; ++ tmpu32 *= sizeof(uint16_t); ++ ++ debug("namesz:%"PRIu32" - tmpu32:%"PRIu32, namesz, tmpu32); ++ if (sub(namesz, tmpu32, &tmpu32)) ++ goto overflow; ++ debug("tmpu32 -> %"PRIu32, tmpu32); ++ ++ debug("namesz:%"PRIu32" - tmpu32:%"PRIu32, namesz, tmpu32); ++ if (sub(namesz, tmpu32, &namesz)) ++ goto overflow; ++ debug("namesz -> %"PRIu32, namesz); ++ ++ debug("needed:%"PRIu32" - tmpu32:%"PRIu32, needed, tmpu32); ++ if (sub(needed, tmpu32, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ debug("datasz:%zu needed: %"PRIu32, datasz, needed); ++ if (datasz < needed) { ++ debug("needed: %"PRIu32" datasz: %zd -> returning needed datasz %"PRIu32, ++ needed, datasz, needed); ++ return needed; ++ } ++ ++ *(uint32_t *)ptr = namesz; ++ ptr += sizeof (uint32_t); ++ ++ *(uint32_t *)ptr = var->data_size; ++ ptr += sizeof (uint32_t); ++ ++ ptr += namesz; ++ ++ memcpy(ptr, var->guid, sizeof (efi_guid_t)); ++ ptr += sizeof(efi_guid_t); ++ ++ *(uint32_t *)ptr = var->attrs; ++ ptr += sizeof (uint32_t); ++ ++ memcpy(ptr, var->data, var->data_size); ++ ptr += var->data_size; ++ ++ crc = efi_crc32(data, needed - sizeof(uint32_t)); ++ debug("efi_crc32(%p, %lu) -> 0x%"PRIx32, ++ data, needed - sizeof(uint32_t), crc); ++ *(uint32_t *)ptr = crc; ++ ++ return needed; ++} ++ ++ssize_t NONNULL(1) PUBLIC ++efi_variable_export(efi_variable_t *var, uint8_t *data, size_t datasz) ++{ ++ uint32_t tmpu32; ++ ssize_t tmpssz; ++ uint32_t namesz; ++ uint32_t needed = sizeof (uint32_t) /* magic */ ++ + sizeof (uint32_t) /* version */ ++ + sizeof (uint64_t) /* attr */ ++ + sizeof (efi_guid_t) /* guid */ ++ + sizeof (uint32_t) /* name_len */ ++ + sizeof (uint32_t) /* data_len */ ++ + 2 /* name */ ++ + 1 /* data */ ++ + 4; /* crc32 */ ++ uint8_t *ptr; ++ uint32_t crc; ++ ++ if (!var) { ++ errno = EINVAL; ++ efi_error("var cannot be NULL"); ++ return -1; ++ } ++ if (!var->name) { ++ errno = EINVAL; ++ efi_error("var->name cannot be NULL"); ++ return -1; ++ } ++ if (!var->data) { ++ errno = EINVAL; ++ efi_error("var->data cannot be NULL"); ++ return -1; ++ } ++ ++ debug("data: %p datasz: %zu", data, datasz); ++ ++ namesz = utf8size(var->name, -1); ++ debug("sizeof(uint16_t):%zd * namesz:%"PRIu32, sizeof(uint16_t), namesz); ++ if (mul(sizeof (uint16_t), namesz, &namesz)) { ++overflow: ++ errno = EOVERFLOW; ++ efi_error("arithmetic overflow computing name size"); ++ return -1; ++ } ++ debug("namesz -> %"PRIu32, namesz); ++ ++ /* ++ * Remove our stand-ins for name size and data size before we add ++ * them back in. ++ */ ++ needed -= 3; ++ ++ debug("needed:%"PRIu32" + namesz:%"PRIu32, needed, namesz); ++ if (add(needed, namesz, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ debug("needed:%"PRIu32" + var->data_size:%zd", needed, var->data_size); ++ if (add(needed, var->data_size, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ if (!data || datasz == 0) { ++ debug("data: %p datasz: %zd -> returning needed datasz %"PRIu32, ++ data, datasz, needed); ++ return needed; ++ } ++ ++ debug("datasz:%zu needed: %"PRIu32, datasz, needed); ++ if (datasz < needed) { ++ efi_error("needed: %"PRIu32" datasz: %zd -> returning needed datasz %zd", ++ needed, datasz, needed - datasz); ++ return needed - datasz; ++ } ++ ++ ptr = data; + + *(uint32_t *)ptr = EFIVAR_MAGIC; + ptr += sizeof (uint32_t); +@@ -181,21 +569,51 @@ efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size) + memcpy(ptr, var->guid, sizeof (efi_guid_t)); + ptr += sizeof (efi_guid_t); + +- *(uint32_t *)ptr = (uint32_t)(sizeof (char16_t) * name_len); ++ tmpssz = utf8_to_ucs2(ptr + 8, datasz - 8, true, var->name); ++ if (tmpssz < 0) { ++ efi_error("UTF-8 to UCS-2 conversion failed"); ++ return -1; ++ } ++ tmpu32 = tmpssz; ++ tmpu32 *= sizeof(uint16_t); ++ ++ debug("namesz:%"PRIu32" - tmpu32:%"PRIu32, namesz, tmpu32); ++ if (sub(namesz, tmpu32, &tmpu32)) ++ goto overflow; ++ debug("tmpu32 -> %"PRIu32, tmpu32); ++ ++ debug("needed:%"PRIu32" - tmpu32:%"PRIu32, needed, tmpu32); ++ if (sub(needed, tmpu32, &needed)) ++ goto overflow; ++ debug("needed -> %"PRIu32, needed); ++ ++ debug("namesz:%"PRIu32" - tmpu32:%"PRIu32, namesz, tmpu32); ++ if (sub(namesz, tmpu32, &namesz)) ++ goto overflow; ++ debug("namesz -> %"PRIu32, namesz); ++ ++ debug("datasz:%zu needed: %"PRIu32, datasz, needed); ++ if (datasz < needed) { ++ efi_error("needed: %"PRIu32" datasz: %zd -> returning needed datasz %zd", ++ needed, datasz, needed - datasz); ++ return needed - datasz; ++ } ++ ++ *(uint32_t *)ptr = namesz; + ptr += sizeof (uint32_t); + + *(uint32_t *)ptr = var->data_size; + ptr += sizeof (uint32_t); + +- for (uint32_t i = 0; i < name_len; i++) { +- *(char16_t *)ptr = var->name[i]; +- ptr += sizeof (char16_t); +- } ++ ptr += namesz; + + memcpy(ptr, var->data, var->data_size); + ptr += var->data_size; + +- *(uint32_t *)ptr = EFIVAR_MAGIC; ++ crc = efi_crc32(data, needed - sizeof(uint32_t)); ++ debug("efi_crc32(%p, %lu) -> 0x%"PRIx32, ++ data, needed - sizeof(uint32_t), crc); ++ *(uint32_t *)ptr = crc; + + return needed; + } +diff --git a/src/gpt.c b/src/gpt.c +index aa4055b9812..8babafeb588 100644 +--- a/src/gpt.c ++++ b/src/gpt.c +@@ -48,24 +48,6 @@ struct blkdev_ioctl_param { + char * block_contents; + }; + +-/** +- * efi_crc32() - EFI version of crc32 function +- * @buf: buffer to calculate crc32 of +- * @len - length of buf +- * +- * Description: Returns EFI-style CRC32 value for @buf +- * +- * This function uses the little endian Ethernet polynomial +- * but seeds the function with ~0, and xor's with ~0 at the end. +- * Note, the EFI Specification, v1.02, has a reference to +- * Dr. Dobbs Journal, May 1994 (actually it's in May 1992). +- */ +-static inline uint32_t +-efi_crc32(const void *buf, unsigned long len) +-{ +- return (crc32(buf, len, ~0L) ^ ~0L); +-} +- + /** + * is_pmbr_valid(): test Protective MBR for validity + * @mbr: pointer to a legacy mbr structure +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 729b6fe80f7..8ad14b9be57 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -139,6 +139,9 @@ extern ssize_t efi_variable_import(uint8_t *data, size_t size, + extern ssize_t efi_variable_export(efi_variable_t *var, uint8_t *data, + size_t size) + __attribute__((__nonnull__ (1))); ++extern ssize_t efi_variable_export_dmpstore(efi_variable_t *var, uint8_t *data, ++ size_t size) ++ __attribute__((__nonnull__ (1))); + + extern efi_variable_t *efi_variable_alloc(void) + __attribute__((__visibility__ ("default"))); +-- +2.24.1 + diff --git a/SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch b/SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch new file mode 100644 index 0000000..431272c --- /dev/null +++ b/SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch @@ -0,0 +1,187 @@ +From 3b4336d1f894ee0ee4180d6b50f4b7febbea3476 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 13:21:45 -0400 +Subject: [PATCH 38/86] Add some test cases for efivar export/import + +Signed-off-by: Peter Jones +--- + Makefile | 3 ++ + tests/.gitignore | 2 + + tests/Makefile | 86 ++++++++++++++++++++++++++++++++++++++++++ + tests/test.0.goal.var | Bin 0 -> 562 bytes + tests/test.1.goal.var | Bin 0 -> 574 bytes + tests/test.3.goal.var | Bin 0 -> 66 bytes + tests/test.4.goal.var | Bin 0 -> 365 bytes + 7 files changed, 91 insertions(+) + create mode 100644 tests/.gitignore + create mode 100644 tests/Makefile + create mode 100644 tests/test.0.goal.var + create mode 100644 tests/test.1.goal.var + create mode 100644 tests/test.3.goal.var + create mode 100644 tests/test.4.goal.var + +diff --git a/Makefile b/Makefile +index 9c2620cb485..2d134ea9d6f 100644 +--- a/Makefile ++++ b/Makefile +@@ -51,6 +51,9 @@ clean : + done + @rm -vf efivar.spec vgcore.* core.* + ++test : all ++ @$(MAKE) -C tests ++ + test-archive: abicheck efivar.spec + @rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp + @mkdir -p /tmp/efivar-$(GITTAG)-tmp +diff --git a/tests/.gitignore b/tests/.gitignore +new file mode 100644 +index 00000000000..a0149cf75de +--- /dev/null ++++ b/tests/.gitignore +@@ -0,0 +1,2 @@ ++!*.var ++*.result.* +diff --git a/tests/Makefile b/tests/Makefile +new file mode 100644 +index 00000000000..5e0c604e355 +--- /dev/null ++++ b/tests/Makefile +@@ -0,0 +1,86 @@ ++# ++# Makefile ++# Peter Jones, 2019-06-18 11:10 ++# ++ ++all: clean test0 test1 test2 test3 test4 ++ ++GRUB_PREFIX ?= grub2 ++TOPDIR ?= .. ++EFIVAR ?= ../src/efivar ++ ++clean: ++ @rm -f *.result.env *.result.var ++ ++test0: ++ @echo testing export to DMPSTORE format ++ @$(GRUB_PREFIX)-editenv test.0.result.env create ++ @$(GRUB_PREFIX)-editenv test.0.result.env set debug=all,-scripting,-lexer ++ @truncate -s 512 test.0.result.env ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.0.result.env -D -e test.0.result.var ++ @cmp test.0.result.var test.0.goal.var ++ @rm test.0.result.* ++ @echo passed ++ ++test1: ++ @echo testing export to libefivar format ++ @$(GRUB_PREFIX)-editenv test.1.result.env create ++ @$(GRUB_PREFIX)-editenv test.1.result.env set debug=all,-scripting,-lexer ++ @truncate -s 512 test.1.result.env ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.1.result.env -e test.1.result.var ++ @cmp test.1.result.var test.1.goal.var ++ @rm test.1.result.* ++ @echo passed ++ ++test2: ++ @$(GRUB_PREFIX)-editenv test.2.result.env create ++ @$(GRUB_PREFIX)-editenv test.2.result.env set debug=all,-scripting,-lexer ++ @truncate -s 512 test.2.result.env ++ @echo test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.2.result.env -D -e test.2.0.goal.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.0.goal.var -e test.2.0.result.var -D ++ @cmp test.2.0.result.var test.2.0.result.var ++ @rm test.2.0.* ++ @echo passed ++ @echo test importing from DMPSTORE and exporting to libefivar ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.2.result.env -D -e test.2.1.goal.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.1.goal.var -e test.2.1.result.var ++ @cmp test.2.1.result.var test.2.1.result.var ++ @rm test.2.1.* ++ @echo passed ++ @echo test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.2.result.env -e test.2.2.goal.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.2.goal.var -e test.2.2.result.var -D ++ @cmp test.2.2.result.var test.2.2.result.var ++ @rm test.2.2.* ++ @echo passed ++ @echo test importing from libefivar and exporting to libefivar and guid-name validation ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.2.result.env -e test.2.3.goal.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.2.3.goal.var -e test.2.3.result.var ++ @cmp test.2.3.result.var test.2.3.result.var ++ @rm test.2.3.* test.2.result.env ++ @echo passed ++ @echo testing efivar -L ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -L | \ ++ grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$$' ++ @echo passed ++ ++test3: ++ @echo testing with BootOrder variable dmpstore generated ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.3.goal.var -e test.3.0.result.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.3.0.result.var -e test.3.1.result.var -D ++ @cmp test.3.goal.var test.3.1.result.var ++ @rm test.3.0.result.var test.3.1.result.var ++ @echo passed ++ ++test4: ++ @echo testing with ConIn variable dmpstore generated ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.4.goal.var -e test.4.0.result.var ++ @LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.4.0.result.var -e test.4.1.result.var -D ++ @cmp test.4.goal.var test.4.1.result.var ++ @rm test.4.0.result.var test.4.1.result.var ++ @echo passed ++ ++.PHONY: all clean test0 ++# vim:ft=make ++# +diff --git a/tests/test.0.goal.var b/tests/test.0.goal.var +new file mode 100644 +index 0000000000000000000000000000000000000000..a3bfb4db5ea49c8b26b0b9a0e118da4109969efb +GIT binary patch +literal 562 +zcmWe)00Jfk26u)ahEN74hIj^720w-{py2;3^NGt&?{k_mm+kKhL5&yeKrv+n_n=TG +z1=qZ?%%c3f+|;}h1*e?+T<#Pa%YGIxL + +literal 0 +HcmV?d00001 + +diff --git a/tests/test.3.goal.var b/tests/test.3.goal.var +new file mode 100644 +index 0000000000000000000000000000000000000000..972dd553e2043e782b096c9a8ad509c07b73782d +GIT binary patch +literal 66 +zcmWe(U|`?_Vkd@tAS_|FT;Zw%-TKdKru!JW+2JL +Pz{0@Fz{b#`@+=nsxhf5! + +literal 0 +HcmV?d00001 + +diff --git a/tests/test.4.goal.var b/tests/test.4.goal.var +new file mode 100644 +index 0000000000000000000000000000000000000000..549ed5b717dd23843883d3d45f65f4dafeede870 +GIT binary patch +literal 365 +zcmWe)U|_IjWMFV+$Y;o7@C0HPhE#?!plIU#C*7weUlLr!%kW?Zvvv;~P>hj9gu%OZ +z#$~DL@ybztU}R+G5@85-KlotZ&r5={co-(A+aL6;XJjEo +zduqb6`;uEO3(nFdOFQ@Rb=42T%Y6FU_2+4DG&_@MdqeKT+KtgYu1oqK#orBlKZQi? +e*A|Gbebas3YeDe^+2?h-9rgcN7(R2c?F0Zk6=943 + +literal 0 +HcmV?d00001 + +-- +2.24.1 + diff --git a/SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch b/SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch new file mode 100644 index 0000000..6233f69 --- /dev/null +++ b/SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch @@ -0,0 +1,119 @@ +From 272b216e197b2b3d05da68ef51861545a36dc6d8 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 15:54:58 -0400 +Subject: [PATCH 39/86] Fix a case clang-analyzer found where we may try to + parse a NULL + +I don't think this is something that can *actually* happen - it didn't +trigger before save_variable() was added, and the save_variable() path +that calls this calls validate_name() immediately prior to this call. +validate_name() calls exit() if it's NULL. But that's weird as well, +because that's the same pattern all the other users of parse_name() use. + +Anyway, this patch expands validate_name() and moves it into +parse_name() so we don't need to call it from everywhere when we're just +calling the two in a row anyway. + +Signed-off-by: Peter Jones +--- + src/efivar.c | 45 ++++++++++++++++++++++++++++++--------------- + 1 file changed, 30 insertions(+), 15 deletions(-) + +diff --git a/src/efivar.c b/src/efivar.c +index 885a9af864b..8b1da8888f6 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -95,6 +95,34 @@ show_errors(void) + } + } + ++static inline void ++validate_name(const char *name) ++{ ++ if (name == NULL) { ++err: ++ warnx("Invalid variable name \"%s\"", ++ (name == NULL) ? "(null)" : name); ++ show_errors(); ++ exit(1); ++ } ++ if (name[0] == '{') { ++ const char *next = strchr(name+1, '}'); ++ if (!next) ++ goto err; ++ if (next[1] != '-') ++ goto err; ++ if (next[2] == '\000') ++ goto err; ++ } else { ++ if (strlen(name) < 38) ++ goto err; ++ if (name[8] != '-' || name[13] != '-' || ++ name[18] != '-' || name[23] != '-' || ++ name[36] != '-') ++ goto err; ++ } ++} ++ + static void + list_all_variables(void) + { +@@ -124,6 +152,8 @@ parse_name(const char *guid_name, char **name, efi_guid_t *guid) + + const char *left, *right; + ++ validate_name(guid_name); ++ + left = strchr(guid_name, '{'); + right = strchr(guid_name, '}'); + if (left && right) { +@@ -408,16 +438,6 @@ edit_variable(const char *guid_name, void *data, size_t data_size, + } + } + +-static void +-validate_name(const char *name) +-{ +- if (name == NULL) { +- fprintf(stderr, "Invalid variable name\n"); +- show_errors(); +- exit(1); +- } +-} +- + static void + prepare_data(const char *filename, uint8_t **data, size_t *data_size) + { +@@ -588,21 +608,17 @@ int main(int argc, char *argv[]) + list_all_variables(); + break; + case ACTION_PRINT: +- validate_name(guid_name); + show_variable(guid_name, SHOW_VERBOSE); + break; + case ACTION_PRINT_DEC | ACTION_PRINT: +- validate_name(guid_name); + show_variable(guid_name, SHOW_DECIMAL); + break; + case ACTION_APPEND | ACTION_PRINT: +- validate_name(guid_name); + prepare_data(infile, &data, &data_size); + edit_variable(guid_name, data, data_size, attributes, + EDIT_APPEND); + break; + case ACTION_WRITE | ACTION_PRINT: +- validate_name(guid_name); + prepare_data(infile, &data, &data_size); + edit_variable(guid_name, data, data_size, attributes, + EDIT_WRITE); +@@ -653,7 +669,6 @@ int main(int argc, char *argv[]) + + efi_variable_free(var, false); + } else { +- validate_name(guid_name); + save_variable(guid_name, outfile, dmpstore); + } + break; +-- +2.24.1 + diff --git a/SOURCES/0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch b/SOURCES/0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch new file mode 100644 index 0000000..c176e2b --- /dev/null +++ b/SOURCES/0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch @@ -0,0 +1,37 @@ +From 81346196bb262156fd436c78323d161af61dd6c1 Mon Sep 17 00:00:00 2001 +From: Dmitry Torokhov +Date: Tue, 6 Aug 2019 09:22:25 -0700 +Subject: [PATCH 40/86] Make sure makeguids helper is compiled for the host's + arch + +Currently makeguids is compiled with the same flags/settings as the rest +of the package, which does not work in case of cross-compiles when arch +of the build host and the target host are different. Let's force +compiling for the native host arch to avoid this issue. + +Note that this is not a full cross-compile solution as this does not +account for potential differences in host/target compilers (versions, +clang vs gcc, etc), but it removes one of the issue with package build +aborting due to invalid instruction on the host. + +Signed-off-by: Dmitry Torokhov +--- + src/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/Makefile b/src/Makefile +index addfaa03c85..3729d2b8f35 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -52,7 +52,7 @@ include/efivar/efivar-guids.h : makeguids guids.txt + ./makeguids guids.txt guids.bin names.bin \ + guid-symbols.c include/efivar/efivar-guids.h + +-makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT ++makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT -march=native + makeguids : LIBS=dl + makeguids : $(MAKEGUIDS_SOURCES) + makeguids : CCLD=$(CCLD_FOR_BUILD) +-- +2.24.1 + diff --git a/SOURCES/0041-Makefile-sort-wildcard-output-for-reproducibility.patch b/SOURCES/0041-Makefile-sort-wildcard-output-for-reproducibility.patch new file mode 100644 index 0000000..89268ac --- /dev/null +++ b/SOURCES/0041-Makefile-sort-wildcard-output-for-reproducibility.patch @@ -0,0 +1,49 @@ +From 641a1626543ca3bf0cdd5ea0bd6cc3a82462521a Mon Sep 17 00:00:00 2001 +From: Pierre Bourdon +Date: Tue, 13 Aug 2019 05:08:20 +0200 +Subject: [PATCH 41/86] Makefile: sort $(wildcard) output for reproducibility + +https://reproducible-builds.org/docs/stable-inputs/ + +This should fix reproducibility issues noticed on Debian[1] and NixOS[2] + +[1] https://tests.reproducible-builds.org/debian/rb-pkg/buster/i386/diffoscope-results/efivar.html +[2] https://r13y.com/diff/b32a9d1c4159dab6aa15e873c0e5fc315ea2bdf545416d21d5b4a29f3c138727-3473019ee52f59732b13253b828bf2eb545384510f30db34413eb6c91dd3d047.html +--- + src/Makefile | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index 3729d2b8f35..253d1f1d56c 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -15,7 +15,7 @@ TARGETS=$(LIBTARGETS) $(BINTARGETS) $(PCTARGETS) + STATICTARGETS=$(STATICLIBTARGETS) $(STATICBINTARGETS) + + LIBEFIBOOT_SOURCES = crc32.c creator.c disk.c gpt.c loadopt.c path-helpers.c \ +- linux.c $(wildcard linux-*.c) ++ linux.c $(sort $(wildcard linux-*.c)) + LIBEFIBOOT_OBJECTS = $(patsubst %.c,%.o,$(LIBEFIBOOT_SOURCES)) + LIBEFIVAR_SOURCES = crc32.c dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \ + efivarfs.c error.c export.c guid.c guids.S guid-symbols.c \ +@@ -25,7 +25,7 @@ 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) ++ $(sort $(wildcard include/efivar/*.h)) $(GENERATED_SOURCES) $(EFIVAR_SOURCES) + + $(call deps-of,$(ALL_SOURCES)) : | deps + -include $(call deps-of,$(ALL_SOURCES)) +@@ -103,7 +103,7 @@ install : all + $(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));) ++ $(foreach x, $(sort $(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);) + +-- +2.24.1 + diff --git a/SOURCES/0042-guids.txt-correct-sentinal-typo.patch b/SOURCES/0042-guids.txt-correct-sentinal-typo.patch new file mode 100644 index 0000000..2992141 --- /dev/null +++ b/SOURCES/0042-guids.txt-correct-sentinal-typo.patch @@ -0,0 +1,22 @@ +From d45b4193d98e7d8416dc7fd33637b9cbfcb4696a Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 29 Aug 2019 10:39:39 +0100 +Subject: [PATCH 42/86] guids.txt: correct "sentinal" typo + +--- + src/guids.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/guids.txt b/src/guids.txt +index 2486255b26c..f2f0282b3be 100644 +--- a/src/guids.txt ++++ b/src/guids.txt +@@ -1,4 +1,4 @@ +-00000000-0000-0000-0000-000000000000 zero zeroed sentinal guid ++00000000-0000-0000-0000-000000000000 zero zeroed sentinel guid + 093e0fae-a6c4-4f50-9f1b-d41e2b89c19a sha512 SHA-512 + 0abba7dc-e516-4167-bbf5-4d9d1c739416 fwupdate Linux Firmware Update Tool + 0b6e5233-a65c-44c9-9407-d9ab83bfc8bd sha224 SHA-224 +-- +2.24.1 + diff --git a/SOURCES/0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch b/SOURCES/0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch new file mode 100644 index 0000000..1cb2dc3 --- /dev/null +++ b/SOURCES/0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch @@ -0,0 +1,73 @@ +From 1c23cc5e02bfd9be78a9e7f49bf2d8756a7942ce Mon Sep 17 00:00:00 2001 +From: Robert Bisewski +Date: Wed, 25 Sep 2019 15:38:02 -0500 +Subject: [PATCH 43/86] update manpage for efivar such that it reflects the + current options of the efivar util + +--- + docs/efivar.1 | 30 ++++++++++++++++++++++-------- + 1 file changed, 22 insertions(+), 8 deletions(-) + +diff --git a/docs/efivar.1 b/docs/efivar.1 +index e4c84bb1fe8..6a3036f5dcd 100644 +--- a/docs/efivar.1 ++++ b/docs/efivar.1 +@@ -1,5 +1,4 @@ +-.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.45.1. +-.TH EFIVAR "1" "June 2014" "efivar 0.10" "User Commands" ++.TH EFIVAR "1" "September 2019" "efivar 37" "User Commands" + .SH NAME + efivar \- Tool to manipulate UEFI variables + .SH SYNOPSIS +@@ -7,8 +6,8 @@ efivar \- Tool to manipulate UEFI variables + [\fI\,OPTION\/\fR...] + .SH DESCRIPTION + .TP +-\fB\-L\fR, \fB\-\-list\-guids\fR +-list guids efivar knows about ++\fB\-t\fR, \fB\-\-attributes=\fR ++attributes to use on append + .TP + \fB\-l\fR, \fB\-\-list\fR + list current variables +@@ -16,6 +15,12 @@ list current variables + \fB\-p\fR, \fB\-\-print\fR + print variable specified by \fB\-\-name\fR + .TP ++\fB\-D\fR, \fB\-\-dmpstore\fR ++use DMPSTORE format when exporting ++.TP ++\fB\-d\fR, \fB\-\-print\-decimal\fR ++print variable in decimal format values specified by \fB\-\-name\fR ++.TP + \fB\-n\fR, \fB\-\-name=\fR + variable to manipulate, in the form + 8be4df61\-93ca\-11d2\-aa0d\-00e098032b8c\-Boot0000 +@@ -23,11 +28,20 @@ variable to manipulate, in the form + \fB\-a\fR, \fB\-\-append\fR + append to variable specified by \fB\-\-name\fR + .TP +-\fB\-f\fR, \fB\-\-fromfile=\fR +-use data from ++\fB\-f\fR, \fB\-\-datafile=\fR ++load or save variable contents from + .TP +-\fB\-t\fR, \fB\-\-attributes=\fR +-attributes to use on append ++\fB\-e\fR, \fB\-\-export=\fR ++export variable to ++.TP ++\fB\-i\fR, \fB\-\-import=\fR ++import variable from ++.TP ++\fB\-L\fR, \fB\-\-list\-guids\fR ++show internal guid list ++.TP ++\fB\-w\fR, \fB\-\-write\fR ++write to variable specified by \fB\-\-name\fR + .SS "Help options:" + .TP + \-?, \fB\-\-help\fR +-- +2.24.1 + diff --git a/SOURCES/0044-Fix-some-32-bit-size_t-format-specifier-errors.patch b/SOURCES/0044-Fix-some-32-bit-size_t-format-specifier-errors.patch new file mode 100644 index 0000000..fe50e6a --- /dev/null +++ b/SOURCES/0044-Fix-some-32-bit-size_t-format-specifier-errors.patch @@ -0,0 +1,53 @@ +From ee045255da9c047aa170cde78a1749723138bb68 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 10:44:53 -0400 +Subject: [PATCH 44/86] Fix some 32-bit size_t format specifier errors + +Signed-off-by: Peter Jones +--- + src/export.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/export.c b/src/export.c +index cfb021525ff..732b4bf30ad 100644 +--- a/src/export.c ++++ b/src/export.c +@@ -149,7 +149,7 @@ overflow: + } + + crc = efi_crc32(data, size - sizeof(uint32_t)); +- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32", expected 0x%"PRIx32, ++ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32", expected 0x%"PRIx32, + data, size - sizeof(uint32_t), crc, + *(uint32_t*)(data + size - sizeof(uint32_t))); + +@@ -282,7 +282,7 @@ efi_variable_import_efivar(uint8_t *data, size_t datasz, efi_variable_t **var_ou + } + + crc = efi_crc32(data, datasz - sizeof(uint32_t)); +- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32", expected 0x%"PRIx32, ++ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32", expected 0x%"PRIx32, + data, datasz - sizeof(uint32_t), crc, + *(uint32_t*)(data + datasz - sizeof(uint32_t))); + +@@ -473,7 +473,7 @@ overflow: + ptr += var->data_size; + + crc = efi_crc32(data, needed - sizeof(uint32_t)); +- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32, ++ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32, + data, needed - sizeof(uint32_t), crc); + *(uint32_t *)ptr = crc; + +@@ -611,7 +611,7 @@ overflow: + ptr += var->data_size; + + crc = efi_crc32(data, needed - sizeof(uint32_t)); +- debug("efi_crc32(%p, %lu) -> 0x%"PRIx32, ++ debug("efi_crc32(%p, %zu) -> 0x%"PRIx32, + data, needed - sizeof(uint32_t), crc); + *(uint32_t *)ptr = crc; + +-- +2.24.1 + diff --git a/SOURCES/0045-Make-the-top-level-makefile-not-parallelize.patch b/SOURCES/0045-Make-the-top-level-makefile-not-parallelize.patch new file mode 100644 index 0000000..5971fc0 --- /dev/null +++ b/SOURCES/0045-Make-the-top-level-makefile-not-parallelize.patch @@ -0,0 +1,34 @@ +From f27c2a9e2602b54066e8d557e1cee3aabfd0ec38 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 10:52:12 -0400 +Subject: [PATCH 45/86] Make the top level makefile not parallelize. + +Right now if you run: + + make + make -j9 clean all + +"clean" and "all" will run in parallel, and "all" will often finish +before "clean" will. This is obviously wrong. + +This patch adds .NOTPARALLEL: at the top level, so none of the top-level +targets will parallelize, because we really never want that. + +Signed-off-by: Peter Jones +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 2d134ea9d6f..61b79a60369 100644 +--- a/Makefile ++++ b/Makefile +@@ -83,4 +83,4 @@ archive: abicheck bumpver abidw tag efivar.spec + @rm -rf /tmp/efivar-$(GITTAG) + @echo "The archive is in efivar-$(GITTAG).tar.bz2" + +- ++.NOTPARALLEL: +-- +2.24.1 + diff --git a/SOURCES/0046-guids-add-auto_created_boot_option.patch b/SOURCES/0046-guids-add-auto_created_boot_option.patch new file mode 100644 index 0000000..8c4eae4 --- /dev/null +++ b/SOURCES/0046-guids-add-auto_created_boot_option.patch @@ -0,0 +1,25 @@ +From b33e00224121e81a46c8cac9d685a3317d764236 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 14:30:42 -0400 +Subject: [PATCH 46/86] guids: add auto_created_boot_option + +Signed-off-by: Peter Jones +--- + src/guids.txt | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/guids.txt b/src/guids.txt +index f2f0282b3be..95d93c0df74 100644 +--- a/src/guids.txt ++++ b/src/guids.txt +@@ -18,6 +18,7 @@ + 721c8b66-426c-4e86-8e99-3457c46ab0b9 lenovo_setup Lenovo Firmware Setup + 77fa9abd-0359-4d32-bd60-28f4e78f784b microsoft Microsoft + 7FACC7B6-127F-4E9C-9C5D-080F98994345 lenovo_2 Lenovo ++8108ac4e-9f11-4d59-850e-e21a522c59b2 auto_created_boot_option Automatically Created Boot Option + 826ca512-cf10-4ac9-b187-be01496631bd sha1 SHA-1 + 82988420-7467-4490-9059-feb448dd1963 lenovo_me_config Lenovo ME Configuration Menu + 8be4df61-93ca-11d2-aa0d-00e098032b8c global EFI Global Variable +-- +2.24.1 + diff --git a/SOURCES/0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch b/SOURCES/0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch new file mode 100644 index 0000000..b3c9f61 --- /dev/null +++ b/SOURCES/0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch @@ -0,0 +1,260 @@ +From 3ba12ff9ba5ebcb55c1e3a8c720e265fa05888b2 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 13:52:22 -0400 +Subject: [PATCH 47/86] Move our infrastructure makefiles out of the topdir. + +No sense in leaving all this cluttering up what's usually my working +directory... + +Signed-off-by: Peter Jones +--- + Makefile | 22 ++++++++++---------- + docs/Makefile | 11 +++++----- + src/Android.mk | 2 +- + src/Makefile | 11 +++++----- + Make.coverity => src/include/coverity.mk | 0 + Make.defaults => src/include/defaults.mk | 2 +- + Make.deprecated => src/include/deprecated.mk | 0 + src/{Make.deps => include/deps.mk} | 7 +++---- + gcc.specs => src/include/gcc.specs | 0 + Make.rules => src/include/rules.mk | 2 +- + Make.scan-build => src/include/scan-build.mk | 0 + Make.version => src/include/version.mk | 0 + src/test/Makefile | 7 +++---- + tests/Makefile | 3 +-- + 14 files changed, 31 insertions(+), 36 deletions(-) + rename Make.coverity => src/include/coverity.mk (100%) + rename Make.defaults => src/include/defaults.mk (97%) + rename Make.deprecated => src/include/deprecated.mk (100%) + rename src/{Make.deps => include/deps.mk} (65%) + rename gcc.specs => src/include/gcc.specs (100%) + rename Make.rules => src/include/rules.mk (98%) + rename Make.scan-build => src/include/scan-build.mk (100%) + rename Make.version => src/include/version.mk (100%) + +diff --git a/Makefile b/Makefile +index 61b79a60369..7a4ac8c62e4 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,15 +1,15 @@ +-TOPDIR = $(shell echo $$PWD) ++export TOPDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) + +-include $(TOPDIR)/Make.deprecated +-include $(TOPDIR)/Make.version +-include $(TOPDIR)/Make.rules +-include $(TOPDIR)/Make.defaults +-include $(TOPDIR)/Make.coverity +-include $(TOPDIR)/Make.scan-build ++include $(TOPDIR)/src/include/deprecated.mk ++include $(TOPDIR)/src/include/version.mk ++include $(TOPDIR)/src/include/rules.mk ++include $(TOPDIR)/src/include/defaults.mk ++include $(TOPDIR)/src/include/coverity.mk ++include $(TOPDIR)/src/include/scan-build.mk + + SUBDIRS := src docs + +-all : | efivar.spec Make.version ++all : | efivar.spec src/include/version.mk + all : + @set -e ; for x in $(SUBDIRS) ; do \ + $(MAKE) -C $$x $@ ; \ +@@ -43,7 +43,7 @@ a : + + GITTAG = $(shell bash -c "echo $$(($(VERSION) + 1))") + +-efivar.spec : | Makefile Make.version ++efivar.spec : | Makefile src/include/version.mk + + clean : + @set -e ; for x in $(SUBDIRS) ; do \ +@@ -66,8 +66,8 @@ test-archive: abicheck efivar.spec + @echo "The archive is in efivar-$(GITTAG).tar.bz2" + + bumpver : +- @echo VERSION=$(GITTAG) > Make.version +- @git add Make.version ++ @echo VERSION=$(GITTAG) > src/include/version.mk ++ @git add src/include/version.mk + git commit -m "Bump version to $(GITTAG)" -s + + tag: +diff --git a/docs/Makefile b/docs/Makefile +index 0f610d9d9a9..2f6fc89b694 100644 +--- a/docs/Makefile ++++ b/docs/Makefile +@@ -1,10 +1,9 @@ + SRCDIR = $(realpath .) +-TOPDIR = $(realpath ..) + +-include $(TOPDIR)/Make.deprecated +-include $(TOPDIR)/Make.version +-include $(TOPDIR)/Make.rules +-include $(TOPDIR)/Make.defaults ++include $(TOPDIR)/src/include/deprecated.mk ++include $(TOPDIR)/src/include/version.mk ++include $(TOPDIR)/src/include/rules.mk ++include $(TOPDIR)/src/include/defaults.mk + + MAN1TARGETS = efivar.1 + MAN3TARGETS = efi_append_variable.3 \ +@@ -51,4 +50,4 @@ install : + + .PHONY: all clean install + +-include $(TOPDIR)/Make.rules ++include $(TOPDIR)/src/include/rules.mk +diff --git a/src/Android.mk b/src/Android.mk +index bf6cfb2e91b..ea6ee3f9432 100644 +--- a/src/Android.mk ++++ b/src/Android.mk +@@ -46,7 +46,7 @@ LIBEFIVAR_SOURCES := \ + lib.c \ + vars.c + +-include $(LOCAL_PATH)/../Make.version ++include $(LOCAL_PATH)/../version.mk + + LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) + LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION) +diff --git a/src/Makefile b/src/Makefile +index 253d1f1d56c..e5f10d4c7bf 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -1,10 +1,9 @@ + SRCDIR = $(realpath .) +-TOPDIR = $(realpath ..) + +-include $(TOPDIR)/Make.deprecated +-include $(TOPDIR)/Make.version +-include $(TOPDIR)/Make.rules +-include $(TOPDIR)/Make.defaults ++include $(TOPDIR)/src/include/deprecated.mk ++include $(TOPDIR)/src/include/version.mk ++include $(TOPDIR)/src/include/rules.mk ++include $(TOPDIR)/src/include/defaults.mk + + LIBTARGETS=libefivar.so libefiboot.so + STATICLIBTARGETS=libefivar.a libefiboot.a +@@ -84,7 +83,7 @@ libefiboot.so : LIBS=efivar + libefiboot.so : MAP=libefiboot.map + + deps : $(ALL_SOURCES) +- @$(MAKE) -f $(SRCDIR)/Make.deps deps SOURCES="$(ALL_SOURCES)" ++ @$(MAKE) -f $(SRCDIR)/include/deps.mk deps SOURCES="$(ALL_SOURCES)" + + clean : + @rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \ +diff --git a/Make.coverity b/src/include/coverity.mk +similarity index 100% +rename from Make.coverity +rename to src/include/coverity.mk +diff --git a/Make.defaults b/src/include/defaults.mk +similarity index 97% +rename from Make.defaults +rename to src/include/defaults.mk +index 36e922f5ba7..7290187ceba 100644 +--- a/Make.defaults ++++ b/src/include/defaults.mk +@@ -34,7 +34,7 @@ CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION) + clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \ + -funsigned-char -Wall -Wno-nonnull-compare \ + -Werror -Wno-error=cpp +-gcc_cflags = -specs=$(TOPDIR)/gcc.specs ++gcc_cflags = -specs=$(TOPDIR)/src/include/gcc.specs + cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \ + $(if $(findstring clang,$(CC)),$(clang_cflags),) \ + $(if $(findstring ccc-analyzer,$(CC)),$(clang_cflags),) \ +diff --git a/Make.deprecated b/src/include/deprecated.mk +similarity index 100% +rename from Make.deprecated +rename to src/include/deprecated.mk +diff --git a/src/Make.deps b/src/include/deps.mk +similarity index 65% +rename from src/Make.deps +rename to src/include/deps.mk +index c3df9e46559..a797d1bdbf5 100644 +--- a/src/Make.deps ++++ b/src/include/deps.mk +@@ -1,11 +1,10 @@ + SRCDIR = $(realpath .) +-TOPDIR = $(realpath ..) + + all : deps + +-include $(TOPDIR)/Make.version +-include $(TOPDIR)/Make.rules +-include $(TOPDIR)/Make.defaults ++include $(TOPDIR)/src/include/version.mk ++include $(TOPDIR)/src/include/rules.mk ++include $(TOPDIR)/src/include/defaults.mk + + .%.d : %.c + $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^ +diff --git a/gcc.specs b/src/include/gcc.specs +similarity index 100% +rename from gcc.specs +rename to src/include/gcc.specs +diff --git a/Make.rules b/src/include/rules.mk +similarity index 98% +rename from Make.rules +rename to src/include/rules.mk +index 042585b533c..1783dda573b 100644 +--- a/Make.rules ++++ b/src/include/rules.mk +@@ -2,7 +2,7 @@ default : all + + .PHONY: default all clean install test + +-include $(TOPDIR)/Make.version ++include $(TOPDIR)/src/include/version.mk + + %.a : + $(AR) -cvqs $@ $^ +diff --git a/Make.scan-build b/src/include/scan-build.mk +similarity index 100% +rename from Make.scan-build +rename to src/include/scan-build.mk +diff --git a/Make.version b/src/include/version.mk +similarity index 100% +rename from Make.version +rename to src/include/version.mk +diff --git a/src/test/Makefile b/src/test/Makefile +index 4c2a18f8426..df16c7a5f3b 100644 +--- a/src/test/Makefile ++++ b/src/test/Makefile +@@ -1,8 +1,7 @@ + SRCDIR = $(realpath .) +-TOPDIR = $(realpath $(SRCDIR)/../..) + +-include $(TOPDIR)/Make.defaults +-include $(TOPDIR)/Make.version ++include $(TOPDIR)/src/include/defaults.mk ++include $(TOPDIR)/src/include/version.mk + + ccldflags += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/ + LIBS=efivar +@@ -22,4 +21,4 @@ tester :: tester.o + + .PHONY: all clean install test + +-include $(TOPDIR)/Make.rules ++include $(TOPDIR)/src/include/rules.mk +diff --git a/tests/Makefile b/tests/Makefile +index 5e0c604e355..6f233d53fd1 100644 +--- a/tests/Makefile ++++ b/tests/Makefile +@@ -6,8 +6,7 @@ + all: clean test0 test1 test2 test3 test4 + + GRUB_PREFIX ?= grub2 +-TOPDIR ?= .. +-EFIVAR ?= ../src/efivar ++EFIVAR ?= $(TOPDIR)/src/efivar + + clean: + @rm -f *.result.env *.result.var +-- +2.24.1 + diff --git a/SOURCES/0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch b/SOURCES/0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch new file mode 100644 index 0000000..4f0fd4b --- /dev/null +++ b/SOURCES/0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch @@ -0,0 +1,33 @@ +From 53e10dd9a55f6c5db0fec2ea44f176e3f013e233 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 13:52:46 -0400 +Subject: [PATCH 48/86] Make CC_FOR_BUILD and CCLD_FOR_BUILD override + HOSTCC/HOSTCCLD + +--- + src/include/deprecated.mk | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/src/include/deprecated.mk b/src/include/deprecated.mk +index a31b080dbf6..00abc8c8226 100644 +--- a/src/include/deprecated.mk ++++ b/src/include/deprecated.mk +@@ -38,5 +38,15 @@ ifneq ($(origin bindir),undefined) + override BINDIR = $(bindir) + endif + endif ++ifneq ($(origin CC_FOR_BUILD),undefined) ++ ifeq ($(origin HOSTCC),file) ++ override HOSTCC = $(CC_FOR_BUILD) ++ endif ++endif ++ifneq ($(origin CCLD_FOR_BUILD),undefined) ++ ifeq ($(origin HOSTCCLD),file) ++ override HOSTCCLD = $(CCLD_FOR_BUILD) ++ endif ++endif + + # vim:ft=make +-- +2.24.1 + diff --git a/SOURCES/0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch b/SOURCES/0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch new file mode 100644 index 0000000..1533cf7 --- /dev/null +++ b/SOURCES/0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch @@ -0,0 +1,299 @@ +From 998f617cec92d526e1fadb745673ceef63fa1483 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 15:45:10 -0400 +Subject: [PATCH 49/86] Rework some makefile bits to make overriding some + options simpler. + +This reworks a lot of defaults.mk to make some variables more regularly +partially overridden on the command line, making e.g. suppression of +-Werror easier when warranted. It also makes having per-compiler +versions of each thing simpler. + +The following variables can be overridden, though in some cases only +partially: + +name kind of things in it +COMPILER gcc +CROSS_COMPILE arm-linux-gnu- +CC $(CROSS_COMPILE)$(COMPILER) +DEBUGINFO -g +OPTIMIZE -O2 -flto +WARNINGS -Wfoo -Wno-bar +ERRORS -Werror -Wno-error=cpp +CPPFLAGS -D and -I +CFLAGS $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS) +LDFLAGS linker options (add-only) +CCLDFLAGS -Wl, prefixed linker options (add-only and it's + normally machine generated from LDFLAGS +HOSTCC $(COMPILER) +HOST_CPPFLAGS $(CPPFLAGS) (add-only) +HOST_CFLAGS $(CFLAGS) (add-only) +HOST_CCLDFLAGS $(CCLDFLAGS) (add-only) + +This resolves issue #31 + +Signed-off-by: Peter Jones +--- + src/Makefile | 5 ++- + src/include/defaults.mk | 83 +++++++++++++++++++++++++++-------------- + src/include/gcc.specs | 11 +----- + src/include/rules.mk | 51 +++++++++++++------------ + src/test/Makefile | 2 +- + 5 files changed, 87 insertions(+), 65 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index e5f10d4c7bf..1d0e217c89b 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -51,10 +51,11 @@ include/efivar/efivar-guids.h : makeguids guids.txt + ./makeguids guids.txt guids.bin names.bin \ + guid-symbols.c include/efivar/efivar-guids.h + +-makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT -march=native ++makeguids : CPPFLAGS=$(HOST_CPPFLAGS) + makeguids : LIBS=dl ++makeguids : CCLD=$(HOSTCCLD) ++makeguids : CFLAGS=$(HOST_CFLAGS) + makeguids : $(MAKEGUIDS_SOURCES) +-makeguids : CCLD=$(CCLD_FOR_BUILD) + + guids.o : guids.S | guids.bin names.bin + +diff --git a/src/include/defaults.mk b/src/include/defaults.mk +index 7290187ceba..df738feddea 100644 +--- a/src/include/defaults.mk ++++ b/src/include/defaults.mk +@@ -8,19 +8,63 @@ BINDIR ?= $(EXEC_PREFIX)/bin + PCDIR ?= $(LIBDIR)/pkgconfig + DESTDIR ?= + +-INSTALL ?= install + CROSS_COMPILE ?= + COMPILER ?= gcc +-PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi) +-CC_FOR_BUILD ?= cc +-CC := $(if $(filter default,$(origin CC)),$(CROSS_COMPILE)$(COMPILER),$(CC)) +-CCLD_FOR_BUILD ?= $(CC_FOR_BUILD) +-CCLD := $(if $(filter undefined,$(origin CCLD)),$(CC),$(CCLD)) ++$(call set-if-undefined,CC,$(CROSS_COMPILE)$(COMPILER)) ++$(call set-if-undefined,CCLD,$(CC)) ++$(call set-if-undefined,HOSTCC,$(COMPILER)) ++$(call set-if-undefined,HOSTCCLD,$(HOSTCC)) ++ + OPTIMIZE ?= -O2 -flto +-CFLAGS ?= $(OPTIMIZE) -g3 +-CFLAGS := $(CFLAGS) ++DEBUGINFO ?= -g3 ++WARNINGS_GCC ?= -Wmaybe-uninitialized \ ++ -Wno-nonnull-compare ++WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC) ++WARNINGS ?= -Wall -Wextra \ ++ -Wno-address-of-packed-member \ ++ $(call family,WARNINGS) ++ERRORS ?= -Werror -Wno-error=cpp $(call family,ERRORS) ++CPPFLAGS ?= ++override _CPPFLAGS := $(CPPFLAGS) ++override CPPFLAGS = $(_CPPFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) \ ++ -D_GNU_SOURCE \ ++ -I$(TOPDIR)/src/include/ ++CFLAGS ?= $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS) ++CFLAGS_GCC ?= -specs=$(TOPDIR)/src/include/gcc.specs \ ++ -fno-merge-constants ++override _CFLAGS := $(CFLAGS) ++override CFLAGS = $(_CFLAGS) \ ++ -std=gnu11 \ ++ -funsigned-char \ ++ -fvisibility=hidden \ ++ $(call family,CFLAGS) \ ++ $(call pkg-config-cflags) ++LDFLAGS_CLANG ?= --fatal-warnings -pie -z relro + LDFLAGS ?= +-LDFLAGS := $(LDFLAGS) ++override _LDFLAGS := $(LDFLAGS) ++override LDFLAGS = $(_LDFLAGS) \ ++ --add-needed \ ++ --build-id \ ++ --no-allow-shlib-undefined \ ++ --no-undefined-version \ ++ -z now \ ++ -z muldefs \ ++ $(call family,LDFLAGS) ++CCLDFLAGS ?= ++override _CCLDFLAGS := $(CCLDFLAGS) ++override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \ ++ $(call add-prefix,-Wl,$(LDFLAGS)) \ ++ $(call pkg-config-ccldflags) ++HOST_CPPFLAGS ?= $(CPPFLAGS) ++override _HOST_CPPFLAGS := $(HOST_CPPFLAGS) ++override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \ ++ -DEFIVAR_BUILD_ENVIRONMENT -march=native ++HOST_CFLAGS ?= $(CFLAGS) ++override _HOST_CFLAGS := $(HOST_CFLAGS) ++override HOST_CFLAGS = $(_HOST_CFLAGS) ++ ++PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi) ++INSTALL ?= install + AR := $(CROSS_COMPILE)$(COMPILER)-ar + NM := $(CROSS_COMPILE)$(COMPILER)-nm + RANLIB := $(CROSS_COMPILE)$(COMPILER)-ranlib +@@ -29,26 +73,7 @@ ABIDIFF := abidiff + + PKGS = + +-CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION) +- +-clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \ +- -funsigned-char -Wall -Wno-nonnull-compare \ +- -Werror -Wno-error=cpp +-gcc_cflags = -specs=$(TOPDIR)/src/include/gcc.specs +-cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \ +- $(if $(findstring clang,$(CC)),$(clang_cflags),) \ +- $(if $(findstring ccc-analyzer,$(CC)),$(clang_cflags),) \ +- $(if $(findstring gcc,$(CC)),$(gcc_cflags),) \ +- $(call pkg-config-cflags) +-clang_ccldflags = +-gcc_ccldflags = +-ccldflags = $(cflags) -L. $(CCLDFLAGS) $(LDFLAGS) \ +- -Wl,-z,muldefs \ +- $(if $(findstring clang,$(CCLD)),$(clang_ccldflags),) \ +- $(if $(findstring ccc-analyzer,$(CCLD)),$(clang_ccldflags),) \ +- $(if $(findstring gcc,$(CCLD)),$(gcc_ccldflags),) \ +- $(call pkg-config-ldflags) +-SOFLAGS=-shared ++SOFLAGS=-shared $(call family,SOFLAGS) + LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs) + + COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master) +diff --git a/src/include/gcc.specs b/src/include/gcc.specs +index 9d2b145ee6e..ef28e2bb51a 100644 +--- a/src/include/gcc.specs ++++ b/src/include/gcc.specs +@@ -1,14 +1,5 @@ +-*cpp: +-+ -D_GNU_SOURCE +- +-*efivar_cpp_options: +- -Wall -Wno-nonnull-compare -Werror -Wno-error=cpp -std=gnu11 -Wextra -funsigned-char +- +-*cpp_options: +-+ %(efivar_cpp_options) +- + *cc1_options: +-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -funsigned-char -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches +++ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches + + *self_spec: + + %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches +diff --git a/src/include/rules.mk b/src/include/rules.mk +index 1783dda573b..ff0ff4ef61b 100644 +--- a/src/include/rules.mk ++++ b/src/include/rules.mk +@@ -4,20 +4,32 @@ default : all + + include $(TOPDIR)/src/include/version.mk + ++comma:= , ++empty:= ++space:= $(empty) $(empty) ++ ++set-if-undefined = $(call eval,$(1) := $(if $(filter default undefined,$(origin $(1))),$(2),$($(1)))) ++add-prefix = $(subst $(space),$(empty),$(1)$(foreach x,$(2),$(comma)$(x))) ++ ++FAMILY_SUFFIXES = $(if $(findstring clang,$(CC)),CLANG,) \ ++ $(if $(findstring ccc-analyzer,$(CC)),CCC_ANALYZER,) \ ++ $(if $(findstring gcc,$(CC)),GCC,) ++family = $(foreach FAMILY_SUFFIX,$(FAMILY_SUFFIXES),$($(1)_$(FAMILY_SUFFIX))) ++ + %.a : + $(AR) -cvqs $@ $^ + + % : %.c + + % : %.c +- $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS) ++ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS) + +-%-static : ccldflags+=-static ++%-static : CCLDFLAGS+=-static + %-static : %.c +- $(CCLD) $(ccldflags) $(CPPFLAGS) -o $@ $^ $(LDLIBS) ++ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS) + + %.so : +- $(CCLD) $(ccldflags) $(CPPFLAGS) $(SOFLAGS) \ ++ $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \ + -Wl,-soname,$@.1 \ + -Wl,--version-script=$(MAP) \ + -o $@ $^ $(LDLIBS) +@@ -35,22 +47,22 @@ include $(TOPDIR)/src/include/version.mk + $< + + %.o : %.c +- $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) ++ $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) + + %.static.o : %.c +- $(CC) $(cflags) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) ++ $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) + + %.o : %.S +- $(CC) $(cflags) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.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,$^) ++ $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) + + %.S: %.c +- $(CC) $(cflags) $(CPPFLAGS) -S $< -o $@ ++ $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ + + %.E: %.c +- $(CC) $(cflags) $(CPPFLAGS) -E $< -o $@ ++ $(CC) $(CFLAGS) $(CPPFLAGS) -E $< -o $@ + + %.c : %.h + +@@ -71,20 +83,13 @@ endef + %.map : %.map.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) ++pkg-config-cflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --cflags $(PKGS))) ++pkg-config-ccldflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-L --libs-only-other $(PKGS))) ++pkg-config-ldlibs = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-l $(PKGS))) + +-define deps-of +- $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \ +- $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src))) +-endef ++deps-of = $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \ ++ $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src))) + +-define get-config +-$(shell git config --local --get "efivar.$(1)") +-endef ++get-config = $(shell git config --local --get "efivar.$(1)") + + # vim:ft=make +diff --git a/src/test/Makefile b/src/test/Makefile +index df16c7a5f3b..7a2aa496b48 100644 +--- a/src/test/Makefile ++++ b/src/test/Makefile +@@ -3,7 +3,7 @@ SRCDIR = $(realpath .) + include $(TOPDIR)/src/include/defaults.mk + include $(TOPDIR)/src/include/version.mk + +-ccldflags += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/ ++CCLDFLAGS += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/ + LIBS=efivar + + all : tester +-- +2.24.1 + diff --git a/SOURCES/0050-Make-add-Wno-missing-field-initializers.patch b/SOURCES/0050-Make-add-Wno-missing-field-initializers.patch new file mode 100644 index 0000000..53cd058 --- /dev/null +++ b/SOURCES/0050-Make-add-Wno-missing-field-initializers.patch @@ -0,0 +1,55 @@ +From 9b8213eee6889e859edc73569d3076e6a574b197 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:49:54 -0400 +Subject: [PATCH 50/86] Make: add -Wno-missing-field-initializers +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Ritchie wrote in '84: + + If there are fewer initializers in the list than there are members of + the aggregate, then the aggregate is padded with 0's. + +c99 §6.7.8 and c11 §6.7.9 each say: + + 10 If an object that has automatic storage duration is not initialized + explicitly, its value is indeterminate. If an object that has static + storage duration is not initialized explicitly, then: + — if it has pointer type, it is initialized to a null pointer; + — if it has arithmetic type, it is initialized to (positive or + unsigned) zero; + — if it is an aggregate, every member is initialized (recursively) + according to these rules; + — if it is a union, the first named member is initialized + (recursively) according to these rules. +... + 21 If there are fewer initializers in a brace-enclosed list than there + are elements or members of an aggregate, or fewer characters in a + string literal used to initialize an array of known size than there + are elements in the array, the remainder of the aggregate shall be + initialized implicitly the same as objects that have static storage + duration. + +This warning is thoroughly pointless. + +Signed-off-by: Peter Jones +--- + src/include/defaults.mk | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/include/defaults.mk b/src/include/defaults.mk +index df738feddea..af6a41a9824 100644 +--- a/src/include/defaults.mk ++++ b/src/include/defaults.mk +@@ -22,6 +22,7 @@ WARNINGS_GCC ?= -Wmaybe-uninitialized \ + WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC) + WARNINGS ?= -Wall -Wextra \ + -Wno-address-of-packed-member \ ++ -Wno-missing-field-initializers \ + $(call family,WARNINGS) + ERRORS ?= -Werror -Wno-error=cpp $(call family,ERRORS) + CPPFLAGS ?= +-- +2.24.1 + diff --git a/SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch b/SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch new file mode 100644 index 0000000..25a7537 --- /dev/null +++ b/SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch @@ -0,0 +1,86 @@ +From fa28009b861dc9fd67ddd1a8f5372d10f3f9c663 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:27:39 -0400 +Subject: [PATCH 51/86] debug(): don't write newlines to memfd + +If we know our log will only be seen by strace, the newlines don't add +anything to the strings but clutter. + +Signed-off-by: Peter Jones +--- + src/error.c | 18 +++++++++++++++--- + 1 file changed, 15 insertions(+), 3 deletions(-) + +diff --git a/src/error.c b/src/error.c +index 083de15e984..b1a56ef629c 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2015 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2000-2001 Dell Computer Corporation + * + * This library is free software; you can redistribute it and/or +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -166,6 +167,7 @@ efi_error_pop(void) + static int efi_verbose; + static FILE *efi_errlog, *efi_dbglog; + static int efi_dbglog_fd = -1; ++static intptr_t efi_dbglog_cookie; + static int log_level; + static char efi_dbglog_buf[4096]; + +@@ -176,7 +178,7 @@ efi_set_loglevel(int level) + } + + static ssize_t +-dbglog_write(void *cookie UNUSED, const char *buf, size_t size) ++dbglog_write(void *cookie, const char *buf, size_t size) + { + FILE *log = efi_errlog ? efi_errlog : stderr; + ssize_t ret = size; +@@ -185,6 +187,11 @@ dbglog_write(void *cookie UNUSED, const char *buf, size_t size) + ret = fwrite(buf, 1, size, log); + } else if (efi_dbglog_fd >= 0) { + lseek(efi_dbglog_fd, 0, SEEK_SET); ++ if ((intptr_t)cookie != 0 && ++ (intptr_t)cookie == efi_dbglog_cookie && ++ size > 0 && ++ buf[size-1] == '\n') ++ size -= 1; + ret = write(efi_dbglog_fd, buf, size); + } + return ret; +@@ -248,6 +255,7 @@ efi_error_fini(void) + static void CONSTRUCTOR + efi_error_init(void) + { ++ ssize_t bytes; + cookie_io_functions_t io_funcs = { + .write = dbglog_write, + .seek = dbglog_seek, +@@ -258,7 +266,11 @@ efi_error_init(void) + if (efi_dbglog_fd == -1) + return; + +- efi_dbglog = fopencookie(NULL, "a", io_funcs); ++ bytes = getrandom(&efi_dbglog_cookie, sizeof(efi_dbglog_cookie), 0); ++ if (bytes < (ssize_t)sizeof(efi_dbglog_cookie)) ++ efi_dbglog_cookie = 0; ++ ++ efi_dbglog = fopencookie((void *)efi_dbglog_cookie, "a", io_funcs); + if (efi_dbglog) + setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF, + sizeof(efi_dbglog_buf)); +-- +2.24.1 + diff --git a/SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch b/SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch new file mode 100644 index 0000000..75c075e --- /dev/null +++ b/SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch @@ -0,0 +1,402 @@ +From 097ff1033c6ee258b47720d079e27350f7189bbd Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 16:59:14 -0400 +Subject: [PATCH 52/86] sysfs parsing: add some more debugging output + +This adds highlights under the things we've found when searching, like: + +linux-pci.c:66 parse_pci(): searching for 0000:00:00.0/ +linux-pci.c:69 parse_pci(): current:'0000:00:1d.4/0000:6e:00.0/nvme/nvme0/nvme0n1' rc:4 pos0:0 pos1:13 +linux-pci.c:70 parse_pci(): ^^^^^^^^^^^^^ + +Signed-off-by: Peter Jones +--- + src/linux-acpi-root.c | 5 ++++- + src/linux-emmc.c | 3 ++- + src/linux-md.c | 3 ++- + src/linux-nvme.c | 3 ++- + src/linux-pci-root.c | 4 +++- + src/linux-pci.c | 3 ++- + src/linux-pmem.c | 4 +++- + src/linux-sata.c | 6 +++++- + src/linux-scsi.c | 10 +++++++++- + src/linux-soc-root.c | 4 +++- + src/linux-virtblk.c | 3 ++- + src/util.h | 35 +++++++++++++++++++++++++++++++++++ + 12 files changed, 72 insertions(+), 11 deletions(-) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index f48d4be9ac6..8aa5c96cdb9 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -63,6 +63,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + */ + rc = sscanf(devpart, "../../devices/platform/%n", &pos); + debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ dbgmk(" ", pos); + if (rc != 0 || pos < 1) + return 0; + devpart += pos; +@@ -97,6 +98,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + + pos -= 4; + debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ dbgmk(" ", pos); + acpi_header = strndupa(devpart, pos); + if (!acpi_header) + return 0; +@@ -114,6 +116,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + } + debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", + devpart, pad0, pad1, pos, rc); ++ dbgmk(" ", pos); + + devpart += pos; + +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index 8af316a1723..bcd061cb0b2 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -58,6 +58,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + &tosser0, &tosser1, &tosser2, &slot_id, + &pos0, &tosser3, &partition, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If it isn't of that form, it's not one of our emmc devices. + */ +diff --git a/src/linux-md.c b/src/linux-md.c +index 3d5975d8195..b0809f8295a 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -51,6 +51,7 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED) + rc = sscanf(current, "md%d/%nmd%dp%d%n", + &md, &pos0, &tosser0, &part, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If it isn't of that form, it's not one of our partitioned md devices. + */ +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index e6e42c7a3fc..530259c38e6 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -62,6 +62,7 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + &tosser0, &ctrl_id, &ns_id, &pos0, + &tosser1, &tosser2, &partition, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If it isn't of that form, it's not one of our nvme devices. + */ +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index ede9321395c..def8fdaa526 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -57,6 +57,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + * ^d ^p + */ + rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos); ++ debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ dbgmk(" ", pos); + /* + * If we can't find that, it's not a PCI device. + */ +diff --git a/src/linux-pci.c b/src/linux-pci.c +index 4c715df3d6e..4e7e636c463 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -68,6 +68,7 @@ parse_pci(struct device *dev, const char *current, const char *root) + rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", + &domain, &bus, &device, &function, &pos); + debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ dbgmk(" ", pos); + if (rc != 4) + break; + devpart += pos; +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index 099ac8aef8c..a11e1644094 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -105,6 +105,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) + "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", + &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ®ion, + &btt_region_id, &btt_id, &pos); ++ debug("current:\"%s\" rc:%d pos:%d", current, rc, pos); ++ dbgmk(" ", pos); + if (rc < 8) + return 0; + +diff --git a/src/linux-sata.c b/src/linux-sata.c +index ee285d84a76..f3a921c2f79 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -162,6 +162,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + debug("searching for ata1/"); + rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ dbgmk(" ", pos); + /* + * If we don't find this one, it isn't an ata device, so return 0 not + * error. Later errors mean it is an ata device, but we can't parse +@@ -175,6 +176,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + debug("searching for host0/"); + rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ dbgmk(" ", pos); + if (rc != 1) + return -1; + current += pos; +@@ -184,6 +186,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", + &scsi_device, &scsi_target, &scsi_lun, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ dbgmk(" ", pos); + if (rc != 3) + return -1; + current += pos; +@@ -193,6 +196,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", + &tosser0, &tosser1, &tosser2, &tosser3, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ dbgmk(" ", pos); + if (rc != 4) + return -1; + current += pos; +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 90a85836b1c..21fa0b7420c 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -101,6 +101,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for host4/"); + rc = sscanf(current, "host%d/%n", scsi_host, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ dbgmk(" ", pos0); + if (rc != 1) + return -1; + sz += pos0; +@@ -118,6 +119,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0, + &tosser1, &pos0, &tosser2, &pos1); + debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc == 2 || rc == 3) { + sz += pos0; + pos0 = 0; +@@ -143,6 +145,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for expander-4:0/"); + rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ dbgmk(" ", pos0); + if (rc == 2) { + if (!remote_target_id) { + efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); +@@ -158,6 +161,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + debug("searching for port-2:0:2/"); + rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ dbgmk(" ", pos0); + if (rc != 3) { + efi_error("Couldn't parse port expander port string"); + return -1; +@@ -182,6 +186,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); + if (rc != 0 && rc != 1) + return -1; ++ dbgmk(" ", pos0, pos0+pos1); + if (remote_port_id && rc == 1) + *remote_port_id = tosser2; + if (local_port_id && rc == 0) +@@ -203,6 +208,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, + &tosser3, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ dbgmk(" ", pos0); + if (rc != 3) + return -1; + sz += pos0; +@@ -215,6 +221,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", + scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); + debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ dbgmk(" ", pos0); + if (rc != 4) + return -1; + sz += pos0; +@@ -242,6 +249,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + &dev->scsi_info.scsi_lun, + &pos); + debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); ++ dbgmk(" ", pos); + if (rc != 4) + return 0; + +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index 27633d69c97..f4191dbd323 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -49,6 +49,8 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root + rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); + if (rc != 0) + return 0; ++ debug("current:\"%s\" rc:%d pos:%d", current, rc, pos); ++ dbgmk(" ", pos); + devpart += pos; + debug("new position is \"%s\"", devpart); + +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index 891c262fe05..e376e0480e6 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -56,6 +56,7 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + debug("searching for virtio0/"); + rc = sscanf(current, "virtio%x/%n", &tosser, &pos); + debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); ++ dbgmk(" ", pos); + /* + * If we couldn't find virtioX/ then it isn't a virtio device. + */ +diff --git a/src/util.h b/src/util.h +index 3f68d812700..845989bbfe9 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -284,6 +284,40 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + u16[1] = __builtin_bswap16(u16[1]); + } + ++static inline void UNUSED ++debug_markers_(const char * const file, int line, ++ const char * const func, int level, ++ const char * const prefix, ...) ++{ ++ FILE *logfile; ++ va_list ap; ++ int pos; ++ int n = 0; ++ bool on = false; ++ ++ va_start(ap, prefix); ++ for (n = 0, pos = va_arg(ap, int); pos >= 0; pos = va_arg(ap, int), n++) ++ ; ++ va_end(ap); ++ if (n < 2) ++ return; ++ n = 0; ++ ++ efi_set_loglevel(level); ++ logfile = efi_get_logfile(); ++ fprintf(logfile, "%s:%d %s(): %s", file, line, func, prefix ? prefix : ""); ++ va_start(ap, prefix); ++ while ((pos = va_arg(ap, int)) >= 0) { ++ for (; n <= pos; n++) { ++ if (n == pos) ++ on = !on; ++ fprintf(logfile, "%c", on ? '^' : ' '); ++ } ++ } ++ fprintf(logfile, "\n"); ++ va_end(ap); ++} ++ + #define log_(file, line, func, level, fmt, args...) \ + ({ \ + efi_set_loglevel(level); \ +@@ -312,6 +346,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid) + }) + #define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size) + #define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size) ++#define dbgmk(prefix, args...) debug_markers_(__FILE__, __LINE__, __func__, LOG_DEBUG, prefix, ## args, -1) + + #endif /* EFIVAR_UTIL_H */ + +-- +2.24.1 + diff --git a/SOURCES/0053-gitignore-ignore-.strace.patch b/SOURCES/0053-gitignore-ignore-.strace.patch new file mode 100644 index 0000000..29c7f48 --- /dev/null +++ b/SOURCES/0053-gitignore-ignore-.strace.patch @@ -0,0 +1,25 @@ +From 95e98e10cbabad4bfd99787dddb12afad1cb6331 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 16 Oct 2019 10:01:00 -0400 +Subject: [PATCH 53/86] gitignore: ignore *.strace + +Signed-off-by: Peter Jones +--- + .gitignore | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/.gitignore b/.gitignore +index 947d88eec42..f61b0bcb340 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -14,6 +14,7 @@ + *.so + *.so.* + *.spec ++*.strace + *.tar.* + *.var + core.* +-- +2.24.1 + diff --git a/SOURCES/0054-Fix-the-error-path-in-set_disk_and_part_name.patch b/SOURCES/0054-Fix-the-error-path-in-set_disk_and_part_name.patch new file mode 100644 index 0000000..0c11a96 --- /dev/null +++ b/SOURCES/0054-Fix-the-error-path-in-set_disk_and_part_name.patch @@ -0,0 +1,71 @@ +From 22bc0866e941cbfe57de6522db51e9cf2c6b3ff1 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 17:01:00 -0400 +Subject: [PATCH 54/86] Fix the error path in set_disk_and_part_name() + +Signed-off-by: Peter Jones +--- + src/linux.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/src/linux.c b/src/linux.c +index 45b1ee2d96f..1f37933f546 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2015 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation + * + * This library is free software; you can redistribute it and/or +@@ -169,6 +169,8 @@ set_disk_name(struct device *dev, const char * const fmt, ...) + int HIDDEN + set_disk_and_part_name(struct device *dev) + { ++ int rc = -1; ++ + /* + * results are like such: + * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART +@@ -200,6 +202,7 @@ set_disk_and_part_name(struct device *dev) + set_disk_name(dev, "%s", penultimate); + set_part_name(dev, "%s", ultimate); + debug("disk:%s part:%s", penultimate, ultimate); ++ rc = 0; + } else if (ultimate && approximate && !strcmp(approximate, "nvme")) { + /* + * 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 +@@ -207,6 +210,7 @@ set_disk_and_part_name(struct device *dev) + set_disk_name(dev, "%s", ultimate); + set_part_name(dev, "%sp%d", ultimate, dev->part); + debug("disk:%s part:%sp%d", ultimate, ultimate, dev->part); ++ rc = 0; + } else if (ultimate && penultimate && !strcmp(penultimate, "block")) { + /* + * 253:0 -> ../../devices/virtual/block/dm-0 (... I guess) +@@ -220,15 +224,19 @@ set_disk_and_part_name(struct device *dev) + set_disk_name(dev, "%s", ultimate); + set_part_name(dev, "%s%d", ultimate, dev->part); + debug("disk:%s part:%s%d", ultimate, ultimate, dev->part); ++ rc = 0; + } else if (ultimate && approximate && !strcmp(approximate, "mtd")) { + /* + * 31:0 -> ../../devices/platform/1e000000.palmbus/1e000b00.spi/spi_master/spi32766/spi32766.0/mtd/mtd0/mtdblock0 + */ + set_disk_name(dev, "%s", ultimate); + debug("disk:%s", ultimate); ++ rc = 0; + } + +- return 0; ++ if (rc < 0) ++ efi_error("Could not parse disk name:\"%s\"", dev->link); ++ return rc; + } + + static struct dev_probe *dev_probes[] = { +-- +2.24.1 + diff --git a/SOURCES/0055-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch b/SOURCES/0055-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch new file mode 100644 index 0000000..effc7e7 --- /dev/null +++ b/SOURCES/0055-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch @@ -0,0 +1,1084 @@ +From 4718694094647b981b74453445d000b0296b6544 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:53:27 -0400 +Subject: [PATCH 55/86] sysfs parsers: make all the /sys/block link parsers + work the same way + +Apparently I wrote some of these one way and some the other, and the one +special case where everything was "current+sz" instead of some form of +"current += pos; sz += pos; ...; return sz;" or the subtraction version. + +Make them all the same, where possible. + +Signed-off-by: Peter Jones +--- + src/linux-acpi-root.c | 97 +++++++++-------- + src/linux-ata.c | 10 +- + src/linux-emmc.c | 22 ++-- + src/linux-nvme.c | 24 +++-- + src/linux-pci-root.c | 17 +-- + src/linux-pci.c | 28 +++-- + src/linux-pmem.c | 22 ++-- + src/linux-sas.c | 8 +- + src/linux-sata.c | 51 ++++----- + src/linux-scsi.c | 239 ++++++++++++++++++++++-------------------- + src/linux-soc-root.c | 20 ++-- + src/linux-virtblk.c | 15 +-- + 12 files changed, 296 insertions(+), 257 deletions(-) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 8aa5c96cdb9..9154c950bb1 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -41,17 +41,16 @@ + * ^ root hub ^pci dev ^pci dev ^ blockdev stuff + */ + static ssize_t +-parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED) ++parse_acpi_root(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + int rc; +- int pos = 0; ++ int pos0 = -1, pos1 = -1, pos2 = -1; + uint16_t pad0; + uint8_t pad1; + char *acpi_header = NULL; + char *colon; + +- const char *devpart = current; +- + debug("entry"); + + /* +@@ -61,23 +60,25 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + * This is annoying because "/%04ms%h:%hhx/" won't bind from the right + * side in sscanf. + */ +- rc = sscanf(devpart, "../../devices/platform/%n", &pos); +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- dbgmk(" ", pos); +- if (rc != 0 || pos < 1) ++ rc = sscanf(current, "../../devices/%nplatform/%n", &pos0, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ if (rc != 0 || pos0 == -1 || pos1 == -1) + return 0; +- devpart += pos; ++ current += pos1; + ++ debug("searching for an ACPI string like A0000:00 or ACPI0000:00"); ++ pos0 = 0; + /* + * If it's too short to be A0000:00, it's not an ACPI string + */ +- if (strlen(devpart) < 8) ++ if (strlen(current) < 8) + return 0; + +- colon = strchr(devpart, ':'); ++ colon = strchr(current, ':'); + if (!colon) + return 0; +- pos = colon - devpart; ++ pos1 = colon - current; + + /* + * If colon doesn't point at something between one of these: +@@ -85,61 +86,71 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + * ^ 5 ^ 8 + * Then it's not an ACPI string. + */ +- if (pos < 5 || pos > 8) ++ if (pos1 < 5 || pos1 > 8) + return 0; + +- dev->acpi_root.acpi_hid_str = strndup(devpart, pos + 1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ ++ dev->acpi_root.acpi_hid_str = strndup(current, pos1 + 1); + if (!dev->acpi_root.acpi_hid_str) { + efi_error("Could not allocate memory"); + return -1; + } +- dev->acpi_root.acpi_hid_str[pos] = 0; +- debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); ++ dev->acpi_root.acpi_hid_str[pos1] = 0; ++ debug("acpi_hid_str:'%s'", dev->acpi_root.acpi_hid_str); + +- pos -= 4; +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- dbgmk(" ", pos); +- acpi_header = strndupa(devpart, pos); ++ /* ++ * The string is like ACPI0000:00. ++ * ^^^^ ++ * Here we're saying only this bit has been parsed, though we've ++ * partially parsed up to the colon. ++ */ ++ pos1 -= 4; ++ acpi_header = strndupa(current, pos1); + if (!acpi_header) + return 0; +- acpi_header[pos] = 0; +- debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); +- devpart += pos; ++ acpi_header[pos1] = 0; ++ debug("acpi_header:'%s'", acpi_header); + + /* + * If we can't find these numbers, it's not an ACPI string + */ +- rc = sscanf(devpart, "%hx:%hhx/%n", &pad0, &pad1, &pos); ++ rc = sscanf(current+pos1, "%hx:%hhx/%n", &pad0, &pad1, &pos2); + if (rc != 2) { +- efi_error("Could not parse ACPI path \"%s\"", devpart); ++ efi_error("Could not parse ACPI path \"%s\"", current); + return 0; + } +- debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", +- devpart, pad0, pad1, pos, rc); +- dbgmk(" ", pos); +- +- devpart += pos; +- +- rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX", +- acpi_header, pad0, pad1); +- debug("rc:%d acpi_header:%s pad0:%04hX pad1:%02hhX", +- rc, acpi_header, pad0, pad1); +- if (rc < 0 && errno == ENOENT) { +- rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hx:%02hhx", +- acpi_header, pad0, pad1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d", ++ current, rc, pos0, pos1, pos2); ++ dbgmk(" ", pos0, pos2); ++ current += pos2; ++ ++ const char * const formats[] = { ++ "devices/platform/%s%04hX:%02hhX", ++ "devices/platform/%s%04hx:%02hhx", ++ NULL ++ }; ++ ++ for (unsigned int i = 0; formats[i]; i++) { ++ rc = parse_acpi_hid_uid(dev, formats[i], ++ acpi_header, pad0, pad1); + debug("rc:%d acpi_header:%s pad0:%04hx pad1:%02hhx", + rc, acpi_header, pad0, pad1); +- } +- if (rc < 0) { +- efi_error("Could not parse hid/uid"); +- return rc; ++ if (rc >= 0) ++ break; ++ if (errno != ENOENT) { ++ efi_error("Could not parse hid/uid"); ++ return rc; ++ } + } + debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"", + dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, + dev->acpi_root.acpi_uid_str, + dev->acpi_root.acpi_cid_str); + +- return devpart - current; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-ata.c b/src/linux-ata.c +index b6a7c2dcf8a..a05a2feb8b9 100644 +--- a/src/linux-ata.c ++++ b/src/linux-ata.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -58,7 +58,7 @@ is_pata(struct device *dev) + * 11:0 -> ../../devices/pci0000:00/0000:00:11.5/ata3/host2/target2:0:0/2:0:0:0/block/sr0 + */ + static ssize_t +-parse_ata(struct device *dev, const char *current, const char *root UNUSED) ++parse_ata(struct device *dev, const char *path, const char *root UNUSED) + { + uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; + uint64_t scsi_lun; +@@ -108,7 +108,7 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) + return 0; + } + +- char *host = strstr(current, "/host"); ++ char *host = strstr(path, "/host"); + if (!host) + return -1; + +@@ -125,10 +125,10 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) + dev->ata_info.scsi_target = scsi_target; + dev->ata_info.scsi_lun = scsi_lun; + +- char *block = strstr(current, "/block/"); ++ char *block = strstr(path, "/block/"); + if (!block) + return -1; +- return block + 1 - current; ++ return block + 1 - path; + } + + static ssize_t +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index bcd061cb0b2..2b8ae64f0fb 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -45,20 +46,21 @@ + */ + + static ssize_t +-parse_emmc(struct device *dev, const char *current, const char *root UNUSED) ++parse_emmc(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char * current = path; + int rc; + int32_t tosser0, tosser1, tosser2, tosser3, slot_id, partition; +- int pos0 = 0, pos1 = 0; ++ int pos0 = -1, pos1 = -1, pos2 = -1; + + debug("entry"); + + debug("searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1"); +- rc = sscanf(current, "mmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n", +- &tosser0, &tosser1, &tosser2, &slot_id, +- &pos0, &tosser3, &partition, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- dbgmk(" ", pos0, pos1); ++ rc = sscanf(current, "%nmmc_host/mmc%d/mmc%d:%d/block/mmcblk%d%n/mmcblk%dp%d%n", ++ &pos0, &tosser0, &tosser1, &tosser2, &slot_id, ++ &pos1, &tosser3, &partition, &pos2); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2); ++ dbgmk(" ", pos0, MAX(pos1,pos2)); + /* + * If it isn't of that form, it's not one of our emmc devices. + */ +@@ -72,10 +74,12 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + if (dev->part == -1) + dev->part = partition; + +- pos0 = pos1; ++ pos2 = pos1; + } ++ current += pos2; + +- return pos0; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 530259c38e6..b83c631119a 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -48,26 +49,29 @@ + */ + + static ssize_t +-parse_nvme(struct device *dev, const char *current, const char *root UNUSED) ++parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + int rc; + int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; + uint8_t *filebuf = NULL; +- int pos0 = 0, pos1 = 0; ++ int pos0 = -1, pos1 = -1, pos2 = -1; + + debug("entry"); + + debug("searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1"); +- rc = sscanf(current, "nvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", +- &tosser0, &ctrl_id, &ns_id, &pos0, +- &tosser1, &tosser2, &partition, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- dbgmk(" ", pos0, pos1); ++ rc = sscanf(current, "%nnvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", ++ &pos0, &tosser0, &ctrl_id, &ns_id, ++ &pos1, &tosser1, &tosser2, &partition, &pos2); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2); ++ dbgmk(" ", pos0, MAX(pos1,pos2)); + /* + * If it isn't of that form, it's not one of our nvme devices. + */ + if (rc != 3 && rc != 6) + return 0; ++ if (rc == 3) ++ pos2 = pos1; + + dev->nvme_info.ctrl_id = ctrl_id; + dev->nvme_info.ns_id = ns_id; +@@ -78,8 +82,9 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + if (dev->part == -1) + dev->part = partition; + +- pos0 = pos1; ++ pos1 = pos2; + } ++ current += pos1; + + /* + * now fish the eui out of sysfs is there is one... +@@ -111,7 +116,8 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + memcpy(dev->nvme_info.eui, eui, sizeof(eui)); + } + +- return pos0; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index def8fdaa526..8cd3849b1db 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -41,13 +41,13 @@ + * + */ + static ssize_t +-parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) ++parse_pci_root(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char * current = path; + int rc; +- int pos = 0; ++ int pos0 = -1, pos1 = -1; + uint16_t root_domain; + uint8_t root_bus; +- const char *devpart = current; + + debug("entry"); + +@@ -56,15 +56,15 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + * pci0000:00/ + * ^d ^p + */ +- rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos); +- debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If we can't find that, it's not a PCI device. + */ + if (rc != 2) + return 0; +- devpart += pos; ++ current += pos1; + + dev->pci_root.pci_domain = root_domain; + dev->pci_root.pci_bus = root_bus; +@@ -75,7 +75,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + return -1; + + errno = 0; +- return devpart - current; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-pci.c b/src/linux-pci.c +index 4e7e636c463..2cd450bc470 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -43,11 +43,10 @@ + * + */ + static ssize_t +-parse_pci(struct device *dev, const char *current, const char *root) ++parse_pci(struct device *dev, const char *path, const char *root) + { ++ const char *current = path; + int rc; +- int pos = 0; +- const char *devpart = current; + + debug("entry"); + +@@ -55,23 +54,22 @@ parse_pci(struct device *dev, const char *current, const char *root) + * 0000:00:01.0/0000:01:00.0/ + * ^d ^b ^d ^f (of the last one in the series) + */ +- while (*devpart) { ++ while (*current) { + uint16_t domain; + uint8_t bus, device, function; + struct pci_dev_info *pci_dev; + unsigned int i = dev->n_pci_devs; + struct stat statbuf; ++ int pos0 = -1, pos1 = -1; + +- debug("devpart is \"%s\"", devpart); +- pos = 0; + debug("searching for 0000:00:00.0/"); +- rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", +- &domain, &bus, &device, &function, &pos); +- debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%n%hx:%hhx:%hhx.%hhx/%n", ++ &pos0, &domain, &bus, &device, &function, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 4) + break; +- devpart += pos; ++ current += pos1; + + debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", + domain, bus, device, function); +@@ -88,13 +86,13 @@ parse_pci(struct device *dev, const char *current, const char *root) + dev->pci_dev[i].pci_bus = bus; + dev->pci_dev[i].pci_device = device; + dev->pci_dev[i].pci_function = function; +- char *tmp = strndup(root, devpart-root+1); ++ char *tmp = strndup(root, current-root+1); + char *linkbuf = NULL; + if (!tmp) { + efi_error("could not allocate memory"); + return -1; + } +- tmp[devpart - root] = '\0'; ++ tmp[current - root] = '\0'; + rc = sysfs_stat(&statbuf, "class/block/%s/driver", tmp); + if (rc < 0 && errno == ENOENT) { + debug("No driver link for /sys/class/block/%s", tmp); +@@ -115,8 +113,8 @@ parse_pci(struct device *dev, const char *current, const char *root) + dev->n_pci_devs += 1; + } + +- debug("next:\"%s\"", devpart); +- return devpart - current; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index a11e1644094..e5de3264d03 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -70,12 +70,14 @@ + */ + + static ssize_t +-parse_pmem(struct device *dev, const char *current, const char *root UNUSED) ++parse_pmem(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + uint8_t *filebuf = NULL; + uint8_t system, sysbus, acpi_id; + uint16_t pnp_id; +- int ndbus, region, btt_region_id, btt_id, rc, pos; ++ int ndbus, region, btt_region_id, btt_id, rc; ++ int pos0 = -1, pos1 = -1; + char *namespace = NULL; + + debug("entry"); +@@ -95,20 +97,21 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) + } + + /* +- * We're not actually using any of the values here except pos (our ++ * We're not actually using any of the values here except pos1 (our + * return value), but rather just being paranoid that this is the sort + * of device we care about. + * + * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s + */ + rc = sscanf(current, +- "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", +- &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ®ion, +- &btt_region_id, &btt_id, &pos); +- debug("current:\"%s\" rc:%d pos:%d", current, rc, pos); +- dbgmk(" ", pos); ++ "../../devices/%nLNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", ++ &pos0, &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ++ ®ion, &btt_region_id, &btt_id, &pos1); ++ debug("current:\"%s\" rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc < 8) + return 0; ++ current += pos1; + + /* + * but the UUID we really do need to have. +@@ -158,7 +161,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) + + dev->interface_type = nd_pmem; + +- return pos; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-sas.c b/src/linux-sas.c +index f985deeaa3f..16f77d7259b 100644 +--- a/src/linux-sas.c ++++ b/src/linux-sas.c +@@ -148,8 +148,9 @@ get_local_sas_address(uint64_t *sas_address, struct device *dev) + * anywhere. + */ + static ssize_t +-parse_sas(struct device *dev, const char *current, const char *root UNUSED) ++parse_sas(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + struct stat statbuf = { 0, }; + int rc; + uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; +@@ -172,6 +173,7 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED) + */ + if (pos < 0) + return 0; ++ current += pos; + + /* + * Make sure it has the actual /SAS/ bits before we continue +@@ -236,7 +238,9 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED) + dev->scsi_info.scsi_target = scsi_target; + dev->scsi_info.scsi_lun = scsi_lun; + dev->interface_type = sas; +- return pos; ++ ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-sata.c b/src/linux-sata.c +index f3a921c2f79..314a49c4337 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -138,15 +138,15 @@ sysfs_sata_get_port_info(uint32_t print_id, struct device *dev) + } + + static ssize_t +-parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) ++parse_sata(struct device *dev, const char *path, const char *root UNUSED) + { +- const char *current = devlink; ++ const char *current = path; + uint32_t print_id; + uint32_t scsi_bus, tosser0; + uint32_t scsi_device, tosser1; + uint32_t scsi_target, tosser2; + uint64_t scsi_lun, tosser3; +- int pos = 0; ++ int pos0 = -1, pos1 = -1; + int rc; + + debug("entry"); +@@ -160,9 +160,9 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + * ^dev ^host x y z + */ + debug("searching for ata1/"); +- rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%nata%"PRIu32"/%n", &pos0, &print_id, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If we don't find this one, it isn't an ata device, so return 0 not + * error. Later errors mean it is an ata device, but we can't parse +@@ -170,36 +170,36 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + */ + if (rc != 1) + return 0; +- current += pos; +- pos = 0; ++ current += pos1; ++ pos0 = pos1 = -1; + + debug("searching for host0/"); +- rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%nhost%"PRIu32"/%n", &pos0, &scsi_bus, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 1) + return -1; +- current += pos; +- pos = 0; ++ current += pos1; ++ pos0 = pos1 = -1; + + debug("searching for target0:0:0:0/"); +- rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", +- &scsi_device, &scsi_target, &scsi_lun, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%ntarget%"PRIu32":%"PRIu32":%"PRIu64"/%n", ++ &pos0, &scsi_device, &scsi_target, &scsi_lun, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 3) + return -1; +- current += pos; +- pos = 0; ++ current += pos1; ++ pos0 = pos1 = -1; + + debug("searching for 0:0:0:0/"); +- rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", +- &tosser0, &tosser1, &tosser2, &tosser3, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%n%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", ++ &pos0, &tosser0, &tosser1, &tosser2, &tosser3, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 4) + return -1; +- current += pos; ++ current += pos1; + + rc = sysfs_sata_get_port_info(print_id, dev); + if (rc < 0) +@@ -213,7 +213,8 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + if (dev->interface_type == unknown) + dev->interface_type = sata; + +- return current - devlink; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 21fa0b7420c..7f68e03a1b0 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -36,15 +37,15 @@ + * helper for scsi formats... + */ + ssize_t HIDDEN +-parse_scsi_link(const char *current, uint32_t *scsi_host, ++parse_scsi_link(const char *path, uint32_t *scsi_host, + uint32_t *scsi_bus, uint32_t *scsi_device, + uint32_t *scsi_target, uint64_t *scsi_lun, + uint32_t *local_port_id, uint32_t *remote_port_id, + uint32_t *remote_target_id) + { ++ const char *current = path; + int rc; +- int sz = 0; +- int pos0 = 0, pos1 = 0; ++ int pos0 = -1, pos1 = -1, pos2 = -1; + + debug("entry"); + /* +@@ -99,13 +100,13 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * or host4/port-4:0:0 + */ + debug("searching for host4/"); +- rc = sscanf(current, "host%d/%n", scsi_host, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- dbgmk(" ", pos0); ++ rc = sscanf(current, "%nhost%d/%n", scsi_host, &pos0, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 1) + return -1; +- sz += pos0; +- pos0 = 0; ++ current += pos1; ++ pos0 = pos1 = -1; + + /* + * We might have this next: +@@ -116,149 +117,154 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 + */ + debug("searching for port-4:0 or port-4:0:0"); +- rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0, +- &tosser1, &pos0, &tosser2, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); +- dbgmk(" ", pos0, pos1); +- if (rc == 2 || rc == 3) { +- sz += pos0; +- pos0 = 0; +- if (local_port_id && rc == 2) +- *local_port_id = tosser1; +- if (remote_port_id && rc == 3) +- *remote_port_id = tosser2; +- +- if (current[sz] == '/') +- sz += 1; +- +- /* +- * We might have this next: +- * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 +- * ^ port id +- * ^ scsi target id +- * ^ host number +- * ^ host number +- * We don't actually care about either number in expander-.../, +- * because they're replicated in all the other places. We just need +- * to get past it. +- */ +- debug("searching for expander-4:0/"); +- rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- dbgmk(" ", pos0); +- if (rc == 2) { +- if (!remote_target_id) { +- efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); +- return -1; +- } +- *remote_target_id = tosser1; +- sz += pos0; +- pos0 = 0; +- +- /* +- * if we have that, we should have a 3-part port next +- */ +- debug("searching for port-2:0:2/"); +- rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- dbgmk(" ", pos0); +- if (rc != 3) { +- efi_error("Couldn't parse port expander port string"); +- return -1; +- } +- sz += pos0; +- } +- pos0 = 0; +- +- /* next: +- * /end_device-4:0 +- * or /end_device-4:0:0 +- * awesomely these are the exact same fields that go into port-blah, +- * but we don't care for now about any of them anyway. +- */ +- debug("searching for end_device-4:0/ or end_device-4:0:0/"); +- rc = sscanf(current + sz, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- if (rc != 2) +- return -1; +- +- pos1 = 0; +- rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); +- if (rc != 0 && rc != 1) +- return -1; +- dbgmk(" ", pos0, pos0+pos1); +- if (remote_port_id && rc == 1) +- *remote_port_id = tosser2; +- if (local_port_id && rc == 0) +- *local_port_id = tosser1; +- sz += pos0 + pos1; +- pos0 = pos1 = 0; +- +- if (current[sz] == '/') +- sz += 1; ++ rc = sscanf(current, "%nport-%d:%d%n:%d%n", ++ &pos0, &tosser0, &tosser1, &pos1, &tosser2, &pos2); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2); ++ dbgmk(" ", pos0, MAX(pos1, pos2)); ++ if (rc == 3) { ++ if (remote_port_id) ++ *remote_port_id = tosser2; ++ pos1 = pos2; ++ } else if (rc == 2) { ++ if (local_port_id) ++ *local_port_id = tosser1; + } else if (rc != 0) { +- return -1; ++ return -1; ++ } else { ++ pos1 = 0; + } ++ current += pos1; ++ ++ if (current[0] == '/') ++ current += 1; ++ pos0 = pos1 = pos2 = -1; ++ ++ /* ++ * We might have this next: ++ * expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:0/2:0:0:0/block/sda/sda1 ++ * ^ port id ++ * ^ scsi target id ++ * ^ host number ++ * ^ host number ++ * We don't actually care about either number in expander-.../, ++ * because they're replicated in all the other places. We just need ++ * to get past it. ++ */ ++ debug("searching for expander-4:0/"); ++ rc = sscanf(current, "%nexpander-%d:%d/%n", &pos0, &tosser0, &tosser1, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ if (rc == 2) { ++ if (!remote_target_id) { ++ efi_error("Device is PHY is a remote target, but remote_target_id is NULL"); ++ return -1; ++ } ++ *remote_target_id = tosser1; ++ current += pos1; ++ pos0 = pos1 = -1; ++ ++ /* ++ * if we have that, we should have a 3-part port next ++ */ ++ debug("searching for port-2:0:2/"); ++ rc = sscanf(current, "%nport-%d:%d:%d/%n", &pos0, &tosser0, &tosser1, &tosser2, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ if (rc != 3) { ++ efi_error("Couldn't parse port expander port string"); ++ return -1; ++ } ++ current += pos1; ++ } ++ pos0 = pos1 = -1; ++ ++ /* next: ++ * /end_device-4:0 ++ * or /end_device-4:0:0 ++ * awesomely these are the exact same fields that go into port-blah, ++ * but we don't care for now about any of them anyway. ++ */ ++ debug("searching for end_device-4:0/ or end_device-4:0:0/"); ++ rc = sscanf(current, "%nend_device-%d:%d%n:%d%n", ++ &pos0, &tosser0, &tosser1, &pos1, &tosser2, &pos2); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); ++ dbgmk(" ", pos0, MAX(pos1, pos2)); ++ if (rc == 3) { ++ if (remote_port_id) ++ *remote_port_id = tosser2; ++ pos1 = pos2; ++ } else if (rc == 2) { ++ if (local_port_id) ++ *local_port_id = tosser1; ++ } else { ++ pos1 = 0; ++ } ++ current += pos1; ++ pos0 = pos1 = pos2 = -1; ++ ++ if (current[0] == '/') ++ current += 1; + + /* now: + * /target4:0:0/ + */ + uint64_t tosser3; + debug("searching for target4:0:0/"); +- rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, +- &tosser3, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- dbgmk(" ", pos0); ++ rc = sscanf(current, "%ntarget%d:%d:%"PRIu64"/%n", ++ &pos0, &tosser0, &tosser1, &tosser3, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 3) + return -1; +- sz += pos0; +- pos0 = 0; ++ current += pos1; ++ pos0 = pos1 = -1; + + /* now: + * %d:%d:%d:%llu/ + */ + debug("searching for 4:0:0:0/"); +- rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", +- scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); +- dbgmk(" ", pos0); ++ rc = sscanf(current, "%n%d:%d:%d:%"PRIu64"/%n", ++ &pos0, scsi_bus, scsi_device, scsi_target, scsi_lun, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 4) + return -1; +- sz += pos0; ++ current += pos1; + +- debug("returning %d", sz); +- return sz; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +-parse_scsi(struct device *dev, const char *current, const char *root UNUSED) ++parse_scsi(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; + uint64_t scsi_lun; +- ssize_t sz; +- int pos; ++ int pos0, pos1; + int rc; + + debug("entry"); + +- debug("searching for ../../../0:0:0:0"); +- rc = sscanf(dev->device, "../../../%d:%d:%d:%"PRIu64"%n", ++ debug("searching device for ../../../0:0:0:0"); ++ pos0 = pos1 = -1; ++ rc = sscanf(dev->device, "../../../%n%d:%d:%d:%"PRIu64"%n", ++ &pos0, + &dev->scsi_info.scsi_bus, + &dev->scsi_info.scsi_device, + &dev->scsi_info.scsi_target, + &dev->scsi_info.scsi_lun, +- &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); +- dbgmk(" ", pos); ++ &pos1); ++ debug("device:'%s' rc:%d pos0:%d pos1:%d\n", dev->device, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 4) + return 0; + +- sz = parse_scsi_link(current, &scsi_host, +- &scsi_bus, &scsi_device, +- &scsi_target, &scsi_lun, +- NULL, NULL, NULL); +- if (sz < 0) ++ pos0 = parse_scsi_link(current, &scsi_host, &scsi_bus, &scsi_device, ++ &scsi_target, &scsi_lun, NULL, NULL, NULL); ++ if (pos0 < 0) + return 0; ++ current += pos0; + + /* + * SCSI disks can have up to 16 partitions, or 4 bits worth +@@ -281,7 +287,8 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + return -1; + } + +- return sz; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index f4191dbd323..53686d614a0 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -38,23 +38,23 @@ + * I don't *think* the devicetree nodes stack. + */ + static ssize_t +-parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED) ++parse_soc_root(struct device *dev UNUSED, const char *path, const char *root UNUSED) + { ++ const char *current = path; + int rc; +- int pos = 0; +- const char *devpart = current; ++ int pos0 = -1, pos1 = -1; + + debug("entry"); + +- rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); +- if (rc != 0) ++ rc = sscanf(current, "../../devices/%nplatform/soc/%*[^/]/%n", &pos0, &pos1); ++ if (rc != 0 || pos0 == -1 || pos1 == -1) + return 0; +- debug("current:\"%s\" rc:%d pos:%d", current, rc, pos); +- dbgmk(" ", pos); +- devpart += pos; +- debug("new position is \"%s\"", devpart); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ current += pos1; + +- return devpart - current; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + enum interface_type soc_root_iftypes[] = { soc_root, unknown }; +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index e376e0480e6..fc87717ef96 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -45,18 +45,19 @@ + * But usually we just write the HD() entry, of course. + */ + static ssize_t +-parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) ++parse_virtblk(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + uint32_t tosser; +- int pos = 0; ++ int pos0 = -1, pos1 = -1; + int rc; + + debug("entry"); + + debug("searching for virtio0/"); +- rc = sscanf(current, "virtio%x/%n", &tosser, &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos); +- dbgmk(" ", pos); ++ rc = sscanf(current, "%nvirtio%x/%n", &pos0, &tosser, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + /* + * If we couldn't find virtioX/ then it isn't a virtio device. + */ +@@ -64,8 +65,10 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + return 0; + + dev->interface_type = virtblk; ++ current += pos1; + +- return pos; ++ debug("current:'%s' sz:%zd\n", current, current - path); ++ return current - path; + } + + enum interface_type virtblk_iftypes[] = { virtblk, unknown }; +-- +2.24.1 + diff --git a/SOURCES/0056-Improve-consistency-of-debug-prints.patch b/SOURCES/0056-Improve-consistency-of-debug-prints.patch new file mode 100644 index 0000000..30c0c65 --- /dev/null +++ b/SOURCES/0056-Improve-consistency-of-debug-prints.patch @@ -0,0 +1,306 @@ +From d153ca75d0323eb125e525ebdf4ac5c982941d15 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:26:30 -0400 +Subject: [PATCH 56/86] Improve consistency of debug prints + +This changes debug prints in a couple of ways: +- always calls the path we're parsing "current" in the output +- always use ' not " for quoting in the debug output, so tools that + escape strings won't change the lenghts +- everything that parses "current" has a debug print after each parse + attempt and before returning. + +Signed-off-by: Peter Jones +--- + src/dp-acpi.c | 8 ++++---- + src/linux-acpi-root.c | 4 ++-- + src/linux-acpi.c | 6 +++--- + src/linux-ata.c | 11 +++++++---- + src/linux-i2o.c | 10 +++++----- + src/linux-md.c | 4 ++-- + src/linux-pci-root.c | 2 +- + src/linux-pmem.c | 5 +++-- + src/linux.c | 27 +++++++++++++++++---------- + 9 files changed, 44 insertions(+), 33 deletions(-) + +diff --git a/src/dp-acpi.c b/src/dp-acpi.c +index 02ec70eec7a..ae4102cdf56 100644 +--- a/src/dp-acpi.c ++++ b/src/dp-acpi.c +@@ -1,6 +1,6 @@ + /* + * libefivar - library for the manipulation of EFI variables +- * Copyright 2012-2015 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -52,9 +52,9 @@ _format_acpi_hid_ex(unsigned char *buf, size_t size, + { + ssize_t off = 0; + +- debug("hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr); +- debug("cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr); +- debug("uid:0x%08x uidstr:\"%s\"", dp->acpi_hid_ex.uid, uidstr); ++ debug("hid:0x%08x hidstr:'%s'", dp->acpi_hid_ex.hid, hidstr); ++ debug("cid:0x%08x cidstr:'%s'", dp->acpi_hid_ex.cid, cidstr); ++ debug("uid:0x%08x uidstr:'%s'", dp->acpi_hid_ex.uid, uidstr); + + if (!hidstr && !cidstr && (uidstr || dp->acpi_hid_ex.uid)) { + format(buf, size, off, "AcpiExp", +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 9154c950bb1..86693c81878 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -144,7 +144,7 @@ parse_acpi_root(struct device *dev, const char *path, const char *root UNUSED) + return rc; + } + } +- debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"", ++ debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:'%s' path:'%s'", + dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, + dev->acpi_root.acpi_uid_str, + dev->acpi_root.acpi_cid_str); +@@ -162,7 +162,7 @@ dp_create_acpi_root(struct device *dev, + debug("entry buf:%p size:%zd off:%zd", buf, size, off); + + if (dev->acpi_root.acpi_uid_str || dev->acpi_root.acpi_cid_str) { +- debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"", ++ debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:'%s' cidstr:'%s'", + dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid, + dev->acpi_root.acpi_uid_str, dev->acpi_root.acpi_cid_str); + new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, +diff --git a/src/linux-acpi.c b/src/linux-acpi.c +index 919f4654ae3..534573f32c1 100644 +--- a/src/linux-acpi.c ++++ b/src/linux-acpi.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -54,7 +54,7 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...) + if (l > 1) { + fbuf[l-1] = 0; + dev->acpi_root.acpi_cid_str = strdup(fbuf); +- debug("Setting ACPI root path to \"%s\"", fbuf); ++ debug("Setting ACPI root path to '%s'", fbuf); + } + } + +@@ -111,7 +111,7 @@ hid_err: + } + } + } +- debug("acpi root UID:0x%"PRIx64" uidstr:\"%s\"", ++ debug("acpi root UID:0x%"PRIx64" uidstr:'%s'", + dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str); + + errno = 0; +diff --git a/src/linux-ata.c b/src/linux-ata.c +index a05a2feb8b9..a51ed5abbe0 100644 +--- a/src/linux-ata.c ++++ b/src/linux-ata.c +@@ -60,6 +60,7 @@ is_pata(struct device *dev) + static ssize_t + parse_ata(struct device *dev, const char *path, const char *root UNUSED) + { ++ const char *current = path; + uint32_t scsi_host, scsi_bus, scsi_device, scsi_target; + uint64_t scsi_lun; + int pos; +@@ -118,6 +119,7 @@ parse_ata(struct device *dev, const char *path, const char *root UNUSED) + NULL, NULL, NULL); + if (pos < 0) + return -1; ++ current += pos; + + dev->ata_info.scsi_host = scsi_host; + dev->ata_info.scsi_bus = scsi_bus; +@@ -125,10 +127,11 @@ parse_ata(struct device *dev, const char *path, const char *root UNUSED) + dev->ata_info.scsi_target = scsi_target; + dev->ata_info.scsi_lun = scsi_lun; + +- char *block = strstr(path, "/block/"); +- if (!block) +- return -1; +- return block + 1 - path; ++ char *block = strstr(current, "/block/"); ++ if (block) ++ current += block + 1 - current; ++ debug("current:'%s' sz:%zd", current, current - path); ++ return current - path; + } + + static ssize_t +diff --git a/src/linux-i2o.c b/src/linux-i2o.c +index ebd92aeeb53..b53f4516309 100644 +--- a/src/linux-i2o.c ++++ b/src/linux-i2o.c +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as +@@ -33,7 +33,7 @@ + * ... probably doesn't work. + */ + static ssize_t +-parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED) ++parse_i2o(struct device *dev, const char *current, const char *root UNUSED) + { + debug("entry"); + /* I2O disks can have up to 16 partitions, or 4 bits worth. */ +@@ -47,9 +47,9 @@ parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSE + } + + char *block = strstr(current, "/block/"); +- if (!block) +- return -1; +- return block + 1 - current; ++ ssize_t sz = block ? block + 1 - current : -1; ++ debug("current:'%s' sz:%zd", current, sz); ++ return sz; + } + + enum interface_type i2o_iftypes[] = { i2o, unknown }; +diff --git a/src/linux-md.c b/src/linux-md.c +index b0809f8295a..2aacb87469a 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -50,7 +50,7 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED) + debug("searching for mdM/mdMpN"); + rc = sscanf(current, "md%d/%nmd%dp%d%n", + &md, &pos0, &tosser0, &part, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); + dbgmk(" ", pos0, pos1); + /* + * If it isn't of that form, it's not one of our partitioned md devices. +@@ -63,10 +63,10 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED) + if (dev->part == -1) + dev->part = part; + ++ debug("current:'%s' sz:%d\n", current, pos1); + return pos1; + } + +- + static char * + make_part_name(struct device *dev) + { +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index 8cd3849b1db..84189ffbaca 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -87,7 +87,7 @@ dp_create_pci_root(struct device *dev UNUSED, + debug("entry buf:%p size:%zd off:%zd", buf, size, off); + debug("returning 0"); + if (dev->acpi_root.acpi_uid_str) { +- debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"", ++ debug("creating acpi_hid_ex dp hid:0x%08x uid:'%s'", + dev->acpi_root.acpi_hid, + dev->acpi_root.acpi_uid_str); + new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index e5de3264d03..b9f83e12e7b 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -103,11 +103,12 @@ parse_pmem(struct device *dev, const char *path, const char *root UNUSED) + * + * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s + */ ++ pos0 = pos1 = -1; + rc = sscanf(current, + "../../devices/%nLNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n", + &pos0, &system, &sysbus, &pnp_id, &acpi_id, &ndbus, + ®ion, &btt_region_id, &btt_id, &pos1); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); + dbgmk(" ", pos0, pos1); + if (rc < 8) + return 0; +@@ -126,7 +127,7 @@ parse_pmem(struct device *dev, const char *path, const char *root UNUSED) + return -1; + + filebuf = NULL; +- debug("nvdimm namespace is \"%s\"", namespace); ++ debug("nvdimm namespace is '%s'", namespace); + rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace); + free(namespace); + if (rc < 0 || filebuf == NULL) +diff --git a/src/linux.c b/src/linux.c +index 1f37933f546..1051894e7bc 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -184,10 +184,10 @@ set_disk_and_part_name(struct device *dev) + errno = 0; + debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name); + debug("dev->part:%d", dev->part); +- debug("ultimate:\"%s\"", ultimate ? : ""); +- debug("penultimate:\"%s\"", penultimate ? : ""); +- debug("approximate:\"%s\"", approximate ? : ""); +- debug("proximate:\"%s\"", proximate ? : ""); ++ debug("ultimate:'%s'", ultimate ? : ""); ++ debug("penultimate:'%s'", penultimate ? : ""); ++ debug("approximate:'%s'", approximate ? : ""); ++ debug("proximate:'%s'", proximate ? : ""); + + if (ultimate && penultimate && + ((proximate && !strcmp(proximate, "nvme")) || +@@ -463,7 +463,11 @@ struct device HIDDEN + efi_error("parsing %s failed", probe->name); + goto err; + } else if (pos > 0) { +- debug("%s matched %s", probe->name, current); ++ char match[pos+1]; ++ ++ strncpy(match, current, pos); ++ match[pos] = '\0'; ++ debug("%s matched '%s'", probe->name, match); + dev->flags |= probe->flags; + + if (probe->flags & DEV_PROVIDES_HD || +@@ -473,7 +477,10 @@ struct device HIDDEN + + dev->probes[n++] = dev_probes[i]; + current += pos; +- debug("current:%s", current); ++ if (current[0] == '\0') ++ debug("finished"); ++ else ++ debug("current:'%s'", current); + last_successful_probe = i; + + if (!*current || !strncmp(current, "block/", 6)) +@@ -482,8 +489,8 @@ struct device HIDDEN + continue; + } + +- debug("dev_probes[i+1]: %p dev->interface_type: %d\n", +- dev_probes[i+1], dev->interface_type); ++ debug("dev_probes[%d]: %p dev->interface_type: %d\n", ++ i+1, dev_probes[i+1], dev->interface_type); + if (dev_probes[i+1] == NULL && dev->interface_type == unknown) { + pos = 0; + rc = sscanf(current, "%*[^/]/%n", &pos); +@@ -499,8 +506,8 @@ slash_err: + if (!current[pos]) + goto slash_err; + +- debug("Cannot parse device link segment \"%s\"", current); +- debug("Skipping to \"%s\"", current + pos); ++ debug("Cannot parse device link segment '%s'", current); ++ debug("Skipping to '%s'", current + pos); + debug("This means we can only create abbreviated paths"); + dev->flags |= DEV_ABBREV_ONLY; + i = last_successful_probe; +-- +2.24.1 + diff --git a/SOURCES/0057-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch b/SOURCES/0057-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch new file mode 100644 index 0000000..367bc2e --- /dev/null +++ b/SOURCES/0057-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch @@ -0,0 +1,212 @@ +From c9c1424d0e09bf33b747d37c43177c63367b1290 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 14:20:54 -0400 +Subject: [PATCH 57/86] Try even harder to find disk device symlinks in sysfs. + +Today's realization is that the thing encoded into the structure of +sysfs is, in the best case, the dependency graph of the makefile targets +to build a device driver. + +In the case of nvme-fabric, or really wherever the kernel has +class_create() and device_create() in the same function, there's an +extra level of indirection. + +Anyway, in this patch we stop pretending sysfs isn't completely absurd, +and just try adding "/device" in the middle of the driver symlink path, +until we actually either get ENOENT on the device symlink or find a +device symlink that actually has a driver symlink under it. + +Signed-off-by: Peter Jones +--- + src/linux-nvme.c | 13 ++++----- + src/linux.c | 46 +++++++++++++++++-------------- + src/linux.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++- + 3 files changed, 102 insertions(+), 28 deletions(-) + +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index b83c631119a..5d69a33c715 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -89,13 +89,12 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + /* + * now fish the eui out of sysfs is there is one... + */ +- rc = read_sysfs_file(&filebuf, +- "class/block/nvme%dn%d/eui", +- ctrl_id, ns_id); +- if ((rc < 0 && errno == ENOENT) || filebuf == NULL) { +- rc = read_sysfs_file(&filebuf, +- "class/block/nvme%dn%d/device/eui", +- ctrl_id, ns_id); ++ char *euipath = NULL; ++ rc = read_sysfs_file(&filebuf, "class/block/nvme%dn%d/eui", ctrl_id, ns_id); ++ if (rc < 0 && (errno == ENOENT || errno == ENOTDIR)) { ++ rc = find_device_file(&euipath, "eui", "class/block/nvme%dn%d", ctrl_id, ns_id); ++ if (rc >= 0 && euipath != NULL) ++ rc = read_sysfs_file(&filebuf, "%s", euipath); + } + if (rc >= 0 && filebuf != NULL) { + uint8_t eui[8]; +diff --git a/src/linux.c b/src/linux.c +index 1051894e7bc..0324e20c8cf 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -401,26 +401,32 @@ struct device HIDDEN + goto err; + } + +- if (dev->device[0] != 0) { +- rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name); ++ /* ++ * So, on a normal disk, you get something like: ++ * /sys/block/sda/device -> ../../0:0:0:0 ++ * /sys/block/sda/device/driver -> ../../../../../../../bus/scsi/drivers/sd ++ * ++ * On a directly attached nvme device you get: ++ * /sys/block/nvme0n1/device -> ../../nvme0 ++ * /sys/block/nvme0n1/device/device -> ../../../0000:6e:00.0 ++ * /sys/block/nvme0n1/device/device/driver -> ../../../../bus/pci/drivers/nvme ++ * ++ * On a fabric-attached nvme device, you get something like: ++ * /sys/block/nvme0n1/device -> ../../nvme0 ++ * /sys/block/nvme0n1/device/device -> ../../ctl ++ * /sys/block/nvme0n1/device/device/device -> ../../../../../0000:6e:00.0 ++ * /sys/block/nvme0n1/device/device/device/driver -> ../../../../../../bus/pci/drivers/nvme-fabrics ++ * ++ * ... I think? I don't have one in front of me. ++ */ ++ ++ char *filepath = NULL; ++ rc = find_device_file(&filepath, "driver", "block/%s", dev->disk_name); ++ if (rc >= 0) { ++ rc = sysfs_readlink(&tmpbuf, "%s", filepath); + if (rc < 0 || !tmpbuf) { +- if (errno == ENOENT) { +- /* +- * nvme, for example, will have nvme0n1/device point +- * at nvme0, and we need to look for device/driver +- * there. +- */ +- rc = sysfs_readlink(&tmpbuf, +- "block/%s/device/device/driver", +- dev->disk_name); +- if (rc >= 0 && tmpbuf) +- efi_error_pop(); +- } +- if (rc < 0 || !tmpbuf) { +- efi_error("readlink of /sys/block/%s/device/driver failed", +- dev->disk_name); +- goto err; +- } ++ efi_error("readlink of /sys/%s failed", filepath); ++ goto err; + } + + linkbuf = pathseg(tmpbuf, -1); +@@ -431,7 +437,7 @@ struct device HIDDEN + + dev->driver = strdup(linkbuf); + } else { +- dev->driver = strdup(""); ++ dev->driver = strdup(""); + } + + if (!dev->driver) { +diff --git a/src/linux.h b/src/linux.h +index 5ae64ffaacf..97f9518bb5c 100644 +--- a/src/linux.h ++++ b/src/linux.h +@@ -1,6 +1,6 @@ + /* + * libefiboot - library for the manipulation of EFI boot variables +- * Copyright 2012-2015 Red Hat, Inc. ++ * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation + * + * This library is free software; you can redistribute it and/or +@@ -218,6 +218,22 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size, + _rc; \ + }) + ++#define sysfs_access(mode, fmt, args...) \ ++ ({ \ ++ int rc_; \ ++ char *pn_; \ ++ \ ++ rc_ = asprintfa(&pn_, "/sys/" fmt, ## args); \ ++ if (rc_ >= 0) { \ ++ rc_ = access(pn_, mode); \ ++ if (rc_ < 0) \ ++ efi_error("could not access %s", pn_); \ ++ } else { \ ++ efi_error("could not allocate memory"); \ ++ } \ ++ rc_; \ ++ }) ++ + #define sysfs_stat(statbuf, fmt, args...) \ + ({ \ + int rc_; \ +@@ -251,6 +267,59 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size, + dir_; \ + }) + ++/* ++ * Iterate a /sys/block directory looking for device/foo, device/device/foo, ++ * etc. I'm not proud of this method. ++ */ ++#define find_device_file(result, name, fmt, args...) \ ++ ({ \ ++ int rc_ = 0; \ ++ debug("searching for %s from in %s", name, dev->disk_name); \ ++ for (unsigned int try_ = 0; true; try_++) { \ ++ char slashdev_[sizeof("device") \ ++ + try_ * strlen("/device")]; \ ++ \ ++ char *nul_ = stpcpy(slashdev_, "device"); \ ++ for (unsigned int i_ = 0; i_ < try_; i_++) \ ++ nul_ = stpcpy(nul_, "/device"); \ ++ \ ++ debug("trying /sys/" fmt "/%s/%s", \ ++ ## args, slashdev_, name); \ ++ \ ++ rc_ = sysfs_access(F_OK, fmt "/%s", ## args, slashdev_);\ ++ if (rc_ < 0) { \ ++ if (errno == ENOENT) { \ ++ efi_error_pop(); \ ++ break; \ ++ } \ ++ efi_error("cannot access /sys/"fmt"/%s: %m", \ ++ ## args, slashdev_); \ ++ goto find_device_link_err_; \ ++ } \ ++ \ ++ rc_ = sysfs_access(F_OK, fmt "/%s/%s", \ ++ ## args, slashdev_, name); \ ++ if (rc_ < 0) { \ ++ if (errno == ENOENT) { \ ++ efi_error_pop(); \ ++ break; \ ++ } \ ++ efi_error("cannot access /sys/"fmt"/%s/%s: %m", \ ++ ## args, slashdev_, name); \ ++ goto find_device_link_err_; \ ++ } \ ++ \ ++ rc_ = asprintfa(result, fmt "/%s/%s", \ ++ ## args, slashdev_, name); \ ++ if (rc_ < 0) { \ ++ efi_error("cannot allocate memory: %m"); \ ++ goto find_device_link_err_; \ ++ } \ ++ } \ ++find_device_link_err_: \ ++ rc_; \ ++ }) ++ + #define DEV_PROVIDES_ROOT 1 + #define DEV_PROVIDES_HD 2 + #define DEV_ABBREV_ONLY 4 +-- +2.24.1 + diff --git a/SOURCES/0058-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch b/SOURCES/0058-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch new file mode 100644 index 0000000..4484a91 --- /dev/null +++ b/SOURCES/0058-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch @@ -0,0 +1,313 @@ +From c41da0bdce04ab0f99b992d51ff6fd0ab55d040a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 17:04:12 -0400 +Subject: [PATCH 58/86] Handle + /sys/devices/virtual/{nvme-fabrics,nvme-subsystem} devices + +Signed-off-by: Peter Jones +--- + src/linux-nvme.c | 52 ++++++++++++++++++++---- + src/linux-virtual-root.c | 88 ++++++++++++++++++++++++++++++++++++++++ + src/linux.c | 43 +++++++++++++++++--- + src/linux.h | 4 +- + 4 files changed, 173 insertions(+), 14 deletions(-) + create mode 100644 src/linux-virtual-root.c + +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 5d69a33c715..d0941e85e08 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -15,7 +15,6 @@ + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * . +- * + */ + + #include "fix_coverity.h" +@@ -35,6 +34,12 @@ + * /sys/dev/block/$major:$minor looks like: + * 259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 + * 259:1 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1/nvme0n1p1 ++ * or: ++ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1 ++ * 259:1 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1 ++ * or: ++ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1 ++ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1 + * + * /sys/dev/block/259:0/device looks like: + * device -> ../../nvme0 +@@ -56,14 +61,42 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; + uint8_t *filebuf = NULL; + int pos0 = -1, pos1 = -1, pos2 = -1; ++ ssize_t sz = 0; ++ struct subdir { ++ const char * const name; ++ const char * const fmt; ++ int *pos0, *pos1; ++ } subdirs[] = { ++ {"nvme-subsysN/", "%nnvme-subsys%d/%n", &pos0, &pos2}, ++ {"ctl/", "%nctl/%n%n", &pos0, &pos1}, ++ {"nvme/", "%nnvme/%n%n", &pos0, &pos1}, ++ {NULL, } ++ }; + + debug("entry"); + +- debug("searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1"); +- rc = sscanf(current, "%nnvme/nvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", +- &pos0, &tosser0, &ctrl_id, &ns_id, +- &pos1, &tosser1, &tosser2, &partition, &pos2); +- debug("current:\"%s\" rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2); ++ /* ++ * in this case, *any* of these is okay. ++ */ ++ for (int i = 0; subdirs[i].name; i++) { ++ debug("searching for %s", subdirs[i].name); ++ pos0 = tosser0 = pos1 = -1; ++ rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1, &pos2); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, ++ *subdirs[i].pos0, *subdirs[i].pos1); ++ dbgmk(" ", *subdirs[i].pos0, *subdirs[i].pos1); ++ if (*subdirs[i].pos0 >= 0 && *subdirs[i].pos1 >= *subdirs[i].pos0) { ++ sz += *subdirs[i].pos1; ++ current += *subdirs[i].pos1; ++ break; ++ } ++ } ++ ++ debug("searching for nvme0/nvme0n1 or nvme0/nvme0n1/nvme0n1p1"); ++ rc = sscanf(current, "%nnvme%d/nvme%dn%d%n/nvme%dn%dp%d%n", ++ &pos0, &tosser0, &ctrl_id, &ns_id, &pos1, ++ &tosser1, &tosser2, &partition, &pos2); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d pos2:%d\n", current, rc, pos0, pos1, pos2); + dbgmk(" ", pos0, MAX(pos1,pos2)); + /* + * If it isn't of that form, it's not one of our nvme devices. +@@ -82,13 +115,15 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + if (dev->part == -1) + dev->part = partition; + +- pos1 = pos2; ++ pos1 = pos2; + } ++ + current += pos1; + + /* + * now fish the eui out of sysfs is there is one... + */ ++ debug("looking for the eui"); + char *euipath = NULL; + rc = read_sysfs_file(&filebuf, "class/block/nvme%dn%d/eui", ctrl_id, ns_id); + if (rc < 0 && (errno == ENOENT || errno == ENOTDIR)) { +@@ -111,6 +146,9 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + errno = EINVAL; + return -1; + } ++ debug("eui is %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", ++ eui[0], eui[1], eui[2], eui[3], ++ eui[4], eui[5], eui[6], eui[7]); + dev->nvme_info.has_eui = 1; + memcpy(dev->nvme_info.eui, eui, sizeof(eui)); + } +diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c +new file mode 100644 +index 00000000000..75fbbfc1de6 +--- /dev/null ++++ b/src/linux-virtual-root.c +@@ -0,0 +1,88 @@ ++/* ++ * libefiboot - library for the manipulation of EFI boot variables ++ * Copyright 2012-2019 Red Hat, Inc. ++ * ++ * This library is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public License as ++ * published by the Free Software Foundation; either version 2.1 of the ++ * License, or (at your option) any later version. ++ * ++ * This library 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library; if not, see ++ * . ++ */ ++ ++#include "fix_coverity.h" ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "efiboot.h" ++ ++/* ++ * Support virtually rooted devices (fibre+nvme, etc.) ++ * ++ * /sys/dev/block/$major:$minor looks like: ++ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1 ++ * 259:1 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1 ++ * or: ++ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1 ++ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1 ++ */ ++ ++static ssize_t ++parse_virtual_root(struct device *dev UNUSED, const char *current, const char *root UNUSED) ++{ ++ int rc; ++ ssize_t sz; ++ int pos0 = 0, pos1 = 0; ++ struct subdir { ++ const char * const name; ++ const char * const fmt; ++ } subdirs[] = { ++ {"../../devices/virtual", "%n../../devices/virtual/%n"}, ++ {"nvme-subsystem/", "%nnvme-subsystem/%n"}, ++ {"nvme-fabrics/ctl/", "%nnvme-fabrics/ctl/%n"}, ++ {NULL, NULL} ++ }; ++ ++ debug("entry"); ++ ++ for (int i = 0; subdirs[i].name; i++) { ++ debug("searching for %s", subdirs[i].name); ++ pos0 = pos1 = -1; ++ rc = sscanf(current, subdirs[i].fmt, &pos0, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ if (rc == 1) { ++ sz += pos1; ++ current += pos1; ++ if (i > 0) ++ goto found; ++ } ++ } ++ ++ sz = 0; ++found: ++ debug("current:'%s' sz:%zd\n", current, sz); ++ return sz; ++} ++ ++static enum interface_type virtual_root_iftypes[] = { virtual_root, unknown }; ++ ++struct dev_probe HIDDEN virtual_root_parser = { ++ .name = "virtual_root", ++ .iftypes = virtual_root_iftypes, ++ .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT, ++ .parse = parse_virtual_root, ++}; ++ ++// vim:fenc=utf-8:tw=75:noet +diff --git a/src/linux.c b/src/linux.c +index 0324e20c8cf..67fbb1be059 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -170,16 +170,17 @@ int HIDDEN + set_disk_and_part_name(struct device *dev) + { + int rc = -1; +- +- /* +- * results are like such: +- * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART +- */ +- + char *ultimate = pathseg(dev->link, -1); + char *penultimate = pathseg(dev->link, -2); + char *approximate = pathseg(dev->link, -3); + char *proximate = pathseg(dev->link, -4); ++ char *psl5 = pathseg(dev->link, -5); ++ ++ ++ /* ++ * devlinks look something like: ++ * maj:min -> ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART ++ */ + + errno = 0; + debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name); +@@ -188,6 +189,7 @@ set_disk_and_part_name(struct device *dev) + debug("penultimate:'%s'", penultimate ? : ""); + debug("approximate:'%s'", approximate ? : ""); + debug("proximate:'%s'", proximate ? : ""); ++ debug("psl5:'%s'", psl5 ? : ""); + + if (ultimate && penultimate && + ((proximate && !strcmp(proximate, "nvme")) || +@@ -232,6 +234,34 @@ set_disk_and_part_name(struct device *dev) + set_disk_name(dev, "%s", ultimate); + debug("disk:%s", ultimate); + rc = 0; ++ } else if ((proximate && ultimate && !strcmp(proximate, "nvme-fabrics")) || ++ (approximate && ultimate && !strcmp(approximate, "nvme-subsystem"))) { ++ /* ++ * 259:0 ->../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1 ++ * ^ proximate ^ ultimate ++ * or ++ * 259:5 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1 ++ * ^ approximate ^ penultimate ++ * ultimate ^ ++ */ ++ set_disk_name(dev, "%s", ultimate); ++ debug("disk:%s", ultimate); ++ rc = 0; ++ } else if ((psl5 && penultimate && ultimate && !strcmp(psl5, "nvme-fabrics")) || ++ (proximate && penultimate && ultimate && !strcmp(proximate, "nvme-subsystem"))) { ++ /* ++ * 259:1 -> ../../devices/virtual/nvme-fabrics/ctl/nvme0/nvme0n1/nvme0n1p1 ++ * ^psl5 ^ penultimate ++ * ultimate ^ ++ * or ++ * 259:6 -> ../../devices/virtual/nvme-subsystem/nvme-subsys0/nvme0n1/nvme0n1p1 ++ * ^ proximate ^ penultimate ++ * ultimate ^ ++ */ ++ set_disk_name(dev, "%s", penultimate); ++ set_part_name(dev, "%s", ultimate); ++ debug("disk:%s part:%s", penultimate, ultimate); ++ rc = 0; + } + + if (rc < 0) +@@ -248,6 +278,7 @@ static struct dev_probe *dev_probes[] = { + &acpi_root_parser, + &pci_root_parser, + &soc_root_parser, ++ &virtual_root_parser, + &pci_parser, + &virtblk_parser, + &sas_parser, +diff --git a/src/linux.h b/src/linux.h +index 97f9518bb5c..a5ef0dfa154 100644 +--- a/src/linux.h ++++ b/src/linux.h +@@ -99,7 +99,8 @@ struct emmc_info { + + enum interface_type { + unknown, +- isa, acpi_root, pci_root, soc_root, pci, network, ++ isa, acpi_root, pci_root, soc_root, virtual_root, ++ pci, network, + ata, atapi, scsi, sata, sas, + usb, i1394, fibre, i2o, + md, virtblk, +@@ -346,6 +347,7 @@ extern struct dev_probe pmem_parser; + extern struct dev_probe pci_root_parser; + extern struct dev_probe acpi_root_parser; + extern struct dev_probe soc_root_parser; ++extern struct dev_probe virtual_root_parser; + extern struct dev_probe pci_parser; + extern struct dev_probe sas_parser; + extern struct dev_probe sata_parser; +-- +2.24.1 + diff --git a/SOURCES/0059-Put-some-EFI-device-paths-into-the-debug-log.patch b/SOURCES/0059-Put-some-EFI-device-paths-into-the-debug-log.patch new file mode 100644 index 0000000..9bed768 --- /dev/null +++ b/SOURCES/0059-Put-some-EFI-device-paths-into-the-debug-log.patch @@ -0,0 +1,72 @@ +From ca85d518ab6063ff07af41672dcb366610f51a20 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:58:19 -0400 +Subject: [PATCH 59/86] Put some EFI device paths into the debug log + +Signed-off-by: Peter Jones +--- + src/linux.c | 41 +++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 41 insertions(+) + +diff --git a/src/linux.c b/src/linux.c +index 67fbb1be059..6b88bfb7e9b 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -336,6 +336,44 @@ device_free(struct device *dev) + free(dev); + } + ++static void ++print_dev_dp_node(struct device *dev, struct dev_probe *probe) ++{ ++ ssize_t dpsz; ++ uint8_t *dp; ++ ssize_t bufsz; ++ uint8_t *buf; ++ ++ dpsz = probe->create(dev, NULL, 0, 0); ++ if (dpsz <= 0) ++ return; ++ ++ dp = alloca(dpsz + 4); ++ if (!dp) ++ return; ++ ++ dpsz = probe->create(dev, dp, dpsz, 0); ++ if (dpsz <= 0) ++ return; ++ ++ efidp_make_end_entire(dp + dpsz, 4); ++ bufsz = efidp_format_device_path(NULL, 0, ++ (const_efidp)dp, dpsz + 4); ++ if (bufsz <= 0) ++ return; ++ ++ buf = alloca(bufsz); ++ if (!buf) ++ return; ++ ++ bufsz = efidp_format_device_path(buf, bufsz, ++ (const_efidp)dp, dpsz + 4); ++ if (bufsz <= 0) ++ return; ++ ++ debug("Device path node is %s", buf); ++} ++ + struct device HIDDEN + *device_get(int fd, int partition) + { +@@ -512,6 +550,9 @@ struct device HIDDEN + probe->flags & DEV_ABBREV_ONLY) + needs_root = false; + ++ if (probe->create) ++ print_dev_dp_node(dev, probe); ++ + dev->probes[n++] = dev_probes[i]; + current += pos; + if (current[0] == '\0') +-- +2.24.1 + diff --git a/SOURCES/0060-Update-abixml.patch b/SOURCES/0060-Update-abixml.patch new file mode 100644 index 0000000..0bcc75c --- /dev/null +++ b/SOURCES/0060-Update-abixml.patch @@ -0,0 +1,99 @@ +From 9fa8c3a91ac834564ef6e3d1455a63b1eaee4c14 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 09:51:56 -0500 +Subject: [PATCH 60/86] Update abixml + +--- + src/libefiboot.abixml | 10 +++++----- + src/libefivar.abixml | 10 +++++----- + 2 files changed, 10 insertions(+), 10 deletions(-) + +diff --git a/src/libefiboot.abixml b/src/libefiboot.abixml +index ffdae048021..4b673d5c3e9 100644 +--- a/src/libefiboot.abixml ++++ b/src/libefiboot.abixml +@@ -1577,13 +1577,13 @@ + + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1685,7 +1685,7 @@ + + + +- ++ + + + +@@ -1709,7 +1709,7 @@ + + + +- ++ + + + +diff --git a/src/libefivar.abixml b/src/libefivar.abixml +index 4aadf5079a7..094f43d7b27 100644 +--- a/src/libefivar.abixml ++++ b/src/libefivar.abixml +@@ -639,7 +639,7 @@ + + + +- ++ + + + +@@ -648,7 +648,7 @@ + + + +- ++ + + + +@@ -678,7 +678,7 @@ + + + +- ++ + + + +@@ -693,13 +693,13 @@ + + + +- ++ + + + + + +- ++ + + + +-- +2.24.1 + diff --git a/SOURCES/0061-Update-abixml-files-and-work-around-some-inconsequen.patch b/SOURCES/0061-Update-abixml-files-and-work-around-some-inconsequen.patch new file mode 100644 index 0000000..a86116c --- /dev/null +++ b/SOURCES/0061-Update-abixml-files-and-work-around-some-inconsequen.patch @@ -0,0 +1,3314 @@ +From 3c204df4d8f9efb83257bd94af55f339d846c8fb Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 09:54:48 -0500 +Subject: [PATCH 61/86] Update abixml files and work around some + inconsequential ABI breakage + +Commit 998f617cec92 had the side effect of accidentally making +-funsigned-char actually work correctly, which cause abidiff to notice +this: + +Functions changes summary: 0 Removed, 5 Changed (10 filtered out), 0 Added (5 filtered out) functions +Variables changes summary: 0 Removed, 0 Changed, 0 Added (1 filtered out) variable + +5 functions with some indirect sub-type change: + + [C]'function char* efi_variable_get_name(efi_variable_t*)' at stat.h:661:1 has some indirect sub-type changes: + return type changed: + in pointed to type 'char': + type name changed from 'char' to 'unsigned char' + type size hasn't changed + + [C]'function int efi_variable_set_name(efi_variable_t*, char*)' at stat.h:654:1 has some indirect sub-type changes: + parameter 2 of type 'char*' changed: + in pointed to type 'char': + type name changed from 'char' to 'unsigned char' + type size hasn't changed + + [C]'function ssize_t efidp_format_device_path(char*, size_t, const_efidp, ssize_t)' has some indirect sub-type changes: + parameter 1 of type 'char*' changed: + in pointed to type 'char': + type name changed from 'char' to 'unsigned char' + type size hasn't changed + + [C]'function ssize_t efidp_parse_device_node(char*, efidp, size_t)' has some indirect sub-type changes: + parameter 1 of type 'char*' changed: + in pointed to type 'char': + type name changed from 'char' to 'unsigned char' + type size hasn't changed + + [C]'function ssize_t efidp_parse_device_path(char*, efidp, size_t)' has some indirect sub-type changes: + parameter 1 of type 'char*' changed: + in pointed to type 'char': + type name changed from 'char' to 'unsigned char' + type size hasn't changed + +I don't think there's any case where it actually makes any difference, +since nothing really treats these as characters (rather than 8-bit +bytes) anyway. + +This patch updates the .abixml files with new ABI bits as well as fixing +that problem. + +Signed-off-by: Peter Jones +--- + src/libefiboot.abixml | 247 +++--- + src/libefivar.abixml | 1792 +++++++++++++++++++++-------------------- + 2 files changed, 1041 insertions(+), 998 deletions(-) + +diff --git a/src/libefiboot.abixml b/src/libefiboot.abixml +index 4b673d5c3e9..4a0253b277d 100644 +--- a/src/libefiboot.abixml ++++ b/src/libefiboot.abixml +@@ -7,6 +7,7 @@ + + + ++ + + + +@@ -1157,22 +1158,23 @@ + + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +@@ -1180,62 +1182,62 @@ + + + +- ++ + + + + + +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1243,53 +1245,53 @@ + + + +- ++ + + + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1412,27 +1414,27 @@ + + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1545,30 +1547,31 @@ + + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + + + +- ++ + + +- ++ + + + +@@ -1598,22 +1601,22 @@ + + + +- ++ + + + + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1622,82 +1625,88 @@ + + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ ++ ++ ++ ++ ++ ++ + + +- ++ + + + +@@ -1712,6 +1721,9 @@ + + + ++ ++ ++ + + + +@@ -1754,15 +1766,21 @@ + + + ++ ++ ++ + + + + + + +- ++ + + ++ ++ ++ + + + +@@ -1799,9 +1817,6 @@ + + + +- +- +- + + + +diff --git a/src/libefivar.abixml b/src/libefivar.abixml +index 094f43d7b27..a719b8baa47 100644 +--- a/src/libefivar.abixml ++++ b/src/libefivar.abixml +@@ -11,7 +11,9 @@ + + + ++ + ++ + + + +@@ -27,10 +29,13 @@ + + + ++ + + + ++ + ++ + + + +@@ -73,6 +78,7 @@ + + + ++ + + + +@@ -105,57 +111,60 @@ + + + +- ++ + + + +- +- +- ++ ++ ++ ++ ++ + +- ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- + + +- ++ + + + + + +- ++ + + + +- +- ++ ++ + +- +- +- +- ++ ++ ++ ++ + +- +- +- ++ ++ ++ + + + +@@ -176,456 +185,472 @@ + + + +- +- +- ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + + + +- ++ + + +- ++ + + ++ ++ + +- +- +- +- ++ ++ ++ ++ + +- ++ + + + +- +- +- ++ ++ ++ + +- ++ + +- +- ++ ++ + +- ++ + + + +- ++ + +- +- +- +- ++ ++ ++ ++ + +- ++ + + +- +- ++ ++ + +- ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- + + + +@@ -634,383 +659,393 @@ + + + +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- +- +- +- ++ + + +- +- +- +- ++ + +- +- +- +- +- ++ ++ + +- +- ++ ++ + +- +- ++ ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + +- +- +- +- +- ++ ++ + +- +- ++ ++ + + +- ++ + + +- ++ ++ ++ ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ ++ ++ ++ ++ ++ ++ + + +- ++ + + +- ++ + + +- ++ ++ ++ ++ + + +- ++ + + +- ++ + + + +- ++ + + +- +- ++ ++ + + + +- +- ++ ++ + + + + + +- ++ + + + +- +- +- ++ ++ ++ + + + +- +- +- ++ ++ ++ + + + +- ++ + + +- ++ + + + +- +- +- +- ++ ++ ++ ++ + + + +- ++ + + + +- +- +- +- ++ ++ ++ ++ + + + +- ++ + + +- +- ++ ++ + +- ++ + +- ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1018,10 +1053,10 @@ + + + +- ++ + + +- ++ + + + +@@ -1029,13 +1064,13 @@ + + + +- ++ + + +- +- ++ ++ + +- ++ + + + +@@ -1044,22 +1079,22 @@ + + + +- +- ++ ++ + +- ++ + + + + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1068,36 +1103,36 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + + +@@ -1106,59 +1141,59 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + + +@@ -1167,28 +1202,28 @@ + + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1197,42 +1232,42 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + + + +- +- ++ ++ + +- ++ + + + +@@ -1241,16 +1276,16 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +@@ -1262,134 +1297,134 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- +- +- ++ ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1402,32 +1437,32 @@ + + + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + + +@@ -1437,11 +1472,11 @@ + + + +- +- ++ ++ + + +- ++ + + + +@@ -1449,13 +1484,13 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1470,40 +1505,40 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +@@ -1518,19 +1553,19 @@ + + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + + +@@ -1539,55 +1574,55 @@ + + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + + +@@ -1596,116 +1631,116 @@ + + + +- +- ++ ++ + +- ++ + + + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + + + + +- +- ++ ++ + +- ++ + + +- ++ + + + + + +- +- ++ ++ + +- ++ + + + + + +- ++ + + +- ++ + +- ++ + + +- ++ + + +- ++ + + + +- +- ++ ++ + + +- ++ + +- ++ + + +- +- ++ ++ + +- ++ + + +- +- ++ ++ + +- +- ++ ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1714,7 +1749,7 @@ + + + +- ++ + + + +@@ -1723,13 +1758,13 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1738,61 +1773,61 @@ + + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + + +@@ -1801,10 +1836,10 @@ + + + +- +- ++ ++ + +- ++ + + + +@@ -1813,82 +1848,82 @@ + + + +- ++ + + +- ++ + + +- +- ++ ++ + +- ++ + + +- ++ + + +- ++ + + +- ++ + + +- +- +- +- ++ ++ ++ ++ + + +- ++ + +- ++ + + + +- ++ + +- ++ + +- +- +- +- ++ ++ ++ ++ + +- +- +- +- ++ ++ ++ ++ + + +- +- +- ++ ++ ++ + + +- +- +- +- ++ ++ ++ ++ + + +- +- +- +- ++ ++ ++ ++ + + +- +- ++ ++ + +- ++ + + + + +- +- +- ++ ++ ++ + + + +@@ -1909,93 +1944,86 @@ + + + +- +- +- +- +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +- +- +- +- +- +- +- +- +- +- ++ + +- +- ++ ++ + +- +- ++ ++ + +- +- ++ ++ + +- ++ + +- +- ++ ++ + +- ++ + +- +- ++ ++ + +- +- ++ ++ + +- +- ++ ++ + + +- ++ + +- +- ++ ++ + + +- ++ + +- +- ++ ++ + ++ + +- + +- ++ + +- +- ++ ++ + + + +- +- ++ ++ + +- +- ++ ++ + + + +- ++ + +- ++ + + + + ++ + + +-- +2.24.1 + diff --git a/SOURCES/0062-Don-t-use-march-native-on-ia64.patch b/SOURCES/0062-Don-t-use-march-native-on-ia64.patch new file mode 100644 index 0000000..ef9c3fb --- /dev/null +++ b/SOURCES/0062-Don-t-use-march-native-on-ia64.patch @@ -0,0 +1,43 @@ +From b99adbbd711ff4c4cc0caa9d171d07914ee7ddef Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 15:58:47 -0500 +Subject: [PATCH 62/86] Don't use -march=native on ia64. + +I don't understand why this architecture hasn't been fully pushed into +the sea*, but somehow there are bug reports anyway. In this case, +because the gcc port is inadequately maintained. + +(* don't pollute the planet this way, destroy the device responsibly.) + +Resolves github issue #144 + +Signed-off-by: Peter Jones +--- + src/include/defaults.mk | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/include/defaults.mk b/src/include/defaults.mk +index af6a41a9824..8a784d00be3 100644 +--- a/src/include/defaults.mk ++++ b/src/include/defaults.mk +@@ -56,10 +56,16 @@ override _CCLDFLAGS := $(CCLDFLAGS) + override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \ + $(call add-prefix,-Wl,$(LDFLAGS)) \ + $(call pkg-config-ccldflags) ++HOST_ARCH=$(shell uname -m) ++ifneq ($(HOST_ARCH),ia64) ++ HOST_MARCH=-march=native ++else ++ HOST_MARCH= ++endif + HOST_CPPFLAGS ?= $(CPPFLAGS) + override _HOST_CPPFLAGS := $(HOST_CPPFLAGS) + override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \ +- -DEFIVAR_BUILD_ENVIRONMENT -march=native ++ -DEFIVAR_BUILD_ENVIRONMENT $(HOST_MARCH) + HOST_CFLAGS ?= $(CFLAGS) + override _HOST_CFLAGS := $(HOST_CFLAGS) + override HOST_CFLAGS = $(_HOST_CFLAGS) +-- +2.24.1 + diff --git a/SOURCES/0063-Work-around-autoconf-existing-in-the-world.patch b/SOURCES/0063-Work-around-autoconf-existing-in-the-world.patch new file mode 100644 index 0000000..cfb089b --- /dev/null +++ b/SOURCES/0063-Work-around-autoconf-existing-in-the-world.patch @@ -0,0 +1,56 @@ +From 191e3b01463548fc3a99494cd0c0ec15c41e9382 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 16:27:42 -0500 +Subject: [PATCH 63/86] Work around autoconf existing in the world. + +Long long ago, autoconf added a variable called to pass linker flags to +the compiler. For some misguided reason, they prefixed it with LD (the +linker) instead of "CC" (the compiler). Now people unquestioningly +complain if you use that name a more reasonable way, so we're stuck with +names that are counter-descriptive. You just can't win, the well is too +full of poison. + +Resolves github issue #142. + +Signed-off-by: Peter Jones +--- + src/include/defaults.mk | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/src/include/defaults.mk b/src/include/defaults.mk +index 8a784d00be3..781587b4215 100644 +--- a/src/include/defaults.mk ++++ b/src/include/defaults.mk +@@ -40,21 +40,21 @@ override CFLAGS = $(_CFLAGS) \ + -fvisibility=hidden \ + $(call family,CFLAGS) \ + $(call pkg-config-cflags) +-LDFLAGS_CLANG ?= --fatal-warnings -pie -z relro ++LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-pie,-z,relro + LDFLAGS ?= + override _LDFLAGS := $(LDFLAGS) + override LDFLAGS = $(_LDFLAGS) \ +- --add-needed \ +- --build-id \ +- --no-allow-shlib-undefined \ +- --no-undefined-version \ +- -z now \ +- -z muldefs \ ++ -Wl,--add-needed \ ++ -Wl,--build-id \ ++ -Wl,--no-allow-shlib-undefined \ ++ -Wl,--no-undefined-version \ ++ -Wl,-z,now \ ++ -Wl,-z,muldefs \ + $(call family,LDFLAGS) + CCLDFLAGS ?= + override _CCLDFLAGS := $(CCLDFLAGS) + override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \ +- $(call add-prefix,-Wl,$(LDFLAGS)) \ ++ $(LDFLAGS) \ + $(call pkg-config-ccldflags) + HOST_ARCH=$(shell uname -m) + ifneq ($(HOST_ARCH),ia64) +-- +2.24.1 + diff --git a/SOURCES/0064-Fix-efivar-w-and-efivar-a.patch b/SOURCES/0064-Fix-efivar-w-and-efivar-a.patch new file mode 100644 index 0000000..4c8eb07 --- /dev/null +++ b/SOURCES/0064-Fix-efivar-w-and-efivar-a.patch @@ -0,0 +1,37 @@ +From fa29161221937243dd7c3a11908aa020aa5e990c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 16:40:32 -0500 +Subject: [PATCH 64/86] Fix "efivar -w" and "efivar -a" + +When adding --export, I broke -w and -a by accidentally using the wrong +variable to get the data from. Woops. + +Resolves github issue #143 + +Signed-off-by: Peter Jones +--- + src/efivar.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/efivar.c b/src/efivar.c +index 8b1da8888f6..edfd4af7e01 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -614,12 +614,12 @@ int main(int argc, char *argv[]) + show_variable(guid_name, SHOW_DECIMAL); + break; + case ACTION_APPEND | ACTION_PRINT: +- prepare_data(infile, &data, &data_size); ++ prepare_data(datafile, &data, &data_size); + edit_variable(guid_name, data, data_size, attributes, + EDIT_APPEND); + break; + case ACTION_WRITE | ACTION_PRINT: +- prepare_data(infile, &data, &data_size); ++ prepare_data(datafile, &data, &data_size); + edit_variable(guid_name, data, data_size, attributes, + EDIT_WRITE); + break; +-- +2.24.1 + diff --git a/SOURCES/0065-Android-fix-incorrect-include-path.patch b/SOURCES/0065-Android-fix-incorrect-include-path.patch new file mode 100644 index 0000000..3aac815 --- /dev/null +++ b/SOURCES/0065-Android-fix-incorrect-include-path.patch @@ -0,0 +1,28 @@ +From c98d11a74f29c91e850aeafd7e09a42b4d883704 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Wed, 22 Jan 2020 10:47:20 +0800 +Subject: [PATCH 65/86] Android: fix incorrect include path + +Fixes: 3ba12ff9 ("Move our infrastructure makefiles out of the topdir") + +Signed-off-by: Chih-Wei Huang +--- + src/Android.mk | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/Android.mk b/src/Android.mk +index ea6ee3f9432..57ac2b55846 100644 +--- a/src/Android.mk ++++ b/src/Android.mk +@@ -46,7 +46,7 @@ LIBEFIVAR_SOURCES := \ + lib.c \ + vars.c + +-include $(LOCAL_PATH)/../version.mk ++include $(LOCAL_PATH)/include/version.mk + + LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) + LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION) +-- +2.24.1 + diff --git a/SOURCES/0066-Android-fix-missing-field-initializers.patch b/SOURCES/0066-Android-fix-missing-field-initializers.patch new file mode 100644 index 0000000..77871bc --- /dev/null +++ b/SOURCES/0066-Android-fix-missing-field-initializers.patch @@ -0,0 +1,35 @@ +From e79af5540f11bf04905fd13660b0bb80ec995094 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Wed, 22 Jan 2020 11:36:58 +0800 +Subject: [PATCH 66/86] Android: fix missing field initializers + +To fix the error: + +external/efivar/src/linux-nvme.c:73:10: error: missing field 'fmt' initializer [-Werror,-Wmissing-field-initializers] + {NULL, } + ^ +1 error generated. + +Fixes: c41da0bd ("Handle /sys/devices/virtual/{nvme-fabrics,nvme-subsystem} devices") + +Signed-off-by: Chih-Wei Huang +--- + src/Android.mk | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/Android.mk b/src/Android.mk +index 57ac2b55846..f6af87c51ac 100644 +--- a/src/Android.mk ++++ b/src/Android.mk +@@ -49,7 +49,7 @@ LIBEFIVAR_SOURCES := \ + include $(LOCAL_PATH)/include/version.mk + + LOCAL_SRC_FILES := $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) +-LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION) ++LOCAL_CFLAGS := -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -std=gnu11 -DLIBEFIVAR_VERSION=$(VERSION) -Wno-missing-field-initializers + LOCAL_C_INCLUDES := $(LOCAL_PATH)/include + LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_C_INCLUDES) $(LOCAL_C_INCLUDES)/efivar $(local-generated-sources-dir) + LIBEFIVAR_GUIDS_H := $(local-generated-sources-dir)/efivar/efivar-guids.h +-- +2.24.1 + diff --git a/SOURCES/0067-Fix-variable-sz-uninitialized-error.patch b/SOURCES/0067-Fix-variable-sz-uninitialized-error.patch new file mode 100644 index 0000000..2117c37 --- /dev/null +++ b/SOURCES/0067-Fix-variable-sz-uninitialized-error.patch @@ -0,0 +1,39 @@ +From 9dc04c2fd88b6e0e0fe411885041925d52f71af3 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Wed, 22 Jan 2020 12:16:12 +0800 +Subject: [PATCH 67/86] Fix variable 'sz' uninitialized error + +To fix the error: + +external/efivar/src/linux-virtual-root.c:66:4: error: variable 'sz' is uninitialized when used here [-Werror,-Wuninitialized] + sz += pos1; + ^~ +external/efivar/src/linux-virtual-root.c:45:12: note: initialize the variable 'sz' to silence this warning + ssize_t sz; + ^ + = 0 +1 error generated. + +Fixes: c41da0bd ("Handle /sys/devices/virtual/{nvme-fabrics,nvme-subsystem} devices") + +Signed-off-by: Chih-Wei Huang +--- + src/linux-virtual-root.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c +index 75fbbfc1de6..2d39c28ebb6 100644 +--- a/src/linux-virtual-root.c ++++ b/src/linux-virtual-root.c +@@ -42,7 +42,7 @@ static ssize_t + parse_virtual_root(struct device *dev UNUSED, const char *current, const char *root UNUSED) + { + int rc; +- ssize_t sz; ++ ssize_t sz = 0; + int pos0 = 0, pos1 = 0; + struct subdir { + const char * const name; +-- +2.24.1 + diff --git a/SOURCES/0068-Fix-an-argument-mismatch-error.patch b/SOURCES/0068-Fix-an-argument-mismatch-error.patch new file mode 100644 index 0000000..89f1247 --- /dev/null +++ b/SOURCES/0068-Fix-an-argument-mismatch-error.patch @@ -0,0 +1,45 @@ +From 3cf3b3d5cf3f6ff7ddb315676e338a0632aa6dc8 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Wed, 22 Jan 2020 12:19:35 +0800 +Subject: [PATCH 68/86] Fix an argument mismatch error + +MSDOS_MBR_MAGIC is an int, no need to specify the 'h' (unsigned short) +modifier. This avoids the error (built with clang): + +external/efivar/src/disk.c:59:18: error: format specifies type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat] + mbr->magic, MSDOS_MBR_MAGIC); + ^~~~~~~~~~~~~~~ +external/efivar/src/include/efivar/efivar.h:244:66: note: expanded from macro 'efi_error' + efi_error_real__(errno, __FILE__, __func__, __LINE__, (fmt), ## args) + ^~~~ +external/efivar/src/include/efivar/efivar.h:241:56: note: expanded from macro 'efi_error_real__' + efi_error_set(file, function, line, errval, (fmt), ## args) + ^~~~ +external/efivar/src/gpt.h:32:25: note: expanded from macro 'MSDOS_MBR_MAGIC' + #define MSDOS_MBR_MAGIC 0xaa55 + ^~~~~~ +1 error generated. + +Fixes: 038afd7a ("Always refer to MBR and GPT fixed values as 'magic' not 'signature'") + +Signed-off-by: Chih-Wei Huang +--- + src/disk.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/disk.c b/src/disk.c +index 3b5bf8330b1..2eaf57436a2 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -55,7 +55,7 @@ is_mbr_valid(legacy_mbr *mbr) + ret = (mbr->magic == MSDOS_MBR_MAGIC); + if (!ret) { + errno = ENOTTY; +- efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04hx)", ++ efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04x)", + mbr->magic, MSDOS_MBR_MAGIC); + } + return ret; +-- +2.24.1 + diff --git a/SOURCES/0069-Android-fix-building-errors.patch b/SOURCES/0069-Android-fix-building-errors.patch new file mode 100644 index 0000000..66c04c6 --- /dev/null +++ b/SOURCES/0069-Android-fix-building-errors.patch @@ -0,0 +1,66 @@ +From 301bf0d2968136df30bcd6ae9f294e504ec347a8 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Wed, 22 Jan 2020 12:26:27 +0800 +Subject: [PATCH 69/86] Android: fix building errors + +Android bionic doesn't have cookie_io_functions_t, memfd_create and +fopencookie yet. So just disable the debug feature. + +Signed-off-by: Chih-Wei Huang +--- + src/error.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/error.c b/src/error.c +index b1a56ef629c..f865bb61e51 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -166,10 +166,12 @@ efi_error_pop(void) + + static int efi_verbose; + static FILE *efi_errlog, *efi_dbglog; ++#ifndef ANDROID + static int efi_dbglog_fd = -1; + static intptr_t efi_dbglog_cookie; +-static int log_level; + static char efi_dbglog_buf[4096]; ++#endif ++static int log_level; + + void PUBLIC + efi_set_loglevel(int level) +@@ -177,6 +179,7 @@ efi_set_loglevel(int level) + log_level = level; + } + ++#ifndef ANDROID + static ssize_t + dbglog_write(void *cookie, const char *buf, size_t size) + { +@@ -226,6 +229,7 @@ dbglog_close(void *cookie UNUSED) + errno = EBADF; + return -1; + } ++#endif + + void PUBLIC + efi_error_clear(void) +@@ -255,6 +259,7 @@ efi_error_fini(void) + static void CONSTRUCTOR + efi_error_init(void) + { ++#ifndef ANDROID + ssize_t bytes; + cookie_io_functions_t io_funcs = { + .write = dbglog_write, +@@ -274,6 +279,7 @@ efi_error_init(void) + if (efi_dbglog) + setvbuf(efi_dbglog, efi_dbglog_buf, _IOLBF, + sizeof(efi_dbglog_buf)); ++#endif + } + + FILE PUBLIC * +-- +2.24.1 + diff --git a/SOURCES/0070-Fix-the-MSDOS_MBR_MAGIC-type-not-the-format-string.patch b/SOURCES/0070-Fix-the-MSDOS_MBR_MAGIC-type-not-the-format-string.patch new file mode 100644 index 0000000..957fa5e --- /dev/null +++ b/SOURCES/0070-Fix-the-MSDOS_MBR_MAGIC-type-not-the-format-string.patch @@ -0,0 +1,49 @@ +From db5e7f4244150b108970093fdc97072934e2bf2a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 Jan 2020 13:15:51 -0500 +Subject: [PATCH 70/86] Fix the MSDOS_MBR_MAGIC type, not the format string. + +The value of MSDOS_MBR_MAGIC is 16 bits; make it evaluate that way, +instead of promoting it to int for efi_error() formatting. + +Fixes: 3cf3b3d5cf3f6ff7ddb315676e338a0632aa6dc8 + +Signed-off-by: Peter Jones +--- + src/disk.c | 2 +- + src/gpt.h | 6 +++--- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/disk.c b/src/disk.c +index 2eaf57436a2..3b5bf8330b1 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -55,7 +55,7 @@ is_mbr_valid(legacy_mbr *mbr) + ret = (mbr->magic == MSDOS_MBR_MAGIC); + if (!ret) { + errno = ENOTTY; +- efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04x)", ++ efi_error("mbr magic is 0x%04hx not MSDOS_MBR_MAGIC (0x%04hx)", + mbr->magic, MSDOS_MBR_MAGIC); + } + return ret; +diff --git a/src/gpt.h b/src/gpt.h +index 66fbc21106c..45a048b21e1 100644 +--- a/src/gpt.h ++++ b/src/gpt.h +@@ -27,9 +27,9 @@ + + #include + +-#define EFI_PMBR_OSTYPE_EFI 0xEF +-#define EFI_PMBR_OSTYPE_EFI_GPT 0xEE +-#define MSDOS_MBR_MAGIC 0xaa55 ++#define EFI_PMBR_OSTYPE_EFI ((uint8_t)0xEF) ++#define EFI_PMBR_OSTYPE_EFI_GPT ((uint8_t)0xEE) ++#define MSDOS_MBR_MAGIC ((uint16_t)0xaa55) + #define GPT_BLOCK_SIZE 512 + + #define GPT_HEADER_MAGIC ((uint64_t)(0x5452415020494645ULL)) +-- +2.24.1 + diff --git a/SOURCES/0071-Make-scan-build-and-CC-clang-work-again.patch b/SOURCES/0071-Make-scan-build-and-CC-clang-work-again.patch new file mode 100644 index 0000000..8bb5cc8 --- /dev/null +++ b/SOURCES/0071-Make-scan-build-and-CC-clang-work-again.patch @@ -0,0 +1,174 @@ +From 2bec15e310de37398cf5bb8135f15d15ab2bb54b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 Jan 2020 15:35:17 -0500 +Subject: [PATCH 71/86] Make scan-build and CC=clang work again. + +Signed-off-by: Peter Jones +--- + src/Makefile | 3 +++ + src/include/defaults.mk | 58 ++++++++++++++++++++++++++++++++--------- + src/include/deps.mk | 4 +-- + src/include/rules.mk | 2 -- + 4 files changed, 50 insertions(+), 17 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index 1d0e217c89b..144289d4709 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -53,8 +53,11 @@ include/efivar/efivar-guids.h : makeguids guids.txt + + makeguids : CPPFLAGS=$(HOST_CPPFLAGS) + makeguids : LIBS=dl ++makeguids : CC=$(HOSTCC) + makeguids : CCLD=$(HOSTCCLD) + makeguids : CFLAGS=$(HOST_CFLAGS) ++makeguids : LDFLAGS=$(HOST_LDFLAGS) ++makeguids : CCLDFLAGS=$(HOST_CCLDFLAGS) + makeguids : $(MAKEGUIDS_SOURCES) + + guids.o : guids.S | guids.bin names.bin +diff --git a/src/include/defaults.mk b/src/include/defaults.mk +index 781587b4215..bc515e36305 100644 +--- a/src/include/defaults.mk ++++ b/src/include/defaults.mk +@@ -9,13 +9,18 @@ PCDIR ?= $(LIBDIR)/pkgconfig + DESTDIR ?= + + CROSS_COMPILE ?= +-COMPILER ?= gcc ++COMPILER ?= gcc ++ifeq ($(origin CC),command line) ++override COMPILER := $(CC) ++override CC := $(CROSS_COMPILE)$(COMPILER) ++endif + $(call set-if-undefined,CC,$(CROSS_COMPILE)$(COMPILER)) + $(call set-if-undefined,CCLD,$(CC)) + $(call set-if-undefined,HOSTCC,$(COMPILER)) + $(call set-if-undefined,HOSTCCLD,$(HOSTCC)) + +-OPTIMIZE ?= -O2 -flto ++OPTIMIZE_GCC = -flto ++OPTIMIZE ?= -O2 $(call family,OPTIMIZE) + DEBUGINFO ?= -g3 + WARNINGS_GCC ?= -Wmaybe-uninitialized \ + -Wno-nonnull-compare +@@ -30,7 +35,7 @@ override _CPPFLAGS := $(CPPFLAGS) + override CPPFLAGS = $(_CPPFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) \ + -D_GNU_SOURCE \ + -I$(TOPDIR)/src/include/ +-CFLAGS ?= $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS) ++CFLAGS ?= $(FULL_OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS) + CFLAGS_GCC ?= -specs=$(TOPDIR)/src/include/gcc.specs \ + -fno-merge-constants + override _CFLAGS := $(CFLAGS) +@@ -40,22 +45,32 @@ override CFLAGS = $(_CFLAGS) \ + -fvisibility=hidden \ + $(call family,CFLAGS) \ + $(call pkg-config-cflags) +-LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-pie,-z,relro ++LDFLAGS_CLANG ?= -rtlib=compiler-rt ++CCLDFLAGS ?= + LDFLAGS ?= ++override _CCLDFLAGS := $(CCLDFLAGS) + override _LDFLAGS := $(LDFLAGS) +-override LDFLAGS = $(_LDFLAGS) \ ++override LDFLAGS = $(CFLAGS) -L. $(_LDFLAGS) $(_CCLDFLAGS) \ + -Wl,--add-needed \ + -Wl,--build-id \ + -Wl,--no-allow-shlib-undefined \ + -Wl,--no-undefined-version \ + -Wl,-z,now \ + -Wl,-z,muldefs \ +- $(call family,LDFLAGS) +-CCLDFLAGS ?= +-override _CCLDFLAGS := $(CCLDFLAGS) +-override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \ +- $(LDFLAGS) \ +- $(call pkg-config-ccldflags) ++ -Wl,-z,relro \ ++ -Wl,--fatal-warnings \ ++ $(call family,LDFLAGS) $(call family,CCLDFLAGS) \ ++ $(call pkg-config-ccldflags) ++override CCLDFLAGS = $(LDFLAGS) ++SOFLAGS_GCC = ++SOFLAGS_CLANG = ++SOFLAGS ?= ++override _SOFLAGS := $(SOFLAGS) ++override SOFLAGS = $(_SOFLAGS) \ ++ -shared -Wl,-soname,$@.1 \ ++ -Wl,--version-script=$(MAP) \ ++ $(call family,SOFLAGS) ++ + HOST_ARCH=$(shell uname -m) + ifneq ($(HOST_ARCH),ia64) + HOST_MARCH=-march=native +@@ -66,9 +81,27 @@ HOST_CPPFLAGS ?= $(CPPFLAGS) + override _HOST_CPPFLAGS := $(HOST_CPPFLAGS) + override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \ + -DEFIVAR_BUILD_ENVIRONMENT $(HOST_MARCH) +-HOST_CFLAGS ?= $(CFLAGS) ++HOST_CFLAGS_CLANG ?= ++HOST_CFLAGS ?= $(CFLAGS) $(call family,HOST_CFLAGS) + override _HOST_CFLAGS := $(HOST_CFLAGS) + override HOST_CFLAGS = $(_HOST_CFLAGS) ++HOST_LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-z,relro -rtlib=compiler-rt ++HOST_LDFLAGS_GCC ?= -Wl,--no-undefined-version ++HOST_LDFLAGS ?= ++HOST_CCLDFLAGS ?= ++override _HOST_LDFLAGS := $(HOST_LDFLAGS) ++override _HOST_CCLDFLAGS := $(HOST_CCLDFLAGS) ++override HOST_LDFLAGS = $(HOST_CFLAGS) -L. \ ++ $(_HOST_LDFLAGS) $(_HOST_CCLDFLAGS) \ ++ -Wl,--add-needed \ ++ -Wl,--build-id \ ++ -Wl,--no-allow-shlib-undefined \ ++ -Wl,-z,now \ ++ -Wl,-z,muldefs \ ++ $(call family,HOST_LDFLAGS) \ ++ $(call family,HOST_CCLDFLAGS) \ ++ $(call pkg-config-ccldflags) ++override HOST_CCLDFLAGS = $(HOST_LDFLAGS) + + PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi) + INSTALL ?= install +@@ -80,7 +113,6 @@ ABIDIFF := abidiff + + PKGS = + +-SOFLAGS=-shared $(call family,SOFLAGS) + LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs) + + COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master) +diff --git a/src/include/deps.mk b/src/include/deps.mk +index a797d1bdbf5..3c8243144dc 100644 +--- a/src/include/deps.mk ++++ b/src/include/deps.mk +@@ -7,10 +7,10 @@ include $(TOPDIR)/src/include/rules.mk + include $(TOPDIR)/src/include/defaults.mk + + .%.d : %.c +- $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^ ++ $(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^ + + .%.d : %.S +- $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^ ++ $(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^ + + SOURCES ?= + +diff --git a/src/include/rules.mk b/src/include/rules.mk +index ff0ff4ef61b..99a6329e3fe 100644 +--- a/src/include/rules.mk ++++ b/src/include/rules.mk +@@ -30,8 +30,6 @@ family = $(foreach FAMILY_SUFFIX,$(FAMILY_SUFFIXES),$($(1)_$(FAMILY_SUFFIX))) + + %.so : + $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \ +- -Wl,-soname,$@.1 \ +- -Wl,--version-script=$(MAP) \ + -o $@ $^ $(LDLIBS) + ln -vfs $@ $@.1 + +-- +2.24.1 + diff --git a/SOURCES/0072-Remove-a-dead-store.patch b/SOURCES/0072-Remove-a-dead-store.patch new file mode 100644 index 0000000..3fe83bc --- /dev/null +++ b/SOURCES/0072-Remove-a-dead-store.patch @@ -0,0 +1,42 @@ +From 025e71fb477bfc227d1ba59b85ee8153703cc4a3 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Jan 2020 10:35:35 -0500 +Subject: [PATCH 72/86] Remove a dead store. + +ccc-analyzer noticed: + +Bug Group Bug Type File Function/Method Line Path Length +Dead store Dead increment linux-nvme.c parse_nvme 89 1 + +Which is a "sz += ..." I accidentally left in when I switched all the +file path parsers to just using the string pointer "current" and +subtracting it from "path" at the end. + +Signed-off-by: Peter Jones +--- + src/linux-nvme.c | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index d0941e85e08..33edcd4fc7d 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -61,7 +61,6 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; + uint8_t *filebuf = NULL; + int pos0 = -1, pos1 = -1, pos2 = -1; +- ssize_t sz = 0; + struct subdir { + const char * const name; + const char * const fmt; +@@ -86,7 +85,6 @@ parse_nvme(struct device *dev, const char *path, const char *root UNUSED) + *subdirs[i].pos0, *subdirs[i].pos1); + dbgmk(" ", *subdirs[i].pos0, *subdirs[i].pos1); + if (*subdirs[i].pos0 >= 0 && *subdirs[i].pos1 >= *subdirs[i].pos0) { +- sz += *subdirs[i].pos1; + current += *subdirs[i].pos1; + break; + } +-- +2.24.1 + diff --git a/SOURCES/0073-makeguids-confuse-ccc-analyzer-less.patch b/SOURCES/0073-makeguids-confuse-ccc-analyzer-less.patch new file mode 100644 index 0000000..33de4c2 --- /dev/null +++ b/SOURCES/0073-makeguids-confuse-ccc-analyzer-less.patch @@ -0,0 +1,38 @@ +From f4952ecf70ab6de206d63f24d050f4303eccce45 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Jan 2020 10:47:11 -0500 +Subject: [PATCH 73/86] makeguids: confuse ccc-analyzer less. + +Putting the non-NULL and non-NUL tests inside the loop confuses +ccc-analyzer into thinking it might be NULL later when we pass it to +strchr(). + +It can't, but I like a clean scan. + +Signed-off-by: Peter Jones +--- + src/makeguids.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/src/makeguids.c b/src/makeguids.c +index f12dac3bb15..c0a9db1509c 100644 +--- a/src/makeguids.c ++++ b/src/makeguids.c +@@ -141,9 +141,11 @@ main(int argc, char *argv[]) + + char *guidstr = inbuf; + unsigned int line; +- for (line = 1; (uintptr_t)guidstr - (uintptr_t)inbuf < inlen; line++) { +- if (guidstr && guidstr[0] == '\0') +- break; ++ for (line = 1; ++ guidstr && guidstr[0] != '\0' && ++ (uintptr_t)guidstr - (uintptr_t)inbuf < inlen; ++ line++) { ++ + outbuf = realloc(outbuf, line * sizeof (struct guidname)); + if (!outbuf) + err(1, "makeguids"); +-- +2.24.1 + diff --git a/SOURCES/0074-SPDX-ify-all-the-license-text-in-source-files.patch b/SOURCES/0074-SPDX-ify-all-the-license-text-in-source-files.patch new file mode 100644 index 0000000..be98601 --- /dev/null +++ b/SOURCES/0074-SPDX-ify-all-the-license-text-in-source-files.patch @@ -0,0 +1,1629 @@ +From ce42f1d567ee931fb1b47e439d29b2071f3e9b98 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Jan 2020 11:27:20 -0500 +Subject: [PATCH 74/86] SPDX-ify all the license text in source files. + +Signed-off-by: Peter Jones +--- + src/crc32.c | 1 + + src/crc32.h | 15 +-------------- + src/creator.c | 16 +--------------- + src/disk.c | 16 +--------------- + src/disk.h | 16 +--------------- + src/dp-acpi.c | 16 +--------------- + src/dp-hw.c | 16 +--------------- + src/dp-media.c | 16 +--------------- + src/dp-message.c | 16 +--------------- + src/dp.c | 16 +--------------- + src/dp.h | 16 +--------------- + src/efiboot.h | 15 +-------------- + src/efivar.c | 16 +--------------- + src/efivar.h | 15 +-------------- + src/efivar_endian.h | 15 +-------------- + src/efivarfs.c | 16 +--------------- + src/error.c | 16 +--------------- + src/export.c | 16 +--------------- + src/fix_coverity.h | 2 +- + src/generics.h | 16 +--------------- + src/gpt.c | 16 +--------------- + src/gpt.h | 18 +++--------------- + src/guid.c | 16 +--------------- + src/guid.h | 17 +---------------- + src/hexdump.h | 5 +++++ + src/include/efivar/efiboot-creator.h | 16 +--------------- + src/include/efivar/efiboot-loadopt.h | 16 +--------------- + src/include/efivar/efiboot.h | 16 +--------------- + src/include/efivar/efivar-dp.h | 15 +-------------- + src/include/efivar/efivar.h | 16 +--------------- + src/lib.c | 16 +--------------- + src/lib.h | 16 +--------------- + src/linux-acpi-root.c | 16 +--------------- + src/linux-acpi.c | 16 +--------------- + src/linux-ata.c | 16 +--------------- + src/linux-emmc.c | 16 +--------------- + src/linux-i2o.c | 16 +--------------- + src/linux-md.c | 16 +--------------- + src/linux-nvme.c | 15 +-------------- + src/linux-pci-root.c | 16 +--------------- + src/linux-pci.c | 16 +--------------- + src/linux-pmem.c | 16 +--------------- + src/linux-sas.c | 16 +--------------- + src/linux-sata.c | 16 +--------------- + src/linux-scsi.c | 16 +--------------- + src/linux-soc-root.c | 16 +--------------- + src/linux-virtblk.c | 16 +--------------- + src/linux-virtual-root.c | 15 +-------------- + src/linux.c | 16 +--------------- + src/linux.h | 16 +--------------- + src/loadopt.c | 16 +--------------- + src/makeguids.c | 16 +--------------- + src/path-helpers.c | 15 +-------------- + src/path-helpers.h | 15 +-------------- + src/safemath.h | 16 +--------------- + src/test/tester.c | 18 ++++-------------- + src/ucs2.h | 16 +--------------- + src/util.h | 15 +-------------- + src/vars.c | 16 +--------------- + 59 files changed, 68 insertions(+), 831 deletions(-) + +diff --git a/src/crc32.c b/src/crc32.c +index 533d2c0f551..4fa4bf44bc5 100644 +--- a/src/crc32.c ++++ b/src/crc32.c +@@ -1,3 +1,4 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * Dec 5, 2000 Matt Domsch + * - Copied crc32.c from the linux/drivers/net/cipe directory. +diff --git a/src/crc32.h b/src/crc32.h +index 4e833aafac0..1027d2be6d1 100644 +--- a/src/crc32.h ++++ b/src/crc32.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * crc32.h - headers for crc32 + * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #ifndef _CRC32_H +diff --git a/src/creator.c b/src/creator.c +index 8a2f8e79aca..0ea27841104 100644 +--- a/src/creator.c ++++ b/src/creator.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/disk.c b/src/disk.c +index 3b5bf8330b1..94a56c7e57a 100644 +--- a/src/disk.c ++++ b/src/disk.c +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2000-2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/disk.h b/src/disk.h +index 8ba0f4602f4..100b8d1e0a2 100644 +--- a/src/disk.h ++++ b/src/disk.h +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIBOOT_DISK_H + #define _EFIBOOT_DISK_H +diff --git a/src/dp-acpi.c b/src/dp-acpi.c +index ae4102cdf56..c9d158626b5 100644 +--- a/src/dp-acpi.c ++++ b/src/dp-acpi.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/dp-hw.c b/src/dp-hw.c +index 28998316d9d..e09984db052 100644 +--- a/src/dp-hw.c ++++ b/src/dp-hw.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/dp-media.c b/src/dp-media.c +index 7f5d1c678ce..df472648862 100644 +--- a/src/dp-media.c ++++ b/src/dp-media.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/dp-message.c b/src/dp-message.c +index d00b2ad5d67..03cd9961d70 100644 +--- a/src/dp-message.c ++++ b/src/dp-message.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/dp.c b/src/dp.c +index f6a4b2ddafa..a25d0f27d43 100644 +--- a/src/dp.c ++++ b/src/dp.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/dp.h b/src/dp.h +index 6609b0d827e..8290cc17022 100644 +--- a/src/dp.h ++++ b/src/dp.h +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIVAR_INTERNAL_DP_H + #define _EFIVAR_INTERNAL_DP_H +diff --git a/src/efiboot.h b/src/efiboot.h +index 23275ed82bf..f3e3236261b 100644 +--- a/src/efiboot.h ++++ b/src/efiboot.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * efiboot.h + * Copyright 2018 Peter Jones +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + + #ifndef PRIVATE_EFIBOOT_H_ +diff --git a/src/efivar.c b/src/efivar.c +index edfd4af7e01..2a8f2353ce2 100644 +--- a/src/efivar.c ++++ b/src/efivar.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/efivar.h b/src/efivar.h +index 646863d14c5..1191cf8b000 100644 +--- a/src/efivar.h ++++ b/src/efivar.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * efivar.h + * Copyright 2018 Peter Jones +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + + #ifndef PRIVATE_EFIVAR_H_ +diff --git a/src/efivar_endian.h b/src/efivar_endian.h +index bed4603ad71..460778491ed 100644 +--- a/src/efivar_endian.h ++++ b/src/efivar_endian.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * Copyright 2009-2015 Red Hat, Inc. + * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + * Author: Peter Jones + */ + #ifndef _EFIVAR_ENDIAN_H +diff --git a/src/efivarfs.c b/src/efivarfs.c +index ec2585a6648..dfd02d5ffbd 100644 +--- a/src/efivarfs.c ++++ b/src/efivarfs.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/error.c b/src/error.c +index f865bb61e51..fb05c74b962 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2000-2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/export.c b/src/export.c +index 732b4bf30ad..30f706484ab 100644 +--- a/src/export.c ++++ b/src/export.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/fix_coverity.h b/src/fix_coverity.h +index acb4cc65eff..8daa5df8fbc 100644 +--- a/src/fix_coverity.h ++++ b/src/fix_coverity.h +@@ -1,8 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * fix_coverity.h + * Copyright 2017 Peter Jones + * +- * Distributed under terms of the GPLv3 license. + */ + + #ifndef FIX_COVERITY_H +diff --git a/src/generics.h b/src/generics.h +index 8ade54ee96b..06cf64cd4bf 100644 +--- a/src/generics.h ++++ b/src/generics.h +@@ -1,20 +1,6 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * Copyright 2012-2016 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #ifndef EFIVAR_BUILD_ENVIRONMENT +diff --git a/src/gpt.c b/src/gpt.c +index 8babafeb588..823edba7cab 100644 +--- a/src/gpt.c ++++ b/src/gpt.c +@@ -1,3 +1,4 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * gpt.[ch] + * Copyright (C) 2000-2001 Dell Computer Corporation +@@ -5,21 +6,6 @@ + * EFI GUID Partition Table handling + * Per Intel EFI Specification v1.02 + * http://developer.intel.com/technology/efi/efi.htm +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/gpt.h b/src/gpt.h +index 45a048b21e1..06696acbb61 100644 +--- a/src/gpt.h ++++ b/src/gpt.h +@@ -1,25 +1,13 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * gpt.[ch] + * Copyright (C) 2000-2001 Dell Computer Corporation ++ * Copyright 2015-2020 Red Hat, Inc. ++ * Copyright 2015-2020 Peter M. Jones + * + * EFI GUID Partition Table handling + * Per Intel EFI Specification v1.02 + * http://developer.intel.com/technology/efi/efi.htm +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #ifndef _EFIBOOT_GPT_H +diff --git a/src/guid.c b/src/guid.c +index 34efb132d51..0d6ed981dc7 100644 +--- a/src/guid.c ++++ b/src/guid.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2014 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/guid.h b/src/guid.h +index 3229621a3f1..2dbf8d92aa8 100644 +--- a/src/guid.h ++++ b/src/guid.h +@@ -1,23 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ +- + #ifndef LIBEFIVAR_GUID_H + #define LIBEFIVAR_GUID_H 1 + +diff --git a/src/hexdump.h b/src/hexdump.h +index d88aa507b8d..80d7330db16 100644 +--- a/src/hexdump.h ++++ b/src/hexdump.h +@@ -1,3 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later ++/* ++ * libefivar - library for the manipulation of EFI variables ++ * Copyright 2018-2020 Peter M. Jones ++ */ + #ifndef STATIC_HEXDUMP_H + #define STATIC_HEXDUMP_H + +diff --git a/src/include/efivar/efiboot-creator.h b/src/include/efivar/efiboot-creator.h +index b6e094c637c..308ea4950a6 100644 +--- a/src/include/efivar/efiboot-creator.h ++++ b/src/include/efivar/efiboot-creator.h +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIBOOT_CREATOR_H + #define _EFIBOOT_CREATOR_H +diff --git a/src/include/efivar/efiboot-loadopt.h b/src/include/efivar/efiboot-loadopt.h +index 97b7892f4b8..3c723a106d9 100644 +--- a/src/include/efivar/efiboot-loadopt.h ++++ b/src/include/efivar/efiboot-loadopt.h +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIBOOT_LOADOPT_H + #define _EFIBOOT_LOADOPT_H 1 +diff --git a/src/include/efivar/efiboot.h b/src/include/efivar/efiboot.h +index 8ae51ffa2a7..e52ab8f4b2a 100644 +--- a/src/include/efivar/efiboot.h ++++ b/src/include/efivar/efiboot.h +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef EFIBOOT_H + #define EFIBOOT_H 1 +diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h +index 706d25bdebd..8a1d29e63df 100644 +--- a/src/include/efivar/efivar-dp.h ++++ b/src/include/efivar/efivar-dp.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2015 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public License +- * along with this library. If not, see . +- * + */ + #ifndef _EFIVAR_DP_H + #define _EFIVAR_DP_H 1 +diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h +index 8ad14b9be57..cc5dcc5657a 100644 +--- a/src/include/efivar/efivar.h ++++ b/src/include/efivar/efivar.h +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2014 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef EFIVAR_H + #define EFIVAR_H 1 +diff --git a/src/lib.c b/src/lib.c +index b2eea6c2569..107e7efe688 100644 +--- a/src/lib.c ++++ b/src/lib.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/lib.h b/src/lib.h +index 3cc29a01fb4..26e0f169bd1 100644 +--- a/src/lib.h ++++ b/src/lib.h +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #ifndef LIBEFIVAR_LIB_H +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 86693c81878..c4c00e7db0a 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-acpi.c b/src/linux-acpi.c +index 534573f32c1..e4adb8a1384 100644 +--- a/src/linux-acpi.c ++++ b/src/linux-acpi.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-ata.c b/src/linux-ata.c +index a51ed5abbe0..064a424787f 100644 +--- a/src/linux-ata.c ++++ b/src/linux-ata.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index 2b8ae64f0fb..800dc14d49f 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-i2o.c b/src/linux-i2o.c +index b53f4516309..3aea7d35338 100644 +--- a/src/linux-i2o.c ++++ b/src/linux-i2o.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-md.c b/src/linux-md.c +index 2aacb87469a..c2912f17875 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 33edcd4fc7d..bccbef6bf6b 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + + #include "fix_coverity.h" +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index 84189ffbaca..5de27a269dd 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-pci.c b/src/linux-pci.c +index 2cd450bc470..fc18f3c4493 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index b9f83e12e7b..af42ca5369d 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-sas.c b/src/linux-sas.c +index 16f77d7259b..345cdd370c9 100644 +--- a/src/linux-sas.c ++++ b/src/linux-sas.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2018 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-sata.c b/src/linux-sata.c +index 314a49c4337..49e935d6e9d 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 7f68e03a1b0..c5813a2e847 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index 53686d614a0..044b628fca7 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index fc87717ef96..34ad45e8840 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c +index 2d39c28ebb6..fca565b2710 100644 +--- a/src/linux-virtual-root.c ++++ b/src/linux-virtual-root.c +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + + #include "fix_coverity.h" +diff --git a/src/linux.c b/src/linux.c +index 6b88bfb7e9b..a9d6801eb2c 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/linux.h b/src/linux.h +index a5ef0dfa154..513f2fa01fd 100644 +--- a/src/linux.h ++++ b/src/linux.h +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2019 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIBOOT_LINUX_H + #define _EFIBOOT_LINUX_H +diff --git a/src/loadopt.c b/src/loadopt.c +index e643d4a4fb8..01544cc628a 100644 +--- a/src/loadopt.c ++++ b/src/loadopt.c +@@ -1,22 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2015 Red Hat, Inc. + * Copyright (C) 2001 Dell Computer Corporation +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/makeguids.c b/src/makeguids.c +index c0a9db1509c..2648a121383 100644 +--- a/src/makeguids.c ++++ b/src/makeguids.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +diff --git a/src/path-helpers.c b/src/path-helpers.c +index dff8f34dfc8..5675809add6 100644 +--- a/src/path-helpers.c ++++ b/src/path-helpers.c +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * path-helper.c + * Copyright 2018 Peter Jones +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + #include "fix_coverity.h" + +diff --git a/src/path-helpers.h b/src/path-helpers.h +index 7dec05b6297..6665eec8cb5 100644 +--- a/src/path-helpers.h ++++ b/src/path-helpers.h +@@ -1,20 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * path-helper.h + * Copyright 2018 Peter Jones +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . + */ + + #ifndef PATH_HELPER_H_ +diff --git a/src/safemath.h b/src/safemath.h +index 08dfef7ec0b..fef19f288d6 100644 +--- a/src/safemath.h ++++ b/src/safemath.h +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * safemath.h + * Copyright 2016-2019 Peter Jones +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #ifndef SAFEMATH_H_ +diff --git a/src/test/tester.c b/src/test/tester.c +index 32886539fea..a4f39ac1a86 100644 +--- a/src/test/tester.c ++++ b/src/test/tester.c +@@ -1,18 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * ++ * tester.c ++ * Copyright 2012-2018 Red Hat, Inc. ++ * Copyright 2012-2018 Peter M. Jones + */ + + #include +diff --git a/src/ucs2.h b/src/ucs2.h +index 3f8a41d8ccc..6f2f6cc1eed 100644 +--- a/src/ucs2.h ++++ b/src/ucs2.h +@@ -1,20 +1,6 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * Copyright 2012-2016 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + #ifndef _EFIVAR_UCS2_H + #define _EFIVAR_UCS2_H +diff --git a/src/util.h b/src/util.h +index 845989bbfe9..4791223d962 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -1,21 +1,8 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * Copyright 2011-2014 Red Hat, Inc. + * All rights reserved. + * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + * Author(s): Peter Jones + */ + #ifndef EFIVAR_UTIL_H +diff --git a/src/vars.c b/src/vars.c +index 148dd7943bc..cd0863d0213 100644 +--- a/src/vars.c ++++ b/src/vars.c +@@ -1,21 +1,7 @@ ++// SPDX-License-Identifier: LGPL-2.1-or-later + /* + * libefivar - library for the manipulation of EFI variables + * Copyright 2012-2013 Red Hat, Inc. +- * +- * This library is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public License as +- * published by the Free Software Foundation; either version 2.1 of the +- * License, or (at your option) any later version. +- * +- * This library 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with this library; if not, see +- * . +- * + */ + + #include "fix_coverity.h" +-- +2.24.1 + diff --git a/SOURCES/0075-Makefile-minor-typo-fix.patch b/SOURCES/0075-Makefile-minor-typo-fix.patch new file mode 100644 index 0000000..550f465 --- /dev/null +++ b/SOURCES/0075-Makefile-minor-typo-fix.patch @@ -0,0 +1,25 @@ +From 46c0623dad819a75ed479ac2576ce836a2dda2a6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 3 Feb 2020 11:30:33 -0500 +Subject: [PATCH 75/86] Makefile: minor typo fix. + +--- + src/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/Makefile b/src/Makefile +index 144289d4709..0783cb3b55f 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -115,7 +115,7 @@ test : all + + .PHONY: test deps abiclean abixml + .SECONDARY : libefivar.so.1.$(VERSION) libefivar.so.1 +-.SECONDARY : libefiboot.so.1.$(VERSION) libefivar.so.1 ++.SECONDARY : libefiboot.so.1.$(VERSION) libefiboot.so.1 + .SECONDARY : include/efivar/efivar-guids.h guid-symbols.c + .INTERMEDIATE : guids.bin names.bin + .PRECIOUS : guid-symbols.o makeguids +-- +2.24.1 + diff --git a/SOURCES/0076-util.h-minor-whitespace-cleanup.patch b/SOURCES/0076-util.h-minor-whitespace-cleanup.patch new file mode 100644 index 0000000..563adba --- /dev/null +++ b/SOURCES/0076-util.h-minor-whitespace-cleanup.patch @@ -0,0 +1,135 @@ +From c6122e960a412dd181dbea3ef0559640139a3c26 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Jan 2020 13:54:34 -0500 +Subject: [PATCH 76/86] util.h: minor whitespace cleanup + +Signed-off-by: Peter Jones +--- + src/util.h | 102 ++++++++++++++++++++++++++--------------------------- + 1 file changed, 51 insertions(+), 51 deletions(-) + +diff --git a/src/util.h b/src/util.h +index 4791223d962..b7b03931d7e 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -144,66 +144,66 @@ lcm(uint64_t x, uint64_t y) + } + + #ifndef strdupa +-#define strdupa(s) \ +- (__extension__ ({ \ +- const char *__in = (s); \ +- size_t __len = strlen (__in); \ +- char *__out = (char *) alloca (__len + 1); \ +- strcpy(__out, __in); \ +- __out; \ ++#define strdupa(s) \ ++ (__extension__ ({ \ ++ const char *__in = (s); \ ++ size_t __len = strlen (__in); \ ++ char *__out = (char *) alloca (__len + 1); \ ++ strcpy(__out, __in); \ ++ __out; \ + })) + #endif + + #ifndef strndupa +-#define strndupa(s, l) \ +- (__extension__ ({ \ +- const char *__in = (s); \ +- size_t __len = strnlen (__in, (l)); \ +- char *__out = (char *) alloca (__len + 1); \ +- strncpy(__out, __in, __len); \ +- __out[__len] = '\0'; \ +- __out; \ ++#define strndupa(s, l) \ ++ (__extension__ ({ \ ++ const char *__in = (s); \ ++ size_t __len = strnlen (__in, (l)); \ ++ char *__out = (char *) alloca (__len + 1); \ ++ strncpy(__out, __in, __len); \ ++ __out[__len] = '\0'; \ ++ __out; \ + })) + #endif + +-#define asprintfa(str, fmt, args...) \ +- ({ \ +- char *_tmp = NULL; \ +- int _rc; \ +- *(str) = NULL; \ +- _rc = asprintf((str), (fmt), ## args); \ +- if (_rc > 0) { \ +- _tmp = strdupa(*(str)); \ +- if (!_tmp) { \ +- _rc = -1; \ +- } else { \ +- free(*(str)); \ +- *(str) = _tmp; \ +- } \ +- } else { \ +- _rc = -1; \ +- } \ +- _rc; \ ++#define asprintfa(str, fmt, args...) \ ++ ({ \ ++ char *_tmp = NULL; \ ++ int _rc; \ ++ *(str) = NULL; \ ++ _rc = asprintf((str), (fmt), ## args); \ ++ if (_rc > 0) { \ ++ _tmp = strdupa(*(str)); \ ++ if (!_tmp) { \ ++ _rc = -1; \ ++ } else { \ ++ free(*(str)); \ ++ *(str) = _tmp; \ ++ } \ ++ } else { \ ++ _rc = -1; \ ++ } \ ++ _rc; \ + }) + +-#define vasprintfa(str, fmt, ap) \ +- ({ \ +- char *_tmp = NULL; \ +- int _rc; \ +- *(str) = NULL; \ +- _rc = vasprintf((str), (fmt), (ap)); \ +- if (_rc > 0) { \ +- _tmp = strdupa(*(str)); \ +- if (!_tmp) { \ +- _rc = -1; \ +- } else { \ +- free(*(str)); \ +- *(str) = _tmp; \ +- } \ +- } else { \ +- _rc = -1; \ +- } \ +- _rc; \ ++#define vasprintfa(str, fmt, ap) \ ++ ({ \ ++ char *_tmp = NULL; \ ++ int _rc; \ ++ *(str) = NULL; \ ++ _rc = vasprintf((str), (fmt), (ap)); \ ++ if (_rc > 0) { \ ++ _tmp = strdupa(*(str)); \ ++ if (!_tmp) { \ ++ _rc = -1; \ ++ } else { \ ++ free(*(str)); \ ++ *(str) = _tmp; \ ++ } \ ++ } else { \ ++ _rc = -1; \ ++ } \ ++ _rc; \ + }) + + static inline ssize_t +-- +2.24.1 + diff --git a/SOURCES/0077-util.h-make-strdupa-and-strndupa-pass-NULL-straight-.patch b/SOURCES/0077-util.h-make-strdupa-and-strndupa-pass-NULL-straight-.patch new file mode 100644 index 0000000..dac3089 --- /dev/null +++ b/SOURCES/0077-util.h-make-strdupa-and-strndupa-pass-NULL-straight-.patch @@ -0,0 +1,54 @@ +From 07fbba7acf9c757a3ae8192a64cb3a1f631c5f74 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Jan 2020 13:57:18 -0500 +Subject: [PATCH 77/86] util.h: make strdupa() and strndupa() pass NULL + straight through. + +Signed-off-by: Peter Jones +--- + src/util.h | 22 +++++++++++++++------- + 1 file changed, 15 insertions(+), 7 deletions(-) + +diff --git a/src/util.h b/src/util.h +index b7b03931d7e..f4c6c27cc73 100644 +--- a/src/util.h ++++ b/src/util.h +@@ -147,9 +147,13 @@ lcm(uint64_t x, uint64_t y) + #define strdupa(s) \ + (__extension__ ({ \ + const char *__in = (s); \ +- size_t __len = strlen (__in); \ +- char *__out = (char *) alloca (__len + 1); \ +- strcpy(__out, __in); \ ++ size_t __len; \ ++ char *__out = NULL; \ ++ if (__in) { \ ++ __len = strlen (__in); \ ++ __out = (char *) alloca (__len + 1); \ ++ strcpy(__out, __in); \ ++ } \ + __out; \ + })) + #endif +@@ -158,10 +162,14 @@ lcm(uint64_t x, uint64_t y) + #define strndupa(s, l) \ + (__extension__ ({ \ + const char *__in = (s); \ +- size_t __len = strnlen (__in, (l)); \ +- char *__out = (char *) alloca (__len + 1); \ +- strncpy(__out, __in, __len); \ +- __out[__len] = '\0'; \ ++ size_t __len; \ ++ char *__out = NULL; \ ++ if (__in) { \ ++ __len = strnlen (__in, (l)); \ ++ __out = (char *) alloca (__len + 1); \ ++ strncpy(__out, __in, __len); \ ++ __out[__len] = '\0'; \ ++ } \ + __out; \ + })) + #endif +-- +2.24.1 + diff --git a/SOURCES/0078-Update-travis-to-use-a-newer-distro.patch b/SOURCES/0078-Update-travis-to-use-a-newer-distro.patch new file mode 100644 index 0000000..0f25efd --- /dev/null +++ b/SOURCES/0078-Update-travis-to-use-a-newer-distro.patch @@ -0,0 +1,26 @@ +From 0e42eb90521c8cd4f67196c6620c0672c1106f2c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Feb 2020 18:03:13 -0500 +Subject: [PATCH 78/86] Update travis to use a newer distro. + +Signed-off-by: Peter Jones +--- + .travis.yml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/.travis.yml b/.travis.yml +index 0b1fa856fd6..f651234da83 100644 +--- a/.travis.yml ++++ b/.travis.yml +@@ -7,7 +7,7 @@ branches: + matrix: + include: + - os: linux +- dist: trusty ++ dist: bionic + services: docker + + before_install: +-- +2.24.1 + diff --git a/SOURCES/efivar.patches b/SOURCES/efivar.patches new file mode 100644 index 0000000..d405834 --- /dev/null +++ b/SOURCES/efivar.patches @@ -0,0 +1,78 @@ +Patch0001: 0001-util.h-add-unlikely-and-likely-macros.patch +Patch0002: 0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch +Patch0003: 0003-linux-pci-root-remove-an-unused-assignment.patch +Patch0004: 0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch +Patch0005: 0005-Get-rid-of-the-arrows-in-our-debug-messages.patch +Patch0006: 0006-Define-strdupa-if-it-is-not-defined.patch +Patch0007: 0007-Android-inital-porting-of-libefivar.patch +Patch0008: 0008-Remove-an-unused-function.patch +Patch0009: 0009-Fix-another-error-of-Werror-address-of-packed-member.patch +Patch0010: 0010-ucs2.h-remove-unused-variable.patch +Patch0011: 0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch +Patch0012: 0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch +Patch0013: 0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch +Patch0014: 0014-Add-more-hexdump-logging-functions.patch +Patch0015: 0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch +Patch0016: 0016-Always-log-to-a-memfd-regardless-of-loglevel.patch +Patch0017: 0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch +Patch0018: 0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch +Patch0019: 0019-Fix-dbglog_seek-to-update-the-offset.patch +Patch0020: 0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch +Patch0021: 0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch +Patch0022: 0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch +Patch0023: 0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch +Patch0024: 0024-efi_stash_loglevel_-efi_set_loglevel.patch +Patch0025: 0025-guids-add-grub-guid-for-grubenv.patch +Patch0026: 0026-gcc.specs-add-grecord-gcc-switches.patch +Patch0027: 0027-Makefile-don-t-echo-our-deps-submake-invocation.patch +Patch0028: 0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch +Patch0029: 0029-Make-scan-build-rules-slightly-more-intuitive.patch +Patch0030: 0030-Local-header-whitespace-cleanup.patch +Patch0031: 0031-Exported-header-whitespace-cleanup.patch +Patch0032: 0032-Main-code-whitespace-cleanup.patch +Patch0033: 0033-efivar-rework-usage.patch +Patch0034: 0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch +Patch0035: 0035-ucs2-document-things-a-little-better.patch +Patch0036: 0036-util.h-implement-add-mul-sub-for-more-integer-types.patch +Patch0037: 0037-Implement-efivar-export-foo.var.patch +Patch0038: 0038-Add-some-test-cases-for-efivar-export-import.patch +Patch0039: 0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch +Patch0040: 0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch +Patch0041: 0041-Makefile-sort-wildcard-output-for-reproducibility.patch +Patch0042: 0042-guids.txt-correct-sentinal-typo.patch +Patch0043: 0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch +Patch0044: 0044-Fix-some-32-bit-size_t-format-specifier-errors.patch +Patch0045: 0045-Make-the-top-level-makefile-not-parallelize.patch +Patch0046: 0046-guids-add-auto_created_boot_option.patch +Patch0047: 0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch +Patch0048: 0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch +Patch0049: 0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch +Patch0050: 0050-Make-add-Wno-missing-field-initializers.patch +Patch0051: 0051-debug-don-t-write-newlines-to-memfd.patch +Patch0052: 0052-sysfs-parsing-add-some-more-debugging-output.patch +Patch0053: 0053-gitignore-ignore-.strace.patch +Patch0054: 0054-Fix-the-error-path-in-set_disk_and_part_name.patch +Patch0055: 0055-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch +Patch0056: 0056-Improve-consistency-of-debug-prints.patch +Patch0057: 0057-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch +Patch0058: 0058-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch +Patch0059: 0059-Put-some-EFI-device-paths-into-the-debug-log.patch +Patch0060: 0060-Update-abixml.patch +Patch0061: 0061-Update-abixml-files-and-work-around-some-inconsequen.patch +Patch0062: 0062-Don-t-use-march-native-on-ia64.patch +Patch0063: 0063-Work-around-autoconf-existing-in-the-world.patch +Patch0064: 0064-Fix-efivar-w-and-efivar-a.patch +Patch0065: 0065-Android-fix-incorrect-include-path.patch +Patch0066: 0066-Android-fix-missing-field-initializers.patch +Patch0067: 0067-Fix-variable-sz-uninitialized-error.patch +Patch0068: 0068-Fix-an-argument-mismatch-error.patch +Patch0069: 0069-Android-fix-building-errors.patch +Patch0070: 0070-Fix-the-MSDOS_MBR_MAGIC-type-not-the-format-string.patch +Patch0071: 0071-Make-scan-build-and-CC-clang-work-again.patch +Patch0072: 0072-Remove-a-dead-store.patch +Patch0073: 0073-makeguids-confuse-ccc-analyzer-less.patch +Patch0074: 0074-SPDX-ify-all-the-license-text-in-source-files.patch +Patch0075: 0075-Makefile-minor-typo-fix.patch +Patch0076: 0076-util.h-minor-whitespace-cleanup.patch +Patch0077: 0077-util.h-make-strdupa-and-strndupa-pass-NULL-straight-.patch +Patch0078: 0078-Update-travis-to-use-a-newer-distro.patch diff --git a/SPECS/efivar.spec b/SPECS/efivar.spec new file mode 100644 index 0000000..109f562 --- /dev/null +++ b/SPECS/efivar.spec @@ -0,0 +1,357 @@ +Name: efivar +Version: 37 +Release: 17%{?dist} +Summary: Tools to manage UEFI variables +License: LGPL-2.1 +URL: https://github.com/rhboot/efivar +Requires: %{name}-libs = %{version}-%{release} +ExclusiveArch: %{efi} + +BuildRequires: gcc +BuildRequires: efi-srpm-macros git glibc-static libabigail +BuildRequires: make +# please don't fix this to reflect github's incomprehensible url that goes +# to a different tarball. +Source0: https://github.com/rhboot/efivar/releases/download/%{version}/efivar-%{version}.tar.bz2 +Source1: efivar.patches + +%include %{SOURCE1} + +# Source1 patches reflect a git snapshot, this is a separate fix on top +# with a gap in between +Patch100: 0001-Fix-sys-block-sysfs-parsing-for-eMMC-s.patch +# Fix XML ABI dumps that were generated with a faulty GCC and missed the +# variadic arguments when building without LTO, bug #1863475, +# +Patch101: 0001-Fix-abidw-output-for-missing-variadic-arguments.patch + +%description +efivar provides a simple command line interface to the UEFI variable facility. + +%package libs +Summary: Library to manage UEFI variables + +%description libs +Library to allow for the simple manipulation of UEFI variables. + +%package devel +Summary: Development headers for libefivar +Requires: %{name}-libs = %{version}-%{release} + +%description devel +development headers required to use libefivar. + +%prep +%setup -q -n %{name}-%{version} +git init +git config user.email "%{name}-owner@fedoraproject.org" +git config user.name "Fedora Ninjas" +git add . +git commit -a -q -m "%{version} baseline." +git am %{patches} +- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags + Related: rhbz#1991688 + +* Thu Apr 15 2021 Mohan Boddu +- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937 + +* Tue Jan 26 2021 Fedora Release Engineering +- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild + +* Tue Oct 27 2020 Petr Pisar - 37-14 +- Fix XML ABI dumps that were generated with a faulty GCC and missed the + variadic arguments when building without LTO (bug #1863475) + +* Thu Aug 06 2020 Jeff Law +- Remove explicit LTO bits from flags + +* Sat Aug 01 2020 Fedora Release Engineering +- Second attempt - Rebuilt for + https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild + +* Mon Jul 27 2020 Jeff Law - 37-11 +- Disable LTO + +* Mon Jul 27 2020 Fedora Release Engineering +- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild + +* Mon Jul 13 2020 Javier Martinez Canillas - 37-9 +- Change License field to LGPL-2.1 to prevent rpminspect test to fail + +* Wed Apr 22 2020 Hans de Goede - 37-8 +- Add a patch to fix eMMC sysfs path parsing + Resolves: rhbz#1826864 + +* Mon Feb 24 2020 Peter Jones - 37-7 +- Package our abignore file to try to shut taskotron up some. + +* Mon Feb 24 2020 Peter Jones - 37-6 +- Pull in a bunch of patches from upstream. + +* Tue Jan 28 2020 Fedora Release Engineering - 37-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild + +* Tue Nov 12 2019 Peter Jones - 37-4 +- Update for some compiler warning fixes. + Resolves: rhbz#1735168 + +* Wed Jul 24 2019 Fedora Release Engineering - 37-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + +* Thu Jan 31 2019 Fedora Release Engineering - 37-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + +* Wed Dec 05 2018 Peter Jones - 37-1 +- Update to efivar 37: + - Minor coverity fixes + - Improve ACPI device path formatting + - Add support for SOC devices that use FDT as their PCI root node + - Make devices we can't parse the "device" sysfs link for use DEV_ABBREV_ONLY + - Handle SCSI port numbers better + - Don't require an EUI for NVMe + - Fix the accidental requirement on ACPI UID nodes existing + - Add support for EMMC devices + - Add support for PCI root nodes without a device link in sysfs + - Add support for partitioned MD devices + - Fix partition number detection when the number isn't provided + - Add support for ACPI Generic Container and Embedded Controller root nodes + - Add limited support for SAS/SATA port expanders + +* Mon Sep 17 2018 Peter Jones - 36-1 +- Update to efivar 36 +- Add NVDIMM support +- Re-written linux interface parser to handle how devices are + partitioned better, and for cleaner code, with one file per device + type. +- lots of verbosity updates +- better CI +- analysis with clang's analyzer as well as coverity +- Better handling of immutable bits in sysfs +- LIBEFIVAR_OPS=help +- lots of code cleanups. + +* Thu Jul 12 2018 Fedora Release Engineering - 35-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild + +* Fri May 04 2018 Peter Jones - 35-3 +- Rebuild for new efi-rpm-macros, now that it has settled down a bit. + +* Tue May 01 2018 Peter Jones - 35-2 +- Use efi-rpm-macros instead of defining efi-related macros ourselves + +* Mon Apr 09 2018 Peter Jones - 35-1 +- Update to efivar 35 +- fixes for older compilers +- efi_get_variable_exists() +- Lots of stuff to make CI work. +- use usleep() to avoid hitting the kernel rate limiter on efivarfs +- better EFI_GUID macro +- add efi_guid_fwupdate (0abba7dc-e516-4167-bbf5-4d9d1c739416) + +* Tue Feb 27 2018 Peter Jones - 34-1 +- Update to efivar 34, and include a patch to avoid upstream rate limiting. + +* Wed Feb 07 2018 Fedora Release Engineering - 33-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Tue Jan 30 2018 Peter Robinson 33-2 +- Enable ARMv7, minor spec cleanups + +* Tue Jan 23 2018 Peter Jones - 33-1 +- Add NVDIMM support +- Bump version to 33 + +* Tue Sep 12 2017 Peter Jones - 32-2 +- Make efi_guid_ux_capsule actually get exported right. + +* Tue Sep 12 2017 Peter Jones - 32-1 +- efivar 32 +- lots of coverity fixes; mostly leaked memory and fds and the like +- fix sysfs pci path formats +- handle device paths for dns, nfit, bluetooth, wifi, emmc, btle. +- improved abi checking on releases +- Fix failures on EDIT_WRITE in edit_variable() when the variable doesn't exist +- Add efi_guid_ux_capsule_guid to our guids +- Now with %%check + +* Wed Aug 02 2017 Fedora Release Engineering - 31-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild + +* Wed Jul 26 2017 Fedora Release Engineering - 31-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Mon Mar 06 2017 Peter Jones - 31-1 +- Update to efivar 31 +- Work around NVMe EUI sysfs change +- Provide some oldish version strings we should have kept. +- lots of overflow checking on our pointer math in dp parsing +- fix major/minor device number handling in the linux code +- Do better formatting checks for MBR partitions +- Fixes for gcc 7 + +* Fri Feb 10 2017 Fedora Release Engineering - 30-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Mon Oct 17 2016 Peter Jones - 30-4 +- Handle NVMe device attributes paths moving around in sysfs. + +* Wed Sep 28 2016 Peter Jones - 30-3 +- Maybe even provide the *right* old linker deps. + +* Tue Sep 27 2016 Peter Jones - 30-2 +- Try not to screw up SONAME stuff quite so badly. + +* Tue Sep 27 2016 Peter Jones - 30-1 +- Fix efidp_*() functions with __pure__ that break with some optimizations +- Fix NVMe EUI parsing. + +* Tue Sep 27 2016 Peter Jones - 29-1 +- Use -pie not -PIE in our linker config +- Fix some overflow checks for gcc < 5.x +- Make variable class probes other than the first one actually work +- Move -flto to CFLAGS +- Pack all of the efi device path headers +- Fix redundant decl of efi_guid_zero() + +* Wed Aug 17 2016 Peter Jones - 28-1 +- Make our sonames always lib$FOO.1 , not lib$FOO.$VERSION . + +* Tue Aug 16 2016 Peter Jones - 27-1 +- Bug fix for 086eeb17 in efivar 26. + +* Wed Aug 10 2016 Peter Jones - 26-1 +- Update to efivar-26 . + +* Thu Jun 30 2016 Peter Jones - 0.24-1 +- Update to 0.24 + +* Mon Feb 15 2016 Peter Jones - 0.23-1 +- Update to 0.23 + +* Wed Feb 03 2016 Fedora Release Engineering - 0.21-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Mon Nov 02 2015 Peter Jones - 0.21-2 +- Bump the release here so f22->f23->f24 updates work. + +* Mon Jul 13 2015 Peter Jones - 0.21-1 +- Rename "make test" so packagers don't think it's a good idea to run it + during builds. +- Error check sizes in vars_get_variable() +- Fix some file size comparisons +- make SONAME reflect the correct values. +- Fix some uses of "const" +- Compile with -O2 by default +- Fix some strict-aliasing violations +- Fix some of the .pc files and how we do linking to work better. + +* Wed Jun 17 2015 Fedora Release Engineering - 0.20-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild + +* Tue Jun 02 2015 Peter Jones - 0.20-1 +- Update to 0.20 +- Make sure tester is build with the right link order for libraries. +- Adjust linker order for pkg-config +- Work around LocateDevicePath() not grokking PcieRoot() devices properly. +- Rectify some missing changelog entries + +* Thu May 28 2015 Peter Jones - 0.19-1 +- Update to 0.19 +- add API from efibootmgr so fwupdate and other tools can use it. + +* Wed Oct 15 2014 Peter Jones - 0.15-1 +- Update to 0.15 +- Make 32-bit builds set variables' DataSize correctly. + +* Wed Oct 08 2014 Peter Jones - 0.14-1 +- Update to 0.14 +- add efi_id_guid_to_guid() and efi_guid_to_id_guid(), which support {ID GUID} + as a concept. +- Add some vendor specific guids to our guid list. +- Call "empty" "zero" now, as many other places do. References to + efi_guid_is_empty() and efi_guid_empty still exist for ABI compatibility. +- add "efivar -L" to the man page. + +* Tue Oct 07 2014 Peter Jones - 0.13-1 +- Update to 0.13: +- add efi_symbol_to_guid() +- efi_name_to_guid() will now fall back on efi_symbol_to_guid() as a last + resort +- "efivar -L" to list all the guids we know about +- better namespacing on libefivar.so (rename well_known_* -> efi_well_known_*) + +* Thu Sep 25 2014 Peter Jones - 0.12-1 +- Update to 0.12 + +* Wed Aug 20 2014 Peter Jones - 0.11-1 +- Update to 0.11 + +* Fri May 02 2014 Peter Jones - 0.10-1 +- Update package to 0.10. +- Fixes a build error due to different cflags in the builders vs updstream + makefile. + +* Fri May 02 2014 Peter Jones - 0.9-0.1 +- Update package to 0.9. + +* Tue Apr 01 2014 Peter Jones - 0.8-0.1 +- Update package to 0.8 as well. + +* Fri Oct 25 2013 Peter Jones - 0.7-1 +- Update package to 0.7 +- adds --append support to the binary. + +* Fri Sep 06 2013 Peter Jones - 0.6-1 +- Update package to 0.6 +- fixes to documentation from lersek +- more validation of uefi guids +- use .xz for archives + +* Thu Sep 05 2013 Peter Jones - 0.5-0.1 +- Update to 0.5 + +* Mon Jun 17 2013 Peter Jones - 0.4-0.2 +- Fix ldconfig invocation + +* Mon Jun 17 2013 Peter Jones - 0.4-0.1 +- Initial spec file