diff mbox series

[v2,1/3] efi_loader: disk: add efi_disk_is_removable()

Message ID 20220512022903.65346-2-takahiro.akashi@linaro.org
State Accepted
Commit 05f391e2fc73bf9f746534929b4436b86518f4fc
Headers show
Series efi_loader: bootmgr: fix a problem in loading an image from a short-path | expand

Commit Message

AKASHI Takahiro May 12, 2022, 2:29 a.m. UTC
This helper function will be used to determine if the device is
removable media, initially for handling a short-path loading.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 include/efi_loader.h      |  3 +++
 lib/efi_loader/efi_disk.c | 27 +++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

Comments

Heinrich Schuchardt May 12, 2022, 6:27 a.m. UTC | #1
On 5/12/22 04:29, AKASHI Takahiro wrote:
> This helper function will be used to determine if the device is
> removable media, initially for handling a short-path loading.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   include/efi_loader.h      |  3 +++
>   lib/efi_loader/efi_disk.c | 27 +++++++++++++++++++++++++++
>   2 files changed, 30 insertions(+)
>
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 40fbab816e2d..839184acb7ff 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -659,6 +659,9 @@ efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
>   /* Call this to signal an event */
>   void efi_signal_event(struct efi_event *event);
>
> +/* return true if the device is removable */
> +bool efi_disk_is_removable(efi_handle_t handle);
> +
>   /* open file system: */
>   struct efi_simple_file_system_protocol *efi_simple_file_system(
>   		struct blk_desc *desc, int part, struct efi_device_path *dp);
> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> index f5b462fb164a..1e82f52dc070 100644
> --- a/lib/efi_loader/efi_disk.c
> +++ b/lib/efi_loader/efi_disk.c
> @@ -73,6 +73,33 @@ static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this,
>   	return EFI_EXIT(EFI_SUCCESS);
>   }
>
> +/**
> + * efi_disk_is_removable() - check if the device is removable media
> + * @handle:		efi object handle;
> + *
> + * Examine the device and determine if the device is a local block device
> + * and removable media.
> + *
> + * Return:		true if removable, false otherwise
> + */
> +bool efi_disk_is_removable(efi_handle_t handle)
> +{
> +	struct efi_handler *handler;
> +	struct efi_block_io *io;
> +	efi_status_t ret;
> +
> +	ret = efi_search_protocol(handle, &efi_block_io_guid, &handler);
> +	if (ret != EFI_SUCCESS)
> +		return false;
> +
> +	io = handler->protocol_interface;
> +
> +	if (!io || !io->media)
> +		return false;
> +
> +	return (bool)io->media->removable_media;

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

> +}
> +
>   enum efi_disk_direction {
>   	EFI_DISK_READ,
>   	EFI_DISK_WRITE,
diff mbox series

Patch

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 40fbab816e2d..839184acb7ff 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -659,6 +659,9 @@  efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
 /* Call this to signal an event */
 void efi_signal_event(struct efi_event *event);
 
+/* return true if the device is removable */
+bool efi_disk_is_removable(efi_handle_t handle);
+
 /* open file system: */
 struct efi_simple_file_system_protocol *efi_simple_file_system(
 		struct blk_desc *desc, int part, struct efi_device_path *dp);
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index f5b462fb164a..1e82f52dc070 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -73,6 +73,33 @@  static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this,
 	return EFI_EXIT(EFI_SUCCESS);
 }
 
+/**
+ * efi_disk_is_removable() - check if the device is removable media
+ * @handle:		efi object handle;
+ *
+ * Examine the device and determine if the device is a local block device
+ * and removable media.
+ *
+ * Return:		true if removable, false otherwise
+ */
+bool efi_disk_is_removable(efi_handle_t handle)
+{
+	struct efi_handler *handler;
+	struct efi_block_io *io;
+	efi_status_t ret;
+
+	ret = efi_search_protocol(handle, &efi_block_io_guid, &handler);
+	if (ret != EFI_SUCCESS)
+		return false;
+
+	io = handler->protocol_interface;
+
+	if (!io || !io->media)
+		return false;
+
+	return (bool)io->media->removable_media;
+}
+
 enum efi_disk_direction {
 	EFI_DISK_READ,
 	EFI_DISK_WRITE,