FwCfg

Struct FwCfg 

Source
pub struct FwCfg { /* private fields */ }
Expand description

A struct for accessing QEMU fw_cfg.

Implementations§

Source§

impl FwCfg

Source

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.

Source

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.

Source

pub fn iter_files(&mut self) -> impl Iterator<Item = FwCfgFile> + '_

Return an iterator of all files in the fw_cfg directory

Source

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);
Source

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();
Source

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().

Source

pub fn read_file(&mut self, file: &FwCfgFile) -> Vec<u8>

Read a file and return the data in Vec<u8>.

Source

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.

Trait Implementations§

Source§

impl Debug for FwCfg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for FwCfg

§

impl RefUnwindSafe for FwCfg

§

impl !Send for FwCfg

§

impl !Sync for FwCfg

§

impl Unpin for FwCfg

§

impl UnwindSafe for FwCfg

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.