|
5 | 5 | //! functions after exiting boot services; see the "Calling Convention" section
|
6 | 6 | //! of the UEFI specification for details.
|
7 | 7 |
|
8 |
| -use crate::{table, CStr16, Error, Result, Status, StatusExt}; |
| 8 | +use crate::table::{self, Revision}; |
| 9 | +use crate::{CStr16, Error, Result, Status, StatusExt}; |
9 | 10 | use core::mem;
|
10 | 11 | use core::ptr::{self, NonNull};
|
11 | 12 |
|
|
17 | 18 | #[cfg(all(feature = "unstable", feature = "alloc"))]
|
18 | 19 | use alloc::alloc::Global;
|
19 | 20 |
|
20 |
| -pub use crate::table::runtime::{Daylight, Time, TimeCapabilities, TimeError, TimeParams}; |
| 21 | +pub use crate::table::runtime::{ |
| 22 | + Daylight, Time, TimeCapabilities, TimeError, TimeParams, VariableStorageInfo, |
| 23 | +}; |
21 | 24 | pub use uefi_raw::capsule::{CapsuleBlockDescriptor, CapsuleFlags, CapsuleHeader};
|
22 | 25 | pub use uefi_raw::table::runtime::{ResetType, VariableAttributes, VariableVendor};
|
23 | 26 |
|
@@ -343,3 +346,35 @@ pub fn set_variable(
|
343 | 346 | pub fn delete_variable(name: &CStr16, vendor: &VariableVendor) -> Result {
|
344 | 347 | set_variable(name, vendor, VariableAttributes::empty(), &[])
|
345 | 348 | }
|
| 349 | + |
| 350 | +/// Get information about UEFI variable storage space for the type |
| 351 | +/// of variable specified in `attributes`. |
| 352 | +/// |
| 353 | +/// This operation is only supported starting with UEFI 2.0. |
| 354 | +/// |
| 355 | +/// See [`VariableStorageInfo`] for details of the information returned. |
| 356 | +/// |
| 357 | +/// # Errors |
| 358 | +/// |
| 359 | +/// * [`Status::INVALID_PARAMETER`]: invalid combination of variable attributes. |
| 360 | +/// * [`Status::UNSUPPORTED`]: the combination of variable attributes is not |
| 361 | +/// supported on this platform, or the UEFI version is less than 2.0. |
| 362 | +pub fn query_variable_info(attributes: VariableAttributes) -> Result<VariableStorageInfo> { |
| 363 | + let rt = runtime_services_raw_panicking(); |
| 364 | + let rt = unsafe { rt.as_ref() }; |
| 365 | + |
| 366 | + if rt.header.revision < Revision::EFI_2_00 { |
| 367 | + return Err(Status::UNSUPPORTED.into()); |
| 368 | + } |
| 369 | + |
| 370 | + let mut info = VariableStorageInfo::default(); |
| 371 | + unsafe { |
| 372 | + (rt.query_variable_info)( |
| 373 | + attributes, |
| 374 | + &mut info.maximum_variable_storage_size, |
| 375 | + &mut info.remaining_variable_storage_size, |
| 376 | + &mut info.maximum_variable_size, |
| 377 | + ) |
| 378 | + .to_result_with_val(|| info) |
| 379 | + } |
| 380 | +} |
0 commit comments