fix(utils): when retrieving the partition guid, if the guid is zero, return none

This commit is contained in:
2025-10-30 23:42:47 -04:00
parent f69d4b942b
commit c3e883c121

View File

@@ -201,12 +201,15 @@ pub fn unique_hash(input: &str) -> String {
/// Represents the type of partition GUID that can be retrieved. /// Represents the type of partition GUID that can be retrieved.
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
pub enum PartitionGuidForm { pub enum PartitionGuidForm {
/// The partition GUID is the unique partition GUID.
Partition, Partition,
/// The partition GUID is the partition type GUID.
PartitionType, PartitionType,
} }
/// Retrieve the partition / partition type GUID of the device root `path`. /// Retrieve the partition / partition type GUID of the device root `path`.
/// This only works on GPT partitions. If the root is not a GPT partition, None is returned. /// This only works on GPT partitions. If the root is not a GPT partition, None is returned.
/// If the GUID is all zeros, this will return None.
pub fn partition_guid(path: &DevicePath, form: PartitionGuidForm) -> Result<Option<Guid>> { pub fn partition_guid(path: &DevicePath, form: PartitionGuidForm) -> Result<Option<Guid>> {
// Clone the path so we can pass it to the UEFI stack. // Clone the path so we can pass it to the UEFI stack.
let path = path.to_boxed(); let path = path.to_boxed();
@@ -238,7 +241,8 @@ pub fn partition_guid(path: &DevicePath, form: PartitionGuidForm) -> Result<Opti
// Match the form of the partition GUID. // Match the form of the partition GUID.
PartitionGuidForm::Partition => entry.unique_partition_guid, PartitionGuidForm::Partition => entry.unique_partition_guid,
PartitionGuidForm::PartitionType => entry.partition_type_guid.0, PartitionGuidForm::PartitionType => entry.partition_type_guid.0,
})) })
.filter(|guid| !guid.is_zero()))
} else { } else {
Ok(None) Ok(None)
} }