efi_loader: disk: add efi_disk_is_system_part()
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Mon, 27 Apr 2020 09:48:20 +0000 (18:48 +0900)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Mon, 4 May 2020 10:26:11 +0000 (12:26 +0200)
This function will check if a given handle to device is an EFI system
partition. It will be utilised in implementing capsule-on-disk feature.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Add function description. Return bool.
Reviewed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
include/efi_loader.h
lib/efi_loader/efi_disk.c

index f92bfe5..0e924ad 100644 (file)
@@ -394,6 +394,8 @@ efi_status_t efi_disk_register(void);
 int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
                               const char *if_typename, int diskid,
                               const char *pdevname);
+/* Check if it is EFI system partition */
+bool efi_disk_is_system_part(efi_handle_t handle);
 /* Called by bootefi to make GOP (graphical) interface available */
 efi_status_t efi_gop_register(void);
 /* Called by bootefi to make the network interface available */
index fd3df80..0582e02 100644 (file)
@@ -588,3 +588,32 @@ efi_status_t efi_disk_register(void)
 
        return EFI_SUCCESS;
 }
+
+/**
+ * efi_disk_is_system_part() - check if handle refers to an EFI system partition
+ *
+ * @handle:    handle of partition
+ *
+ * Return:     true if handle refers to an EFI system partition
+ */
+bool efi_disk_is_system_part(efi_handle_t handle)
+{
+       struct efi_handler *handler;
+       struct efi_disk_obj *diskobj;
+       disk_partition_t info;
+       efi_status_t ret;
+       int r;
+
+       /* check if this is a block device */
+       ret = efi_search_protocol(handle, &efi_block_io_guid, &handler);
+       if (ret != EFI_SUCCESS)
+               return false;
+
+       diskobj = container_of(handle, struct efi_disk_obj, header);
+
+       r = part_get_info(diskobj->desc, diskobj->part, &info);
+       if (r)
+               return false;
+
+       return !!(info.bootable & PART_EFI_SYSTEM_PARTITION);
+}