Skip to content

Commit 2844693

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Add RuntimeServices::query_variable_info
This provides information about variable storage space.
1 parent c0bd89a commit 2844693

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Added `FileHandle::into_directory` and `FileHandle::into_regular_file`.
88
- Added `TimeParams`, `Time::invalid`, and `Time::is_invalid`.
9+
- Added `RuntimeServices::query_variable_info` and `VariableStorageInfo`.
910

1011
### Changed
1112

src/table/runtime.rs

+50
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ pub struct RuntimeServices {
6060
data_size: usize,
6161
data: *const u8,
6262
) -> !,
63+
64+
// UEFI 2.0 Capsule Services.
65+
update_capsule: usize,
66+
query_capsule_capabilities: usize,
67+
68+
// Miscellaneous UEFI 2.0 Service.
69+
query_variable_info: unsafe extern "efiapi" fn(
70+
attributes: VariableAttributes,
71+
maximum_variable_storage_size: *mut u64,
72+
remaining_variable_storage_size: *mut u64,
73+
maximum_variable_size: *mut u64,
74+
) -> Status,
6375
}
6476

6577
impl RuntimeServices {
@@ -227,6 +239,26 @@ impl RuntimeServices {
227239
}
228240
}
229241

242+
/// Get information about UEFI variable storage space for the type
243+
/// of variable specified in `attributes`.
244+
///
245+
/// See [`VariableStorageInfo`] for details of the information returned.
246+
pub fn query_variable_info(
247+
&self,
248+
attributes: VariableAttributes,
249+
) -> Result<VariableStorageInfo> {
250+
let mut info = VariableStorageInfo::default();
251+
unsafe {
252+
(self.query_variable_info)(
253+
attributes,
254+
&mut info.maximum_variable_storage_size,
255+
&mut info.remaining_variable_storage_size,
256+
&mut info.maximum_variable_size,
257+
)
258+
.into_with_val(|| info)
259+
}
260+
}
261+
230262
/// Resets the computer.
231263
pub fn reset(&self, rt: ResetType, status: Status, data: Option<&[u8]>) -> ! {
232264
let (size, data) = match data {
@@ -619,6 +651,24 @@ impl fmt::Display for VariableKey {
619651
}
620652
}
621653

654+
/// Information about UEFI variable storage space returned by
655+
/// [`RuntimeServices::query_variable_info`]. Note that the data here is
656+
/// limited to a specific type of variable (as specified by the
657+
/// `attributes` argument to `query_variable_info`).
658+
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
659+
pub struct VariableStorageInfo {
660+
/// Maximum size in bytes of the storage space available for
661+
/// variables of the specified type.
662+
pub maximum_variable_storage_size: u64,
663+
664+
/// Remaining size in bytes of the storage space available for
665+
/// variables of the specified type.
666+
pub remaining_variable_storage_size: u64,
667+
668+
/// Maximum size of an individual variable of the specified type.
669+
pub maximum_variable_size: u64,
670+
}
671+
622672
/// The type of system reset.
623673
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
624674
#[repr(u32)]

uefi-test-runner/src/runtime/vars.rs

+14
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ fn test_variables(rt: &RuntimeServices) {
4646
}
4747
}
4848

49+
fn test_variable_info(rt: &RuntimeServices) {
50+
info!(
51+
"Storage for non-volatile variabls: {:?}",
52+
rt.query_variable_info(VariableAttributes::NON_VOLATILE),
53+
);
54+
info!(
55+
"Storage for volatile runtime variables: {:?}",
56+
rt.query_variable_info(
57+
VariableAttributes::BOOTSERVICE_ACCESS | VariableAttributes::RUNTIME_ACCESS
58+
),
59+
);
60+
}
61+
4962
pub fn test(rt: &RuntimeServices) {
5063
test_variables(rt);
64+
test_variable_info(rt);
5165
}

0 commit comments

Comments
 (0)