Skip to main content

vmi_os_linux/comps/
file.rs

1use vmi_core::{Va, VmiError, VmiState, VmiVa, driver::VmiRead};
2
3use super::{macros::impl_offsets, path::LinuxPath};
4use crate::{ArchAdapter, LinuxOs};
5
6/// A Linux file struct.
7///
8/// A `file` is a representation of a file in the Linux kernel.
9///
10/// # Implementation Details
11///
12/// Corresponds to `file`.
13pub struct LinuxFile<'a, Driver>
14where
15    Driver: VmiRead,
16    Driver::Architecture: ArchAdapter<Driver>,
17{
18    /// The VMI state.
19    vmi: VmiState<'a, LinuxOs<Driver>>,
20
21    /// The virtual address of the `file` structure.
22    va: Va,
23}
24
25impl<Driver> VmiVa for LinuxFile<'_, Driver>
26where
27    Driver: VmiRead,
28    Driver::Architecture: ArchAdapter<Driver>,
29{
30    fn va(&self) -> Va {
31        self.va
32    }
33}
34
35impl<'a, Driver> LinuxFile<'a, Driver>
36where
37    Driver: VmiRead,
38    Driver::Architecture: ArchAdapter<Driver>,
39{
40    impl_offsets!();
41
42    /// Creates a new `file`.
43    pub fn new(vmi: VmiState<'a, LinuxOs<Driver>>, va: Va) -> Self {
44        Self { vmi, va }
45    }
46
47    /// Returns the path of the file.
48    ///
49    /// # Implementation Details
50    ///
51    /// Corresponds to `file.f_path`.
52    pub fn path(&self) -> Result<LinuxPath<'a, Driver>, VmiError> {
53        let offsets = self.offsets();
54        let __file = &offsets.file;
55
56        Ok(LinuxPath::new(self.vmi, self.va + __file.f_path.offset()))
57    }
58}