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