From 75bb3524120413a9759fce09e4265f2fca23b2da Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Tue, 30 Mar 2021 11:59:00 -0400 Subject: [PATCH] import efivar-37-4.el8 --- .efivar.metadata | 2 +- .gitignore | 2 +- ...syntastic-file-I-use-out-of-the-repo.patch | 56 - ...til.h-add-unlikely-and-likely-macros.patch | 33 + ...-Move-verbosity-headers-to-be-public.patch | 53 - ..._guid-handle-misaligned-guid-pointer.patch | 59 + SOURCES/0003-Pacify-some-coverity-nits.patch | 45 - ...pci-root-remove-an-unused-assignment.patch | 27 + ...es-Werror-address-of-packed-member-c.patch | 172 + ...types-in-L-behavior-to-pacify-coveri.patch | 38 - ...-of-the-arrows-in-our-debug-messages.patch | 372 ++ ..._dn-to-make_hd_dn-and-get-rid-of-the.patch | 88 - ...-Define-strdupa-if-it-is-not-defined.patch | 38 + ...covscan-that-sysfs_read_file-doesn-t.patch | 138 - ...-Android-inital-porting-of-libefivar.patch | 82 + ...file-have-even-more-better-input-con.patch | 58 - ...helpers.c-also-import-fix_coverity.h.patch | 25 - SOURCES/0008-Remove-an-unused-function.patch | 40 + ...ids-building-problem-with-generics.h.patch | 34 - ...r-of-Werror-address-of-packed-member.patch | 54 + ...-Improve-ACPI-device-path-formatting.patch | 402 -- .../0010-ucs2.h-remove-unused-variable.patch | 34 + ...se-functions-the-unmodified-device-l.patch | 177 - ...-that-checks-for-UCS-2-string-termin.patch | 32 + ...ACPI-ID-parsing-to-a-shared-location.patch | 391 -- ...ix-efidp_ipv4_addr-fields-assignment.patch | 44 + ...MBR-and-GPT-fixed-values-as-magic-no.patch | 129 + ...ACPI-root-parser-separate-from-PCI-r.patch | 425 -- ...4-Add-more-hexdump-logging-functions.patch | 87 + ...y-e-3-isn-t-viable-for-a-kind-of-dev.patch | 71 - ...or_pop-and-pop-some-errors-sometimes.patch | 147 + ...ice-root-for-SOC-devices-that-use-FD.patch | 131 - ...og-to-a-memfd-regardless-of-loglevel.patch | 215 + ...e-part-of-the-device-link-skip-it-an.patch | 110 - ...e-any-variable-we-use-with-sscanf-s-.patch | 82 + ...-Pacify-clang-analyzer-just-a-little.patch | 25 - ...fivar_version-and-efi_get_libefiboot.patch | 126 + ...to-convince-coverity-that-get_file-i.patch | 32 - ...Fix-dbglog_seek-to-update-the-offset.patch | 32 + ...9-Make-the-debug-code-less-intrusive.patch | 1063 --- ...7-.abixml-for-new-libabigail-version.patch | 5854 +++++++++++++++++ ...-device-node-skipping-code-pass-cove.patch | 79 - ...cmp-s-alignment-problem-a-different-.patch | 70 + ...ror-on-unknown-type-with-DEV_ABBREV_.patch | 35 - ...-to-always-return-the-status-of-writ.patch | 27 + .../0022-efiboot-fix-a-bad-error-check.patch | 26 - ...of-making-sure-DLIBEFIVAR_VERSION-ha.patch | 36 + ...si_link-fix-the-offset-searching-for.patch | 27 - ...still-doesn-t-believe-in-error-codes.patch | 28 - ...efi_stash_loglevel_-efi_set_loglevel.patch | 102 + ...25-Don-t-require-NVME-to-have-an-EUI.patch | 28 - ...0025-guids-add-grub-guid-for-grubenv.patch | 38 + ...6-gcc.specs-add-grecord-gcc-switches.patch | 30 + .../0026-makeguids-initialize-memory.patch | 27 - ...n-t-echo-our-deps-submake-invocation.patch | 26 + .../0027-emmc_parser-add-emmc_parser.patch | 255 - ...ome-more-stuff-to-the-toplevel-clean.patch | 26 + ...28-abignore-work-around-an-abidw-bug.patch | 55 - ...-build-rules-slightly-more-intuitive.patch | 31 + .../0029-Update-abidw-for-newer-tools.patch | 1780 ----- ...0030-Local-header-whitespace-cleanup.patch | 1511 +++++ ...mmc-update-for-internal-API-breakage.patch | 50 - ...1-Exported-header-whitespace-cleanup.patch | 97 + ...ther-buggy-fake-acpi-pci-root-driver.patch | 64 - ...32-Fix-dev-probes-intialization-test.patch | 28 - .../0032-Main-code-whitespace-cleanup.patch | 5136 +++++++++++++++ ...s-that-don-t-have-a-device-link-in-s.patch | 92 - SOURCES/0033-efivar-rework-usage.patch | 142 + ...-name-parsing-and-formatting-for-par.patch | 124 - ...-some-signof-char-signof-uint8_t-mad.patch | 431 ++ ...mber-detection-when-it-s-not-provide.patch | 79 - ...ucs2-document-things-a-little-better.patch | 219 + ...cpi-fix-HID-vs-HID_EX-formatting-bug.patch | 38 - ...t-add-mul-sub-for-more-integer-types.patch | 370 ++ ...0037-Implement-efivar-export-foo.var.patch | 1194 ++++ ...-ACPI-Generic-Container-and-Embedded.patch | 75 - ...-test-cases-for-efivar-export-import.patch | 187 + ...actually-create-the-device-path-node.patch | 38 - ...-analyzer-found-where-we-may-try-to-.patch | 119 + ...039-sas-handle-port-expanders-at-all.patch | 431 -- ...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 | 78 + ...rsing-add-some-more-debugging-output.patch | 314 + SOURCES/0053-gitignore-ignore-.strace.patch | 25 + ...-Improve-consistency-of-debug-prints.patch | 809 +++ ...error-path-in-set_disk_and_part_name.patch | 63 + ...to-find-disk-device-symlinks-in-sysf.patch | 204 + ...es-virtual-nvme-fabrics-nvme-subsyst.patch | 334 + ...ke-all-the-sys-block-link-parsers-wo.patch | 778 +++ ...-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 + ...-Fix-variable-sz-uninitialized-error.patch | 39 + SPECS/efivar.spec | 126 +- 107 files changed, 24742 insertions(+), 6765 deletions(-) delete mode 100644 SOURCES/0001-Move-the-syntastic-file-I-use-out-of-the-repo.patch create mode 100644 SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch delete mode 100644 SOURCES/0002-Move-verbosity-headers-to-be-public.patch create mode 100644 SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch delete mode 100644 SOURCES/0003-Pacify-some-coverity-nits.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 delete mode 100644 SOURCES/0004-efivar-Fix-some-types-in-L-behavior-to-pacify-coveri.patch create mode 100644 SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch delete mode 100644 SOURCES/0005-Promote-_make_hd_dn-to-make_hd_dn-and-get-rid-of-the.patch create mode 100644 SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch delete mode 100644 SOURCES/0006-Try-to-convince-covscan-that-sysfs_read_file-doesn-t.patch create mode 100644 SOURCES/0007-Android-inital-porting-of-libefivar.patch delete mode 100644 SOURCES/0007-Make-efidp_make_file-have-even-more-better-input-con.patch delete mode 100644 SOURCES/0008-Make-path-helpers.c-also-import-fix_coverity.h.patch create mode 100644 SOURCES/0008-Remove-an-unused-function.patch delete mode 100644 SOURCES/0009-Fix-a-makeguids-building-problem-with-generics.h.patch create mode 100644 SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch delete mode 100644 SOURCES/0010-Improve-ACPI-device-path-formatting.patch create mode 100644 SOURCES/0010-ucs2.h-remove-unused-variable.patch delete mode 100644 SOURCES/0011-Give-linux-s-parse-functions-the-unmodified-device-l.patch create mode 100644 SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch delete mode 100644 SOURCES/0012-Move-ACPI-ID-parsing-to-a-shared-location.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 delete mode 100644 SOURCES/0013-Make-a-platform-ACPI-root-parser-separate-from-PCI-r.patch create mode 100644 SOURCES/0014-Add-more-hexdump-logging-functions.patch delete mode 100644 SOURCES/0014-Make-a-way-to-say-e-3-isn-t-viable-for-a-kind-of-dev.patch create mode 100644 SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch delete mode 100644 SOURCES/0015-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch create mode 100644 SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch delete mode 100644 SOURCES/0016-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch create mode 100644 SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch delete mode 100644 SOURCES/0017-Pacify-clang-analyzer-just-a-little.patch create mode 100644 SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch delete mode 100644 SOURCES/0018-Try-even-harder-to-convince-coverity-that-get_file-i.patch create mode 100644 SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch delete mode 100644 SOURCES/0019-Make-the-debug-code-less-intrusive.patch create mode 100644 SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch delete mode 100644 SOURCES/0020-efiboot-Make-the-device-node-skipping-code-pass-cove.patch create mode 100644 SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch delete mode 100644 SOURCES/0021-efiboot-don-t-error-on-unknown-type-with-DEV_ABBREV_.patch create mode 100644 SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch delete mode 100644 SOURCES/0022-efiboot-fix-a-bad-error-check.patch create mode 100644 SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch delete mode 100644 SOURCES/0023-efiboot-parse_scsi_link-fix-the-offset-searching-for.patch delete mode 100644 SOURCES/0024-Coverity-still-doesn-t-believe-in-error-codes.patch create mode 100644 SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch delete mode 100644 SOURCES/0025-Don-t-require-NVME-to-have-an-EUI.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 delete mode 100644 SOURCES/0026-makeguids-initialize-memory.patch create mode 100644 SOURCES/0027-Makefile-don-t-echo-our-deps-submake-invocation.patch delete mode 100644 SOURCES/0027-emmc_parser-add-emmc_parser.patch create mode 100644 SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch delete mode 100644 SOURCES/0028-abignore-work-around-an-abidw-bug.patch create mode 100644 SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch delete mode 100644 SOURCES/0029-Update-abidw-for-newer-tools.patch create mode 100644 SOURCES/0030-Local-header-whitespace-cleanup.patch delete mode 100644 SOURCES/0030-linux-emmc-update-for-internal-API-breakage.patch create mode 100644 SOURCES/0031-Exported-header-whitespace-cleanup.patch delete mode 100644 SOURCES/0031-Fix-another-buggy-fake-acpi-pci-root-driver.patch delete mode 100644 SOURCES/0032-Fix-dev-probes-intialization-test.patch create mode 100644 SOURCES/0032-Main-code-whitespace-cleanup.patch delete mode 100644 SOURCES/0033-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch create mode 100644 SOURCES/0033-efivar-rework-usage.patch delete mode 100644 SOURCES/0034-Handle-partition-name-parsing-and-formatting-for-par.patch create mode 100644 SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch delete mode 100644 SOURCES/0035-Fix-partition-number-detection-when-it-s-not-provide.patch create mode 100644 SOURCES/0035-ucs2-document-things-a-little-better.patch delete mode 100644 SOURCES/0036-dp-acpi-fix-HID-vs-HID_EX-formatting-bug.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 delete mode 100644 SOURCES/0037-Support-decoding-ACPI-Generic-Container-and-Embedded.patch create mode 100644 SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch delete mode 100644 SOURCES/0038-pci-root-actually-create-the-device-path-node.patch create mode 100644 SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch delete mode 100644 SOURCES/0039-sas-handle-port-expanders-at-all.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-Improve-consistency-of-debug-prints.patch create mode 100644 SOURCES/0055-Fix-the-error-path-in-set_disk_and_part_name.patch create mode 100644 SOURCES/0056-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch create mode 100644 SOURCES/0057-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch create mode 100644 SOURCES/0058-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.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-Fix-variable-sz-uninitialized-error.patch diff --git a/.efivar.metadata b/.efivar.metadata index 0f64cd3..aab069b 100644 --- a/.efivar.metadata +++ b/.efivar.metadata @@ -1 +1 @@ -3c74c8a0d8bc7a39b74de52cad2a791c00cdfd67 SOURCES/efivar-36.tar.bz2 +1ef24e0a06e1a42d7a93ba7a76b2970659c7c0c0 SOURCES/efivar-37.tar.bz2 diff --git a/.gitignore b/.gitignore index 0da8479..54aaf3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -SOURCES/efivar-36.tar.bz2 +SOURCES/efivar-37.tar.bz2 diff --git a/SOURCES/0001-Move-the-syntastic-file-I-use-out-of-the-repo.patch b/SOURCES/0001-Move-the-syntastic-file-I-use-out-of-the-repo.patch deleted file mode 100644 index 158b659..0000000 --- a/SOURCES/0001-Move-the-syntastic-file-I-use-out-of-the-repo.patch +++ /dev/null @@ -1,56 +0,0 @@ -From d5f88bb1d594451733261d62eac4b4f97d39e3f4 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 12 Jun 2018 14:36:20 -0400 -Subject: [PATCH 01/39] Move the syntastic file I use out of the repo - -Signed-off-by: Peter Jones ---- - src/.syntastic_c_config | 36 ------------------------------------ - 1 file changed, 36 deletions(-) - delete mode 100644 src/.syntastic_c_config - -diff --git a/src/.syntastic_c_config b/src/.syntastic_c_config -deleted file mode 100644 -index 3f3f0ca67c7..00000000000 ---- a/src/.syntastic_c_config -+++ /dev/null -@@ -1,36 +0,0 @@ ---g3 ---Og ---Werror=format-security ---Wp,-D_FORTIFY_SOURCE=2 ---fexceptions ---fstack-protector-strong ----param=ssp-buffer-size=4 ---grecord-gcc-switches ---DFWUPDATE_HAVE_LIBSMBIOS__ ---Wall ---Wextra ---Werror ---Wno-error=cpp ---Wno-unused-result ---Wno-unused-function ---Wsign-compare ---Werror=sign-compare ---fshort-wchar ----std=gnu11 ---D_GNU_SOURCE ---Isrc/include ---Isrc/include/efivar ---Iinclude ---Iinclude/efivar ---fPIC ---fmath-errno ---fsigned-zeros ---ftrapping-math ---fno-trapv ---fno-openmp ---fno-openacc ---mtune=generic ---march=x86-64 ---flto ---fno-merge-constants ---fvisibility=hidden --- -2.17.1 - 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..acf5d22 --- /dev/null +++ b/SOURCES/0001-util.h-add-unlikely-and-likely-macros.patch @@ -0,0 +1,33 @@ +From 9a35c81ba28788831a003c071a96acfab81ca354 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 10:30:23 -0500 +Subject: [PATCH 01/63] 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.26.2 + diff --git a/SOURCES/0002-Move-verbosity-headers-to-be-public.patch b/SOURCES/0002-Move-verbosity-headers-to-be-public.patch deleted file mode 100644 index c8af3b8..0000000 --- a/SOURCES/0002-Move-verbosity-headers-to-be-public.patch +++ /dev/null @@ -1,53 +0,0 @@ -From daf3b6c6ae8a766f362c87dc80e40005428a1b2a Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 12 Jun 2018 14:36:20 -0400 -Subject: [PATCH 02/39] Move verbosity headers to be public - -Signed-off-by: Peter Jones ---- - src/include/efivar/efivar.h | 8 ++++++++ - src/util.h | 4 ---- - 2 files changed, 8 insertions(+), 4 deletions(-) - -diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h -index ddcc6771bdb..316891ccae9 100644 ---- a/src/include/efivar/efivar.h -+++ b/src/include/efivar/efivar.h -@@ -25,6 +25,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -227,6 +228,13 @@ efi_error_clear(void) - #define efi_error_val(errval, msg, args...) \ - efi_error_real__(errval, __FILE__, __func__, __LINE__, (fmt), ## args) - -+extern void efi_set_verbose(int verbosity, FILE *errlog) -+ __attribute__((__visibility__("default"))); -+extern int efi_get_verbose(void) -+ __attribute__((__visibility__("default"))); -+extern FILE * efi_get_logfile(void) -+ __attribute__((__visibility__("default"))); -+ - #include - - #endif /* EFIVAR_H */ -diff --git a/src/util.h b/src/util.h -index 96ca66bd54d..cc5f669e6ec 100644 ---- a/src/util.h -+++ b/src/util.h -@@ -369,8 +369,4 @@ swizzle_guid_to_uuid(efi_guid_t *guid) - - #define DEBUG 1 - --extern void PUBLIC efi_set_verbose(int verbosity, FILE *errlog); --extern int PUBLIC efi_get_verbose(void); --extern FILE PUBLIC *efi_get_logfile(void); -- - #endif /* EFIVAR_UTIL_H */ --- -2.17.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..6c9c0d9 --- /dev/null +++ b/SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch @@ -0,0 +1,59 @@ +From 945a87340240b70b3c579773c9481ca913d95a92 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 10:30:59 -0500 +Subject: [PATCH 02/63] 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.26.2 + diff --git a/SOURCES/0003-Pacify-some-coverity-nits.patch b/SOURCES/0003-Pacify-some-coverity-nits.patch deleted file mode 100644 index c8084c6..0000000 --- a/SOURCES/0003-Pacify-some-coverity-nits.patch +++ /dev/null @@ -1,45 +0,0 @@ -From bd609a59369574c95f7f31b15caae8bb86b71f39 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 12 Jun 2018 14:36:20 -0400 -Subject: [PATCH 03/39] Pacify some coverity nits. - -Coverity has trouble tracking data flow sometimes, and believes that -sysfs_readlink() and read_sysfs_file() will sometimes return >= 0 when -the buffer has not been filled out. This changes the check to also test -for a NULL pointer, hopefully pacifying it. - -Signed-off-by: Peter Jones ---- - src/linux-pci.c | 2 +- - src/linux.c | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/linux-pci.c b/src/linux-pci.c -index 87878c39c94..0d2a90ab166 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -166,7 +166,7 @@ parse_pci(struct device *dev, const char *current) - tmp[devpart - current] = '\0'; - rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp); - free(tmp); -- if (rc < 0) { -+ if (rc < 0 || !linkbuf) { - efi_error("Could not find driver for pci device"); - return -1; - } -diff --git a/src/linux.c b/src/linux.c -index c8d1b3a9285..fe45c6004b9 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -356,7 +356,7 @@ struct device HIDDEN - - if (dev->part == -1) { - rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link); -- if (rc < 0) { -+ if (rc < 0 || !tmpbuf) { - efi_error("device has no /partition node; not a partition"); - } else { - rc = sscanf((char *)tmpbuf, "%d\n", &dev->part); --- -2.17.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..871a7a8 --- /dev/null +++ b/SOURCES/0003-linux-pci-root-remove-an-unused-assignment.patch @@ -0,0 +1,27 @@ +From 8c9cb884ebdc79bb69df13f2bfdf99543233588f Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Jan 2019 11:32:41 -0500 +Subject: [PATCH 03/63] 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.26.2 + 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..b217704 --- /dev/null +++ b/SOURCES/0004-Fix-all-the-places-Werror-address-of-packed-member-c.patch @@ -0,0 +1,172 @@ +From d1955bdfb19829221e2b6294bba256c5447677ac Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Feb 2019 15:20:12 -0500 +Subject: [PATCH 04/63] 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.26.2 + diff --git a/SOURCES/0004-efivar-Fix-some-types-in-L-behavior-to-pacify-coveri.patch b/SOURCES/0004-efivar-Fix-some-types-in-L-behavior-to-pacify-coveri.patch deleted file mode 100644 index b7e9571..0000000 --- a/SOURCES/0004-efivar-Fix-some-types-in-L-behavior-to-pacify-coveri.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 4becb1303fee8bd7b377292c74589d6ec69009ae Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 12 Jun 2018 14:36:20 -0400 -Subject: [PATCH 04/39] efivar: Fix some types in -L behavior to pacify - coverity. - -Coverity doesn't realize that efi_well_known_guids is /actually/ an -array, because we didn't tell it so. So fix the declaration so we've -told it so. - -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 9ee3b397e29..228bdb745a7 100644 ---- a/src/efivar.c -+++ b/src/efivar.c -@@ -485,13 +485,13 @@ int main(int argc, char *argv[]) - case ACTION_LIST_GUIDS: { - efi_guid_t sentinal = {0xffffffff,0xffff,0xffff,0xffff, - {0xff,0xff,0xff,0xff,0xff,0xff}}; -- extern struct guidname efi_well_known_guids; -+ extern struct guidname efi_well_known_guids[]; - extern struct guidname efi_well_known_guids_end; - intptr_t start = (intptr_t)&efi_well_known_guids; - intptr_t end = (intptr_t)&efi_well_known_guids_end; - unsigned int i; - -- struct guidname *guid = &efi_well_known_guids; -+ struct guidname *guid = &efi_well_known_guids[0]; - for (i = 0; i < (end-start) / sizeof(*guid); i++) { - if (!efi_guid_cmp(&sentinal, &guid[i].guid)) - break; --- -2.17.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..4c2e6fd --- /dev/null +++ b/SOURCES/0005-Get-rid-of-the-arrows-in-our-debug-messages.patch @@ -0,0 +1,372 @@ +From da19b396ed674a7c9fddca1e3b480a18e642e280 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Feb 2019 15:26:23 -0500 +Subject: [PATCH 05/63] 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.26.2 + diff --git a/SOURCES/0005-Promote-_make_hd_dn-to-make_hd_dn-and-get-rid-of-the.patch b/SOURCES/0005-Promote-_make_hd_dn-to-make_hd_dn-and-get-rid-of-the.patch deleted file mode 100644 index 69850e9..0000000 --- a/SOURCES/0005-Promote-_make_hd_dn-to-make_hd_dn-and-get-rid-of-the.patch +++ /dev/null @@ -1,88 +0,0 @@ -From bd8fc0ebe86da82468b40a4998c3000819e73afe Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 12 Jun 2018 14:36:20 -0400 -Subject: [PATCH 05/39] Promote _make_hd_dn() to make_hd_dn() and get rid of - the wrapper. - -The wrapper is just hiding what the code's doing, and all the other code -around where we use it does the same thing anyway. This hopefully -convinces coverity we're not really dereferencing "buf" there unless -it's nonzero. - -Signed-off-by: Peter Jones ---- - src/creator.c | 3 ++- - src/disk.c | 4 ++-- - src/dp-media.c | 2 ++ - src/disk.h | 7 ++----- - 4 files changed, 8 insertions(+), 8 deletions(-) - -diff --git a/src/creator.c b/src/creator.c -index 93f185fc0bc..76c1c1f7a99 100644 ---- a/src/creator.c -+++ b/src/creator.c -@@ -281,7 +281,8 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - goto err; - } - -- sz = make_hd_dn(buf, size, off, disk_fd, dev->part, options); -+ sz = make_hd_dn(buf+off, size?size-off:0, -+ disk_fd, dev->part, options); - saved_errno = errno; - close(disk_fd); - errno = saved_errno; -diff --git a/src/disk.c b/src/disk.c -index deac512cf71..3efee03b804 100644 ---- a/src/disk.c -+++ b/src/disk.c -@@ -257,8 +257,8 @@ is_partitioned(int fd) - } - - ssize_t HIDDEN --_make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition, -- uint32_t options) -+make_hd_dn(uint8_t *buf, ssize_t size, int fd, int32_t partition, -+ uint32_t options) - { - uint64_t part_start=0, part_size = 0; - uint8_t signature[16]="", format=0, signature_type=0; -diff --git a/src/dp-media.c b/src/dp-media.c -index 0a0993ec3f4..cec6b8bb58d 100644 ---- a/src/dp-media.c -+++ b/src/dp-media.c -@@ -161,6 +161,7 @@ efidp_make_file(uint8_t *buf, ssize_t size, char *filepath) - ssize_t sz; - ssize_t len = utf8len(lf, -1) + 1; - ssize_t req = sizeof (*file) + len * sizeof (uint16_t); -+ - sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE, - req); - if (size && sz == req) { -@@ -182,6 +183,7 @@ efidp_make_hd(uint8_t *buf, ssize_t size, uint32_t num, uint64_t part_start, - efidp_hd *hd = (efidp_hd *)buf; - ssize_t sz; - ssize_t req = sizeof (*hd); -+ - sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_HD, - req); - if (size && sz == req) { -diff --git a/src/disk.h b/src/disk.h -index c040cc92a91..f0fa7f9f42d 100644 ---- a/src/disk.h -+++ b/src/disk.h -@@ -23,10 +23,7 @@ - - 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); --#define make_hd_dn(buf, size, off, fd, partition, option) \ -- _make_hd_dn(((buf)+(off)), ((size)?((size)-(off)):0), (fd),\ -- (partition), (options)) -+extern HIDDEN ssize_t make_hd_dn(uint8_t *buf, ssize_t size, int fd, -+ int32_t partition, uint32_t options); - - #endif /* _EFIBOOT_DISK_H */ --- -2.17.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..eef20d7 --- /dev/null +++ b/SOURCES/0006-Define-strdupa-if-it-is-not-defined.patch @@ -0,0 +1,38 @@ +From be60850c79dcb62cf682ea496ec22d8ea45f9da2 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Thu, 10 Jan 2019 16:44:38 +0800 +Subject: [PATCH 06/63] 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.26.2 + diff --git a/SOURCES/0006-Try-to-convince-covscan-that-sysfs_read_file-doesn-t.patch b/SOURCES/0006-Try-to-convince-covscan-that-sysfs_read_file-doesn-t.patch deleted file mode 100644 index c6f1f7e..0000000 --- a/SOURCES/0006-Try-to-convince-covscan-that-sysfs_read_file-doesn-t.patch +++ /dev/null @@ -1,138 +0,0 @@ -From 5e2174acaf1a51ead0a079776229e0df89c7fd81 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 13 Jun 2018 09:15:17 -0400 -Subject: [PATCH 06/39] Try to convince covscan that sysfs_read_file() doesn't - leak on error. - -Basically, covscan gets confused about some of our return paths and -doesn't think the error condition correlates with not having allocated -(or having freed) the ram we're using to pass the file data back. - -Signed-off-by: Peter Jones ---- - src/linux.h | 5 +++++ - src/util.h | 38 ++++++++++++++++++++------------------ - 2 files changed, 25 insertions(+), 18 deletions(-) - -diff --git a/src/linux.h b/src/linux.h -index 2f9eb0fe66f..39826224a53 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -173,6 +173,11 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size, - 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_; \ - }) -diff --git a/src/util.h b/src/util.h -index cc5f669e6ec..ef85a4c277e 100644 ---- a/src/util.h -+++ b/src/util.h -@@ -149,22 +149,24 @@ - #endif - - static inline int UNUSED --read_file(int fd, uint8_t **buf, size_t *bufsize) -+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 *newbuf; - if (!(newbuf = calloc(size, sizeof (uint8_t)))) { - efi_error("could not allocate memory"); -+ *result = buf = NULL; -+ *bufsize = 0; - return -1; - } -- *buf = newbuf; -+ buf = newbuf; - - do { -- p = *buf + filesize; -+ 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. */ -@@ -179,8 +181,8 @@ read_file(int fd, uint8_t **buf, size_t *bufsize) - continue; - } else if (s < 0) { - int saved_errno = errno; -- free(*buf); -- *buf = NULL; -+ free(buf); -+ *result = buf = NULL; - *bufsize = 0; - errno = saved_errno; - efi_error("could not read from file"); -@@ -194,38 +196,38 @@ read_file(int fd, uint8_t **buf, size_t *bufsize) - /* See if we're going to overrun and return an error - * instead. */ - if (size > (size_t)-1 - 4096) { -- free(*buf); -- *buf = NULL; -+ free(buf); -+ *result = buf = NULL; - *bufsize = 0; - errno = ENOMEM; - efi_error("could not read from file"); - return -1; - } -- newbuf = realloc(*buf, size + 4096); -+ newbuf = realloc(buf, size + 4096); - if (newbuf == NULL) { - int saved_errno = errno; -- free(*buf); -- *buf = NULL; -+ 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); -+ buf = newbuf; -+ memset(buf + size, '\0', 4096); - size += 4096; - } - } while (1); - -- newbuf = realloc(*buf, filesize+1); -+ newbuf = realloc(buf, filesize+1); - if (!newbuf) { -- free(*buf); -- *buf = NULL; -+ free(buf); -+ *result = buf = NULL; - efi_error("could not allocate memory"); - return -1; - } - newbuf[filesize] = '\0'; -- *buf = newbuf; -+ *result = newbuf; - *bufsize = filesize+1; - return 0; - } -@@ -329,7 +331,7 @@ get_file(uint8_t **result, const char * const fmt, ...) - close(fd); - errno = error; - -- if (rc < 0) { -+ if (rc < 0 || bufsize < 1) { - efi_error("could not read file \"%s\"", path); - return -1; - } --- -2.17.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..e1188cc --- /dev/null +++ b/SOURCES/0007-Android-inital-porting-of-libefivar.patch @@ -0,0 +1,82 @@ +From f5932cee024f080a005bbfc252a3596f093e7ecd Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Thu, 10 Jan 2019 16:48:30 +0800 +Subject: [PATCH 07/63] 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.26.2 + diff --git a/SOURCES/0007-Make-efidp_make_file-have-even-more-better-input-con.patch b/SOURCES/0007-Make-efidp_make_file-have-even-more-better-input-con.patch deleted file mode 100644 index abdefd1..0000000 --- a/SOURCES/0007-Make-efidp_make_file-have-even-more-better-input-con.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 9bc1e24859630c933410bfb77658bd69ee400e16 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 13 Jun 2018 09:25:58 -0400 -Subject: [PATCH 07/39] Make efidp_make_file() have even more, better input - constraints. - -This is all in the effort to convince coverity that it doesn't -dereference buf when size==0, which it already doesn't. - -Signed-off-by: Peter Jones ---- - src/dp-media.c | 6 ++++++ - src/dp.c | 10 +++++++++- - 2 files changed, 15 insertions(+), 1 deletion(-) - -diff --git a/src/dp-media.c b/src/dp-media.c -index cec6b8bb58d..96a576fdc2a 100644 ---- a/src/dp-media.c -+++ b/src/dp-media.c -@@ -162,6 +162,12 @@ efidp_make_file(uint8_t *buf, ssize_t size, char *filepath) - ssize_t len = utf8len(lf, -1) + 1; - ssize_t req = sizeof (*file) + len * sizeof (uint16_t); - -+ if (len == 0) { -+ errno = EINVAL; -+ efi_error("%s() called with %s file path", __func__, -+ filepath == NULL ? "NULL" : "empty"); -+ return -1; -+ } - sz = efidp_make_generic(buf, size, EFIDP_MEDIA_TYPE, EFIDP_MEDIA_FILE, - req); - if (size && sz == req) { -diff --git a/src/dp.c b/src/dp.c -index 4e76e25b1a1..82d60b4f9be 100644 ---- a/src/dp.c -+++ b/src/dp.c -@@ -443,9 +443,17 @@ efidp_make_generic(uint8_t *buf, ssize_t size, uint8_t type, uint8_t subtype, - - if (!size) - return total_size; -+ -+ if (!buf) { -+ errno = EINVAL; -+ efi_error("%s was called with nonzero size and NULL buffer", -+ __func__); -+ return -1; -+ } -+ - if (size < total_size) { -+ errno = ENOSPC; - efi_error("total size is bigger than size limit"); -- errno = ENOSPC; - return -1; - } - --- -2.17.1 - diff --git a/SOURCES/0008-Make-path-helpers.c-also-import-fix_coverity.h.patch b/SOURCES/0008-Make-path-helpers.c-also-import-fix_coverity.h.patch deleted file mode 100644 index d1b5193..0000000 --- a/SOURCES/0008-Make-path-helpers.c-also-import-fix_coverity.h.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 025f791b57c988d33249c5c33250229fa0e7e8f1 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 14 Jun 2018 12:15:03 -0400 -Subject: [PATCH 08/39] Make path-helpers.c also import fix_coverity.h - -Signed-off-by: Peter Jones ---- - src/path-helpers.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/path-helpers.c b/src/path-helpers.c -index 1de00860d92..1b328071587 100644 ---- a/src/path-helpers.c -+++ b/src/path-helpers.c -@@ -16,6 +16,7 @@ - * License along with this library; if not, see - * . - */ -+#include "fix_coverity.h" - - #include "efivar.h" - --- -2.17.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..f3300b6 --- /dev/null +++ b/SOURCES/0008-Remove-an-unused-function.patch @@ -0,0 +1,40 @@ +From f9a64ce561b122368118149cb24c20bf3e0c9e1c Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Tue, 26 Feb 2019 14:57:00 +0800 +Subject: [PATCH 08/63] 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.26.2 + diff --git a/SOURCES/0009-Fix-a-makeguids-building-problem-with-generics.h.patch b/SOURCES/0009-Fix-a-makeguids-building-problem-with-generics.h.patch deleted file mode 100644 index ab34c06..0000000 --- a/SOURCES/0009-Fix-a-makeguids-building-problem-with-generics.h.patch +++ /dev/null @@ -1,34 +0,0 @@ -From bf5225b0445cc1b7b69c2a80162d3c1b514a27cf Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 14:12:42 -0400 -Subject: [PATCH 09/39] Fix a makeguids building problem with generics.h. - -Guard generics.h with EFIVAR_BUILD_ENVIRONMENT to keep it from -interfering with the makeguids build if libefivar.so isn't around -already. - -Signed-off-by: Peter Jones ---- - src/generics.h | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/generics.h b/src/generics.h -index e6af2fad79e..66be4bd76ab 100644 ---- a/src/generics.h -+++ b/src/generics.h -@@ -17,6 +17,7 @@ - * - */ - -+#ifndef EFIVAR_BUILD_ENVIRONMENT - #ifndef LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H - #define LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H 1 - -@@ -182,3 +183,4 @@ generic_append_variable(efi_guid_t guid, const char *name, - } - - #endif /* LIBEFIVAR_GENERIC_NEXT_VARIABLE_NAME_H */ -+#endif /* EFIVAR_BUILD_ENVIRONMENT */ --- -2.17.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..f1a9550 --- /dev/null +++ b/SOURCES/0009-Fix-another-error-of-Werror-address-of-packed-member.patch @@ -0,0 +1,54 @@ +From d10381d23097d96afbb8d7c4199e58164da0d870 Mon Sep 17 00:00:00 2001 +From: Chih-Wei Huang +Date: Tue, 26 Feb 2019 18:42:20 +0800 +Subject: [PATCH 09/63] 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.26.2 + diff --git a/SOURCES/0010-Improve-ACPI-device-path-formatting.patch b/SOURCES/0010-Improve-ACPI-device-path-formatting.patch deleted file mode 100644 index fbf176c..0000000 --- a/SOURCES/0010-Improve-ACPI-device-path-formatting.patch +++ /dev/null @@ -1,402 +0,0 @@ -From eb7db33c6cf4172551fe0f9f7cf4aa047dc16d88 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 14:27:11 -0400 -Subject: [PATCH 10/39] Improve ACPI device path formatting - -This factors a bunch of the duplication out to another function, which -also does a better job of it. - -Signed-off-by: Peter Jones ---- - src/dp-acpi.c | 296 ++++++++++++++++++--------------- - src/include/efivar/efivar-dp.h | 2 +- - 2 files changed, 159 insertions(+), 139 deletions(-) - -diff --git a/src/dp-acpi.c b/src/dp-acpi.c -index 70162f320dc..a49ef38488c 100644 ---- a/src/dp-acpi.c -+++ b/src/dp-acpi.c -@@ -44,6 +44,59 @@ _format_acpi_adr(char *buf, size_t size, - #define format_acpi_adr(buf, size, off, dp) \ - 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) -+{ -+ ssize_t off = 0; -+ -+ debug(DEBUG, "hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr); -+ debug(DEBUG, "cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr); -+ debug(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", -+ "AcpiExp(0x%"PRIx32",0x%"PRIx32",", -+ dp->acpi_hid_ex.hid, dp->acpi_hid_ex.cid); -+ if (uidstr) { -+ format(buf, size, off, "AcpiExp", "%s)", uidstr); -+ } else { -+ format(buf, size, off, "AcpiExp", "0x%"PRIx32")", -+ dp->acpi_hid_ex.uid); -+ } -+ return off; -+ } -+ -+ format(buf, size, off, "AcpiEx", "AcpiEx("); -+ if (hidstr) { -+ format(buf, size, off, "AcpiEx", "%s,", hidstr); -+ } else { -+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",", -+ dp->acpi_hid_ex.hid); -+ } -+ -+ if (cidstr) { -+ format(buf, size, off, "AcpiEx", "%s,", cidstr); -+ } else { -+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",", -+ dp->acpi_hid_ex.cid); -+ } -+ -+ if (uidstr) { -+ format(buf, size, off, "AcpiEx", "%s)", uidstr); -+ } else { -+ format(buf, size, off, "AcpiEx", "0x%"PRIx32")", -+ dp->acpi_hid_ex.uid); -+ } -+ -+ return off; -+} -+ -+#define format_acpi_hid_ex(buf, size, off, dp, hidstr, cidstr, uidstr) \ -+ format_helper(_format_acpi_hid_ex, buf, size, off, "AcpiEx", dp,\ -+ hidstr, cidstr, uidstr) -+ - ssize_t - _format_acpi_dn(char *buf, size_t size, const_efidp dp) - { -@@ -53,13 +106,15 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - const char *uidstr = NULL; - size_t uidlen = 0; - const char *cidstr = NULL; -- size_t cidlen = 0; -+ // size_t cidlen = 0; - - if (dp->subtype == EFIDP_ACPI_ADR) { -+ debug(DEBUG, "formatting ACPI _ADR"); - format_acpi_adr(buf, size, off, dp); - return off; - } else if (dp->subtype != EFIDP_ACPI_HID_EX && - dp->subtype != EFIDP_ACPI_HID) { -+ debug(DEBUG, "DP subtype %d, formatting as ACPI Path", dp->subtype); - format(buf, size, off, "AcpiPath", "AcpiPath(%d,", dp->subtype); - format_hex(buf, size, off, "AcpiPath", (uint8_t *)dp+4, - (efidp_node_size(dp)-4) / 2); -@@ -69,6 +124,7 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - ssize_t limit = efidp_node_size(dp) - - offsetof(efidp_acpi_hid_ex, hidstr); - -+ debug(DEBUG, "formatting ACPI HID EX"); - hidstr = dp->acpi_hid_ex.hidstr; - hidlen = strnlen(hidstr, limit); - limit -= hidlen + 1; -@@ -81,7 +137,7 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - - if (limit) { - cidstr = uidstr + uidlen + 1; -- cidlen = strnlen(cidstr, limit); -+ // cidlen = strnlen(cidstr, limit); - // limit -= cidlen + 1; - } - -@@ -96,143 +152,102 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - "PcieRoot(%s)", uidstr); - return off; - default: -- format(buf, size, off, "AcpiEx", "AcpiEx("); -- if (hidlen) -- format(buf, size, off, "AcpiEx", "%s", -- hidstr); -- else -- format(buf, size, off, "AcpiEx", "0x%"PRIx32, -- dp->acpi_hid_ex.hid); -- if (cidlen) -- format(buf, size, off, "AcpiEx", ",%s", -- cidstr); -- else -- format(buf, size, off, "AcpiEx", ",0x%"PRIx32, -- dp->acpi_hid_ex.cid); -- if (uidlen) -- format(buf, size, off, "AcpiEx", ",%s", -- uidstr); -- else -- format(buf, size, off, "AcpiEx", ",0x%"PRIx32, -- dp->acpi_hid_ex.uid); -- format(buf, size, off, "AcpiEx", ")"); -- break; -+ format_acpi_hid_ex(buf, size, off, dp, -+ hidstr, cidstr, uidstr); -+ return off; - } - } -- } -- -- switch (dp->acpi_hid.hid) { -- case EFIDP_ACPI_PCI_ROOT_HID: -- format(buf, size, off, "PciRoot", "PciRoot(0x%"PRIx32")", -- dp->acpi_hid.uid); -- break; -- case EFIDP_ACPI_PCIE_ROOT_HID: -- format(buf, size, off, "PcieRoot", "PcieRoot(0x%"PRIx32")", -- dp->acpi_hid.uid); -- break; -- case EFIDP_ACPI_FLOPPY_HID: -- format(buf, size, off, "Floppy", "Floppy(0x%"PRIx32")", -- dp->acpi_hid.uid); -- break; -- case EFIDP_ACPI_KEYBOARD_HID: -- format(buf, size, off, "Keyboard", "Keyboard(0x%"PRIx32")", -- dp->acpi_hid.uid); -- break; -- case EFIDP_ACPI_SERIAL_HID: -- format(buf, size, off, "Keyboard", "Serial(0x%"PRIx32")", -- dp->acpi_hid.uid); -- break; -- case EFIDP_ACPI_NVDIMM_HID: { -- int rc; -- const_efidp next = NULL; -- efidp_acpi_adr *adrdp; -- int end; -- -- format(buf, size, off, "NvRoot()", "NvRoot()"); -- -- rc = efidp_next_node(dp, &next); -- if (rc < 0 || !next) { -- efi_error("could not format DP"); -- return rc; -- } -+ } else if (dp->subtype == EFIDP_ACPI_HID_EX) { -+ switch (dp->acpi_hid.hid) { -+ case EFIDP_ACPI_PCI_ROOT_HID: -+ format(buf, size, off, "PciRoot", -+ "PciRoot(0x%"PRIx32")", -+ dp->acpi_hid.uid); -+ break; -+ case EFIDP_ACPI_PCIE_ROOT_HID: -+ format(buf, size, off, "PcieRoot", -+ "PcieRoot(0x%"PRIx32")", -+ dp->acpi_hid.uid); -+ break; -+ case EFIDP_ACPI_FLOPPY_HID: -+ format(buf, size, off, "Floppy", -+ "Floppy(0x%"PRIx32")", -+ dp->acpi_hid.uid); -+ break; -+ case EFIDP_ACPI_KEYBOARD_HID: -+ format(buf, size, off, "Keyboard", -+ "Keyboard(0x%"PRIx32")", -+ dp->acpi_hid.uid); -+ break; -+ case EFIDP_ACPI_SERIAL_HID: -+ format(buf, size, off, "Serial", -+ "Serial(0x%"PRIx32")", -+ dp->acpi_hid.uid); -+ break; -+ case EFIDP_ACPI_NVDIMM_HID: { -+ int rc; -+ const_efidp next = NULL; -+ efidp_acpi_adr *adrdp; -+ int end; - -- if (efidp_type(next) != EFIDP_ACPI_TYPE || -- efidp_subtype(next) != EFIDP_ACPI_ADR) { -- efi_error("Invalid child node type (0x%02x,0x%02x)", -- efidp_type(next), efidp_subtype(next)); -- return -EINVAL; -- } -- adrdp = (efidp_acpi_adr *)next; -+ format(buf, size, off, "NvRoot()", "NvRoot()"); - -- end = efidp_size_after(adrdp, header) -- / sizeof(adrdp->adr[0]); -+ rc = efidp_next_node(dp, &next); -+ if (rc < 0 || !next) { -+ efi_error("could not format DP"); -+ return rc; -+ } - -- for (int i = 0; i < end; i++) { -- uint32_t node_controller, socket, memory_controller; -- uint32_t memory_channel, dimm; -- uint32_t adr = adrdp->adr[i]; -+ if (efidp_type(next) != EFIDP_ACPI_TYPE || -+ efidp_subtype(next) != EFIDP_ACPI_ADR) { -+ efi_error("Invalid child node type (0x%02x,0x%02x)", -+ efidp_type(next), efidp_subtype(next)); -+ return -EINVAL; -+ } -+ adrdp = (efidp_acpi_adr *)next; - -- efidp_decode_acpi_nvdimm_adr(adr, &node_controller, -- &socket, -- &memory_controller, -- &memory_channel, &dimm); -+ end = efidp_size_after(adrdp, header) -+ / sizeof(adrdp->adr[0]); - -- if (i != 0) -- format(buf, size, off, "NvDimm", ","); -+ for (int i = 0; i < end; i++) { -+ uint32_t node_controller, socket, memory_controller; -+ uint32_t memory_channel, dimm; -+ uint32_t adr = adrdp->adr[i]; - -- format(buf, size, off, "NvDimm", -- "NvDimm(0x%03x,0x%01x,0x%01x,0x%01x,0x%01x)", -- node_controller, socket, memory_controller, -- memory_channel, dimm); -- } -- break; -- } -- default: -- switch (dp->subtype) { -- case EFIDP_ACPI_HID_EX: -- if (!hidstr && !cidstr && -- (uidstr || dp->acpi_hid_ex.uid)){ -- format(buf, size, off, "AcpiExp", -- "AcpiExp(0x%"PRIx32",0x%"PRIx32",", -- dp->acpi_hid_ex.hid, -- dp->acpi_hid_ex.cid); -- if (uidstr) { -- format(buf, size, off, "AcpiExp", -- "%s)", uidstr); -- } else { -- format(buf, size, off, "AcpiExp", -- "0x%"PRIx32")", -- dp->acpi_hid.uid); -- } -- break; -- } -- format(buf, size, off, "AcpiEx", "AcpiEx("); -- if (hidstr) { -- format(buf, size, off, "AcpiEx", "%s,", hidstr); -- } else { -- format(buf, size, off, "AcpiEx", "0x%"PRIx32",", -- dp->acpi_hid.hid); -- } -+ efidp_decode_acpi_nvdimm_adr(adr, -+ &node_controller, &socket, -+ &memory_controller, &memory_channel, -+ &dimm); - -- if (cidstr) { -- format(buf, size, off, "AcpiEx", "%s,", cidstr); -- } else { -- format(buf, size, off, "AcpiEx", "0x%"PRIx32",", -- dp->acpi_hid_ex.cid); -- } -+ if (i != 0) -+ format(buf, size, off, "NvDimm", ","); - -- if (uidstr) { -- format(buf, size, off, "AcpiEx", "%s)", uidstr); -- } else { -- format(buf, size, off, "AcpiEx", "0x%"PRIx32")", -- dp->acpi_hid.uid); -+ format(buf, size, off, "NvDimm", -+ "NvDimm(0x%03x,0x%01x,0x%01x,0x%01x,0x%01x)", -+ node_controller, socket, memory_controller, -+ memory_channel, dimm); - } - break; -- case EFIDP_ACPI_HID: -- format(buf, size, off, "Acpi", -- "Acpi(0x%"PRIx32",0x%"PRIx32")", -- dp->acpi_hid.hid, dp->acpi_hid.uid); -- break; -+ } -+ default: -+ debug(DEBUG, "Decoding non-well-known HID"); -+ switch (dp->subtype) { -+ case EFIDP_ACPI_HID_EX: -+ format_acpi_hid_ex(buf, size, off, dp, -+ hidstr, cidstr, uidstr); -+ break; -+ case EFIDP_ACPI_HID: -+ debug(DEBUG, "Decoding ACPI HID"); -+ format(buf, size, off, "Acpi", -+ "Acpi(0x%08x,0x%"PRIx32")", -+ dp->acpi_hid.hid, dp->acpi_hid.uid); -+ break; -+ default: -+ debug(DEBUG, "ACPI subtype %d???", -+ dp->subtype); -+ errno = EINVAL; -+ return -1; -+ } - } - } - -@@ -259,7 +274,7 @@ efidp_make_acpi_hid(uint8_t *buf, ssize_t size, uint32_t hid, uint32_t uid) - return sz; - } - --ssize_t PUBLIC NONNULL(6, 7, 8) -+ssize_t PUBLIC - 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, -@@ -268,21 +283,26 @@ efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size, - efidp_acpi_hid_ex *acpi_hid = (efidp_acpi_hid_ex *)buf; - ssize_t req; - ssize_t sz; -+ size_t hidlen = hidstr ? strlen(hidstr) : 0; -+ size_t uidlen = uidstr ? strlen(uidstr) : 0; -+ size_t cidlen = cidstr ? strlen(cidstr) : 0; - -- req = sizeof (*acpi_hid) + 3 + -- strlen(hidstr) + strlen(uidstr) + strlen(cidstr); -+ req = sizeof (*acpi_hid) + 3 + hidlen + uidlen + cidlen; - sz = efidp_make_generic(buf, size, EFIDP_ACPI_TYPE, EFIDP_ACPI_HID_EX, - req); - if (size && sz == req) { -- acpi_hid->uid = uid; -- acpi_hid->hid = hid; -- acpi_hid->cid = cid; -+ acpi_hid->hid = hidlen ? 0 : hid; -+ acpi_hid->uid = uidlen ? 0 : uid; -+ acpi_hid->cid = cidlen ? 0 : cid; - char *next = (char *)buf+offsetof(efidp_acpi_hid_ex, hidstr); -- strcpy(next, hidstr); -- next += strlen(hidstr) + 1; -- strcpy(next, uidstr); -- next += strlen(uidstr) + 1; -- strcpy(next, cidstr); -+ if (hidlen) -+ strcpy(next, hidstr); -+ next += hidlen + 1; -+ if (uidlen) -+ strcpy(next, uidstr); -+ next += uidlen + 1; -+ if (cidlen) -+ strcpy(next, cidstr); - } - - if (sz < 0) -diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h -index 106d3645e21..1b05775ae7e 100644 ---- a/src/include/efivar/efivar-dp.h -+++ b/src/include/efivar/efivar-dp.h -@@ -133,7 +133,7 @@ typedef struct { - /* three ascii string fields follow */ - char hidstr[]; - } EFIVAR_PACKED efidp_acpi_hid_ex; --extern ssize_t __attribute__((__nonnull__ (6,7,8))) -+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, --- -2.17.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..cd03809 --- /dev/null +++ b/SOURCES/0010-ucs2.h-remove-unused-variable.patch @@ -0,0 +1,34 @@ +From 3ae06e10e5e25ca6aab04eba1cb0402bfe068997 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:24 +0100 +Subject: [PATCH 10/63] 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.26.2 + diff --git a/SOURCES/0011-Give-linux-s-parse-functions-the-unmodified-device-l.patch b/SOURCES/0011-Give-linux-s-parse-functions-the-unmodified-device-l.patch deleted file mode 100644 index d3a611f..0000000 --- a/SOURCES/0011-Give-linux-s-parse-functions-the-unmodified-device-l.patch +++ /dev/null @@ -1,177 +0,0 @@ -From ba0655c62978ba64c227f1f87d9da3e1dea4f821 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 14:37:14 -0400 -Subject: [PATCH 11/39] Give linux-*'s ->parse() functions the unmodified - device link as well - -Signed-off-by: Peter Jones ---- - src/linux-ata.c | 2 +- - src/linux-i2o.c | 2 +- - src/linux-nvme.c | 2 +- - src/linux-pci.c | 2 +- - src/linux-pmem.c | 2 +- - src/linux-sas.c | 2 +- - src/linux-sata.c | 2 +- - src/linux-scsi.c | 2 +- - src/linux-virtblk.c | 2 +- - src/linux.c | 4 ++-- - src/linux.h | 3 ++- - 11 files changed, 13 insertions(+), 12 deletions(-) - -diff --git a/src/linux-ata.c b/src/linux-ata.c -index 6a47ff3f279..dab02f3d224 100644 ---- a/src/linux-ata.c -+++ b/src/linux-ata.c -@@ -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) -+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; -diff --git a/src/linux-i2o.c b/src/linux-i2o.c -index e57c0cb344f..4fe79e5719f 100644 ---- a/src/linux-i2o.c -+++ b/src/linux-i2o.c -@@ -33,7 +33,7 @@ - * ... probably doesn't work. - */ - static ssize_t --parse_i2o(struct device *dev, const char *current UNUSED) -+parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED) - { - debug(DEBUG, "entry"); - /* I2O disks can have up to 16 partitions, or 4 bits worth. */ -diff --git a/src/linux-nvme.c b/src/linux-nvme.c -index 6d5196fc082..00f53d5a9a7 100644 ---- a/src/linux-nvme.c -+++ b/src/linux-nvme.c -@@ -48,7 +48,7 @@ - */ - - static ssize_t --parse_nvme(struct device *dev, const char *current) -+parse_nvme(struct device *dev, const char *current, const char *root UNUSED) - { - int rc; - int32_t tosser0, tosser1, tosser2, ctrl_id, ns_id, partition; -diff --git a/src/linux-pci.c b/src/linux-pci.c -index 0d2a90ab166..4fbd108e3ed 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -41,7 +41,7 @@ - * - */ - static ssize_t --parse_pci(struct device *dev, const char *current) -+parse_pci(struct device *dev, const char *current, const char *root UNUSED) - { - int rc; - int pos; -diff --git a/src/linux-pmem.c b/src/linux-pmem.c -index 045650bc471..9a075716f7f 100644 ---- a/src/linux-pmem.c -+++ b/src/linux-pmem.c -@@ -70,7 +70,7 @@ - */ - - static ssize_t --parse_pmem(struct device *dev, const char *current) -+parse_pmem(struct device *dev, const char *current, const char *root UNUSED) - { - uint8_t *filebuf = NULL; - uint8_t system, sysbus, acpi_id; -diff --git a/src/linux-sas.c b/src/linux-sas.c -index 4a11147aef1..5f44f2c1f7b 100644 ---- a/src/linux-sas.c -+++ b/src/linux-sas.c -@@ -45,7 +45,7 @@ - * I'm not sure at the moment if they're the same or not. - */ - static ssize_t --parse_sas(struct device *dev, const char *current) -+parse_sas(struct device *dev, const char *current, const char *root UNUSED) - { - struct stat statbuf = { 0, }; - int rc; -diff --git a/src/linux-sata.c b/src/linux-sata.c -index a670ad9907e..d9a62efdbe6 100644 ---- a/src/linux-sata.c -+++ b/src/linux-sata.c -@@ -138,7 +138,7 @@ sysfs_sata_get_port_info(uint32_t print_id, struct device *dev) - } - - static ssize_t --parse_sata(struct device *dev, const char *devlink) -+parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) - { - const char *current = devlink; - uint32_t print_id; -diff --git a/src/linux-scsi.c b/src/linux-scsi.c -index 87f2f7f7c92..153a4ff87ad 100644 ---- a/src/linux-scsi.c -+++ b/src/linux-scsi.c -@@ -160,7 +160,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - } - - static ssize_t --parse_scsi(struct device *dev, const char *current) -+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; -diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c -index 6dedf0f27ee..9ee7994aeb3 100644 ---- a/src/linux-virtblk.c -+++ b/src/linux-virtblk.c -@@ -45,7 +45,7 @@ - * But usually we just write the HD() entry, of course. - */ - static ssize_t --parse_virtblk(struct device *dev, const char *current) -+parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) - { - uint32_t tosser; - int pos; -diff --git a/src/linux.c b/src/linux.c -index fe45c6004b9..ef560753481 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -352,7 +352,7 @@ struct device HIDDEN - efi_error("strdup(\"%s\") failed", linkbuf); - goto err; - } -- debug(DEBUG, "dev->link: %s\n", dev->link); -+ debug(DEBUG, "dev->link: %s", dev->link); - - if (dev->part == -1) { - rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link); -@@ -431,7 +431,7 @@ struct device HIDDEN - } - - debug(DEBUG, "trying %s", probe->name); -- pos = probe->parse(dev, current); -+ pos = probe->parse(dev, current, dev->link); - if (pos < 0) { - efi_error("parsing %s failed", probe->name); - goto err; -diff --git a/src/linux.h b/src/linux.h -index 39826224a53..35951bb4d16 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -244,7 +244,8 @@ struct dev_probe { - char *name; - enum interface_type *iftypes; - uint32_t flags; -- ssize_t (*parse)(struct device *dev, const char * const current); -+ 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); --- -2.17.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..0960c68 --- /dev/null +++ b/SOURCES/0011-ucs2.h-fix-logic-that-checks-for-UCS-2-string-termin.patch @@ -0,0 +1,32 @@ +From 4468e686c271cd208d741de4b304200bf28832f9 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:32 +0100 +Subject: [PATCH 11/63] 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.26.2 + diff --git a/SOURCES/0012-Move-ACPI-ID-parsing-to-a-shared-location.patch b/SOURCES/0012-Move-ACPI-ID-parsing-to-a-shared-location.patch deleted file mode 100644 index 9e4f586..0000000 --- a/SOURCES/0012-Move-ACPI-ID-parsing-to-a-shared-location.patch +++ /dev/null @@ -1,391 +0,0 @@ -From e2f68c8f9f4fab48f1ef3a4585932f757593fa92 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 14:43:32 -0400 -Subject: [PATCH 12/39] Move ACPI ID parsing to a shared location. - -This is getting out of PCI because we have some other platforms that do -ACPI root parsing, but don't use the PCI roots. - -Signed-off-by: Peter Jones ---- - src/linux-acpi.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ - src/linux-pci.c | 112 +++++--------------------------------------- - src/linux.c | 11 ++++- - src/linux.h | 19 +++++--- - 4 files changed, 152 insertions(+), 109 deletions(-) - create mode 100644 src/linux-acpi.c - -diff --git a/src/linux-acpi.c b/src/linux-acpi.c -new file mode 100644 -index 00000000000..cb93a113ee2 ---- /dev/null -+++ b/src/linux-acpi.c -@@ -0,0 +1,119 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+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; -+ -+ debug(DEBUG, "entry"); -+ -+ va_start(ap, fmt); -+ rc = vasprintfa(&path, fmt, ap); -+ va_end(ap); -+ debug(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) { -+ size_t l = strlen(fbuf); -+ if (l > 1) { -+ fbuf[l-1] = 0; -+ dev->acpi_root.acpi_cid_str = strdup(fbuf); -+ debug(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 = strlen(fbuf); -+ if (rc < 4) { -+hid_err: -+ efi_error("could not parse %s/firmware_node/hid", path); -+ return -1; -+ } -+ rc -= 4; -+ -+ rc = sscanf((char *)fbuf + rc, "%04hx", &tmp16); -+ debug(DEBUG, "rc:%d hid:0x%08x\n", rc, tmp16); -+ if (rc != 1) -+ goto hid_err; -+ -+ 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(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) || 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(DEBUG, "acpi root UID:0x%"PRIx64" uidstr:\"%s\"", -+ dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str); -+ -+ errno = 0; -+ return 0; -+} -diff --git a/src/linux-pci.c b/src/linux-pci.c -index 4fbd108e3ed..aa3e40c0f7c 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -37,21 +37,17 @@ - * ^ root hub ^device ^device - * - * for network devices, we also get: -- * /sys/class/net/$IFACE -> ../../devices/$PCI_STUFF/net/$IFACE -+ * /sys/class/net/$IFACE -> ../../devices/$PCI_DEVICES/net/$IFACE -+ * -+ * In both cases our "current" pointer should be at $PCI_DEVICES. - * - */ - static ssize_t --parse_pci(struct device *dev, const char *current, const char *root UNUSED) -+parse_pci(struct device *dev, const char *current, const char *root) - { - int rc; - int pos; -- uint16_t root_domain; -- uint8_t root_bus; -- uint32_t acpi_hid = 0; -- uint64_t acpi_uid_int = 0; - const char *devpart = current; -- char *fbuf = NULL; -- uint16_t tmp16 = 0; - char *spaces; - - pos = strlen(current); -@@ -62,66 +58,6 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED) - - debug(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; -- -- dev->pci_root.pci_root_domain = root_domain; -- dev->pci_root.pci_root_bus = root_bus; -- -- rc = read_sysfs_file(&fbuf, -- "devices/pci%04hx:%02hhx/firmware_node/hid", -- root_domain, root_bus); -- if (rc < 0 || fbuf == NULL) -- return -1; -- -- rc = sscanf((char *)fbuf, "PNP%hx", &tmp16); -- if (rc != 1) -- return -1; -- 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->pci_root.pci_root_acpi_hid = acpi_hid; -- -- errno = 0; -- fbuf = NULL; -- rc = read_sysfs_file(&fbuf, -- "devices/pci%04hx:%02hhx/firmware_node/uid", -- root_domain, root_bus); -- if ((rc <= 0 && errno != ENOENT) || fbuf == NULL) -- return -1; -- if (rc > 0) { -- rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int); -- if (rc == 1) { -- dev->pci_root.pci_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->pci_root.pci_root_acpi_uid_str = fbuf; -- } -- } -- } -- errno = 0; -- - /* 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) -@@ -136,7 +72,7 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED) - debug(DEBUG, "searching for 0000:00:00.0/"); - rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", - &domain, &bus, &device, &function, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", devpart, rc, pos); -+ debug(DEBUG, "current:\"%s\" rc:%d pos:%d", devpart, rc, pos); - arrow(DEBUG, spaces, 9, pos, rc, 3); - if (rc != 4) - break; -@@ -157,24 +93,26 @@ parse_pci(struct device *dev, const char *current, const char *root UNUSED) - dev->pci_dev[i].pci_bus = bus; - dev->pci_dev[i].pci_device = device; - dev->pci_dev[i].pci_function = function; -- char *tmp = strndup(current, devpart-current+1); -+ char *tmp = strndup(root, devpart-root+1); - char *linkbuf = NULL; - if (!tmp) { - efi_error("could not allocate memory"); - return -1; - } -- tmp[devpart - current] = '\0'; -+ tmp[devpart - root] = '\0'; - rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp); -- free(tmp); - if (rc < 0 || !linkbuf) { -- efi_error("Could not find driver for pci device"); -+ efi_error("Could not find driver for pci device %s", tmp); -+ free(tmp); - return -1; - } -+ free(tmp); - dev->pci_dev[i].driverlink = strdup(linkbuf); - debug(DEBUG, "driver:%s\n", linkbuf); - dev->n_pci_devs += 1; - } - -+ debug(DEBUG, "next:\"%s\"", devpart); - return devpart - current; - } - -@@ -186,34 +124,6 @@ dp_create_pci(struct device *dev, - - debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); - -- if (dev->pci_root.pci_root_acpi_uid_str) { -- debug(DEBUG, "creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"", -- dev->pci_root.pci_root_acpi_hid, -- dev->pci_root.pci_root_acpi_uid_str); -- new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0, -- dev->pci_root.pci_root_acpi_hid, -- 0, 0, "", -- dev->pci_root.pci_root_acpi_uid_str, -- ""); -- if (new < 0) { -- efi_error("efidp_make_acpi_hid_ex() failed"); -- return new; -- } -- } else { -- debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, -- dev->pci_root.pci_root_acpi_hid, -- dev->pci_root.pci_root_acpi_uid); -- new = efidp_make_acpi_hid(buf + off, size ? size - off : 0, -- dev->pci_root.pci_root_acpi_hid, -- dev->pci_root.pci_root_acpi_uid); -- if (new < 0) { -- efi_error("efidp_make_acpi_hid() failed"); -- return new; -- } -- } -- off += new; -- sz += new; -- - debug(DEBUG, "creating PCI device path nodes"); - for (unsigned int i = 0; i < dev->n_pci_devs; i++) { - debug(DEBUG, "creating PCI device path node %u", i); -diff --git a/src/linux.c b/src/linux.c -index ef560753481..9f3a22f7025 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -272,6 +272,13 @@ device_free(struct device *dev) - 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); -@@ -325,8 +332,8 @@ struct device HIDDEN - goto err; - } - -- dev->pci_root.pci_root_domain = 0xffff; -- dev->pci_root.pci_root_bus = 0xff; -+ 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); -diff --git a/src/linux.h b/src/linux.h -index 35951bb4d16..aa9e3d14a83 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -21,12 +21,18 @@ - #ifndef _EFIBOOT_LINUX_H - #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; -+}; -+ - struct pci_root_info { -- uint16_t pci_root_domain; -- uint8_t pci_root_bus; -- uint32_t pci_root_acpi_hid; -- uint64_t pci_root_acpi_uid; -- char *pci_root_acpi_uid_str; -+ uint16_t pci_domain; -+ uint8_t pci_bus; - }; - - struct pci_dev_info { -@@ -121,6 +127,7 @@ struct device { - 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; -@@ -147,7 +154,7 @@ 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); -- -+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); --- -2.17.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..76db801 --- /dev/null +++ b/SOURCES/0012-dp-message-fix-efidp_ipv4_addr-fields-assignment.patch @@ -0,0 +1,44 @@ +From 627860f1c60139b41580929a4c3a3328b579b278 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 5 Mar 2019 17:23:36 +0100 +Subject: [PATCH 12/63] 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.26.2 + 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..9004505 --- /dev/null +++ b/SOURCES/0013-Always-refer-to-MBR-and-GPT-fixed-values-as-magic-no.patch @@ -0,0 +1,129 @@ +From 62d5bb056e8f9ed4517c460d4d7ea5d51bc8125c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2019 11:01:34 -0400 +Subject: [PATCH 13/63] 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.26.2 + diff --git a/SOURCES/0013-Make-a-platform-ACPI-root-parser-separate-from-PCI-r.patch b/SOURCES/0013-Make-a-platform-ACPI-root-parser-separate-from-PCI-r.patch deleted file mode 100644 index c3c665d..0000000 --- a/SOURCES/0013-Make-a-platform-ACPI-root-parser-separate-from-PCI-r.patch +++ /dev/null @@ -1,425 +0,0 @@ -From 6b62aa40cfa1feb924609a065098da98c99e925c Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 14:45:14 -0400 -Subject: [PATCH 13/39] Make a platform ACPI root parser separate from PCI - roots. - -Because apparently PNP0A03 and PNP0A0C weren't good enough. - -Signed-off-by: Peter Jones ---- - src/linux-acpi-root.c | 199 ++++++++++++++++++++++++++++++++++++++++++ - src/linux-pci-root.c | 136 +++++++++++++++++++++++++++++ - src/linux-pci.c | 1 - - src/linux.c | 4 +- - src/linux.h | 4 +- - 5 files changed, 341 insertions(+), 3 deletions(-) - create mode 100644 src/linux-acpi-root.c - create mode 100644 src/linux-pci-root.c - -diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c -new file mode 100644 -index 00000000000..c7d8276a642 ---- /dev/null -+++ b/src/linux-acpi-root.c -@@ -0,0 +1,199 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+/* -+ * support for ACPI-like platform root hub and devices -+ * -+ * 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 -+ * 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 -+ */ -+static ssize_t -+parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED) -+{ -+ int rc; -+ int pos; -+ uint16_t pad0; -+ uint8_t pad1; -+ char *acpi_header = NULL; -+ 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(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(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(DEBUG, "acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); -+ -+ pos -= 4; -+ debug(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(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(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(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(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(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) -+{ -+ ssize_t sz = 0, new = 0; -+ -+ debug(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(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(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; -+ } -+ } -+ off += new; -+ sz += new; -+ -+ debug(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, -+}; -diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c -new file mode 100644 -index 00000000000..8f556a066f3 ---- /dev/null -+++ b/src/linux-pci-root.c -@@ -0,0 +1,136 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+/* -+ * support for PCI root hub and devices -+ * -+ * various devices /sys/dev/block/$major:$minor start with: -+ * maj:min -> ../../devices/pci$PCIROOT/$PCI_DEVICES/$BLOCKDEV_STUFF/block/$DISK/$PART -+ * i.e.: pci0000:00/0000:00:1d.0/0000:05:00.0/ -+ * ^ root hub ^device ^device -+ * -+ * for network devices, we also get: -+ * /sys/class/net/$IFACE -> ../../devices/$PCI_STUFF/net/$IFACE -+ * -+ */ -+static ssize_t -+parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) -+{ -+ int rc; -+ int pos; -+ 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(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; -+ -+ 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; -+ -+ 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) -+{ -+ debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); -+ debug(DEBUG, "returning 0"); -+#if 0 -+ if (dev->acpi_root.acpi_uid_str) { -+ debug(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(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; -+ } -+ } -+ off += new; -+ sz += new; -+ -+ debug(DEBUG, "returning %zd", sz); -+ return sz; -+#else -+ return 0; -+#endif -+} -+ -+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, -+}; -diff --git a/src/linux-pci.c b/src/linux-pci.c -index aa3e40c0f7c..0f59d3e840d 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -147,7 +147,6 @@ enum interface_type pci_iftypes[] = { pci, unknown }; - struct dev_probe HIDDEN pci_parser = { - .name = "pci", - .iftypes = pci_iftypes, -- .flags = DEV_PROVIDES_ROOT, - .parse = parse_pci, - .create = dp_create_pci, - }; -diff --git a/src/linux.c b/src/linux.c -index 9f3a22f7025..436fb882a98 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -235,6 +235,8 @@ static struct dev_probe *dev_probes[] = { - * be found first. - */ - &pmem_parser, -+ &acpi_root_parser, -+ &pci_root_parser, - &pci_parser, - &virtblk_parser, - &sas_parser, -@@ -447,7 +449,7 @@ struct device HIDDEN - } - debug(DEBUG, "%s matched %s", probe->name, current); - -- if (probe->flags & DEV_PROVIDES_HD) -+ if (probe->flags & DEV_PROVIDES_HD || probe->flags & DEV_PROVIDES_ROOT) - needs_root = false; - dev->probes[n++] = dev_probes[i]; - current += pos; -diff --git a/src/linux.h b/src/linux.h -index aa9e3d14a83..7b18bda31c6 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -95,7 +95,7 @@ struct nvdimm_info { - - enum interface_type { - unknown, -- isa, pci, network, -+ isa, acpi_root, pci_root, pci, network, - ata, atapi, scsi, sata, sas, - usb, i1394, fibre, i2o, - md, virtblk, -@@ -264,6 +264,8 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host, - - /* device support implementations */ - extern struct dev_probe pmem_parser; -+extern struct dev_probe pci_root_parser; -+extern struct dev_probe acpi_root_parser; - extern struct dev_probe pci_parser; - extern struct dev_probe sas_parser; - extern struct dev_probe sata_parser; --- -2.17.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..f5b8dc0 --- /dev/null +++ b/SOURCES/0014-Add-more-hexdump-logging-functions.patch @@ -0,0 +1,87 @@ +From 707276197e82e852e9d5c7acb97a9348efe467b7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 13 Mar 2019 11:02:01 -0400 +Subject: [PATCH 14/63] 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.26.2 + diff --git a/SOURCES/0014-Make-a-way-to-say-e-3-isn-t-viable-for-a-kind-of-dev.patch b/SOURCES/0014-Make-a-way-to-say-e-3-isn-t-viable-for-a-kind-of-dev.patch deleted file mode 100644 index eec9e30..0000000 --- a/SOURCES/0014-Make-a-way-to-say-e-3-isn-t-viable-for-a-kind-of-dev.patch +++ /dev/null @@ -1,71 +0,0 @@ -From ca71ba77abee7cea805e71a7faded706d19e4c58 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 16:16:00 -0400 -Subject: [PATCH 14/39] Make a way to say "-e 3" isn't viable for a kind of - device. - -Signed-off-by: Peter Jones ---- - src/creator.c | 7 +++++++ - src/linux.c | 5 ++++- - src/linux.h | 2 ++ - 3 files changed, 13 insertions(+), 1 deletion(-) - -diff --git a/src/creator.c b/src/creator.c -index 76c1c1f7a99..55b411ee3da 100644 ---- a/src/creator.c -+++ b/src/creator.c -@@ -243,6 +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)) { -+ errno = EINVAL; -+ efi_error("Device must use File() or HD() device path"); -+ goto err; -+ } -+ - if ((options & EFIBOOT_ABBREV_EDD10) - && (!(options & EFIBOOT_ABBREV_FILE) - && !(options & EFIBOOT_ABBREV_HD))) { -diff --git a/src/linux.c b/src/linux.c -index 436fb882a98..83adc510944 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -448,8 +448,11 @@ struct device HIDDEN - continue; - } - debug(DEBUG, "%s matched %s", probe->name, current); -+ dev->flags |= probe->flags; - -- if (probe->flags & DEV_PROVIDES_HD || probe->flags & DEV_PROVIDES_ROOT) -+ 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; -diff --git a/src/linux.h b/src/linux.h -index 7b18bda31c6..ef7dba769bd 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -106,6 +106,7 @@ struct dev_probe; - - struct device { - enum interface_type interface_type; -+ uint32_t flags; - char *link; - char *device; - char *driver; -@@ -246,6 +247,7 @@ extern ssize_t HIDDEN make_mac_path(uint8_t *buf, ssize_t size, - - #define DEV_PROVIDES_ROOT 1 - #define DEV_PROVIDES_HD 2 -+#define DEV_ABBREV_ONLY 4 - - struct dev_probe { - char *name; --- -2.17.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..a825c1e --- /dev/null +++ b/SOURCES/0015-Add-efi_error_pop-and-pop-some-errors-sometimes.patch @@ -0,0 +1,147 @@ +From c4e3c85e470705f2e8a3bdebf54ebcea90152963 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 14:02:12 -0400 +Subject: [PATCH 15/63] 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.26.2 + diff --git a/SOURCES/0015-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch b/SOURCES/0015-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch deleted file mode 100644 index 8615a93..0000000 --- a/SOURCES/0015-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch +++ /dev/null @@ -1,131 +0,0 @@ -From d8637ea2b540fc9d16f1d1c1312e49a24082eefe Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 16:16:35 -0400 -Subject: [PATCH 15/39] Make a linux device root for SOC devices that use FDT. - -Add parsing for FDT devices in sysfs. These devices have to use HD() or -File() because we don't have a way to express FDT nodes in a Device -Path. - -Signed-off-by: Peter Jones ---- - src/linux-soc-root.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ - src/linux.c | 1 + - src/linux.h | 3 +- - 3 files changed, 75 insertions(+), 1 deletion(-) - create mode 100644 src/linux-soc-root.c - -diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c -new file mode 100644 -index 00000000000..57dd9b04f2c ---- /dev/null -+++ b/src/linux-soc-root.c -@@ -0,0 +1,72 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+/* -+ * support for soc platforms -+ * -+ * various devices /sys/dev/block/$major:$minor start with: -+ * maj:min -> ../../devices/platform/soc/$DEVICETREE_NODE/$BLOCKDEV_STUFF/block/$DISK/$PART -+ * i.e.: soc/1a400000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1 -+ * ^ dt node ^ blockdev stuff ^ disk -+ * 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) -+{ -+ 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(DEBUG, "entry"); -+ -+ rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); -+ if (rc != 0) -+ return 0; -+ devpart += pos; -+ debug(DEBUG, "new position is \"%s\"", devpart); -+ -+ 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, -+}; -diff --git a/src/linux.c b/src/linux.c -index 83adc510944..1e7db4e3f61 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -237,6 +237,7 @@ static struct dev_probe *dev_probes[] = { - &pmem_parser, - &acpi_root_parser, - &pci_root_parser, -+ &soc_root_parser, - &pci_parser, - &virtblk_parser, - &sas_parser, -diff --git a/src/linux.h b/src/linux.h -index ef7dba769bd..99d61013e02 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -95,7 +95,7 @@ struct nvdimm_info { - - enum interface_type { - unknown, -- isa, acpi_root, pci_root, pci, network, -+ isa, acpi_root, pci_root, soc_root, pci, network, - ata, atapi, scsi, sata, sas, - usb, i1394, fibre, i2o, - md, virtblk, -@@ -268,6 +268,7 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host, - 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 pci_parser; - extern struct dev_probe sas_parser; - extern struct dev_probe sata_parser; --- -2.17.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..fb54cd3 --- /dev/null +++ b/SOURCES/0016-Always-log-to-a-memfd-regardless-of-loglevel.patch @@ -0,0 +1,215 @@ +From 518bca17bd39d87a35b9f7c7f186f08dc9e4be15 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 15:42:37 -0400 +Subject: [PATCH 16/63] 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.26.2 + diff --git a/SOURCES/0016-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch b/SOURCES/0016-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch deleted file mode 100644 index fb60518..0000000 --- a/SOURCES/0016-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch +++ /dev/null @@ -1,110 +0,0 @@ -From bc215d06720b346ba0d888a6149cf90f544a90ad Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 20 Jun 2018 17:00:24 -0400 -Subject: [PATCH 16/39] If we can't parse part of the device link, skip it and - set DEV_ABBREV_ONLY - -If we can't parse some part of the device symlink, we can't write a full -device path, but we can write an abbreviated HD() or File() path. So if -we've exausted all possibilities, skip to the next node, set -DEV_ABBREV_ONLY in the device's flags, and try parsing again. Then when -creator.c checks if that flag conflicts, it'll throw an error if it -does. - -Signed-off-by: Peter Jones ---- - src/linux.c | 62 ++++++++++++++++++++++++++++++++++++++++------------- - 1 file changed, 47 insertions(+), 15 deletions(-) - -diff --git a/src/linux.c b/src/linux.c -index 1e7db4e3f61..8fe21f19f78 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -429,14 +429,17 @@ struct device HIDDEN - - const char *current = dev->link; - bool needs_root = true; -+ int last_successful_probe = -1; - - debug(DEBUG, "searching for device nodes in %s", dev->link); - for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) { - struct dev_probe *probe = dev_probes[i]; - ssize_t pos; - -- if (!needs_root && (probe->flags & DEV_PROVIDES_ROOT)) { -- debug(DEBUG, "not testing %s because flags is 0x%x", probe->name, probe->flags); -+ if (!needs_root && -+ (probe->flags & DEV_PROVIDES_ROOT)) { -+ debug(DEBUG, "not testing %s because flags is 0x%x", -+ probe->name, probe->flags); - continue; - } - -@@ -445,22 +448,51 @@ struct device HIDDEN - if (pos < 0) { - efi_error("parsing %s failed", probe->name); - goto err; -- } else if (pos == 0) { -+ } else if (pos > 0) { -+ debug(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(DEBUG, "current:%s", current); -+ last_successful_probe = i; -+ -+ if (!*current || !strncmp(current, "block/", 6)) -+ break; -+ - continue; - } -- debug(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(DEBUG, "current:%s", current); -- -- if (!*current || !strncmp(current, "block/", 6)) -- break; -+ debug(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) { -+ int new_pos = 0; -+ rc = sscanf(current, "%*[^/]/%n", &new_pos); -+ if (rc < 0) { -+ efi_error( -+ "Cannot parse device link segment \"%s\"", -+ current); -+ goto err; -+ } -+ debug(DEBUG, -+ "Cannot parse device link segment \"%s\"", -+ current); -+ debug(DEBUG, "Skipping to \"%s\"", current + new_pos); -+ debug(DEBUG, -+ "This means we can only write abbreviated paths"); -+ if (rc < 0) -+ goto err; -+ if (new_pos == 0) -+ goto err; -+ dev->flags |= DEV_ABBREV_ONLY; -+ i = last_successful_probe; -+ current += new_pos; -+ } - } - - if (dev->interface_type == unknown) { --- -2.17.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..ab375ba --- /dev/null +++ b/SOURCES/0017-Always-initialize-any-variable-we-use-with-sscanf-s-.patch @@ -0,0 +1,82 @@ +From c723928663b03aed5fb74b3f821ac16a43d9118e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 16:27:31 -0400 +Subject: [PATCH 17/63] 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.26.2 + diff --git a/SOURCES/0017-Pacify-clang-analyzer-just-a-little.patch b/SOURCES/0017-Pacify-clang-analyzer-just-a-little.patch deleted file mode 100644 index a2f9af1..0000000 --- a/SOURCES/0017-Pacify-clang-analyzer-just-a-little.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 8f9c1406a2a50d0c67b1380ad6fddc2c266d39f6 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 11:13:39 -0400 -Subject: [PATCH 17/39] Pacify clang analyzer just a little. - -Signed-off-by: Peter Jones ---- - src/linux-acpi-root.c | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c -index c7d8276a642..e55af5fa385 100644 ---- a/src/linux-acpi-root.c -+++ b/src/linux-acpi-root.c -@@ -181,7 +181,6 @@ dp_create_acpi_root(struct device *dev, - return new; - } - } -- off += new; - sz += new; - - debug(DEBUG, "returning %zd", sz); --- -2.17.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..125b5ff --- /dev/null +++ b/SOURCES/0018-Add-efi_get_libefivar_version-and-efi_get_libefiboot.patch @@ -0,0 +1,126 @@ +From fbda040f70143b207ef8d0daae509d6c15ffca95 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 May 2019 16:08:25 -0400 +Subject: [PATCH 18/63] 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.26.2 + diff --git a/SOURCES/0018-Try-even-harder-to-convince-coverity-that-get_file-i.patch b/SOURCES/0018-Try-even-harder-to-convince-coverity-that-get_file-i.patch deleted file mode 100644 index 0fab7cd..0000000 --- a/SOURCES/0018-Try-even-harder-to-convince-coverity-that-get_file-i.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 576b89de7d1a49d64efab9d494eeea5a296bdccd Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 12:23:20 -0400 -Subject: [PATCH 18/39] Try even harder to convince coverity that get_file - isn't leaking memory... - -Signed-off-by: Peter Jones ---- - src/util.h | 7 +++++++ - 1 file changed, 7 insertions(+) - -diff --git a/src/util.h b/src/util.h -index ef85a4c277e..441ced84fcf 100644 ---- a/src/util.h -+++ b/src/util.h -@@ -332,6 +332,13 @@ get_file(uint8_t **result, const char * const fmt, ...) - 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; - } --- -2.17.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..5c67670 --- /dev/null +++ b/SOURCES/0019-Fix-dbglog_seek-to-update-the-offset.patch @@ -0,0 +1,32 @@ +From b90e0e1722ce442aec747e8d2b77dec4c05d6069 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 09:28:50 -0400 +Subject: [PATCH 19/63] 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.26.2 + diff --git a/SOURCES/0019-Make-the-debug-code-less-intrusive.patch b/SOURCES/0019-Make-the-debug-code-less-intrusive.patch deleted file mode 100644 index ea78fd2..0000000 --- a/SOURCES/0019-Make-the-debug-code-less-intrusive.patch +++ /dev/null @@ -1,1063 +0,0 @@ -From 154d0794827ffe9fd6adbbdf1cd3d04dba18e24d Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 13:32:28 -0400 -Subject: [PATCH 19/39] Make the debug() code less intrusive - -Signed-off-by: Peter Jones ---- - src/creator.c | 17 +++++++------- - src/dp-acpi.c | 18 +++++++-------- - src/linux-acpi-root.c | 26 ++++++++++----------- - src/linux-acpi.c | 12 +++++----- - src/linux-ata.c | 6 ++--- - src/linux-i2o.c | 2 +- - src/linux-nvme.c | 12 +++++----- - src/linux-pci-root.c | 12 +++++----- - src/linux-pci.c | 22 +++++++++--------- - src/linux-pmem.c | 6 ++--- - src/linux-sas.c | 4 ++-- - src/linux-sata.c | 30 ++++++++++++------------ - src/linux-scsi.c | 48 +++++++++++++++++++-------------------- - src/linux-soc-root.c | 4 ++-- - src/linux-virtblk.c | 8 +++---- - src/linux.c | 53 ++++++++++++++++++++----------------------- - src/loadopt.c | 13 +++++------ - src/util.h | 14 ++++++++---- - 18 files changed, 154 insertions(+), 153 deletions(-) - -diff --git a/src/creator.c b/src/creator.c -index 55b411ee3da..ef782e2b647 100644 ---- a/src/creator.c -+++ b/src/creator.c -@@ -178,7 +178,7 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - int fd = -1; - int saved_errno; - -- debug(DEBUG, "partition:%d", partition); -+ debug("partition:%d", partition); - - if (buf && size) - memset(buf, '\0', size); -@@ -198,7 +198,7 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - if (partition < 0) { - int disk_fd; - -- debug(DEBUG, "partition: %d", partition); -+ debug("partition: %d", partition); - disk_fd = open_disk(dev, - (options & EFIBOOT_OPTIONS_WRITE_SIGNATURE) - ? O_RDWR : O_RDONLY); -@@ -211,7 +211,7 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - partition = 1; - else - partition = 0; -- debug(DEBUG, "is_partitioned(): partition -> %d", partition); -+ debug("is_partitioned(): partition -> %d", partition); - - close(disk_fd); - } -@@ -226,13 +226,13 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - } - - if (options & EFIBOOT_ABBREV_NONE) -- debug(DEBUG, "EFIBOOT_ABBREV_NONE"); -+ debug("EFIBOOT_ABBREV_NONE"); - if (options & EFIBOOT_ABBREV_HD) -- debug(DEBUG, "EFIBOOT_ABBREV_HD"); -+ debug("EFIBOOT_ABBREV_HD"); - if (options & EFIBOOT_ABBREV_FILE) -- debug(DEBUG, "EFIBOOT_ABBREV_FILE"); -+ debug("EFIBOOT_ABBREV_FILE"); - if (options & EFIBOOT_ABBREV_EDD10) -- debug(DEBUG, "EFIBOOT_ABBREV_EDD10"); -+ debug("EFIBOOT_ABBREV_EDD10"); - - if (options & EFIBOOT_ABBREV_EDD10) { - va_list aq; -@@ -245,6 +245,7 @@ efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - - 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; -@@ -323,7 +324,7 @@ err: - if (fd >= 0) - close(fd); - errno = saved_errno; -- debug(DEBUG, "= %zd", ret); -+ debug("= %zd", ret); - return ret; - } - -diff --git a/src/dp-acpi.c b/src/dp-acpi.c -index a49ef38488c..6f3e94443e5 100644 ---- a/src/dp-acpi.c -+++ b/src/dp-acpi.c -@@ -51,9 +51,9 @@ _format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED, - { - ssize_t off = 0; - -- debug(DEBUG, "hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr); -- debug(DEBUG, "cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr); -- debug(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", -@@ -109,12 +109,12 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - // size_t cidlen = 0; - - if (dp->subtype == EFIDP_ACPI_ADR) { -- debug(DEBUG, "formatting ACPI _ADR"); -+ debug("formatting ACPI _ADR"); - format_acpi_adr(buf, size, off, dp); - return off; - } else if (dp->subtype != EFIDP_ACPI_HID_EX && - dp->subtype != EFIDP_ACPI_HID) { -- debug(DEBUG, "DP subtype %d, formatting as ACPI Path", dp->subtype); -+ debug("DP subtype %d, formatting as ACPI Path", dp->subtype); - format(buf, size, off, "AcpiPath", "AcpiPath(%d,", dp->subtype); - format_hex(buf, size, off, "AcpiPath", (uint8_t *)dp+4, - (efidp_node_size(dp)-4) / 2); -@@ -124,7 +124,7 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - ssize_t limit = efidp_node_size(dp) - - offsetof(efidp_acpi_hid_ex, hidstr); - -- debug(DEBUG, "formatting ACPI HID EX"); -+ debug("formatting ACPI HID EX"); - hidstr = dp->acpi_hid_ex.hidstr; - hidlen = strnlen(hidstr, limit); - limit -= hidlen + 1; -@@ -230,20 +230,20 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - break; - } - default: -- debug(DEBUG, "Decoding non-well-known HID"); -+ debug("Decoding non-well-known HID"); - switch (dp->subtype) { - case EFIDP_ACPI_HID_EX: - format_acpi_hid_ex(buf, size, off, dp, - hidstr, cidstr, uidstr); - break; - case EFIDP_ACPI_HID: -- debug(DEBUG, "Decoding ACPI HID"); -+ debug("Decoding ACPI HID"); - format(buf, size, off, "Acpi", - "Acpi(0x%08x,0x%"PRIx32")", - dp->acpi_hid.hid, dp->acpi_hid.uid); - break; - default: -- debug(DEBUG, "ACPI subtype %d???", -+ debug("ACPI subtype %d???", - dp->subtype); - errno = EINVAL; - return -1; -diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c -index e55af5fa385..06e69eebe78 100644 ---- a/src/linux-acpi-root.c -+++ b/src/linux-acpi-root.c -@@ -59,7 +59,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - /* - * find the ACPI root dunno0 and dunno1; they basically look like: -@@ -69,7 +69,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED - * side in sscanf. - */ - rc = sscanf(devpart, "../../devices/platform/%n", &pos); -- debug(DEBUG, "devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); -+ debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); - if (rc != 0 || pos < 1) - return 0; - devpart += pos; -@@ -100,15 +100,15 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED - return -1; - } - dev->acpi_root.acpi_hid_str[pos] = 0; -- debug(DEBUG, "acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); -+ debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); - - pos -= 4; -- debug(DEBUG, "devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); -+ 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(DEBUG, "devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); -+ debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); - devpart += pos; - - /* -@@ -119,26 +119,26 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED - efi_error("Could not parse ACPI path \"%s\"", devpart); - return 0; - } -- debug(DEBUG, "devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", -+ 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(DEBUG, "rc:%d acpi_header:%s pad0:%04hX pad1:%02hhX", -+ 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(DEBUG, "rc:%d acpi_header:%s pad0:%04hx pad1:%02hhx", -+ 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(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); -@@ -152,10 +152,10 @@ dp_create_acpi_root(struct device *dev, - { - ssize_t sz = 0, new = 0; - -- debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); -+ 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(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, -@@ -170,7 +170,7 @@ dp_create_acpi_root(struct device *dev, - return new; - } - } else { -- debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, -+ 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, -@@ -183,7 +183,7 @@ dp_create_acpi_root(struct device *dev, - } - sz += new; - -- debug(DEBUG, "returning %zd", sz); -+ debug("returning %zd", sz); - return sz; - } - -diff --git a/src/linux-acpi.c b/src/linux-acpi.c -index cb93a113ee2..3eac526525f 100644 ---- a/src/linux-acpi.c -+++ b/src/linux-acpi.c -@@ -39,12 +39,12 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...) - uint32_t acpi_hid = 0; - uint64_t acpi_uid_int = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - va_start(ap, fmt); - rc = vasprintfa(&path, fmt, ap); - va_end(ap); -- debug(DEBUG, "path:%s rc:%d", path, rc); -+ debug("path:%s rc:%d", path, rc); - if (rc < 0 || path == NULL) - return -1; - -@@ -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(DEBUG, "Setting ACPI root path to \"%s\"", fbuf); -+ debug("Setting ACPI root path to \"%s\"", fbuf); - } - } - -@@ -73,7 +73,7 @@ hid_err: - rc -= 4; - - rc = sscanf((char *)fbuf + rc, "%04hx", &tmp16); -- debug(DEBUG, "rc:%d hid:0x%08x\n", rc, tmp16); -+ debug("rc:%d hid:0x%08x\n", rc, tmp16); - if (rc != 1) - goto hid_err; - -@@ -88,7 +88,7 @@ hid_err: - if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID) - acpi_hid = EFIDP_ACPI_PCI_ROOT_HID; - dev->acpi_root.acpi_hid = acpi_hid; -- debug(DEBUG, "acpi root HID:0x%08x", acpi_hid); -+ debug("acpi root HID:0x%08x", acpi_hid); - - errno = 0; - fbuf = NULL; -@@ -111,7 +111,7 @@ hid_err: - } - } - } -- debug(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 dab02f3d224..32cb99361e5 100644 ---- a/src/linux-ata.c -+++ b/src/linux-ata.c -@@ -64,7 +64,7 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) - uint64_t scsi_lun; - int pos; - -- debug(DEBUG, "entry"); -+ 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. -@@ -95,7 +95,7 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) - dev->interface_type = ata; - set_part(dev, dev->minor & 0x3F); - } else { -- debug(DEBUG, "If this is ATA, it isn't using a traditional IDE inode."); -+ debug("If this is ATA, it isn't using a traditional IDE inode."); - } - - if (is_pata(dev)) { -@@ -136,7 +136,7 @@ dp_create_ata(struct device *dev, - { - ssize_t sz; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_atapi(buf + off, size ? size - off : 0, - dev->ata_info.scsi_device, -diff --git a/src/linux-i2o.c b/src/linux-i2o.c -index 4fe79e5719f..3ce25b957bf 100644 ---- a/src/linux-i2o.c -+++ b/src/linux-i2o.c -@@ -35,7 +35,7 @@ - static ssize_t - parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED) - { -- debug(DEBUG, "entry"); -+ 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; -diff --git a/src/linux-nvme.c b/src/linux-nvme.c -index 00f53d5a9a7..ce931b7e237 100644 ---- a/src/linux-nvme.c -+++ b/src/linux-nvme.c -@@ -62,15 +62,15 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) - spaces[pos0] = '\0'; - pos0 = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - -- debug(DEBUG, "searching for nvme/nvme0/nvme0n1 or nvme/nvme0/nvme0n1/nvme0n1p1"); -+ 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(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); -- arrow(DEBUG, spaces, 9, pos0, rc, 3); -- arrow(DEBUG, spaces, 9, pos1, rc, 6); -+ 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. - */ -@@ -130,7 +130,7 @@ dp_create_nvme(struct device *dev, - { - ssize_t sz; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_nvme(buf + off, size ? size - off : 0, - dev->nvme_info.ns_id, -diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c -index 8f556a066f3..269e30e2c31 100644 ---- a/src/linux-pci-root.c -+++ b/src/linux-pci-root.c -@@ -56,7 +56,7 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - /* - * find the pci root domain and port; they basically look like: -@@ -87,11 +87,11 @@ static ssize_t - dp_create_pci_root(struct device *dev UNUSED, - uint8_t *buf, ssize_t size, ssize_t off) - { -- debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); -- debug(DEBUG, "returning 0"); -+ debug("entry buf:%p size:%zd off:%zd", buf, size, off); -+ debug("returning 0"); - #if 0 - if (dev->acpi_root.acpi_uid_str) { -- debug(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, -@@ -104,7 +104,7 @@ dp_create_pci_root(struct device *dev UNUSED, - return new; - } - } else { -- debug(DEBUG, "creating acpi_hid dp hid:0x%08x uid:0x%0"PRIx64, -+ 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, -@@ -118,7 +118,7 @@ dp_create_pci_root(struct device *dev UNUSED, - off += new; - sz += new; - -- debug(DEBUG, "returning %zd", sz); -+ debug("returning %zd", sz); - return sz; - #else - return 0; -diff --git a/src/linux-pci.c b/src/linux-pci.c -index 0f59d3e840d..e7c864b2d33 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -56,7 +56,7 @@ parse_pci(struct device *dev, const char *current, const char *root) - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - /* find the pci domain/bus/device/function: - * 0000:00:01.0/0000:01:00.0/ -@@ -69,16 +69,16 @@ parse_pci(struct device *dev, const char *current, const char *root) - unsigned int i = dev->n_pci_devs; - - pos = 0; -- debug(DEBUG, "searching for 0000:00:00.0/"); -+ debug("searching for 0000:00:00.0/"); - rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n", - &domain, &bus, &device, &function, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d", devpart, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 3); -+ debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos); -+ arrow(LOG_DEBUG, spaces, 9, pos, rc, 3); - if (rc != 4) - break; - devpart += pos; - -- debug(DEBUG, "found pci domain %04hx:%02hhx:%02hhx.%02hhx", -+ debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", - domain, bus, device, function); - pci_dev = realloc(dev->pci_dev, - sizeof(*pci_dev) * (i + 1)); -@@ -108,11 +108,11 @@ parse_pci(struct device *dev, const char *current, const char *root) - } - free(tmp); - dev->pci_dev[i].driverlink = strdup(linkbuf); -- debug(DEBUG, "driver:%s\n", linkbuf); -+ debug("driver:%s\n", linkbuf); - dev->n_pci_devs += 1; - } - -- debug(DEBUG, "next:\"%s\"", devpart); -+ debug("next:\"%s\"", devpart); - return devpart - current; - } - -@@ -122,11 +122,11 @@ dp_create_pci(struct device *dev, - { - ssize_t sz = 0, new = 0; - -- debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); -+ debug("entry buf:%p size:%zd off:%zd", buf, size, off); - -- debug(DEBUG, "creating PCI device path nodes"); -+ debug("creating PCI device path nodes"); - for (unsigned int i = 0; i < dev->n_pci_devs; i++) { -- debug(DEBUG, "creating PCI device path node %u", 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); -@@ -138,7 +138,7 @@ dp_create_pci(struct device *dev, - off += new; - } - -- debug(DEBUG, "returning %zd", sz); -+ debug("returning %zd", sz); - return sz; - } - -diff --git a/src/linux-pmem.c b/src/linux-pmem.c -index 9a075716f7f..4d981fc8ad3 100644 ---- a/src/linux-pmem.c -+++ b/src/linux-pmem.c -@@ -78,7 +78,7 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) - int ndbus, region, btt_region_id, btt_id, rc, pos; - char *namespace = NULL; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - if (!strcmp(dev->driver, "nd_pmem")) { - ; -@@ -121,7 +121,7 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) - return -1; - - filebuf = NULL; -- debug(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) -@@ -165,7 +165,7 @@ dp_create_pmem(struct device *dev, - { - ssize_t sz, sz1; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_nvdimm(buf + off, size ? size - off : 0, - &dev->nvdimm_info.namespace_label); -diff --git a/src/linux-sas.c b/src/linux-sas.c -index 5f44f2c1f7b..4d77d39a24d 100644 ---- a/src/linux-sas.c -+++ b/src/linux-sas.c -@@ -55,7 +55,7 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED) - uint8_t *filebuf = NULL; - uint64_t sas_address; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - pos = parse_scsi_link(current, &scsi_host, - &scsi_bus, &scsi_device, -@@ -111,7 +111,7 @@ dp_create_sas(struct device *dev, - { - ssize_t sz; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_sas(buf + off, size ? size - off : 0, - dev->sas_info.sas_address); -diff --git a/src/linux-sata.c b/src/linux-sata.c -index d9a62efdbe6..85265022f89 100644 ---- a/src/linux-sata.c -+++ b/src/linux-sata.c -@@ -156,9 +156,9 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - if (is_pata(dev)) { -- debug(DEBUG, "This is a PATA device; skipping."); -+ debug("This is a PATA device; skipping."); - return 0; - } - -@@ -166,10 +166,10 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) - * ata1/host0/target0:0:0/0:0:0:0 - * ^dev ^host x y z - */ -- debug(DEBUG, "searching for ata1/"); -+ debug("searching for ata1/"); - rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 1); -+ 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 -@@ -180,30 +180,30 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) - current += pos; - pos = 0; - -- debug(DEBUG, "searching for host0/"); -+ debug("searching for host0/"); - rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 1); -+ 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; - pos = 0; - -- debug(DEBUG, "searching for target0:0:0:0/"); -+ debug("searching for target0:0:0:0/"); - rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n", - &scsi_device, &scsi_target, &scsi_lun, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 3); -+ 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; - pos = 0; - -- debug(DEBUG, "searching for 0:0:0:0/"); -+ debug("searching for 0:0:0:0/"); - rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n", - &tosser0, &tosser1, &tosser2, &tosser3, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 4); -+ 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; -@@ -229,7 +229,7 @@ dp_create_sata(struct device *dev, - { - ssize_t sz = -1; - -- debug(DEBUG, "entry buf:%p size:%zd off:%zd", buf, size, off); -+ 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, -diff --git a/src/linux-scsi.c b/src/linux-scsi.c -index 153a4ff87ad..80c2fb7d82e 100644 ---- a/src/linux-scsi.c -+++ b/src/linux-scsi.c -@@ -51,7 +51,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - spaces[sz] = '\0'; - sz = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - /* - * This structure is completely ridiculous. - * -@@ -82,21 +82,21 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - * host4/port-4:0 - * or host4/port-4:0:0 - */ -- debug(DEBUG, "searching for host4/"); -+ debug("searching for host4/"); - rc = sscanf(current, "host%d/%n", scsi_host, &pos0); -- debug(DEBUG, "current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(DEBUG, spaces, 9, pos0, rc, 1); -+ 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; - pos0 = 0; - -- debug(DEBUG, "searching for port-4:0 or port-4:0:0"); -+ debug("searching for port-4:0 or port-4:0:0"); - rc = sscanf(current, "port-%d:%d%n:%d%n", &tosser0, - &tosser1, &pos0, &tosser2, &pos1); -- debug(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1); -- arrow(DEBUG, spaces, 9, pos0, rc, 2); -- arrow(DEBUG, spaces, 9, pos1, rc, 3); -+ 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; -@@ -107,18 +107,18 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - * 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(DEBUG, "searching for /end_device-4:0/ or /end_device-4:0:0/"); -+ 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(DEBUG, "current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(DEBUG, spaces, 9, pos0, rc, 2); -+ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); - if (rc != 2) - return -1; - sz += pos0; - pos0 = 0; - - rc = sscanf(current + sz, ":%d%n", &tosser0, &pos0); -- debug(DEBUG, "current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(DEBUG, spaces, 9, pos0, rc, 2); -+ debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); - if (rc != 0 && rc != 1) - return -1; - sz += pos0; -@@ -134,11 +134,11 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - * /target4:0:0/ - */ - uint64_t tosser3; -- debug(DEBUG, "searching for target4:0:0/"); -+ debug("searching for target4:0:0/"); - rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, - &tosser3, &pos0); -- debug(DEBUG, "current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(DEBUG, spaces, 9, pos0, rc, 3); -+ 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; -@@ -147,11 +147,11 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - /* now: - * %d:%d:%d:%llu/ - */ -- debug(DEBUG, "searching for 4:0:0:0/"); -+ 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(DEBUG, "current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(DEBUG, spaces, 9, pos0, rc, 4); -+ 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; -@@ -175,17 +175,17 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - -- debug(DEBUG, "searching for ../../../0:0:0:0"); -+ 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(DEBUG, "current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 3); -+ 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; - -@@ -225,7 +225,7 @@ dp_create_scsi(struct device *dev, - { - ssize_t sz = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_scsi(buf + off, size ? size - off : 0, - dev->scsi_info.scsi_target, -diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c -index 57dd9b04f2c..394f496a453 100644 ---- a/src/linux-soc-root.c -+++ b/src/linux-soc-root.c -@@ -51,13 +51,13 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos); - if (rc != 0) - return 0; - devpart += pos; -- debug(DEBUG, "new position is \"%s\"", devpart); -+ debug("new position is \"%s\"", devpart); - - return devpart - current; - } -diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c -index 9ee7994aeb3..c54a813a947 100644 ---- a/src/linux-virtblk.c -+++ b/src/linux-virtblk.c -@@ -58,12 +58,12 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) - spaces[pos] = '\0'; - pos = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - -- debug(DEBUG, "searching for virtio0/"); -+ debug("searching for virtio0/"); - rc = sscanf(current, "virtio%x/%n", &tosser, &pos); -- debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); -- arrow(DEBUG, spaces, 9, pos, rc, 1); -+ 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/linux.c b/src/linux.c -index 8fe21f19f78..f919dee5b67 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -178,12 +178,12 @@ set_disk_and_part_name(struct device *dev) - char *proximate = pathseg(dev->link, -4); - - errno = 0; -- debug(DEBUG, "dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name); -- debug(DEBUG, "dev->part:%d", dev->part); -- debug(DEBUG, "ultimate:\"%s\"", ultimate ? : ""); -- debug(DEBUG, "penultimate:\"%s\"", penultimate ? : ""); -- debug(DEBUG, "approximate:\"%s\"", approximate ? : ""); -- debug(DEBUG, "proximate:\"%s\"", proximate ? : ""); -+ 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")) || -@@ -197,14 +197,14 @@ set_disk_and_part_name(struct device *dev) - */ - set_disk_name(dev, "%s", penultimate); - set_part_name(dev, "%s", ultimate); -- debug(DEBUG, "disk:%s part:%s", penultimate, 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(DEBUG, "disk:%s part:%sp%d", ultimate, 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) -@@ -217,13 +217,13 @@ set_disk_and_part_name(struct device *dev) - */ - set_disk_name(dev, "%s", ultimate); - set_part_name(dev, "%s%d", ultimate, dev->part); -- debug(DEBUG, "disk:%s part:%s%d", ultimate, 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(DEBUG, "disk:%s", ultimate); -+ debug("disk:%s", ultimate); - } - - return 0; -@@ -321,7 +321,7 @@ struct device HIDDEN - } - - dev->part = partition; -- debug(DEBUG, "partition:%d dev->part:%d", partition, dev->part); -+ 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", -@@ -362,7 +362,7 @@ struct device HIDDEN - efi_error("strdup(\"%s\") failed", linkbuf); - goto err; - } -- debug(DEBUG, "dev->link: %s", dev->link); -+ debug("dev->link: %s", dev->link); - - if (dev->part == -1) { - rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link); -@@ -380,8 +380,8 @@ struct device HIDDEN - efi_error("could not set disk and partition names"); - goto err; - } -- debug(DEBUG, "dev->disk_name: %s", dev->disk_name); -- debug(DEBUG, "dev->part_name: %s", dev->part_name); -+ 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) { -@@ -431,25 +431,25 @@ struct device HIDDEN - bool needs_root = true; - int last_successful_probe = -1; - -- debug(DEBUG, "searching for device nodes in %s", dev->link); -+ debug("searching for device nodes in %s", dev->link); - for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) { - struct dev_probe *probe = dev_probes[i]; - ssize_t pos; - - if (!needs_root && - (probe->flags & DEV_PROVIDES_ROOT)) { -- debug(DEBUG, "not testing %s because flags is 0x%x", -+ debug("not testing %s because flags is 0x%x", - probe->name, probe->flags); - continue; - } - -- debug(DEBUG, "trying %s", probe->name); -+ 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(DEBUG, "%s matched %s", probe->name, current); -+ debug("%s matched %s", probe->name, current); - dev->flags |= probe->flags; - - if (probe->flags & DEV_PROVIDES_HD || -@@ -459,7 +459,7 @@ struct device HIDDEN - - dev->probes[n++] = dev_probes[i]; - current += pos; -- debug(DEBUG, "current:%s", current); -+ debug("current:%s", current); - last_successful_probe = i; - - if (!*current || !strncmp(current, "block/", 6)) -@@ -468,7 +468,7 @@ struct device HIDDEN - continue; - } - -- debug(DEBUG, "dev_probes[i+1]: %p dev->interface_type: %d\n", -+ 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) { - int new_pos = 0; -@@ -479,12 +479,9 @@ struct device HIDDEN - current); - goto err; - } -- debug(DEBUG, -- "Cannot parse device link segment \"%s\"", -- current); -- debug(DEBUG, "Skipping to \"%s\"", current + new_pos); -- debug(DEBUG, -- "This means we can only write abbreviated paths"); -+ debug("Cannot parse device link segment \"%s\"", current); -+ debug("Skipping to \"%s\"", current + pos); -+ debug("This means we can only create abbreviated paths"); - if (rc < 0) - goto err; - if (new_pos == 0) -@@ -512,7 +509,7 @@ make_blockdev_path(uint8_t *buf, ssize_t size, struct device *dev) - { - ssize_t off = 0; - -- debug(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++) { -@@ -531,7 +528,7 @@ make_blockdev_path(uint8_t *buf, ssize_t size, struct device *dev) - off += sz; - } - -- debug(DEBUG, "= %zd", off); -+ debug("= %zd", off); - - return off; - } -diff --git a/src/loadopt.c b/src/loadopt.c -index 23911f6e742..85fb646d107 100644 ---- a/src/loadopt.c -+++ b/src/loadopt.c -@@ -46,7 +46,7 @@ efi_loadopt_create(uint8_t *buf, ssize_t size, uint32_t attributes, - + sizeof (uint16_t) + desc_len - + dp_size + optional_data_size; - -- debug(DEBUG, "entry buf:%p size:%zd dp:%p dp_size:%zd", -+ debug("entry buf:%p size:%zd dp:%p dp_size:%zd", - buf, size, dp, dp_size); - - if (size == 0) -@@ -57,31 +57,30 @@ efi_loadopt_create(uint8_t *buf, ssize_t size, uint32_t attributes, - return -1; - } - -- debug(DEBUG, "testing buf"); -+ debug("testing buf"); - if (!buf) { - invalid: - errno = EINVAL; - return -1; - } - -- debug(DEBUG, "testing optional data presence"); -+ debug("testing optional data presence"); - if (!optional_data && optional_data_size != 0) - goto invalid; - -- debug(DEBUG, "testing dp presence"); -+ debug("testing dp presence"); - if ((!dp && dp_size == 0) || dp_size < 0) - goto invalid; - - if (dp) { -- debug(DEBUG, "testing dp validity"); -+ debug("testing dp validity"); - if (!efidp_is_valid(dp, dp_size)) { - if (efi_get_verbose() >= 1) - hexdump((void *)dp, dp_size); - goto invalid; - } - -- debug(DEBUG, -- "testing dp size: dp_size:%zd efidp_size(dp):%zd", -+ debug("testing dp size: dp_size:%zd efidp_size(dp):%zd", - dp_size, efidp_size(dp)); - if (efidp_size(dp) != dp_size) { - if (efi_get_verbose() >= 1) -diff --git a/src/util.h b/src/util.h -index 441ced84fcf..f63a8907611 100644 ---- a/src/util.h -+++ b/src/util.h -@@ -360,7 +360,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid) - u16[1] = __builtin_bswap16(u16[1]); - } - --#define debug_(file, line, func, level, fmt, args...) \ -+#define log_(file, line, func, level, fmt, args...) \ - ({ \ - if (efi_get_verbose() >= level) { \ - FILE *logfile_ = efi_get_logfile(); \ -@@ -373,9 +373,13 @@ swizzle_guid_to_uuid(efi_guid_t *guid) - } \ - }) - --#define debug(level, fmt, args...) debug_(__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';debug(l,"%s",b);b[o]=' ';b[p+o]=' ';b[p+o+1]=c_;}}) -- --#define DEBUG 1 -+#define LOG_VERBOSE 0 -+#define LOG_DEBUG 1 -+#ifdef log -+#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.17.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..8a7d89d --- /dev/null +++ b/SOURCES/0020-Update-efivar-37-.abixml-for-new-libabigail-version.patch @@ -0,0 +1,5854 @@ +From 51523bb273a416d82fcec1dea8582651a372e75e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 09:33:36 -0400 +Subject: [PATCH 20/63] 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.26.2 + diff --git a/SOURCES/0020-efiboot-Make-the-device-node-skipping-code-pass-cove.patch b/SOURCES/0020-efiboot-Make-the-device-node-skipping-code-pass-cove.patch deleted file mode 100644 index 1fc6dfc..0000000 --- a/SOURCES/0020-efiboot-Make-the-device-node-skipping-code-pass-cove.patch +++ /dev/null @@ -1,79 +0,0 @@ -From bc11451222cc77d8c1b4e752167adabd3c7f64c9 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 13:33:26 -0400 -Subject: [PATCH 20/39] efiboot: Make the device node skipping code pass - coverity. - -Signed-off-by: Peter Jones ---- - src/linux.c | 31 ++++++++++++++++++------------- - 1 file changed, 18 insertions(+), 13 deletions(-) - -diff --git a/src/linux.c b/src/linux.c -index f919dee5b67..6d20c2dbe25 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -308,7 +308,8 @@ struct device HIDDEN - { - struct device *dev; - char *linkbuf = NULL, *tmpbuf = NULL; -- unsigned int i, n = 0; -+ int i = 0; -+ unsigned int n = 0; - int rc; - - size_t nmemb = (sizeof(dev_probes) -@@ -432,9 +433,11 @@ struct device HIDDEN - int last_successful_probe = -1; - - debug("searching for device nodes in %s", dev->link); -- for (i = 0; dev_probes[i] && dev_probes[i]->parse; i++) { -+ for (i = 0; -+ dev_probes[i] && dev_probes[i]->parse && *current; -+ i++) { - struct dev_probe *probe = dev_probes[i]; -- ssize_t pos; -+ int pos; - - if (!needs_root && - (probe->flags & DEV_PROVIDES_ROOT)) { -@@ -471,24 +474,26 @@ struct device HIDDEN - 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) { -- int new_pos = 0; -- rc = sscanf(current, "%*[^/]/%n", &new_pos); -+ pos = 0; -+ rc = sscanf(current, "%*[^/]/%n", &pos); - if (rc < 0) { -- efi_error( -- "Cannot parse device link segment \"%s\"", -- current); -+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"); -- if (rc < 0) -- goto err; -- if (new_pos == 0) -- goto err; - dev->flags |= DEV_ABBREV_ONLY; - i = last_successful_probe; -- current += new_pos; -+ current += pos; - } - } - --- -2.17.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..e27ca88 --- /dev/null +++ b/SOURCES/0021-Fix-up-efi_guid_cmp-s-alignment-problem-a-different-.patch @@ -0,0 +1,70 @@ +From 9985cbbf4073ce9d0beec66bf702db9123758852 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:11:24 -0400 +Subject: [PATCH 21/63] 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.26.2 + diff --git a/SOURCES/0021-efiboot-don-t-error-on-unknown-type-with-DEV_ABBREV_.patch b/SOURCES/0021-efiboot-don-t-error-on-unknown-type-with-DEV_ABBREV_.patch deleted file mode 100644 index 4978e43..0000000 --- a/SOURCES/0021-efiboot-don-t-error-on-unknown-type-with-DEV_ABBREV_.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 22b1a7477c5ef72821e6491c67ad85ca52c1ae85 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 13:55:32 -0400 -Subject: [PATCH 21/39] efiboot: don't error on unknown type with - DEV_ABBREV_ONLY - -Signed-off-by: Peter Jones ---- - src/linux.c | 7 ++++++- - 1 file changed, 6 insertions(+), 1 deletion(-) - -diff --git a/src/linux.c b/src/linux.c -index 6d20c2dbe25..7fac339c50e 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -494,10 +494,15 @@ slash_err: - dev->flags |= DEV_ABBREV_ONLY; - i = last_successful_probe; - current += pos; -+ -+ if (!*current || !strncmp(current, "block/", 6)) -+ break; - } - } - -- if (dev->interface_type == unknown) { -+ if (dev->interface_type == unknown && -+ !(dev->flags & DEV_ABBREV_ONLY) && -+ !strcmp(current, "block/")) { - efi_error("unknown storage interface"); - errno = ENOSYS; - goto err; --- -2.17.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..5f4e42a --- /dev/null +++ b/SOURCES/0022-Fix-dbglog_write-to-always-return-the-status-of-writ.patch @@ -0,0 +1,27 @@ +From b132f9ef8b39ae31870be685566217191f8cde6a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:18:56 -0400 +Subject: [PATCH 22/63] 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.26.2 + diff --git a/SOURCES/0022-efiboot-fix-a-bad-error-check.patch b/SOURCES/0022-efiboot-fix-a-bad-error-check.patch deleted file mode 100644 index d1eedb9..0000000 --- a/SOURCES/0022-efiboot-fix-a-bad-error-check.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 6d87113fc3d9b2b0f520fc97eab9f5a60fda7d30 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 13:55:45 -0400 -Subject: [PATCH 22/39] efiboot: fix a bad error check - -Signed-off-by: Peter Jones ---- - src/linux-acpi.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/linux-acpi.c b/src/linux-acpi.c -index 3eac526525f..88f0084a37e 100644 ---- a/src/linux-acpi.c -+++ b/src/linux-acpi.c -@@ -93,7 +93,7 @@ hid_err: - errno = 0; - fbuf = NULL; - rc = read_sysfs_file(&fbuf, "%s/firmware_node/uid", path); -- if ((rc <= 0 && errno != ENOENT) || fbuf == NULL) { -+ if ((rc < 0 && errno != ENOENT) || (rc > 0 && fbuf == NULL)) { - efi_error("could not read %s/firmware_node/uid", path); - return -1; - } --- -2.17.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..2725cf4 --- /dev/null +++ b/SOURCES/0023-Do-a-better-job-of-making-sure-DLIBEFIVAR_VERSION-ha.patch @@ -0,0 +1,36 @@ +From a4212e47ff20b415e042682944a82623b3f75cee Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:21:32 -0400 +Subject: [PATCH 23/63] 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.26.2 + diff --git a/SOURCES/0023-efiboot-parse_scsi_link-fix-the-offset-searching-for.patch b/SOURCES/0023-efiboot-parse_scsi_link-fix-the-offset-searching-for.patch deleted file mode 100644 index 416c6e5..0000000 --- a/SOURCES/0023-efiboot-parse_scsi_link-fix-the-offset-searching-for.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 50e8c66f92b2d93d20c2524936f6858fd2b07afe Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 14:23:40 -0400 -Subject: [PATCH 23/39] efiboot: parse_scsi_link(): fix the offset searching - for the port - -Signed-off-by: Peter Jones ---- - src/linux-scsi.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/linux-scsi.c b/src/linux-scsi.c -index 80c2fb7d82e..2e4f710badf 100644 ---- a/src/linux-scsi.c -+++ b/src/linux-scsi.c -@@ -92,7 +92,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - pos0 = 0; - - debug("searching for port-4:0 or port-4:0:0"); -- rc = sscanf(current, "port-%d:%d%n:%d%n", &tosser0, -+ 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); --- -2.17.1 - diff --git a/SOURCES/0024-Coverity-still-doesn-t-believe-in-error-codes.patch b/SOURCES/0024-Coverity-still-doesn-t-believe-in-error-codes.patch deleted file mode 100644 index 239d998..0000000 --- a/SOURCES/0024-Coverity-still-doesn-t-believe-in-error-codes.patch +++ /dev/null @@ -1,28 +0,0 @@ -From c2223eb4638c6d8562626917651a11b8aa1e8f9e Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 16:18:32 -0400 -Subject: [PATCH 24/39] Coverity still doesn't believe in error codes... - -So also test fbuf here. - -Signed-off-by: Peter Jones ---- - src/linux-acpi.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/linux-acpi.c b/src/linux-acpi.c -index 88f0084a37e..346eba09041 100644 ---- a/src/linux-acpi.c -+++ b/src/linux-acpi.c -@@ -49,7 +49,7 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...) - return -1; - - rc = read_sysfs_file(&fbuf, "%s/firmware_node/path", path); -- if (rc > 0) { -+ if (rc > 0 && fbuf) { - size_t l = strlen(fbuf); - if (l > 1) { - fbuf[l-1] = 0; --- -2.17.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..aad0457 --- /dev/null +++ b/SOURCES/0024-efi_stash_loglevel_-efi_set_loglevel.patch @@ -0,0 +1,102 @@ +From 118d9afe4febf0ec6dea9327b044979588be2a60 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 29 May 2019 10:28:41 -0400 +Subject: [PATCH 24/63] 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.26.2 + diff --git a/SOURCES/0025-Don-t-require-NVME-to-have-an-EUI.patch b/SOURCES/0025-Don-t-require-NVME-to-have-an-EUI.patch deleted file mode 100644 index f05c0a4..0000000 --- a/SOURCES/0025-Don-t-require-NVME-to-have-an-EUI.patch +++ /dev/null @@ -1,28 +0,0 @@ -From d8d7e54fe01a7a255e649a7734820800edf82633 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 16 Jul 2018 15:40:22 -0400 -Subject: [PATCH 25/39] Don't require NVME to have an EUI - -Resolves: rhbz#1593784 - -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 ce931b7e237..d68d11a3409 100644 ---- a/src/linux-nvme.c -+++ b/src/linux-nvme.c -@@ -117,8 +117,6 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) - } - dev->nvme_info.has_eui = 1; - memcpy(dev->nvme_info.eui, eui, sizeof(eui)); -- } else { -- return -1; - } - - return pos0; --- -2.17.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..518483a --- /dev/null +++ b/SOURCES/0025-guids-add-grub-guid-for-grubenv.patch @@ -0,0 +1,38 @@ +From 03041ba898eef2b73e2d9b336094869cd14e307e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 13:59:29 -0400 +Subject: [PATCH 25/63] 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.26.2 + 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..b727424 --- /dev/null +++ b/SOURCES/0026-gcc.specs-add-grecord-gcc-switches.patch @@ -0,0 +1,30 @@ +From a2ea4f82a036756978e54f6f604f65aa81869051 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:00:05 -0400 +Subject: [PATCH 26/63] 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, 24 Jul 2018 09:34:21 +0200 -Subject: [PATCH 26/39] makeguids: initialize memory - -so that we do not write uninitialized memory into guids.bin and names.bin -which made the resulting libefivar.so.1.36 unreproducible. -See https://reproducible-builds.org/ for why this matters. ---- - src/makeguids.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/makeguids.c b/src/makeguids.c -index f84fbb81166..a15356b152e 100644 ---- a/src/makeguids.c -+++ b/src/makeguids.c -@@ -147,6 +147,7 @@ main(int argc, char *argv[]) - outbuf = realloc(outbuf, line * sizeof (struct guidname)); - if (!outbuf) - err(1, "makeguids"); -+ memset(outbuf + line - 1, 0, sizeof(struct guidname)); - - char *symbol = strchr(guidstr, '\t'); - if (symbol == NULL) --- -2.17.1 - diff --git a/SOURCES/0027-Makefile-don-t-echo-our-deps-submake-invocation.patch b/SOURCES/0027-Makefile-don-t-echo-our-deps-submake-invocation.patch new file mode 100644 index 0000000..ad61b4c --- /dev/null +++ b/SOURCES/0027-Makefile-don-t-echo-our-deps-submake-invocation.patch @@ -0,0 +1,26 @@ +From 24226715b44c2e53a211112092638962123e25d7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 10:05:11 -0400 +Subject: [PATCH 27/63] 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.26.2 + diff --git a/SOURCES/0027-emmc_parser-add-emmc_parser.patch b/SOURCES/0027-emmc_parser-add-emmc_parser.patch deleted file mode 100644 index 3a0b18b..0000000 --- a/SOURCES/0027-emmc_parser-add-emmc_parser.patch +++ /dev/null @@ -1,255 +0,0 @@ -From d6a526a0c819c439a894af625f45b657576f8744 Mon Sep 17 00:00:00 2001 -From: Alek Du -Date: Fri, 27 Jul 2018 21:31:01 +0800 -Subject: [PATCH 27/39] emmc_parser: add emmc_parser - -Signed-off-by: Alek Du ---- - src/dp-message.c | 18 +++++ - src/linux-emmc.c | 129 +++++++++++++++++++++++++++++++++ - src/linux.c | 1 + - src/include/efivar/efivar-dp.h | 2 + - src/linux.h | 7 ++ - src/libefivar.map.in | 1 + - 6 files changed, 158 insertions(+) - create mode 100644 src/linux-emmc.c - -diff --git a/src/dp-message.c b/src/dp-message.c -index 5af66438bfc..3724e5f57bd 100644 ---- a/src/dp-message.c -+++ b/src/dp-message.c -@@ -826,3 +826,21 @@ efidp_make_nvdimm(uint8_t *buf, ssize_t size, efi_guid_t *uuid) - - return sz; - } -+ -+ssize_t PUBLIC -+efidp_make_emmc(uint8_t *buf, ssize_t size, uint32_t slot_id) -+{ -+ efidp_emmc *emmc = (efidp_emmc *)buf; -+ ssize_t req = sizeof (*emmc); -+ ssize_t sz; -+ -+ sz = efidp_make_generic(buf, size, EFIDP_MESSAGE_TYPE, -+ EFIDP_MSG_NVME, sizeof (*emmc)); -+ if (size && sz == req) -+ emmc->slot = slot_id; -+ -+ if (sz < 0) -+ efi_error("efidp_make_generic failed"); -+ -+ return sz; -+} -diff --git a/src/linux-emmc.c b/src/linux-emmc.c -new file mode 100644 -index 00000000000..f0c9e635cb6 ---- /dev/null -+++ b/src/linux-emmc.c -@@ -0,0 +1,129 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+/* -+ * support for emmc devices -+ * -+ * /sys/dev/block/$major:$minor looks like: -+ * 179:0 -> ../../devices/pci0000:00/0000:00:1c.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0 -+ * 179:1 -> ../../devices/pci0000:00/0000:00:1c.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1 -+ * -+ * /sys/dev/block/179:0/device looks like: -+ * device -> ../../../mmc0:0001 -+ * -+ * /sys/dev/block/179:1/partition looks like: -+ * $ cat partition -+ * 1 -+ * -+ */ -+ -+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; -+ char *spaces; -+ -+ pos0 = strlen(current); -+ spaces = alloca(pos0+1); -+ memset(spaces, ' ', pos0+1); -+ spaces[pos0] = '\0'; -+ pos0 = 0; -+ -+ debug(DEBUG, "entry"); -+ -+ debug(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(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); -+ arrow(DEBUG, spaces, 9, pos0, rc, 4); -+ arrow(DEBUG, spaces, 9, pos1, rc, 6); -+ /* -+ * 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) -+{ -+ ssize_t sz; -+ -+ debug(DEBUG, "entry"); -+ -+ 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; -+ -+ 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; -+ } -+ -+ 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, -+}; -diff --git a/src/linux.c b/src/linux.c -index 7fac339c50e..ff8db812ad3 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -246,6 +246,7 @@ static struct dev_probe *dev_probes[] = { - &ata_parser, - &scsi_parser, - &i2o_parser, -+ &emmc_parser, - NULL - }; - -diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h -index 1b05775ae7e..f9ebb059d06 100644 ---- a/src/include/efivar/efivar-dp.h -+++ b/src/include/efivar/efivar-dp.h -@@ -689,6 +689,8 @@ typedef struct { - uint8_t slot; - } EFIVAR_PACKED efidp_emmc; - -+extern ssize_t efidp_make_emmc(uint8_t *buf, ssize_t size, uint32_t slot_id); -+ - #define EFIDP_MSG_BTLE 0x1e - typedef struct { - efidp_header header; -diff --git a/src/linux.h b/src/linux.h -index 99d61013e02..7c7ea91e771 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -93,6 +93,10 @@ struct nvdimm_info { - efi_guid_t nvdimm_label; - }; - -+struct emmc_info { -+ int32_t slot_id; -+}; -+ - enum interface_type { - unknown, - isa, acpi_root, pci_root, soc_root, pci, network, -@@ -100,6 +104,7 @@ enum interface_type { - usb, i1394, fibre, i2o, - md, virtblk, - nvme, nd_pmem, -+ emmc, - }; - - struct dev_probe; -@@ -139,6 +144,7 @@ struct device { - 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; - }; - }; -@@ -277,5 +283,6 @@ extern struct dev_probe virtblk_parser; - extern struct dev_probe i2o_parser; - extern struct dev_probe scsi_parser; - extern struct dev_probe ata_parser; -+extern struct dev_probe emmc_parser; - - #endif /* _EFIBOOT_LINUX_H */ -diff --git a/src/libefivar.map.in b/src/libefivar.map.in -index 31f696d3cb5..b5ee1ce334a 100644 ---- a/src/libefivar.map.in -+++ b/src/libefivar.map.in -@@ -51,6 +51,7 @@ libefivar.so.0 { - efidp_make_sata; - efidp_make_scsi; - efidp_make_vendor; -+ efidp_make_emmc; - efidp_parse_device_node; - efidp_parse_device_path; - efidp_set_node_data; --- -2.17.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..85f220a --- /dev/null +++ b/SOURCES/0028-Make-Add-some-more-stuff-to-the-toplevel-clean.patch @@ -0,0 +1,26 @@ +From 7cfb9bd539ced0fd6fe35e7c08326bc3011d059b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 11:06:09 -0400 +Subject: [PATCH 28/63] 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.26.2 + diff --git a/SOURCES/0028-abignore-work-around-an-abidw-bug.patch b/SOURCES/0028-abignore-work-around-an-abidw-bug.patch deleted file mode 100644 index 814db60..0000000 --- a/SOURCES/0028-abignore-work-around-an-abidw-bug.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 1f385ff1bde1e783eba03df37af9421bac0df82b Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 3 Aug 2018 09:56:01 -0400 -Subject: [PATCH 28/39] abignore: work around an abidw bug - -Some versions of abignore mistakenly treat brackets as section headers, -thus ignoring the rest of the stanza after them. It's fixed upstream, -but I don't have the newer version yet. Moving the braces to be after -the change-kind and other things works around the issue. - -Signed-off-by: Peter Jones ---- - src/abignore | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/abignore b/src/abignore -index a4597b1029c..1badb2dab35 100644 ---- a/src/abignore -+++ b/src/abignore -@@ -14,28 +14,28 @@ - # 'efidp_wifi __anonymous_union__::wifi' at efivar-dp.h:868:1 - # - [suppress_type] -- soname_regexp = libefi(var|boot)\\.so\\..* - name = efidp_data - type_kind = typedef - has_data_member_inserted_at = end -+ soname_regexp = libefi(var|boot)\\.so\\..* - - # 1 Added variable: - # - # 'const __anonymous_struct__ efi_guid_ux_capsule' {efi_guid_ux_capsule@@LIBEFIVAR_1.33} - # - [suppress_variable] -+ change_kind = added-variable - soname_regexp = libefivar\\.so\\..* - symbol_name_regexp = ^efi_guid_[[:alnum:]_]+$ -- change_kind = added-variable - - # allow new functions that are prefixed correctly - [suppress_function] -+ change_kind = added-function - soname_regexp = ^libefi(var|boot)\\.so\\..* - name_regexp = ^(efidp_|efi_)[[:alnum:]_]+ -- change_kind = added-function - - # allow new variables that are prefixed correctly - [suppress_variable] -+ change_kind = added-variable - soname_regexp = libefi(var|boot)\\.so\\..* - symbol_name_regexp = ^(efidp_|efi_)[[:alnum:]_]+ -- change_kind = added-variable --- -2.17.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..86b8ea8 --- /dev/null +++ b/SOURCES/0029-Make-scan-build-rules-slightly-more-intuitive.patch @@ -0,0 +1,31 @@ +From 20928bf97924328d41010aecdbf925c37f633739 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 19 Jun 2019 11:35:28 -0400 +Subject: [PATCH 29/63] 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.26.2 + diff --git a/SOURCES/0029-Update-abidw-for-newer-tools.patch b/SOURCES/0029-Update-abidw-for-newer-tools.patch deleted file mode 100644 index 5432823..0000000 --- a/SOURCES/0029-Update-abidw-for-newer-tools.patch +++ /dev/null @@ -1,1780 +0,0 @@ -From cdb840bc122ff1527416becdf1922962c0251df9 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 8 Jun 2018 15:14:27 -0400 -Subject: [PATCH 29/39] Update abidw for newer tools. - -Signed-off-by: Peter Jones ---- - src/libefiboot.abixml | 34 +- - src/libefivar.abixml | 1026 ++++++++++++++++++++--------------------- - 2 files changed, 530 insertions(+), 530 deletions(-) - -diff --git a/src/libefiboot.abixml b/src/libefiboot.abixml -index 94d96a2f692..97f030865ed 100644 ---- a/src/libefiboot.abixml -+++ b/src/libefiboot.abixml -@@ -21,7 +21,7 @@ - - - -- -+ - - - -@@ -204,12 +204,12 @@ - - - -- -+ - -- -+ - - -- -+ - - - -@@ -416,7 +416,7 @@ - - - -- -+ - - - -@@ -434,30 +434,30 @@ - - - -- -- -- -- -- -- -- -- -- - - - -- -- -- - - - -+ -+ -+ -+ -+ -+ - - - - - - -+ -+ -+ -+ -+ -+ - - - -diff --git a/src/libefivar.abixml b/src/libefivar.abixml -index f0137030eb0..bee8bf60efb 100644 ---- a/src/libefivar.abixml -+++ b/src/libefivar.abixml -@@ -303,115 +303,115 @@ - - - -- -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -+ -+ -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -810,261 +810,294 @@ - - - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ - - -- -+ - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - -- -+ - - - -@@ -1075,7 +1108,7 @@ - - - -- -+ - - - -@@ -1086,10 +1119,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1098,19 +1131,19 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - -@@ -1122,36 +1155,36 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - - -- -+ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - -@@ -1160,10 +1193,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1172,10 +1205,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1190,24 +1223,24 @@ - - - -- -- -+ -+ - -- -+ - - -- -+ - - - -- -+ - - - -- -- -+ -+ - -- -+ - - - -@@ -1219,10 +1252,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1231,10 +1264,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1246,30 +1279,30 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -+ - - - -- -- -+ -+ - - -- -- -+ -+ - -- -+ - - - -@@ -1278,10 +1311,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1290,10 +1323,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1311,10 +1344,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1326,27 +1359,27 @@ - - - -- -+ - - - -- -+ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - -@@ -1358,42 +1391,42 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - -- -+ - - - - - - -- -- -+ -+ - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -+ - - - -@@ -1405,31 +1438,31 @@ - - - -- -+ - - -- -+ - - -- -+ - - - -- -- -+ -+ - - -- -- -- -+ -+ -+ - -- -+ - - -- -+ - - -- -+ - - - -@@ -1451,32 +1484,32 @@ - - - -- -- -+ -+ - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -+ - - - -@@ -1486,11 +1519,11 @@ - - - -- -- -+ -+ - - -- -+ - - - -@@ -1498,10 +1531,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1519,22 +1552,22 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -- -+ -+ - -- -+ - - - -@@ -1543,10 +1576,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1570,16 +1603,16 @@ - - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -+ - - - -@@ -1591,10 +1624,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1603,40 +1636,40 @@ - - - -- -+ - - - - - -- -+ - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -- -+ -+ - -- -+ - - - -@@ -1645,46 +1678,46 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - -@@ -1693,65 +1726,65 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -+ - -- -+ - - -- -+ - - -- -+ - - - -- -- -+ -+ - - -- -+ - -- -+ - - -- -- -+ -+ - -- -+ - - -- -- -+ -+ - -- -+ - - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - - -@@ -1763,7 +1796,7 @@ - - - -- -+ - - - -@@ -1772,10 +1805,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1787,58 +1820,58 @@ - - - -- -- -+ -+ - -- -+ - - - - - -- -+ - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -- -+ -+ - -- -+ - - - - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -- -+ -+ - -- -+ - - -- -+ - - -- -- -+ -+ - -- -+ - - - -@@ -1850,10 +1883,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1868,10 +1901,10 @@ - - - -- -- -+ -+ - -- -+ - - - -@@ -1880,105 +1913,72 @@ - - - -- -+ - - -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -+ -+ -+ -+ - - -- -- -- -- -+ -+ -+ -+ - - -- -- -- -- -- -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -+ -+ -+ -+ -+ -+ -+ - - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - - --- -2.17.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..530cab0 --- /dev/null +++ b/SOURCES/0030-Local-header-whitespace-cleanup.patch @@ -0,0 +1,1511 @@ +From b6db7342f15a86f734445e83198dde024544e492 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:25:21 -0400 +Subject: [PATCH 30/63] 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.26.2 + diff --git a/SOURCES/0030-linux-emmc-update-for-internal-API-breakage.patch b/SOURCES/0030-linux-emmc-update-for-internal-API-breakage.patch deleted file mode 100644 index c8dd61b..0000000 --- a/SOURCES/0030-linux-emmc-update-for-internal-API-breakage.patch +++ /dev/null @@ -1,50 +0,0 @@ -From 0c44e3d75a9c3a2a1d4cef3c1b836aa0d7fb004f Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 3 Aug 2018 10:02:02 -0400 -Subject: [PATCH 30/39] linux-emmc: update for internal API breakage. - -Alek wrote his code before I made debug() imply LOG_DEBUG, so we need to -change that here as well. - -Signed-off-by: Peter Jones ---- - src/linux-emmc.c | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/src/linux-emmc.c b/src/linux-emmc.c -index f0c9e635cb6..87e92477554 100644 ---- a/src/linux-emmc.c -+++ b/src/linux-emmc.c -@@ -58,15 +58,15 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) - spaces[pos0] = '\0'; - pos0 = 0; - -- debug(DEBUG, "entry"); -+ debug("entry"); - -- debug(DEBUG, "searching for mmc_host/mmc0/mmc0:0001/block/mmcblk0 or mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p1"); -+ 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(DEBUG, "current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); -- arrow(DEBUG, spaces, 9, pos0, rc, 4); -- arrow(DEBUG, spaces, 9, pos1, rc, 6); -+ 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. - */ -@@ -92,7 +92,7 @@ dp_create_emmc(struct device *dev, - { - ssize_t sz; - -- debug(DEBUG, "entry"); -+ debug("entry"); - - sz = efidp_make_emmc(buf + off, size ? size - off : 0, - dev->emmc_info.slot_id); --- -2.17.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..a41691c --- /dev/null +++ b/SOURCES/0031-Exported-header-whitespace-cleanup.patch @@ -0,0 +1,97 @@ +From ce7434210d92f0eca1f8e90b82ff4078202c2da9 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:27:08 -0400 +Subject: [PATCH 31/63] 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.26.2 + diff --git a/SOURCES/0031-Fix-another-buggy-fake-acpi-pci-root-driver.patch b/SOURCES/0031-Fix-another-buggy-fake-acpi-pci-root-driver.patch deleted file mode 100644 index f1276ae..0000000 --- a/SOURCES/0031-Fix-another-buggy-fake-acpi-pci-root-driver.patch +++ /dev/null @@ -1,64 +0,0 @@ -From da30e9f2eee235ce11d47bb2e32f976b8c187e5d Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 10 Sep 2018 15:00:03 -0400 -Subject: [PATCH 31/39] Fix another buggy fake acpi pci root driver - -In this case, the platform driver that creates the PCI(e) root device -doesn't fill in its driver link, so we can't look up what driver is in -use - but since it's the root, it *really* doesn't matter. And in -general, we only really care if it's the last node in our path, because -that'll be the controller for the boot device anyway. - -Signed-off-by: Peter Jones ---- - src/linux-pci.c | 24 +++++++++++++++++------- - 1 file changed, 17 insertions(+), 7 deletions(-) - -diff --git a/src/linux-pci.c b/src/linux-pci.c -index e7c864b2d33..f63f5914d9f 100644 ---- a/src/linux-pci.c -+++ b/src/linux-pci.c -@@ -67,7 +67,9 @@ parse_pci(struct device *dev, const char *current, const char *root) - 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", -@@ -100,15 +102,23 @@ parse_pci(struct device *dev, const char *current, const char *root) - return -1; - } - tmp[devpart - root] = '\0'; -- 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; -+ 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->pci_dev[i].driverlink = strdup(linkbuf); -- debug("driver:%s\n", linkbuf); - dev->n_pci_devs += 1; - } - --- -2.17.1 - diff --git a/SOURCES/0032-Fix-dev-probes-intialization-test.patch b/SOURCES/0032-Fix-dev-probes-intialization-test.patch deleted file mode 100644 index a11e118..0000000 --- a/SOURCES/0032-Fix-dev-probes-intialization-test.patch +++ /dev/null @@ -1,28 +0,0 @@ -From e56cf8d480c27bf3ea81af63efb4704896282c6a Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 17 Sep 2018 16:12:25 -0400 -Subject: [PATCH 32/39] Fix dev->probes intialization test - -Signed-off-by: Peter Jones ---- - src/linux.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/src/linux.c b/src/linux.c -index ff8db812ad3..19eb488c992 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -117,7 +117,9 @@ reset_part_name(struct device *dev) - if (dev->part < 1) - return 0; - -- if (dev->probes[dev->n_probes]->make_part_name) { -+ 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; --- -2.17.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..a62846d --- /dev/null +++ b/SOURCES/0032-Main-code-whitespace-cleanup.patch @@ -0,0 +1,5136 @@ +From cfed6e0cce62a920ccd7b09777ae1e0ae62b7c4d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:42:46 -0400 +Subject: [PATCH 32/63] 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.26.2 + diff --git a/SOURCES/0033-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch b/SOURCES/0033-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch deleted file mode 100644 index 6e9fe6c..0000000 --- a/SOURCES/0033-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch +++ /dev/null @@ -1,92 +0,0 @@ -From e83002b08aa6db57b90d89968ab8d34f6c7f73cf Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 17 Sep 2018 16:13:24 -0400 -Subject: [PATCH 33/39] Deal with devices that don't have a ->device link in - sysfs - -Signed-off-by: Peter Jones ---- - src/linux.c | 53 ++++++++++++++++++++++++++++++----------------------- - 1 file changed, 30 insertions(+), 23 deletions(-) - -diff --git a/src/linux.c b/src/linux.c -index 19eb488c992..6d405af8a76 100644 ---- a/src/linux.c -+++ b/src/linux.c -@@ -389,43 +389,50 @@ struct device HIDDEN - - rc = sysfs_readlink(&tmpbuf, "block/%s/device", dev->disk_name); - if (rc < 0 || !tmpbuf) { -- efi_error("readlink of /sys/block/%s/device failed", -+ debug("readlink of /sys/block/%s/device failed", - dev->disk_name); -- goto err; -+ -+ dev->device = strdup(""); -+ } else { -+ dev->device = strdup(tmpbuf); - } - -- dev->device = strdup(tmpbuf); - if (!dev->device) { - efi_error("strdup(\"%s\") failed", tmpbuf); - goto err; - } - -- 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 (dev->device[0] != 0) { -+ rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name); - if (rc < 0 || !tmpbuf) { -- efi_error("readlink of /sys/block/%s/device/driver failed", -- dev->disk_name); -+ 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("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; - } -- } - -- 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(""); - } - -- dev->driver = strdup(linkbuf); - if (!dev->driver) { - efi_error("strdup(\"%s\") failed", linkbuf); - goto err; --- -2.17.1 - diff --git a/SOURCES/0033-efivar-rework-usage.patch b/SOURCES/0033-efivar-rework-usage.patch new file mode 100644 index 0000000..3528ed9 --- /dev/null +++ b/SOURCES/0033-efivar-rework-usage.patch @@ -0,0 +1,142 @@ +From 5f0b2b3460dfa826d75b95450bdc2903fa59e32e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:45:39 -0400 +Subject: [PATCH 33/63] 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.26.2 + diff --git a/SOURCES/0034-Handle-partition-name-parsing-and-formatting-for-par.patch b/SOURCES/0034-Handle-partition-name-parsing-and-formatting-for-par.patch deleted file mode 100644 index 46c3265..0000000 --- a/SOURCES/0034-Handle-partition-name-parsing-and-formatting-for-par.patch +++ /dev/null @@ -1,124 +0,0 @@ -From 576f55b02d9ec478bd5157352c884e3543bcca58 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 17 Sep 2018 16:52:57 -0400 -Subject: [PATCH 34/39] Handle partition name parsing and formatting for - partitioned md. - -Signed-off-by: Peter Jones ---- - src/linux-md.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 103 insertions(+) - create mode 100644 src/linux-md.c - -diff --git a/src/linux-md.c b/src/linux-md.c -new file mode 100644 -index 00000000000..0a5c1cdb435 ---- /dev/null -+++ b/src/linux-md.c -@@ -0,0 +1,103 @@ -+/* -+ * 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" -+ -+#include -+#include -+#include -+#include -+#include -+ -+#include "efiboot.h" -+ -+/* -+ * "support" for partitioned md devices - basically we just need to format -+ * the partition name. -+ * -+ * /sys/dev/block/$major:$minor looks like: -+ * 259:0 -> ../../devices/virtual/block/md1/md1p1 -+ * 9:1 -> ../../devices/virtual/block/md1 -+ * -+ */ -+ -+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; -+ char *spaces; -+ -+ pos0 = strlen(current); -+ spaces = alloca(pos0+1); -+ memset(spaces, ' ', pos0+1); -+ spaces[pos0] = '\0'; -+ pos0 = 0; -+ -+ 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); -+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); -+ /* -+ * 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; -+ -+ if (dev->part == -1) -+ dev->part = part; -+ -+ return pos1; -+} -+ -+ -+static char * -+make_part_name(struct device *dev) -+{ -+ char *ret = NULL; -+ ssize_t rc; -+ -+ 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; -+ } -+ -+ 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, -+}; --- -2.17.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..b0fb925 --- /dev/null +++ b/SOURCES/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch @@ -0,0 +1,431 @@ +From 70e86dc3e48345f1a961aef6173d5126edebf90a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 14:47:24 -0400 +Subject: [PATCH 34/63] 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.26.2 + diff --git a/SOURCES/0035-Fix-partition-number-detection-when-it-s-not-provide.patch b/SOURCES/0035-Fix-partition-number-detection-when-it-s-not-provide.patch deleted file mode 100644 index 0a8b98d..0000000 --- a/SOURCES/0035-Fix-partition-number-detection-when-it-s-not-provide.patch +++ /dev/null @@ -1,79 +0,0 @@ -From cff35642eac6699e30549db2db3341e7657bf4a6 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 18 Sep 2018 14:57:13 -0400 -Subject: [PATCH 35/39] Fix partition number detection when it's not provided. - -We need to actually get the partition number from the child device when -we're called without it. - -Resolves: rhbz#1616305 - -Signed-off-by: Peter Jones ---- - src/creator.c | 43 +++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 43 insertions(+) - -diff --git a/src/creator.c b/src/creator.c -index ef782e2b647..987fa033e5b 100644 ---- a/src/creator.c -+++ b/src/creator.c -@@ -350,6 +350,36 @@ efi_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size, - return ret; - } - -+static int -+get_part(char *devpath) -+{ -+ int fd; -+ int partition = -1; -+ struct device *dev = NULL; -+ -+ fd = open(devpath, O_RDONLY); -+ if (fd < 0) { -+ efi_error("could not open device for ESP"); -+ goto err; -+ } -+ -+ dev = device_get(fd, -1); -+ if (dev == NULL) { -+ efi_error("could not get ESP disk info"); -+ goto err; -+ } -+ -+ partition = dev->part; -+ if (partition < 0) -+ partition = 0; -+err: -+ if (dev) -+ device_free(dev); -+ if (fd >= 0) -+ close(fd); -+ return partition; -+} -+ - ssize_t NONNULL(3) PUBLIC - efi_generate_file_device_path(uint8_t *buf, ssize_t size, - const char * const filepath, -@@ -374,6 +404,19 @@ 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("parent_devpath:%s", parent_devpath); -+ debug("child_devpath:%s", child_devpath); -+ debug("rc:%d", rc); -+ -+ rc = get_part(child_devpath); -+ if (rc < 0) { -+ efi_error("Couldn't get partition number for %s", -+ child_devpath); -+ goto err; -+ } -+ debug("detected partition:%d", rc); - - va_start(ap, options); - --- -2.17.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..13035e7 --- /dev/null +++ b/SOURCES/0035-ucs2-document-things-a-little-better.patch @@ -0,0 +1,219 @@ +From ee7ba570f7c555f93f41badefb63397737ef7810 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 13:12:39 -0400 +Subject: [PATCH 35/63] 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.26.2 + diff --git a/SOURCES/0036-dp-acpi-fix-HID-vs-HID_EX-formatting-bug.patch b/SOURCES/0036-dp-acpi-fix-HID-vs-HID_EX-formatting-bug.patch deleted file mode 100644 index 96a0220..0000000 --- a/SOURCES/0036-dp-acpi-fix-HID-vs-HID_EX-formatting-bug.patch +++ /dev/null @@ -1,38 +0,0 @@ -From ebc0b14923faa8da19dbdc2501a6fef0728906a1 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 1 Oct 2018 14:27:04 -0400 -Subject: [PATCH 36/39] dp-acpi: fix HID vs HID_EX formatting bug. - -Signed-off-by: Peter Jones ---- - src/dp-acpi.c | 7 ++++++- - 1 file changed, 6 insertions(+), 1 deletion(-) - -diff --git a/src/dp-acpi.c b/src/dp-acpi.c -index 6f3e94443e5..019f910c164 100644 ---- a/src/dp-acpi.c -+++ b/src/dp-acpi.c -@@ -157,7 +157,9 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - return off; - } - } -- } else if (dp->subtype == EFIDP_ACPI_HID_EX) { -+ } else if (dp->subtype == EFIDP_ACPI_HID) { -+ debug("formatting ACPI HID 0x%08x", dp->acpi_hid.hid); -+ - switch (dp->acpi_hid.hid) { - case EFIDP_ACPI_PCI_ROOT_HID: - format(buf, size, off, "PciRoot", -@@ -249,6 +251,9 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - return -1; - } - } -+ } else { -+ debug("Unknown ACPI device path type {0x%04hhx,0x%04hhx}", -+ dp->type, dp->subtype); - } - - return off; --- -2.17.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..6ac89cd --- /dev/null +++ b/SOURCES/0036-util.h-implement-add-mul-sub-for-more-integer-types.patch @@ -0,0 +1,370 @@ +From 73635c7e096eb36b52c1e874f9b76856c6a41228 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 16:37:29 -0400 +Subject: [PATCH 36/63] 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.26.2 + 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..5dd5908 --- /dev/null +++ b/SOURCES/0037-Implement-efivar-export-foo.var.patch @@ -0,0 +1,1194 @@ +From 488976e782a7307cc2df4e1a8aaea1f6dfa757dd Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 17 Jun 2019 15:04:11 -0400 +Subject: [PATCH 37/63] 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.26.2 + diff --git a/SOURCES/0037-Support-decoding-ACPI-Generic-Container-and-Embedded.patch b/SOURCES/0037-Support-decoding-ACPI-Generic-Container-and-Embedded.patch deleted file mode 100644 index b327b83..0000000 --- a/SOURCES/0037-Support-decoding-ACPI-Generic-Container-and-Embedded.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 7775b2fdd12151f78f575026bb5e416575dad455 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 1 Oct 2018 14:31:06 -0400 -Subject: [PATCH 37/39] Support decoding ACPI Generic Container and Embedded - Controller dp nodes - -Signed-off-by: Peter Jones ---- - src/dp-acpi.c | 18 ++++++++++++++++++ - src/include/efivar/efivar-dp.h | 3 +++ - 2 files changed, 21 insertions(+) - -diff --git a/src/dp-acpi.c b/src/dp-acpi.c -index 019f910c164..3a80ba9e006 100644 ---- a/src/dp-acpi.c -+++ b/src/dp-acpi.c -@@ -147,10 +147,19 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - format(buf, size, off, "PciRoot", - "PciRoot(%s)", uidstr); - return off; -+ case EFIDP_ACPI_CONTAINER_0A05_HID: -+ case EFIDP_ACPI_CONTAINER_0A06_HID: -+ format(buf, size, off, "AcpiContainer", -+ "AcpiContainer(%s)", uidstr); -+ break; - case EFIDP_ACPI_PCIE_ROOT_HID: - format(buf, size, off, "PcieRoot", - "PcieRoot(%s)", uidstr); - return off; -+ case EFIDP_ACPI_EC_HID: -+ format(buf, size, off, "EmbeddedController", -+ "EmbeddedController()"); -+ return off; - default: - format_acpi_hid_ex(buf, size, off, dp, - hidstr, cidstr, uidstr); -@@ -166,11 +175,20 @@ _format_acpi_dn(char *buf, size_t size, const_efidp dp) - "PciRoot(0x%"PRIx32")", - dp->acpi_hid.uid); - break; -+ case EFIDP_ACPI_CONTAINER_0A05_HID: -+ case EFIDP_ACPI_CONTAINER_0A06_HID: -+ format(buf, size, off, "AcpiContainer", -+ "AcpiContainer()"); -+ break; - case EFIDP_ACPI_PCIE_ROOT_HID: - format(buf, size, off, "PcieRoot", - "PcieRoot(0x%"PRIx32")", - dp->acpi_hid.uid); - break; -+ case EFIDP_ACPI_EC_HID: -+ format(buf, size, off, "EmbeddedController", -+ "EmbeddedController()"); -+ break; - case EFIDP_ACPI_FLOPPY_HID: - format(buf, size, off, "Floppy", - "Floppy(0x%"PRIx32")", -diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h -index f9ebb059d06..eab04f2dfac 100644 ---- a/src/include/efivar/efivar-dp.h -+++ b/src/include/efivar/efivar-dp.h -@@ -155,7 +155,10 @@ efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size, - #define EFIDP_ACPI_ID_TO_NUM(_HID) ((_HID) >> 16) - - #define EFIDP_ACPI_PCI_ROOT_HID EFIDP_EFI_PNP_ID(0x0a03) -+#define EFIDP_ACPI_CONTAINER_0A05_HID EFIDP_EFI_PNP_ID(0x0a05) -+#define EFIDP_ACPI_CONTAINER_0A06_HID EFIDP_EFI_PNP_ID(0x0a06) - #define EFIDP_ACPI_PCIE_ROOT_HID EFIDP_EFI_PNP_ID(0x0a08) -+#define EFIDP_ACPI_EC_HID EFIDP_EFI_PNP_ID(0x0a09) - #define EFIDP_ACPI_FLOPPY_HID EFIDP_EFI_PNP_ID(0x0604) - #define EFIDP_ACPI_KEYBOARD_HID EFIDP_EFI_PNP_ID(0x0301) - #define EFIDP_ACPI_SERIAL_HID EFIDP_EFI_PNP_ID(0x0501) --- -2.17.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..a7eb2cd --- /dev/null +++ b/SOURCES/0038-Add-some-test-cases-for-efivar-export-import.patch @@ -0,0 +1,187 @@ +From 693dbef8d7d6287b438ad7e385b383f60df74a8c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 13:21:45 -0400 +Subject: [PATCH 38/63] 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.26.2 + diff --git a/SOURCES/0038-pci-root-actually-create-the-device-path-node.patch b/SOURCES/0038-pci-root-actually-create-the-device-path-node.patch deleted file mode 100644 index 3ed781d..0000000 --- a/SOURCES/0038-pci-root-actually-create-the-device-path-node.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 0d63973b32767e1c4d44c0c172ae6222d9acefff Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 1 Oct 2018 14:33:20 -0400 -Subject: [PATCH 38/39] pci-root: actually create the device path node. - -Signed-off-by: Peter Jones ---- - src/linux-pci-root.c | 5 +---- - 1 file changed, 1 insertion(+), 4 deletions(-) - -diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c -index 269e30e2c31..a2d9fb04a11 100644 ---- a/src/linux-pci-root.c -+++ b/src/linux-pci-root.c -@@ -87,9 +87,9 @@ static ssize_t - dp_create_pci_root(struct device *dev UNUSED, - 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 0 - if (dev->acpi_root.acpi_uid_str) { - debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"", - dev->acpi_root.acpi_hid, -@@ -120,9 +120,6 @@ dp_create_pci_root(struct device *dev UNUSED, - - debug("returning %zd", sz); - return sz; --#else -- return 0; --#endif - } - - enum interface_type pci_root_iftypes[] = { pci_root, unknown }; --- -2.17.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..f32558c --- /dev/null +++ b/SOURCES/0039-Fix-a-case-clang-analyzer-found-where-we-may-try-to-.patch @@ -0,0 +1,119 @@ +From 9819ec7325089d325ff13af3c3d615209f3fb2c9 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Jun 2019 15:54:58 -0400 +Subject: [PATCH 39/63] 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.26.2 + diff --git a/SOURCES/0039-sas-handle-port-expanders-at-all.patch b/SOURCES/0039-sas-handle-port-expanders-at-all.patch deleted file mode 100644 index 87ea524..0000000 --- a/SOURCES/0039-sas-handle-port-expanders-at-all.patch +++ /dev/null @@ -1,431 +0,0 @@ -From 3e687d8072f3ed53ae727ec2cb99ae56dbcdf02b Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 1 Oct 2018 14:35:01 -0400 -Subject: [PATCH 39/39] sas: handle port expanders at all. - -Signed-off-by: Peter Jones ---- - src/linux-ata.c | 3 +- - src/linux-sas.c | 168 ++++++++++++++++++++++++++++++++++++++++++----- - src/linux-scsi.c | 105 +++++++++++++++++++++++++---- - src/linux.h | 6 +- - 4 files changed, 250 insertions(+), 32 deletions(-) - -diff --git a/src/linux-ata.c b/src/linux-ata.c -index 32cb99361e5..43e5f4c5d23 100644 ---- a/src/linux-ata.c -+++ b/src/linux-ata.c -@@ -114,7 +114,8 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) - - pos = parse_scsi_link(host + 1, &scsi_host, - &scsi_bus, &scsi_device, -- &scsi_target, &scsi_lun); -+ &scsi_target, &scsi_lun, -+ NULL, NULL, NULL); - if (pos < 0) - return -1; - -diff --git a/src/linux-sas.c b/src/linux-sas.c -index 4d77d39a24d..bb04fe83064 100644 ---- a/src/linux-sas.c -+++ b/src/linux-sas.c -@@ -28,6 +28,91 @@ - - #include "efiboot.h" - -+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) -+{ -+ 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 -+ */ -+ -+#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.) -+ */ -+ -+ 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; -+ } -+#endif -+ -+ rc = sscanf((char *)filebuf, "%"PRIx64, sas_address); -+ if (rc != 1) -+ return -1; -+ -+ return 0; -+} -+ -+static int -+get_local_sas_address(uint64_t *sas_address, struct device *dev) -+{ -+ 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 = sscanf((char *)filebuf, "%"PRIx64, sas_address); -+ if (rc != 1) -+ return -1; -+ -+ return 0; -+} -+ - /* - * support for SAS devices - * -@@ -43,6 +128,24 @@ - * /sys/class/block/sdc/device/sas_address - * - * I'm not sure at the moment if they're the same or not. -+ * -+ * There are also other devices that look like: -+ * -+ * 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/dev/block/8:0/device -> ../../../2:0:0:0 -+ * -+ * This exists: -+ * -+ * /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/pci0000:74/0000:74:02.0/host2/port-2:0/expander-2:0/sas_device/expander-2:0/sas_address -+ * -+ * but the device doesn't actually have a sas_host_address, because it's on a -+ * port expander, and sas_address doesn't directly exist under /sys/class/ -+ * anywhere. - */ - static ssize_t - parse_sas(struct device *dev, const char *current, const char *root UNUSED) -@@ -50,16 +153,19 @@ 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; -- uint8_t *filebuf = NULL; -- uint64_t sas_address; -+ uint64_t sas_address = 0; - - debug("entry"); - - pos = parse_scsi_link(current, &scsi_host, - &scsi_bus, &scsi_device, -- &scsi_target, &scsi_lun); -+ &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. -@@ -71,6 +177,7 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED) - * 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); -@@ -79,21 +186,48 @@ parse_sas(struct device *dev, const char *current, const char *root UNUSED) - * 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) -- return 0; -+ 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."); - -- /* -- * we also need to get the actual sas_address from someplace... -- */ -- 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; -+ /* -+ * 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; - -diff --git a/src/linux-scsi.c b/src/linux-scsi.c -index 2e4f710badf..a5e81cf9cb6 100644 ---- a/src/linux-scsi.c -+++ b/src/linux-scsi.c -@@ -38,7 +38,9 @@ - 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 *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; -@@ -70,11 +72,32 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - * /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; - -@@ -91,6 +114,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - 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); -@@ -100,6 +131,52 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - 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); -+ 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"); -+ 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); -+ arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3); -+ if (rc != 3) { -+ efi_error("Couldn't parse port expander port string"); -+ return -1; -+ } -+ sz += pos0; -+ } -+ pos0 = 0; - - /* next: - * /end_device-4:0 -@@ -107,22 +184,24 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - * 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("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); -- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); - if (rc != 2) - return -1; -- sz += pos0; -- pos0 = 0; - -- rc = sscanf(current + sz, ":%d%n", &tosser0, &pos0); -- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); -- arrow(LOG_DEBUG, spaces, 9, pos0, rc, 2); -+ 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; -- sz += pos0; -- pos0 = 0; -+ 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; -@@ -156,6 +235,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, - return -1; - sz += pos0; - -+ debug("returning %d", sz); - return sz; - } - -@@ -191,7 +271,8 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) - - sz = parse_scsi_link(current, &scsi_host, - &scsi_bus, &scsi_device, -- &scsi_target, &scsi_lun); -+ &scsi_target, &scsi_lun, -+ NULL, NULL, NULL); - if (sz < 0) - return 0; - -diff --git a/src/linux.h b/src/linux.h -index 7c7ea91e771..43a9b7899f5 100644 ---- a/src/linux.h -+++ b/src/linux.h -@@ -267,8 +267,10 @@ struct dev_probe { - }; - - 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 *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; --- -2.17.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..233315c --- /dev/null +++ b/SOURCES/0040-Make-sure-makeguids-helper-is-compiled-for-the-host-.patch @@ -0,0 +1,37 @@ +From 4baa930ea79314e778a5ca84e3f85e94b2f9968f Mon Sep 17 00:00:00 2001 +From: Dmitry Torokhov +Date: Tue, 6 Aug 2019 09:22:25 -0700 +Subject: [PATCH 40/63] 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.26.2 + 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..9659090 --- /dev/null +++ b/SOURCES/0041-Makefile-sort-wildcard-output-for-reproducibility.patch @@ -0,0 +1,49 @@ +From 709afd3e2c946a765550992fa93adca8a88f2952 Mon Sep 17 00:00:00 2001 +From: Pierre Bourdon +Date: Tue, 13 Aug 2019 05:08:20 +0200 +Subject: [PATCH 41/63] 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.26.2 + 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..dd9c331 --- /dev/null +++ b/SOURCES/0042-guids.txt-correct-sentinal-typo.patch @@ -0,0 +1,22 @@ +From 636aefebf32527dc8c7a592687a9bca3bdf028d2 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 29 Aug 2019 10:39:39 +0100 +Subject: [PATCH 42/63] 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.26.2 + 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..cbcaf39 --- /dev/null +++ b/SOURCES/0043-update-manpage-for-efivar-such-that-it-reflects-the-.patch @@ -0,0 +1,73 @@ +From f46b0d46545419e9db9853fc73919064f367ca34 Mon Sep 17 00:00:00 2001 +From: Robert Bisewski +Date: Wed, 25 Sep 2019 15:38:02 -0500 +Subject: [PATCH 43/63] 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.26.2 + 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..29fde2c --- /dev/null +++ b/SOURCES/0044-Fix-some-32-bit-size_t-format-specifier-errors.patch @@ -0,0 +1,53 @@ +From 150873b00fdb2d5aca2e7c66d0545ad55801409a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 10:44:53 -0400 +Subject: [PATCH 44/63] 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.26.2 + 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..32c0ac2 --- /dev/null +++ b/SOURCES/0045-Make-the-top-level-makefile-not-parallelize.patch @@ -0,0 +1,34 @@ +From aae6a63e34320299a3707a9a468ab78333230283 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 10:52:12 -0400 +Subject: [PATCH 45/63] 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.26.2 + 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..81c6e43 --- /dev/null +++ b/SOURCES/0046-guids-add-auto_created_boot_option.patch @@ -0,0 +1,25 @@ +From 8922c5692eebfe05e59bd5c4de464f3db10a69f3 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 14:30:42 -0400 +Subject: [PATCH 46/63] 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.26.2 + 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..3481a70 --- /dev/null +++ b/SOURCES/0047-Move-our-infrastructure-makefiles-out-of-the-topdir.patch @@ -0,0 +1,260 @@ +From 1249545850373e9c1717eab077a74b87069e90ba Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 13:52:22 -0400 +Subject: [PATCH 47/63] 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.26.2 + 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..89f818d --- /dev/null +++ b/SOURCES/0048-Make-CC_FOR_BUILD-and-CCLD_FOR_BUILD-override-HOSTCC.patch @@ -0,0 +1,33 @@ +From 9fa2e902ad0581b57e6e387ec629a70b16a26095 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 13:52:46 -0400 +Subject: [PATCH 48/63] 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.26.2 + 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..ce68833 --- /dev/null +++ b/SOURCES/0049-Rework-some-makefile-bits-to-make-overriding-some-op.patch @@ -0,0 +1,299 @@ +From 88663428b13a281d0b759718d7c8faa454b3409a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 Oct 2019 15:45:10 -0400 +Subject: [PATCH 49/63] 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.26.2 + 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..e708a1c --- /dev/null +++ b/SOURCES/0050-Make-add-Wno-missing-field-initializers.patch @@ -0,0 +1,55 @@ +From 1b5da030b19e6f7f086ef2f1719159951c574fa7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:49:54 -0400 +Subject: [PATCH 50/63] 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.26.2 + 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..bf30686 --- /dev/null +++ b/SOURCES/0051-debug-don-t-write-newlines-to-memfd.patch @@ -0,0 +1,78 @@ +From f9797c91e190fc53ce997beb1e7c2a140abfd665 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:27:39 -0400 +Subject: [PATCH 51/63] 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 | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/src/error.c b/src/error.c +index 083de15e984..8ceba31dd55 100644 +--- a/src/error.c ++++ b/src/error.c +@@ -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.26.2 + 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..5a87678 --- /dev/null +++ b/SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch @@ -0,0 +1,314 @@ +From f1d09655cbc47a738410b601ac1f7ddde2d72b26 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 16:59:14 -0400 +Subject: [PATCH 52/63] 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 | 3 +++ + src/linux-emmc.c | 1 + + src/linux-md.c | 1 + + src/linux-nvme.c | 1 + + src/linux-pci-root.c | 2 ++ + src/linux-pci.c | 1 + + src/linux-pmem.c | 2 ++ + src/linux-sata.c | 4 ++++ + src/linux-scsi.c | 8 ++++++++ + src/linux-soc-root.c | 2 ++ + src/linux-virtblk.c | 1 + + src/util.h | 35 +++++++++++++++++++++++++++++++++++ + 12 files changed, 61 insertions(+) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index f48d4be9ac6..5ed4d7f5b86 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -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..59ef8e7524d 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -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..1d7bd3195c0 100644 +--- a/src/linux-md.c ++++ b/src/linux-md.c +@@ -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..0b4eae74f79 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -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..c84b639cbfe 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -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..0de330db628 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -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..18eb7dce5e3 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -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..b0caa3fa401 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -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..96fde7e15fa 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -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..c932670ef15 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -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..7517db55555 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -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.26.2 + diff --git a/SOURCES/0053-gitignore-ignore-.strace.patch b/SOURCES/0053-gitignore-ignore-.strace.patch new file mode 100644 index 0000000..0f0226d --- /dev/null +++ b/SOURCES/0053-gitignore-ignore-.strace.patch @@ -0,0 +1,25 @@ +From 45d1aa955a38541ba8e1554026847e582ae28bfd Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 16 Oct 2019 10:01:00 -0400 +Subject: [PATCH 53/63] 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.26.2 + diff --git a/SOURCES/0054-Improve-consistency-of-debug-prints.patch b/SOURCES/0054-Improve-consistency-of-debug-prints.patch new file mode 100644 index 0000000..f617af9 --- /dev/null +++ b/SOURCES/0054-Improve-consistency-of-debug-prints.patch @@ -0,0 +1,809 @@ +From cb81253cc60d9641ee766fa2be691d82821710ca Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:26:30 -0400 +Subject: [PATCH 54/63] 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 | 6 ++--- + src/linux-acpi-root.c | 20 +++++++++-------- + src/linux-acpi.c | 4 ++-- + src/linux-ata.c | 6 ++--- + src/linux-emmc.c | 5 +++-- + src/linux-i2o.c | 8 +++---- + src/linux-md.c | 4 ++-- + src/linux-nvme.c | 8 +++++-- + src/linux-pci-root.c | 16 ++++++++------ + src/linux-pci.c | 17 +++++++-------- + src/linux-pmem.c | 19 +++++++++------- + src/linux-sas.c | 3 +++ + src/linux-sata.c | 9 ++++---- + src/linux-scsi.c | 51 +++++++++++++++++++++++++++---------------- + src/linux-soc-root.c | 6 ++--- + src/linux-virtblk.c | 5 +++-- + src/linux.c | 27 ++++++++++++++--------- + 17 files changed, 125 insertions(+), 89 deletions(-) + +diff --git a/src/dp-acpi.c b/src/dp-acpi.c +index 02ec70eec7a..4845410c2cf 100644 +--- a/src/dp-acpi.c ++++ b/src/dp-acpi.c +@@ -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 5ed4d7f5b86..57a648981b3 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 = 0; ++ int pos = -1; + uint16_t pad0; + uint8_t pad1; + char *acpi_header = NULL; +@@ -62,7 +62,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + * side in sscanf. + */ + rc = sscanf(devpart, "../../devices/platform/%n", &pos); +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ debug("current:'%s' rc:%d pos:%d", devpart, rc, pos); + dbgmk(" ", pos); + if (rc != 0 || pos < 1) + return 0; +@@ -94,16 +94,16 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + return -1; + } + dev->acpi_root.acpi_hid_str[pos] = 0; +- debug("acpi_hid_str:\"%s\"", dev->acpi_root.acpi_hid_str); ++ debug("acpi_hid_str:'%s'", dev->acpi_root.acpi_hid_str); + + pos -= 4; +- debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos); ++ debug("current:'%s' rc:%d pos:%d", devpart, rc, pos); + dbgmk(" ", pos); + acpi_header = strndupa(devpart, pos); + if (!acpi_header) + return 0; + acpi_header[pos] = 0; +- debug("devpart:\"%s\" acpi_header:\"%s\"", devpart, acpi_header); ++ debug("current:'%s' acpi_header:'%s'", devpart, acpi_header); + devpart += pos; + + /* +@@ -114,7 +114,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + efi_error("Could not parse ACPI path \"%s\"", devpart); + return 0; + } +- debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d", ++ debug("current:'%s' parsed:%04hx:%02hhx pos:%d rc:%d", + devpart, pad0, pad1, pos, rc); + dbgmk(" ", pos); + +@@ -134,12 +134,14 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + efi_error("Could not parse hid/uid"); + 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); + +- return devpart - current; ++ size_t sz = devpart - current; ++ debug("current:'%s' sz:%zd", devpart, sz); ++ return sz; + } + + static ssize_t +@@ -151,7 +153,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..70161ca7b9e 100644 +--- a/src/linux-acpi.c ++++ b/src/linux-acpi.c +@@ -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 b6a7c2dcf8a..7bb23da60f5 100644 +--- a/src/linux-ata.c ++++ b/src/linux-ata.c +@@ -126,9 +126,9 @@ parse_ata(struct device *dev, const char *current, const char *root UNUSED) + dev->ata_info.scsi_lun = scsi_lun; + + 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; + } + + static ssize_t +diff --git a/src/linux-emmc.c b/src/linux-emmc.c +index 59ef8e7524d..74cf54aa336 100644 +--- a/src/linux-emmc.c ++++ b/src/linux-emmc.c +@@ -49,7 +49,7 @@ 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; ++ int pos0 = -1, pos1 = -1; + + debug("entry"); + +@@ -57,7 +57,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + 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); ++ 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. +@@ -75,6 +75,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED) + pos0 = pos1; + } + ++ debug("current:'%s' sz:%d\n", current, pos0); + return pos0; + } + +diff --git a/src/linux-i2o.c b/src/linux-i2o.c +index ebd92aeeb53..76b3d4d5d39 100644 +--- a/src/linux-i2o.c ++++ b/src/linux-i2o.c +@@ -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 1d7bd3195c0..ded7cbd169c 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-nvme.c b/src/linux-nvme.c +index 0b4eae74f79..7b18d7990ac 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -53,6 +53,7 @@ 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; ++ ssize_t sz = 0; + int pos0 = 0, pos1 = 0; + + debug("entry"); +@@ -61,7 +62,7 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + 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); ++ 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. +@@ -81,6 +82,8 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + pos0 = pos1; + } + ++ sz += pos0; ++ + /* + * now fish the eui out of sysfs is there is one... + */ +@@ -111,7 +114,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\n", current, sz); ++ return sz; + } + + static ssize_t +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index c84b639cbfe..c7e279118f5 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 = 0; ++ int pos0 = -1, pos1 = -1; + uint16_t root_domain; + uint8_t root_bus; + const char *devpart = current; +@@ -56,15 +56,16 @@ 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(devpart, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, 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; ++ devpart += pos1; + + dev->pci_root.pci_domain = root_domain; + dev->pci_root.pci_bus = root_bus; +@@ -75,7 +76,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:%d\n", devpart, pos1); ++ return pos1; + } + + static ssize_t +@@ -86,7 +88,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-pci.c b/src/linux-pci.c +index 0de330db628..a3a0dc28afd 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 = 0; ++ int pos0 = -1, pos1 = -1; + const char *devpart = current; + + debug("entry"); +@@ -62,16 +62,15 @@ parse_pci(struct device *dev, const char *current, const char *root) + unsigned int i = dev->n_pci_devs; + struct stat statbuf; + +- debug("devpart is \"%s\"", devpart); +- pos = 0; ++ pos0 = pos1 = -1; + 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(devpart, "%n%hx:%hhx:%hhx.%hhx/%n", ++ &pos0, &domain, &bus, &device, &function, &pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); + if (rc != 4) + break; +- devpart += pos; ++ devpart += pos1; + + debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", + domain, bus, device, function); +@@ -115,7 +114,7 @@ parse_pci(struct device *dev, const char *current, const char *root) + dev->n_pci_devs += 1; + } + +- debug("next:\"%s\"", devpart); ++ debug("current:'%s' sz:%zd\n", devpart, devpart - current); + return devpart - current; + } + +diff --git a/src/linux-pmem.c b/src/linux-pmem.c +index 18eb7dce5e3..49db24560fa 100644 +--- a/src/linux-pmem.c ++++ b/src/linux-pmem.c +@@ -75,7 +75,7 @@ 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; ++ int ndbus, region, btt_region_id, btt_id, rc, pos0, pos1; + char *namespace = NULL; + + debug("entry"); +@@ -101,14 +101,16 @@ parse_pmem(struct device *dev, const char *current, 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/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. +@@ -123,7 +125,7 @@ parse_pmem(struct device *dev, const char *current, 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) +@@ -158,7 +160,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED) + + dev->interface_type = nd_pmem; + +- return pos; ++ debug("current:'%s' sz:%d\n", current, pos1); ++ return pos1; + } + + static ssize_t +diff --git a/src/linux-sas.c b/src/linux-sas.c +index f985deeaa3f..d14fcfb231a 100644 +--- a/src/linux-sas.c ++++ b/src/linux-sas.c +@@ -172,6 +172,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,6 +237,8 @@ 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; ++ ++ debug("current:'%s' sz:%zd\n", current, pos); + return pos; + } + +diff --git a/src/linux-sata.c b/src/linux-sata.c +index b0caa3fa401..4f4e983568e 100644 +--- a/src/linux-sata.c ++++ b/src/linux-sata.c +@@ -161,7 +161,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); ++ 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 +@@ -175,7 +175,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); ++ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos); + dbgmk(" ", pos); + if (rc != 1) + return -1; +@@ -185,7 +185,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + 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); ++ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos); + dbgmk(" ", pos); + if (rc != 3) + return -1; +@@ -195,7 +195,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + 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); ++ debug("current:'%s' rc:%d pos:%d\n", current, rc, pos); + dbgmk(" ", pos); + if (rc != 4) + return -1; +@@ -213,6 +213,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + if (dev->interface_type == unknown) + dev->interface_type = sata; + ++ debug("current:'%s' sz:%zd\n", current, current - devlink); + return current - devlink; + } + +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 96fde7e15fa..6b92908d6bc 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -43,7 +43,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + uint32_t *remote_target_id) + { + int rc; +- int sz = 0; ++ ssize_t sz = 0; + int pos0 = 0, pos1 = 0; + + debug("entry"); +@@ -100,10 +100,11 @@ 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); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + dbgmk(" ", pos0); + if (rc != 1) + return -1; ++ current += pos0; + sz += pos0; + pos0 = 0; + +@@ -116,11 +117,12 @@ 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, ++ rc = sscanf(current, "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); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); + dbgmk(" ", pos0, pos1); + if (rc == 2 || rc == 3) { ++ current += pos0; + sz += pos0; + pos0 = 0; + if (local_port_id && rc == 2) +@@ -128,8 +130,10 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + if (remote_port_id && rc == 3) + *remote_port_id = tosser2; + +- if (current[sz] == '/') ++ if (current[0] == '/') { ++ current += 1; + sz += 1; ++ } + + /* + * We might have this next: +@@ -143,8 +147,8 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * 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); ++ rc = sscanf(current, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + dbgmk(" ", pos0); + if (rc == 2) { + if (!remote_target_id) { +@@ -152,6 +156,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + return -1; + } + *remote_target_id = tosser1; ++ current += pos0; + sz += pos0; + pos0 = 0; + +@@ -159,13 +164,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * 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); ++ rc = sscanf(current, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + dbgmk(" ", pos0); + if (rc != 3) { + efi_error("Couldn't parse port expander port string"); + return -1; + } ++ current += pos0; + sz += pos0; + } + pos0 = 0; +@@ -177,13 +183,13 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * 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); ++ rc = sscanf(current, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + if (rc != 2) + return -1; + + pos1 = 0; +- rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1); ++ rc = sscanf(current + pos0, ":%d%n", &tosser2, &pos1); + if (rc != 0 && rc != 1) + return -1; + dbgmk(" ", pos0, pos0+pos1); +@@ -191,11 +197,14 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + *remote_port_id = tosser2; + if (local_port_id && rc == 0) + *local_port_id = tosser1; ++ current += pos0 + pos1; + sz += pos0 + pos1; + pos0 = pos1 = 0; + +- if (current[sz] == '/') ++ if (current[0] == '/') { ++ current += sz; + sz += 1; ++ } + } else if (rc != 0) { + return -1; + } +@@ -205,12 +214,13 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + */ + uint64_t tosser3; + debug("searching for target4:0:0/"); +- rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, ++ rc = sscanf(current, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, + &tosser3, &pos0); +- debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + dbgmk(" ", pos0); + if (rc != 3) + return -1; ++ current += pos0; + sz += pos0; + pos0 = 0; + +@@ -218,15 +228,16 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + * %d:%d:%d:%llu/ + */ + debug("searching for 4:0:0:0/"); +- rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n", ++ rc = sscanf(current, "%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); ++ debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); + dbgmk(" ", pos0); + if (rc != 4) + return -1; ++ current += pos0; + sz += pos0; + +- debug("returning %d", sz); ++ debug("current:'%s' sz:%zd\n", current, sz); + return sz; + } + +@@ -248,7 +259,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + &dev->scsi_info.scsi_target, + &dev->scsi_info.scsi_lun, + &pos); +- debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos); ++ debug("current:'%s' rc:%d pos:%d\n", dev->device, rc, pos); + dbgmk(" ", pos); + if (rc != 4) + return 0; +@@ -259,6 +270,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + NULL, NULL, NULL); + if (sz < 0) + return 0; ++ current += sz; + + /* + * SCSI disks can have up to 16 partitions, or 4 bits worth +@@ -281,6 +293,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED) + return -1; + } + ++ debug("current:'%s' sz:%zd\n", current, sz); + return sz; + } + +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index c932670ef15..9c9e9573dcd 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -49,12 +49,12 @@ 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); ++ debug("current:'%s' rc:%d pos:%d", current, rc, pos); + dbgmk(" ", pos); + devpart += pos; +- debug("new position is \"%s\"", devpart); + +- return devpart - current; ++ debug("current:'%s' sz:%d\n", devpart, pos); ++ return pos; + } + + enum interface_type soc_root_iftypes[] = { soc_root, unknown }; +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index 7517db55555..df14673dac8 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -48,14 +48,14 @@ static ssize_t + parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + { + uint32_t tosser; +- int pos = 0; ++ int pos = -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); ++ 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. +@@ -65,6 +65,7 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + + dev->interface_type = virtblk; + ++ debug("current:'%s' sz:%d\n", current, pos); + return pos; + } + +diff --git a/src/linux.c b/src/linux.c +index 45b1ee2d96f..45f07d3913c 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -182,10 +182,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")) || +@@ -455,7 +455,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 || +@@ -465,7 +469,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)) +@@ -474,8 +481,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); +@@ -491,8 +498,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.26.2 + diff --git a/SOURCES/0055-Fix-the-error-path-in-set_disk_and_part_name.patch b/SOURCES/0055-Fix-the-error-path-in-set_disk_and_part_name.patch new file mode 100644 index 0000000..601edc2 --- /dev/null +++ b/SOURCES/0055-Fix-the-error-path-in-set_disk_and_part_name.patch @@ -0,0 +1,63 @@ +From 74aa359f7474040aef2bd18b66201412f853b5c4 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 17:01:00 -0400 +Subject: [PATCH 55/63] Fix the error path in set_disk_and_part_name() + +Signed-off-by: Peter Jones +--- + src/linux.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/linux.c b/src/linux.c +index 45f07d3913c..73c67cbafd3 100644 +--- a/src/linux.c ++++ b/src/linux.c +@@ -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.26.2 + diff --git a/SOURCES/0056-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch b/SOURCES/0056-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch new file mode 100644 index 0000000..542c7cf --- /dev/null +++ b/SOURCES/0056-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch @@ -0,0 +1,204 @@ +From 156d7a1e123f85863db854aae5c10acd3864f9d8 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Oct 2019 14:20:54 -0400 +Subject: [PATCH 56/63] 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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 101 insertions(+), 27 deletions(-) + +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 7b18d7990ac..455c4c7ba9b 100644 +--- a/src/linux-nvme.c ++++ b/src/linux-nvme.c +@@ -87,13 +87,12 @@ parse_nvme(struct device *dev, const char *current, 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 73c67cbafd3..30db22d95dd 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..ae9835ef7ce 100644 +--- a/src/linux.h ++++ b/src/linux.h +@@ -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.26.2 + diff --git a/SOURCES/0057-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch b/SOURCES/0057-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch new file mode 100644 index 0000000..8cce53d --- /dev/null +++ b/SOURCES/0057-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch @@ -0,0 +1,334 @@ +From ad1d30fc5e20b933b6ad59d35c13e0193cd68a2d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 2 Oct 2019 17:04:12 -0400 +Subject: [PATCH 57/63] Handle + /sys/devices/virtual/{nvme-fabrics,nvme-subsystem} devices + +Signed-off-by: Peter Jones +--- + src/linux-nvme.c | 59 ++++++++++++++++++++++----- + src/linux-virtual-root.c | 88 ++++++++++++++++++++++++++++++++++++++++ + src/linux.c | 43 +++++++++++++++++--- + src/linux.h | 4 +- + 4 files changed, 176 insertions(+), 18 deletions(-) + create mode 100644 src/linux-virtual-root.c + +diff --git a/src/linux-nvme.c b/src/linux-nvme.c +index 455c4c7ba9b..7ca2fa3c283 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 +@@ -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" +@@ -24,6 +23,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -34,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 +@@ -53,17 +59,44 @@ 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 = -1, pos1 = -1, pos2 = -1; + ssize_t sz = 0; +- int pos0 = 0, pos1 = 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, "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); ++ /* ++ * 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. + */ +@@ -79,14 +112,15 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED) + if (dev->part == -1) + dev->part = partition; + +- pos0 = pos1; ++ pos1 = pos2; + } + +- sz += pos0; ++ sz += 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)) { +@@ -109,6 +143,9 @@ parse_nvme(struct device *dev, const char *current, 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..b2d36b4095f +--- /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 30db22d95dd..7dd8d4cd858 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 ae9835ef7ce..6bfc5869254 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.26.2 + diff --git a/SOURCES/0058-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch b/SOURCES/0058-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch new file mode 100644 index 0000000..66aa5ac --- /dev/null +++ b/SOURCES/0058-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.patch @@ -0,0 +1,778 @@ +From fa9336914ef43d1a1dbc3384c8051362eea12cd7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:53:27 -0400 +Subject: [PATCH 58/63] 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;". + +Make them all the same, where possible. + +Signed-off-by: Peter Jones +--- + src/linux-acpi-root.c | 65 +++++----- + src/linux-pci-root.c | 9 +- + src/linux-pci.c | 21 ++-- + src/linux-sata.c | 56 +++++---- + src/linux-scsi.c | 248 ++++++++++++++++++++------------------- + src/linux-soc-root.c | 19 +-- + src/linux-virtblk.c | 15 ++- + src/linux-virtual-root.c | 2 +- + 8 files changed, 227 insertions(+), 208 deletions(-) + +diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c +index 57a648981b3..6bfc1ad9a2b 100644 +--- a/src/linux-acpi-root.c ++++ b/src/linux-acpi-root.c +@@ -44,14 +44,13 @@ static ssize_t + parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED) + { + int rc; +- int pos = -1; ++ int pos0 = -1, pos1 = -1, pos2 = -1; ++ ssize_t sz = 0; + uint16_t pad0; + uint8_t pad1; + char *acpi_header = NULL; + char *colon; + +- const char *devpart = current; +- + debug("entry"); + + /* +@@ -61,23 +60,26 @@ 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("current:'%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; ++ sz += 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,40 +87,44 @@ 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; ++ dev->acpi_root.acpi_hid_str[pos1] = 0; + debug("acpi_hid_str:'%s'", dev->acpi_root.acpi_hid_str); + +- pos -= 4; +- debug("current:'%s' rc:%d pos:%d", devpart, rc, pos); +- dbgmk(" ", pos); +- acpi_header = strndupa(devpart, pos); ++ pos2 = pos1 - 4; ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos2); ++ dbgmk(" ", pos0, pos2); ++ acpi_header = strndupa(current, pos2); + if (!acpi_header) + return 0; +- acpi_header[pos] = 0; +- debug("current:'%s' acpi_header:'%s'", devpart, acpi_header); +- devpart += pos; ++ acpi_header[pos2] = 0; ++ debug("current:'%s' acpi_header:'%s'", current, acpi_header); ++ current += pos1; ++ sz += pos1; + + /* + * 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, "%n%hx:%hhx/%n", &pos0, &pad0, &pad1, &pos1); + if (rc != 2) { +- efi_error("Could not parse ACPI path \"%s\"", devpart); ++ efi_error("Could not parse ACPI path \"%s\"", current); + return 0; + } +- debug("current:'%s' parsed:%04hx:%02hhx pos:%d rc:%d", +- devpart, pad0, pad1, pos, rc); +- dbgmk(" ", pos); +- +- devpart += pos; ++ debug("current:'%s' parsed:%04hx:%02hhx rc:%d pos0:%d pos1:%d", ++ current, pad0, pad1, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ current += pos1; ++ sz += pos1; + + rc = parse_acpi_hid_uid(dev, "devices/platform/%s%04hX:%02hhX", + acpi_header, pad0, pad1); +@@ -139,8 +145,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED + dev->acpi_root.acpi_uid_str, + dev->acpi_root.acpi_cid_str); + +- size_t sz = devpart - current; +- debug("current:'%s' sz:%zd", devpart, sz); ++ debug("current:'%s' sz:%zd", current, sz); + return sz; + } + +diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c +index c7e279118f5..8f7cfe293bf 100644 +--- a/src/linux-pci-root.c ++++ b/src/linux-pci-root.c +@@ -47,7 +47,6 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + int pos0 = -1, pos1 = -1; + uint16_t root_domain; + uint8_t root_bus; +- const char *devpart = current; + + debug("entry"); + +@@ -56,8 +55,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + * pci0000:00/ + * ^d ^p + */ +- rc = sscanf(devpart, "%n../../devices/pci%hx:%hhx/%n", &pos0, &root_domain, &root_bus, &pos1); +- debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1); ++ 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); + + /* +@@ -65,7 +64,7 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + */ + if (rc != 2) + return 0; +- devpart += pos1; ++ current += pos1; + + dev->pci_root.pci_domain = root_domain; + dev->pci_root.pci_bus = root_bus; +@@ -76,7 +75,7 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED) + return -1; + + errno = 0; +- debug("current:'%s' sz:%d\n", devpart, pos1); ++ debug("current:'%s' sz:%d\n", current, pos1); + return pos1; + } + +diff --git a/src/linux-pci.c b/src/linux-pci.c +index a3a0dc28afd..ca6f693cd8a 100644 +--- a/src/linux-pci.c ++++ b/src/linux-pci.c +@@ -46,8 +46,7 @@ static ssize_t + parse_pci(struct device *dev, const char *current, const char *root) + { + int rc; +- int pos0 = -1, pos1 = -1; +- const char *devpart = current; ++ ssize_t sz = 0; + + debug("entry"); + +@@ -55,22 +54,24 @@ 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; + + pos0 = pos1 = -1; + debug("searching for 0000:00:00.0/"); +- rc = sscanf(devpart, "%n%hx:%hhx:%hhx.%hhx/%n", ++ rc = sscanf(current, "%n%hx:%hhx:%hhx.%hhx/%n", + &pos0, &domain, &bus, &device, &function, &pos1); +- debug("current:'%s' rc:%d pos0:%d pos1:%d", devpart, rc, pos0, pos1); ++ debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); + dbgmk(" ", pos0, pos1); + if (rc != 4) + break; +- devpart += pos1; ++ current += pos1; ++ sz += pos1; + + debug("found pci domain %04hx:%02hhx:%02hhx.%02hhx", + domain, bus, device, function); +@@ -87,13 +88,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); +@@ -114,8 +115,8 @@ parse_pci(struct device *dev, const char *current, const char *root) + dev->n_pci_devs += 1; + } + +- debug("current:'%s' sz:%zd\n", devpart, devpart - current); +- return devpart - current; ++ debug("current:'%s' sz:%zd\n", current, sz); ++ return sz; + } + + static ssize_t +diff --git a/src/linux-sata.c b/src/linux-sata.c +index 4f4e983568e..b49cf99dcb7 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 *current, 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 pos0 = -1, pos1 = -1; ++ size_t sz = 0; + 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,40 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + */ + if (rc != 1) + return 0; +- current += pos; +- pos = 0; ++ current += pos1; ++ sz += 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; ++ sz += 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; ++ sz += 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; ++ sz += pos1; + + rc = sysfs_sata_get_port_info(print_id, dev); + if (rc < 0) +@@ -213,8 +217,8 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED) + if (dev->interface_type == unknown) + dev->interface_type = sata; + +- debug("current:'%s' sz:%zd\n", current, current - devlink); +- return current - devlink; ++ debug("current:'%s' sz:%zd\n", current, sz); ++ return sz; + } + + static ssize_t +diff --git a/src/linux-scsi.c b/src/linux-scsi.c +index 6b92908d6bc..73db53b3ed6 100644 +--- a/src/linux-scsi.c ++++ b/src/linux-scsi.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #include "efiboot.h" +@@ -44,7 +45,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + { + int rc; + ssize_t sz = 0; +- int pos0 = 0, pos1 = 0; ++ int pos0 = -1, pos1 = -1, pos2 = -1; + + debug("entry"); + /* +@@ -99,14 +100,14 @@ 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, 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; +- current += pos0; +- sz += pos0; +- pos0 = 0; ++ current += pos1; ++ sz += pos1; ++ pos0 = pos1 = -1; + + /* + * We might have this next: +@@ -117,96 +118,100 @@ 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, "port-%d:%d%n:%d%n", &tosser0, +- &tosser1, &pos0, &tosser2, &pos1); +- debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1); +- dbgmk(" ", pos0, pos1); +- if (rc == 2 || rc == 3) { +- current += pos0; +- 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[0] == '/') { +- current += 1; +- 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, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0); +- debug("current:'%s' rc:%d pos0:%d\n", current, 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; +- current += pos0; +- 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, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0); +- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); +- dbgmk(" ", pos0); +- if (rc != 3) { +- efi_error("Couldn't parse port expander port string"); +- return -1; +- } +- current += pos0; +- 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, "end_device-%d:%d%n", &tosser0, &tosser1, &pos0); +- debug("current:'%s' rc:%d pos0:%d\n", current, rc, pos0); +- if (rc != 2) +- return -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; ++ } else { ++ pos1 = 0; ++ } ++ current += pos1; ++ sz += pos1; + +- pos1 = 0; +- rc = sscanf(current + 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; +- current += pos0 + pos1; +- sz += pos0 + pos1; +- pos0 = pos1 = 0; ++ if (current[0] == '/') { ++ current += 1; ++ sz += 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; ++ sz += 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; ++ sz += 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; ++ sz += pos1; ++ pos0 = pos1 = pos2 = -1; + +- if (current[0] == '/') { +- current += sz; +- sz += 1; +- } +- } else if (rc != 0) { +- return -1; ++ if (current[0] == '/') { ++ current += sz; ++ sz += 1; + } + + /* now: +@@ -214,28 +219,28 @@ parse_scsi_link(const char *current, uint32_t *scsi_host, + */ + uint64_t tosser3; + debug("searching for target4:0:0/"); +- rc = sscanf(current, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1, +- &tosser3, &pos0); +- debug("current:'%s' rc:%d pos0:%d\n", current, 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; +- current += pos0; +- sz += pos0; +- pos0 = 0; ++ current += pos1; ++ sz += pos1; ++ pos0 = pos1 = -1; + + /* now: + * %d:%d:%d:%llu/ + */ + debug("searching for 4:0:0:0/"); +- rc = sscanf(current, "%d:%d:%d:%"PRIu64"/%n", +- scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0); +- debug("current:'%s' rc:%d pos0:%d\n", current, 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; +- current += pos0; +- sz += pos0; ++ current += pos1; ++ sz += pos1; + + debug("current:'%s' sz:%zd\n", current, sz); + return sz; +@@ -246,31 +251,32 @@ 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; ++ ssize_t sz = 0; ++ 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 += sz; ++ current += pos0; ++ sz += pos0; + + /* + * SCSI disks can have up to 16 partitions, or 4 bits worth +diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c +index 9c9e9573dcd..bad37c9f874 100644 +--- a/src/linux-soc-root.c ++++ b/src/linux-soc-root.c +@@ -41,20 +41,21 @@ 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 pos0 = -1, pos1 = -1; ++ ssize_t sz = 0; + + 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("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1); ++ dbgmk(" ", pos0, pos1); ++ current += pos1; ++ sz += pos1; + +- debug("current:'%s' sz:%d\n", devpart, pos); +- return pos; ++ debug("current:'%s' sz:%zd\n", current, sz); ++ return sz; + } + + enum interface_type soc_root_iftypes[] = { soc_root, unknown }; +diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c +index df14673dac8..a3366c9c677 100644 +--- a/src/linux-virtblk.c ++++ b/src/linux-virtblk.c +@@ -48,15 +48,16 @@ static ssize_t + parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + { + uint32_t tosser; +- int pos = -1; ++ int pos0 = -1, pos1 = -1; ++ ssize_t sz = 0; + 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,9 +65,11 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED) + return 0; + + dev->interface_type = virtblk; ++ current += pos1; ++ sz += pos1; + +- debug("current:'%s' sz:%d\n", current, pos); +- return pos; ++ debug("current:'%s' sz:%zd\n", current, sz); ++ return sz; + } + + enum interface_type virtblk_iftypes[] = { virtblk, unknown }; +diff --git a/src/linux-virtual-root.c b/src/linux-virtual-root.c +index b2d36b4095f..75fbbfc1de6 100644 +--- a/src/linux-virtual-root.c ++++ b/src/linux-virtual-root.c +@@ -61,7 +61,7 @@ parse_virtual_root(struct device *dev UNUSED, const char *current, const char *r + 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); ++ dbgmk(" ", pos0, pos1); + if (rc == 1) { + sz += pos1; + current += pos1; +-- +2.26.2 + 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..8851332 --- /dev/null +++ b/SOURCES/0059-Put-some-EFI-device-paths-into-the-debug-log.patch @@ -0,0 +1,72 @@ +From effecb5ce0baf2fae011dd61e45852cd2fb1ec19 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 15 Oct 2019 16:58:19 -0400 +Subject: [PATCH 59/63] 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 7dd8d4cd858..9d8480a94a9 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.26.2 + diff --git a/SOURCES/0060-Update-abixml.patch b/SOURCES/0060-Update-abixml.patch new file mode 100644 index 0000000..2983845 --- /dev/null +++ b/SOURCES/0060-Update-abixml.patch @@ -0,0 +1,99 @@ +From 5c6adc21cd219d5868507ae00c8c95c6542dac42 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 09:51:56 -0500 +Subject: [PATCH 60/63] 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.26.2 + 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..cdce31a --- /dev/null +++ b/SOURCES/0061-Update-abixml-files-and-work-around-some-inconsequen.patch @@ -0,0 +1,3314 @@ +From 4fa201844bc4b57e06f1ca2a4ea41e70c206a672 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 09:54:48 -0500 +Subject: [PATCH 61/63] 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.26.2 + 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..2525092 --- /dev/null +++ b/SOURCES/0062-Don-t-use-march-native-on-ia64.patch @@ -0,0 +1,43 @@ +From ec3079ee6252808ff6961a165306cb1ae427d04f Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 15:58:47 -0500 +Subject: [PATCH 62/63] 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.26.2 + 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..0c00115 --- /dev/null +++ b/SOURCES/0063-Work-around-autoconf-existing-in-the-world.patch @@ -0,0 +1,56 @@ +From 1b35f9a4b396f21139ab64de0510aa829548682d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 13 Jan 2020 16:27:42 -0500 +Subject: [PATCH 63/63] 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.26.2 + 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..876c259 --- /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] 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.26.2 + diff --git a/SOURCES/0065-Fix-variable-sz-uninitialized-error.patch b/SOURCES/0065-Fix-variable-sz-uninitialized-error.patch new file mode 100644 index 0000000..17ba146 --- /dev/null +++ b/SOURCES/0065-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] 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.26.2 + diff --git a/SPECS/efivar.spec b/SPECS/efivar.spec index bc35b15..8fabbd6 100644 --- a/SPECS/efivar.spec +++ b/SPECS/efivar.spec @@ -1,8 +1,8 @@ Name: efivar -Version: 36 -Release: 1%{?dist} +Version: 37 +Release: 4%{?dist} Summary: Tools to manage UEFI variables -License: LGPLv2.1 +License: LGPL-2.1 URL: https://github.com/rhboot/efivar Requires: %{name}-libs = %{version}-%{release} ExclusiveArch: %{ix86} x86_64 aarch64 %{arm} @@ -11,45 +11,71 @@ BuildRequires: popt-devel git glibc-static libabigail # please don't fix this to reflect github's incomprehensible url that goes # to a different tarball. Source0: https://github.com/rhboot/efivar/archive/efivar-%{version}.tar.bz2 -Patch0001: 0001-Move-the-syntastic-file-I-use-out-of-the-repo.patch -Patch0002: 0002-Move-verbosity-headers-to-be-public.patch -Patch0003: 0003-Pacify-some-coverity-nits.patch -Patch0004: 0004-efivar-Fix-some-types-in-L-behavior-to-pacify-coveri.patch -Patch0005: 0005-Promote-_make_hd_dn-to-make_hd_dn-and-get-rid-of-the.patch -Patch0006: 0006-Try-to-convince-covscan-that-sysfs_read_file-doesn-t.patch -Patch0007: 0007-Make-efidp_make_file-have-even-more-better-input-con.patch -Patch0008: 0008-Make-path-helpers.c-also-import-fix_coverity.h.patch -Patch0009: 0009-Fix-a-makeguids-building-problem-with-generics.h.patch -Patch0010: 0010-Improve-ACPI-device-path-formatting.patch -Patch0011: 0011-Give-linux-s-parse-functions-the-unmodified-device-l.patch -Patch0012: 0012-Move-ACPI-ID-parsing-to-a-shared-location.patch -Patch0013: 0013-Make-a-platform-ACPI-root-parser-separate-from-PCI-r.patch -Patch0014: 0014-Make-a-way-to-say-e-3-isn-t-viable-for-a-kind-of-dev.patch -Patch0015: 0015-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch -Patch0016: 0016-If-we-can-t-parse-part-of-the-device-link-skip-it-an.patch -Patch0017: 0017-Pacify-clang-analyzer-just-a-little.patch -Patch0018: 0018-Try-even-harder-to-convince-coverity-that-get_file-i.patch -Patch0019: 0019-Make-the-debug-code-less-intrusive.patch -Patch0020: 0020-efiboot-Make-the-device-node-skipping-code-pass-cove.patch -Patch0021: 0021-efiboot-don-t-error-on-unknown-type-with-DEV_ABBREV_.patch -Patch0022: 0022-efiboot-fix-a-bad-error-check.patch -Patch0023: 0023-efiboot-parse_scsi_link-fix-the-offset-searching-for.patch -Patch0024: 0024-Coverity-still-doesn-t-believe-in-error-codes.patch -Patch0025: 0025-Don-t-require-NVME-to-have-an-EUI.patch -Patch0026: 0026-makeguids-initialize-memory.patch -Patch0027: 0027-emmc_parser-add-emmc_parser.patch -Patch0028: 0028-abignore-work-around-an-abidw-bug.patch -Patch0029: 0029-Update-abidw-for-newer-tools.patch -Patch0030: 0030-linux-emmc-update-for-internal-API-breakage.patch -Patch0031: 0031-Fix-another-buggy-fake-acpi-pci-root-driver.patch -Patch0032: 0032-Fix-dev-probes-intialization-test.patch -Patch0033: 0033-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch -Patch0034: 0034-Handle-partition-name-parsing-and-formatting-for-par.patch -Patch0035: 0035-Fix-partition-number-detection-when-it-s-not-provide.patch -Patch0036: 0036-dp-acpi-fix-HID-vs-HID_EX-formatting-bug.patch -Patch0037: 0037-Support-decoding-ACPI-Generic-Container-and-Embedded.patch -Patch0038: 0038-pci-root-actually-create-the-device-path-node.patch -Patch0039: 0039-sas-handle-port-expanders-at-all.patch +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-Improve-consistency-of-debug-prints.patch +Patch0055: 0055-Fix-the-error-path-in-set_disk_and_part_name.patch +Patch0056: 0056-Try-even-harder-to-find-disk-device-symlinks-in-sysf.patch +Patch0057: 0057-Handle-sys-devices-virtual-nvme-fabrics-nvme-subsyst.patch +Patch0058: 0058-sysfs-parsers-make-all-the-sys-block-link-parsers-wo.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-Fix-variable-sz-uninitialized-error.patch %description efivar provides a simple command line interface to the UEFI variable facility. @@ -111,6 +137,22 @@ make libdir=%{_libdir} bindir=%{_bindir} CFLAGS="$RPM_OPT_FLAGS -flto" LDFLAGS=" %{_libdir}/*.so.* %changelog +* Tue Jul 14 2020 Javier Martinez Canillas - 37-4 +- Fix efivar "-w" and "-a" options that broke due the rebase + Related: rhbz#1755645 + +* Tue Jul 14 2020 Javier Martinez Canillas - 37-3 +- Fix uninitialized variable found by covscan + Related: rhbz#1755645 + +* Mon Jul 13 2020 Javier Martinez Canillas - 37-2 +- Change License field to LGPL-2.1 to prevent rpminspect test to fail + Related: rhbz#1755645 + +* Thu Jul 02 2020 Javier Martinez Canillas - 37-1 +- Update to efivar 37 and some changes to support NVMe over FC + Resolves: rhbz#1755645 + * Tue Oct 02 2018 Peter Jones - 36-1 - Update to efivar 36 (and some change) Resolves: rhbz#1635019