aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / proto / boot_policy.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | //! Module for the [`BootPolicy`] helper type. |
| 4 | |
| 5 | use uefi_raw::Boolean; |
| 6 | |
| 7 | /// The UEFI boot policy is a property that influences the behaviour of |
| 8 | /// various UEFI functions that load files (typically UEFI images). |
| 9 | /// |
| 10 | /// This type is not ABI compatible. On the ABI level, this corresponds to |
| 11 | /// a [`Boolean`]. |
| 12 | #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd)] |
| 13 | pub enum BootPolicy { |
| 14 | /// Indicates that the request originates from the boot manager, and that |
| 15 | /// the boot manager is attempting to load the provided `file_path` as a |
| 16 | /// boot selection. |
| 17 | /// |
| 18 | /// Boot selection refers to what a user has chosen in the (GUI) boot menu. |
| 19 | /// |
| 20 | /// This corresponds to the underlying [`Boolean`] being `true`. |
| 21 | BootSelection, |
| 22 | /// The provided `file_path` must match an exact file to be loaded. |
| 23 | /// |
| 24 | /// This corresponds to the underlying [`Boolean`] being `false`. |
| 25 | #[default] |
| 26 | ExactMatch, |
| 27 | } |
| 28 | |
| 29 | impl From<BootPolicy> for Boolean { |
| 30 | fn from(value: BootPolicy) -> Self { |
| 31 | match value { |
| 32 | BootPolicy::BootSelection => Self::TRUE, |
| 33 | BootPolicy::ExactMatch => Self::FALSE, |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl From<Boolean> for BootPolicy { |
| 39 | fn from(value: Boolean) -> Self { |
| 40 | let boolean: bool = value.into(); |
| 41 | match boolean { |
| 42 | true => Self::BootSelection, |
| 43 | false => Self::ExactMatch, |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | #[cfg(test)] |
| 49 | mod tests { |
| 50 | use super::*; |
| 51 | |
| 52 | #[test] |
| 53 | fn boot_policy() { |
| 54 | assert_eq!(BootPolicy::from(Boolean::TRUE), BootPolicy::BootSelection); |
| 55 | assert_eq!(BootPolicy::from(Boolean::FALSE), BootPolicy::ExactMatch); |
| 56 | assert_eq!(Boolean::from(BootPolicy::BootSelection), Boolean::TRUE); |
| 57 | assert_eq!(Boolean::from(BootPolicy::ExactMatch), Boolean::FALSE); |
| 58 | } |
| 59 | } |