2025-10-24 02:36:47 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
fs::{
|
|
|
|
|
procfs::template::{FileOps, ProcFileBuilder},
|
|
|
|
|
utils::{mkmod, Inode},
|
|
|
|
|
},
|
|
|
|
|
prelude::*,
|
|
|
|
|
process::posix_thread::AsPosixThread,
|
|
|
|
|
thread::Thread,
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-24 06:06:55 +00:00
|
|
|
/// Represents the inode at `/proc/[pid]/task/[tid]/mountinfo` (and also `/proc/[pid]/mountinfo`).
|
2025-10-24 02:36:47 +00:00
|
|
|
pub struct MountInfoFileOps {
|
|
|
|
|
thread_ref: Arc<Thread>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MountInfoFileOps {
|
|
|
|
|
pub fn new_inode(thread_ref: Arc<Thread>, parent: Weak<dyn Inode>) -> Arc<dyn Inode> {
|
2025-10-24 06:06:55 +00:00
|
|
|
// Reference: <https://elixir.bootlin.com/linux/v6.16.5/source/fs/proc/base.c#L3352>
|
2025-10-24 02:36:47 +00:00
|
|
|
ProcFileBuilder::new(Self { thread_ref }, mkmod!(a+r))
|
|
|
|
|
.parent(parent)
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FileOps for MountInfoFileOps {
|
|
|
|
|
fn data(&self) -> Result<Vec<u8>> {
|
2025-10-24 06:06:55 +00:00
|
|
|
unreachable!()
|
2025-10-24 02:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_at(&self, offset: usize, writer: &mut VmWriter) -> Result<usize> {
|
|
|
|
|
let posix_thread = self.thread_ref.as_posix_thread().unwrap();
|
2025-10-24 06:06:55 +00:00
|
|
|
let fs = posix_thread.read_fs();
|
2025-10-24 02:36:47 +00:00
|
|
|
let fs_resolver = fs.resolver().read();
|
|
|
|
|
let root_mount = fs_resolver.root().mount_node();
|
|
|
|
|
|
|
|
|
|
root_mount.read_mount_info(offset, writer)
|
|
|
|
|
}
|
|
|
|
|
}
|