use vmi_core::{Va, VmiError, VmiState, VmiVa, driver::VmiRead};
use super::{LinuxDEntry, macros::impl_offsets};
use crate::{ArchAdapter, LinuxError, LinuxOs};
pub struct LinuxVFSMount<'a, Driver>
where
Driver: VmiRead,
Driver::Architecture: ArchAdapter<Driver>,
{
vmi: VmiState<'a, LinuxOs<Driver>>,
va: Va,
}
impl<Driver> VmiVa for LinuxVFSMount<'_, Driver>
where
Driver: VmiRead,
Driver::Architecture: ArchAdapter<Driver>,
{
fn va(&self) -> Va {
self.va
}
}
impl<'a, Driver> LinuxVFSMount<'a, Driver>
where
Driver: VmiRead,
Driver::Architecture: ArchAdapter<Driver>,
{
impl_offsets!();
pub fn new(vmi: VmiState<'a, LinuxOs<Driver>>, va: Va) -> Self {
Self { vmi, va }
}
pub fn mnt_root(&self) -> Result<LinuxDEntry<'a, Driver>, VmiError> {
let offsets = self.offsets();
let __vfsmount = &offsets.vfsmount;
let mnt_root = self
.vmi
.read_va_native(self.va + __vfsmount.mnt_root.offset())?;
if mnt_root.is_null() {
return Err(LinuxError::CorruptedStruct("vfsmount->mnt_root").into());
}
Ok(LinuxDEntry::new(self.vmi, mnt_root))
}
}