use crate::handle::open_shared;
use alloc::boxed::Box;
use alloc::vec::Vec;
use anyhow::{Context, Result};
use uefi::proto::device_path::{DevicePath, DevicePathNode, DeviceSubType, DeviceType};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi::proto::media::partition::PartitionInfo;
use uefi::{Guid, guid};
/// The GPT partition type of the Extended Boot Loader Partition.
/// Reference:
pub const XBOOTLDR_PARTITION_TYPE: Guid = guid!("bc13c2ff-59e6-4262-a352-b275fd6f7172");
/// Whether `node` is the node of a partition on a hard drive.
fn is_hard_drive_node(node: &DevicePathNode) -> bool {
node.full_type() == (DeviceType::MEDIA, DeviceSubType::MEDIA_HARD_DRIVE)
}
/// The device nodes of `path`, without the file path nodes that follow the device.
fn device_nodes(path: &DevicePath) -> Vec<&DevicePathNode> {
path.node_iter()
.filter(|node| node.full_type() != (DeviceType::MEDIA, DeviceSubType::MEDIA_FILE_PATH))
.collect()
}
/// Find the Extended Boot Loader Partition on the same disk as the partition at `path`,
/// which is usually the EFI system partition that Sprout was loaded from. Only a partition
/// that has a filesystem the firmware can read is found. Returns the device path of its
/// filesystem, or None if there is no such partition, such as on a disk without a GPT.
pub fn find_xbootldr(path: &DevicePath) -> Result