]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: disk: add efi_disk_is_removable()
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Thu, 12 May 2022 02:29:01 +0000 (11:29 +0900)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 28 May 2022 08:59:27 +0000 (10:59 +0200)
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>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/efi_loader.h
lib/efi_loader/efi_disk.c

index 733ee03cd77a8f69e60e57fdd70da753004ca42f..f6651e2c6040506226496dac242bcc162ee0d07d 100644 (file)
@@ -663,6 +663,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);
index f5b462fb164a7ef3d1e361940008589b54e1200d..1e82f52dc07098b059bb8c87d5d8087ca1b4117e 100644 (file)
@@ -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,