Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nRAGB-0000Kl-BG for mharc-grub-devel@gnu.org; Mon, 07 Mar 2022 05:06:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRAG7-0000BU-2v for grub-devel@gnu.org; Mon, 07 Mar 2022 05:06:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:31767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRAG5-0003WJ-BJ for grub-devel@gnu.org; Mon, 07 Mar 2022 05:06:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646647588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a0zCQ+xRS/hiQwj/KOLWKuEnqO8Afh4sY+zr4ASdSxo=; b=QTb59px+HNpQd9UaIxiizt7/kMCGkd1eHE8Koa9htHxjprTXio1akgXp7ojimVoagETKYm rvAyGXBiNcDuC1w7r87NNfHbbpLQKCG1tvhfm18oy3n6DviTV+vnw78iAq1KVLKFtTJhue K11yMP782JUjoPVXfO+6zk87G+UF15w= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-NysHyJHjNkWFXf9eQDwxBA-1; Mon, 07 Mar 2022 05:06:27 -0500 X-MC-Unique: NysHyJHjNkWFXf9eQDwxBA-1 Received: by mail-wr1-f71.google.com with SMTP id e6-20020a5d4e86000000b001f045d4a962so4163879wru.21 for ; Mon, 07 Mar 2022 02:06:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a0zCQ+xRS/hiQwj/KOLWKuEnqO8Afh4sY+zr4ASdSxo=; b=4EUdkbA4rz/pIKMC3tLXFfelSlI0uJyJ8Wk4RxCPn2qvOOdcqlCgUY3uclSJ0wvU6/ XeX0Aocy9qoPnwSey0qgjj9Yi4ZTgFIRi+K+dEQOTWdf2oTm2dE7CLhNEK8WWGmthz4k 5vJA3wH3xBeu7pUJUMOkzDp78dyPWLIaw1XdDJ+zyMSir0ty4wmlKr++u4rfOLfBnR9T DmiGsZheGjRKrxm7xSYFkeuLqeEcizBKcDzz+aQaNf1a6TFT005cUCDGouvxLjZWwn03 vA6Dg+TtbKP+baocU07GAFC00ofgKRfkdiD/P2WiaG7maxAJ6sgMsB5z+hGjJgG2rFxv 750Q== X-Gm-Message-State: AOAM531HMVymiBh3vS8Qw/FhiLFM7pXdZzILjDp9u8vgA8kndh/6coZu p3e0RCtR3/MZeMXknXpRPBPH8/jLKr54c4cQDdVZCkSQwg9aTStwG0nmZOFzv/lgxpVqEtUEvgh Je5GzqoCKqMweOVtWGadxGPGNA4WOPidYS5ODK8uj79kAWPctCZNRLKyYUaZM8wc= X-Received: by 2002:a5d:64ac:0:b0:1e7:1415:2548 with SMTP id m12-20020a5d64ac000000b001e714152548mr7769004wrp.267.1646647586043; Mon, 07 Mar 2022 02:06:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwF5tC/gfVjdtlrMmAVctPS7Yy2KUldFfsbsyeKkmL3sz1TIzLJVYer7bRAX5hBIJAzcL6z+Q== X-Received: by 2002:a5d:64ac:0:b0:1e7:1415:2548 with SMTP id m12-20020a5d64ac000000b001e714152548mr7768983wrp.267.1646647585772; Mon, 07 Mar 2022 02:06:25 -0800 (PST) Received: from t590.redhat.com (82-64-217-13.subs.proxad.net. [82.64.217.13]) by smtp.gmail.com with ESMTPSA id r186-20020a1c2bc3000000b0037bdd94a4e5sm12654976wmr.39.2022.03.07.02.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 02:06:25 -0800 (PST) From: =?UTF-8?q?Renaud=20M=C3=A9trich?= To: grub-devel@gnu.org Cc: =?UTF-8?q?Renaud=20M=C3=A9trich?= Subject: [PATCH v5 3/3] search: new --efidisk-only option on EFI systems Date: Mon, 7 Mar 2022 11:06:20 +0100 Message-Id: <20220307100620.34309-4-rmetrich@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307100620.34309-1-rmetrich@redhat.com> References: <20220307100620.34309-1-rmetrich@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=rmetrich@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=rmetrich@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2022 10:06:31 -0000 When using 'search' on EFI systems, we sometimes want to exclude devices that are not EFI disks (e.g. md, lvm). This is typically used when wanting to chainload when having a software raid (md) for EFI partition: with no option, 'search --file /EFI/redhat/shimx64.efi' sets root envvar to 'md/boot_efi' which cannot be used for chainloading since there is no effective EFI device behind. Signed-off-by: Renaud Métrich --- docs/grub.texi | 5 ++++- grub-core/commands/search.c | 19 +++++++++++++++++++ grub-core/commands/search_wrap.c | 5 +++++ include/grub/search.h | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index a72d73ce3..acdb479e0 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -5003,7 +5003,7 @@ unbootable. @xref{Using digital signatures}, for more information. @deffn Command search @ [@option{--file}|@option{--label}|@option{--fs-uuid}] @ - [@option{--set} [var]] [@option{--no-floppy}] name + [@option{--set} [var]] [@option{--no-floppy}|@option{--efidisk-only}] name Search devices by file (@option{-f}, @option{--file}), filesystem label (@option{-l}, @option{--label}), or filesystem UUID (@option{-u}, @option{--fs-uuid}). @@ -5015,6 +5015,9 @@ set as the value of environment variable @var{var}. The default variable is The (@option{-n}, @option{--no-floppy}) option prevents searching floppy devices, which can be slow. +The (@option{--efidisk-only}) option prevents searching any other devices then +EFI disks. This is typically used when chainloading to local EFI partition. + The @samp{search.file}, @samp{search.fs_label}, and @samp{search.fs_uuid} commands are aliases for @samp{search --file}, @samp{search --label}, and @samp{search --fs-uuid} respectively. diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index 197eccdf8..57d26ced8 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -66,6 +66,25 @@ iterate_device (const char *name, void *data) name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9') return 0; + /* Limit to EFI disks when requested. */ + if (ctx->flags & SEARCH_FLAGS_EFIDISK_ONLY) + { + grub_device_t dev; + dev = grub_device_open (name); + if (! dev) + { + grub_errno = GRUB_ERR_NONE; + return 0; + } + if (! dev->disk || dev->disk->dev->id != GRUB_DISK_DEVICE_EFIDISK_ID) + { + grub_device_close (dev); + grub_errno = GRUB_ERR_NONE; + return 0; + } + grub_device_close (dev); + } + #ifdef DO_SEARCH_FS_UUID #define compare_fn grub_strcasecmp #else diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index 8e90bbdcc..0b62acf85 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -40,6 +40,7 @@ static const struct grub_arg_option options[] = N_("Set a variable to the first device found."), N_("VARNAME"), ARG_TYPE_STRING}, {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0}, + {"efidisk-only", 0, 0, N_("Only probe EFI disks."), 0, 0}, {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE, N_("First try the device HINT. If HINT ends in comma, " "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, @@ -73,6 +74,7 @@ enum options SEARCH_FS_UUID, SEARCH_SET, SEARCH_NO_FLOPPY, + SEARCH_EFIDISK_ONLY, SEARCH_HINT, SEARCH_HINT_IEEE1275, SEARCH_HINT_BIOS, @@ -184,6 +186,9 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) if (state[SEARCH_NO_FLOPPY].set) flags |= SEARCH_FLAGS_NO_FLOPPY; + if (state[SEARCH_EFIDISK_ONLY].set) + flags |= SEARCH_FLAGS_EFIDISK_ONLY; + if (state[SEARCH_LABEL].set) grub_search_label (id, var, flags, hints, nhints); else if (state[SEARCH_FS_UUID].set) diff --git a/include/grub/search.h b/include/grub/search.h index bbfa6a787..4190aeb2c 100644 --- a/include/grub/search.h +++ b/include/grub/search.h @@ -21,7 +21,8 @@ enum search_flags { - SEARCH_FLAGS_NO_FLOPPY = 1 + SEARCH_FLAGS_NO_FLOPPY = 1, + SEARCH_FLAGS_EFIDISK_ONLY = 2 }; void grub_search_fs_file (const char *key, const char *var, -- 2.35.1