Skip to content

Commit 2d2c1b7

Browse files
committed
uefi: add BootPolicy type
This type is used in three functions of the UEFI spec. Having an enum instead of a boolean simplifies the interface as the variants can be properly documented.
1 parent 88b7356 commit 2d2c1b7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

uefi/src/proto/mod.rs

+54
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,57 @@ pub mod shell_params;
8181
pub mod shim;
8282
pub mod string;
8383
pub mod tcg;
84+
85+
/// The UEFI boot policy is a property that influences the behaviour of
86+
/// various UEFI functions that load files (typically UEFI images).
87+
///
88+
/// This type is not ABI compatible. On the ABI level, this is an UEFI
89+
/// boolean.
90+
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq, Ord)]
91+
pub enum BootPolicy {
92+
/// Indicates that the request originates from the boot manager, and that
93+
/// the boot manager is attempting to load the provided `file_path` as a
94+
/// boot selection.
95+
///
96+
/// Boot selection refers to what a user has chosen in the (GUI) boot menu.
97+
TRUE,
98+
/// The provided `file_path` must match an exact file to be loaded.
99+
FALSE,
100+
}
101+
102+
impl From<BootPolicy> for bool {
103+
fn from(value: BootPolicy) -> Self {
104+
match value {
105+
BootPolicy::TRUE => true,
106+
BootPolicy::FALSE => false,
107+
}
108+
}
109+
}
110+
111+
impl From<bool> for BootPolicy {
112+
fn from(value: bool) -> Self {
113+
match value {
114+
true => Self::TRUE,
115+
false => Self::FALSE,
116+
}
117+
}
118+
}
119+
120+
impl From<BootPolicy> for u8 {
121+
fn from(value: BootPolicy) -> Self {
122+
match value {
123+
BootPolicy::TRUE => 1,
124+
BootPolicy::FALSE => 0,
125+
}
126+
}
127+
}
128+
129+
impl From<u8> for BootPolicy {
130+
fn from(value: u8) -> Self {
131+
match value {
132+
0 => Self::FALSE,
133+
1 => Self::TRUE ,
134+
_ => panic!("Invalid variant")
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)