os/fs/proc/generators/process/
cmdline.rs

1use alloc::{sync::Weak, vec::Vec};
2
3use crate::{fs::proc::ContentGenerator, kernel::TaskStruct, sync::SpinLock, vfs::FsError};
4
5/// 为指定任务生成 /proc/\[pid\]/cmdline 内容的生成器
6pub struct CmdlineGenerator {
7    task: Weak<SpinLock<TaskStruct>>,
8}
9
10impl CmdlineGenerator {
11    pub fn new(task: Weak<SpinLock<TaskStruct>>) -> Self {
12        Self { task }
13    }
14}
15
16impl ContentGenerator for CmdlineGenerator {
17    fn generate(&self) -> Result<Vec<u8>, FsError> {
18        let task_arc = self.task.upgrade().ok_or(FsError::NotFound)?;
19        let task = task_arc.lock();
20
21        // TODO: 从任务中获取真实的命令行参数
22        // 目前简化实现:返回空内容或者进程名
23        // Linux cmdline 格式: 参数之间用 \0 分隔,最后也以 \0 结尾
24
25        // 简化实现:返回 "task_<tid>\0"
26        let mut content = alloc::format!("task_{}", task.tid).into_bytes();
27        content.push(0); // null terminator
28
29        Ok(content)
30    }
31}