Date: Fri, 26 Jun 2026 14:59:18 +0000 From: Warner Losh <imp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: ce9bfd781679 - main - loader.efi: Refactor try_boot_device_partitions Message-ID: <6a3e93c6.204ba.2bd6bcfa@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=ce9bfd781679ba67123345352a754c2e2dd1ef0b commit ce9bfd781679ba67123345352a754c2e2dd1ef0b Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2026-06-26 14:45:51 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2026-06-26 14:54:36 +0000 loader.efi: Refactor try_boot_device_partitions Break out the probing into try_disk_and_partitions and adjust the trying message slightly to be a little clearer what we're doing. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D57802 --- stand/efi/loader/main.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index e11f8b1c3833..961ccc8f7065 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -375,6 +375,29 @@ try_as_currdev(pdinfo_t *pp, bool verbose) return (sanity_check_currdev()); } +/* + * Given a disk, try each of its partitions as the boot device. + */ +static int +try_disk_and_partitions(pdinfo_t *disk, EFI_HANDLE skip_handle) +{ + pdinfo_t *pp; + + if (disk == NULL) + return (ENOENT); + + if (try_as_currdev(disk, true)) + return (0); + + STAILQ_FOREACH(pp, &disk->pd_part, pd_link) { + if (pp->pd_handle == skip_handle) + continue; + if (try_as_currdev(pp, true)) + return (0); + } + return (ENOENT); +} + /* * Search the boot device first (i.e. the ESP and any sibling partitions). * Per the UEFI specification, filesystems on other devices must not be @@ -383,7 +406,7 @@ try_as_currdev(pdinfo_t *pp, bool verbose) static int try_boot_device_partitions(void) { - pdinfo_t *dp, *pp, *espdp; + pdinfo_t *dp; CHAR16 *text; dp = efiblk_get_pdinfo_by_handle(boot_img->DeviceHandle); @@ -392,30 +415,11 @@ try_boot_device_partitions(void) text = efi_devpath_name(dp->pd_devpath); if (text != NULL) { - printf("Trying ESP: %S\n", text); + printf("Trying ESP device: %S\n", text); efi_free_devpath_name(text); } - set_currdev_pdinfo(dp); - if (sanity_check_currdev()) - return (0); - if (dp->pd_parent == NULL) - return (ENOENT); - - espdp = dp; - dp = dp->pd_parent; - STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { - if (espdp == pp) - continue; - text = efi_devpath_name(pp->pd_devpath); - if (text != NULL) { - printf("Trying: %S\n", text); - efi_free_devpath_name(text); - } - if (try_as_currdev(dp, pp)) - return (0); - } - return (ENOENT); + return (try_disk_and_partitions(dp->pd_parent, dp->pd_handle)); } /*home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a3e93c6.204ba.2bd6bcfa>
