On 12/21/22 17:38, Andrey Drobyshev wrote:
> This patch is merely a refactoring and does not introduce any changes in
> behaviour.  It's used as a prelude for the next patch which prioritizes
> BIOS boot partition when searching for the right firmware.
> 
> Co-authored-by: Laszlo Ersek <ler...@redhat.com>
> Signed-off-by: Andrey Drobyshev <andrey.drobys...@virtuozzo.com>
> ---
>  convert/inspect_source.ml | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/convert/inspect_source.ml b/convert/inspect_source.ml
> index 056d0bca..42a26f68 100644
> --- a/convert/inspect_source.ml
> +++ b/convert/inspect_source.ml
> @@ -225,26 +225,30 @@ and list_applications g root = function
>   * Otherwise, [BIOS] is returned.
>   *)
>  and get_firmware_bootable_device g =
> -  let rec uefi_ESP_guid = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
> -  and is_uefi_ESP dev part =
> -    let partnum = g#part_to_partnum part in
> -    g#part_get_gpt_type dev partnum = uefi_ESP_guid
> -  and parttype_is_gpt dev =
> +  let parttype_is_gpt dev =
>      try g#part_get_parttype dev = "gpt"
>      with G.Error msg as exn ->
>           (* If it's _not_ "unrecognised disk label" then re-raise it. *)
>           if g#last_errno () <> G.Errno.errno_EINVAL then raise exn;
>           debug "%s (ignored)" msg;
>           false
> -  and is_uefi_bootable_part part =
> +  in
> +  let accumulate_partition esp_parts part =
>      let dev = g#part_to_dev part in
> -    parttype_is_gpt dev && is_uefi_ESP dev part
> +    if parttype_is_gpt dev then
> +      let partnum = g#part_to_partnum part in
> +      let part_type_guid = g#part_get_gpt_type dev partnum in
> +      match part_type_guid with
> +      (* EFI system partition *)
> +      | "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" -> part :: esp_parts
> +      | _ -> esp_parts
> +    else esp_parts
>    in
>  
> -  let partitions = Array.to_list (g#list_partitions ()) in
> -  let partitions = List.filter is_uefi_bootable_part partitions in
> +  let esp_partitions =
> +    Array.fold_left accumulate_partition [] (g#list_partitions ()) in
>  
> -  match partitions with
> +  match esp_partitions with
>    | [] -> I_BIOS
>    | partitions -> I_UEFI partitions
>  

I've replaced "List.fold_left" with "Array.fold_left" in the commit
message (subject line).

Merged as commit d04b9a05b2a5.

Laszlo
_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to