pub struct FwCfg { /* private fields */ }Expand description
A struct for accessing QEMU fw_cfg.
Implementations§
Source§impl FwCfg
impl FwCfg
Sourcepub unsafe fn new_for_x86() -> Result<FwCfg, FwCfgError>
pub unsafe fn new_for_x86() -> Result<FwCfg, FwCfgError>
Build FwCfg for the x86/x86-64 I/O port.
§Safety
This may only be called when running inside QEMU since I/O ports are accessed without additional checks.
Only one FwCfg value may exist at the same time
since it accesses a global shared stateful resource.
Sourcepub unsafe fn new_memory_mapped(base_ptr: *mut ()) -> Result<FwCfg, FwCfgError>
pub unsafe fn new_memory_mapped(base_ptr: *mut ()) -> Result<FwCfg, FwCfgError>
Build FwCfg for the device memory-mapped at the give base pointer.
§Safety
The pointer must point to a valid fw_cfg device.
Only one FwCfg value may exist at the same time for that pointer.
Sourcepub fn iter_files(&mut self) -> impl Iterator<Item = FwCfgFile> + '_
pub fn iter_files(&mut self) -> impl Iterator<Item = FwCfgFile> + '_
Return an iterator of all files in the fw_cfg directory
Sourcepub fn find_files(&mut self, entries: &mut [(&str, Option<FwCfgFile>)])
pub fn find_files(&mut self, entries: &mut [(&str, Option<FwCfgFile>)])
Find one or more files by their name.
Each tuple in entries must consisted of file name and a space for
Option<FwCfgFile>. If a file is found, the result will be stored by
replacing the value in Option<FwCfgFile> of the corresponding tuple,
otherwise it will retained the same value as before.
§Examples
use qemu_fw_cfg::FwCfg;
let fw_cfg = unsafe { FwCfg::new().unwrap() };
let mut files = [
("etc/igd-opregion", None),
("opt/another/file.txt", None),
];
fw_cfg.find_files(&mut files);Sourcepub fn find_file(&mut self, name: &str) -> Option<FwCfgFile>
pub fn find_file(&mut self, name: &str) -> Option<FwCfgFile>
Find a single file by its name. Returns None if the file is missing.
§Examples
use qemu_fw_cfg::FwCfg;
let fw_cfg = unsafe { FwCfg::new().unwrap() };
let file = fw_cfg.find_file("etc/igd-opregion").unwrap();Sourcepub fn read_file_to_buffer(&mut self, file: &FwCfgFile, buffer: &mut [u8])
pub fn read_file_to_buffer(&mut self, file: &FwCfgFile, buffer: &mut [u8])
Read a file and fill its data in buffer.
If the size of buffer is greater or equals to the size of the file,
then it will fill the entire data in buffer[0..file.size()], otherwise
it will only fill up to buffer.len().
Sourcepub fn read_file(&mut self, file: &FwCfgFile) -> Vec<u8>
pub fn read_file(&mut self, file: &FwCfgFile) -> Vec<u8>
Read a file and return the data in Vec<u8>.
Sourcepub fn write_to_file(
&mut self,
file: &FwCfgFile,
data: &[u8],
) -> Result<(), FwCfgWriteError>
pub fn write_to_file( &mut self, file: &FwCfgFile, data: &[u8], ) -> Result<(), FwCfgWriteError>
Write provided data into a file, starting at file offset 0.
This requires the DMA interface, which QEMU supports since version 2.9.