vmi_os_linux/comps/
path.rs1use vmi_core::{Va, VmiError, VmiState, VmiVa, driver::VmiRead};
2
3use super::{LinuxDEntry, LinuxVFSMount, macros::impl_offsets};
4use crate::{ArchAdapter, LinuxError, LinuxOs};
5
6pub struct LinuxPath<'a, Driver>
15where
16 Driver: VmiRead,
17 Driver::Architecture: ArchAdapter<Driver>,
18{
19 vmi: VmiState<'a, LinuxOs<Driver>>,
21
22 va: Va,
24}
25
26impl<Driver> VmiVa for LinuxPath<'_, Driver>
27where
28 Driver: VmiRead,
29 Driver::Architecture: ArchAdapter<Driver>,
30{
31 fn va(&self) -> Va {
32 self.va
33 }
34}
35
36impl<'a, Driver> LinuxPath<'a, Driver>
37where
38 Driver: VmiRead,
39 Driver::Architecture: ArchAdapter<Driver>,
40{
41 impl_offsets!();
42
43 pub fn new(vmi: VmiState<'a, LinuxOs<Driver>>, va: Va) -> Self {
45 Self { vmi, va }
46 }
47
48 pub fn dentry(&self) -> Result<LinuxDEntry<'a, Driver>, VmiError> {
54 let offsets = self.offsets();
55 let __path = &offsets.path;
56
57 let dentry = self.vmi.read_va_native(self.va + __path.dentry.offset())?;
58
59 if dentry.is_null() {
60 return Err(LinuxError::CorruptedStruct("path->dentry").into());
61 }
62
63 Ok(LinuxDEntry::new(self.vmi, dentry))
64 }
65
66 pub fn mnt(&self) -> Result<LinuxVFSMount<'a, Driver>, VmiError> {
72 let offsets = self.offsets();
73 let __path = &offsets.path;
74
75 let mnt = self.vmi.read_va_native(self.va + __path.mnt.offset())?;
76
77 if mnt.is_null() {
78 return Err(LinuxError::CorruptedStruct("path->mnt").into());
79 }
80
81 Ok(LinuxVFSMount::new(self.vmi, mnt))
82 }
83}