Skip to content

Commit cda3d00

Browse files
committed
provisioning: Propogate GPT attributes
Signed-off-by: Ikey Doherty <[email protected]>
1 parent 69dfa13 commit cda3d00

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

crates/provisioning/src/commands/create_partition.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// SPDX-License-Identifier: MPL-2.0
55

6+
use partitioning::{gpt::partition_types, GptAttributes, PartitionAttributes};
7+
68
use crate::{
79
get_kdl_entry, get_kdl_property, get_property_str, Constraints, Context, Filesystem, FromKdlProperty, FromKdlType,
810
PartitionRole, PartitionTypeGuid, PartitionTypeKDL,
@@ -30,6 +32,19 @@ pub struct Command {
3032
pub filesystem: Option<Filesystem>,
3133
}
3234

35+
impl Command {
36+
pub fn attributes(&self) -> PartitionAttributes {
37+
PartitionAttributes::Gpt(GptAttributes {
38+
type_guid: match &self.partition_type {
39+
Some(p) => p.as_guid(),
40+
None => partition_types::BASIC,
41+
},
42+
name: self.partition_type.as_ref().map(|p| p.to_string()),
43+
uuid: None,
44+
})
45+
}
46+
}
47+
3348
/// Generate a command to create a partition
3449
pub(crate) fn parse(context: Context<'_>) -> Result<super::Command, crate::Error> {
3550
let disk = get_property_str(context.node, "disk")?;

crates/provisioning/src/provisioner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl Provisioner {
163163
Constraints::Range { min, max } => SizeRequirement::Range { min: *min, max: *max },
164164
_ => SizeRequirement::Remaining,
165165
},
166+
attributes: Some(command.attributes()),
166167
});
167168
} else {
168169
warn!("Could not find disk {} to create partition", command.disk);

crates/provisioning/src/types/partition_type.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ pub enum PartitionTypeGuid {
5858
EfiSystemPartition,
5959
ExtendedBootLoader,
6060
LinuxSwap,
61+
LinuxFilesystem,
6162
}
6263

6364
impl fmt::Display for PartitionTypeGuid {
6465
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6566
match self {
66-
Self::EfiSystemPartition => f.write_str("efi-system-partition"),
67-
Self::ExtendedBootLoader => f.write_str("linux-extended-boot"),
68-
Self::LinuxSwap => f.write_str("linux-swap"),
67+
Self::EfiSystemPartition => f.write_str("EFI System Partition"),
68+
Self::ExtendedBootLoader => f.write_str("Linux Extended Boot"),
69+
Self::LinuxFilesystem => f.write_str("Linux Filesystem"),
70+
Self::LinuxSwap => f.write_str("Linux Swap"),
6971
}
7072
}
7173
}
@@ -78,6 +80,7 @@ impl FromStr for PartitionTypeGuid {
7880
"efi-system-partition" => Ok(Self::EfiSystemPartition),
7981
"linux-extended-boot" => Ok(Self::ExtendedBootLoader),
8082
"linux-swap" => Ok(Self::LinuxSwap),
83+
"linux-fs" => Ok(Self::LinuxFilesystem),
8184
_ => Err(crate::Error::UnknownVariant),
8285
}
8386
}
@@ -90,14 +93,17 @@ impl PartitionTypeGuid {
9093
Self::EfiSystemPartition => gpt::partition_types::EFI,
9194
Self::ExtendedBootLoader => gpt::partition_types::FREEDESK_BOOT,
9295
Self::LinuxSwap => gpt::partition_types::LINUX_SWAP,
96+
Self::LinuxFilesystem => gpt::partition_types::LINUX_FS,
9397
}
9498
}
9599

96100
pub fn from_kdl_node(node: &kdl::KdlNode) -> Result<Self, crate::Error> {
97101
let value = kdl_value_to_string(get_kdl_entry(node, &0)?)?;
98102
let v = value.parse().map_err(|_| crate::UnsupportedValue {
99103
at: node.span(),
100-
advice: Some("'efi-system-partition', 'linux-swap', and 'linux-extended-boot' are supported".into()),
104+
advice: Some(
105+
"'efi-system-partition', 'linux-swap' 'linux-extended-boot' and 'linux-fs' are supported".into(),
106+
),
101107
})?;
102108
Ok(v)
103109
}

crates/provisioning/tests/use_whole_disk.kdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ strategy name="whole_disk" summary="Wipe and use an entire disk" {
4343
min (GiB)25
4444
max (GiB)120
4545
}
46+
type (GUID)"linux-fs"
4647
filesystem {
4748
type "any"
4849
label "ROOT"

0 commit comments

Comments
 (0)