os/fs/proc/generators/
mounts.rs

1use alloc::format;
2use alloc::string::String;
3use alloc::vec::Vec;
4
5use crate::fs::proc::inode::ContentGenerator;
6use crate::vfs::{FsError, MOUNT_TABLE};
7
8pub struct MountsGenerator;
9
10impl ContentGenerator for MountsGenerator {
11    fn generate(&self) -> Result<Vec<u8>, FsError> {
12        let mut content = String::new();
13
14        // 获取所有挂载点
15        let mounts = MOUNT_TABLE.list_all();
16
17        for (path, mount_point) in mounts {
18            let device = mount_point.device.as_deref().unwrap_or("none");
19            let fs_type = mount_point.fs.fs_type();
20
21            // 构建挂载选项
22            let mut options = Vec::new();
23            if mount_point
24                .flags
25                .contains(crate::vfs::MountFlags::READ_ONLY)
26            {
27                options.push("ro");
28            } else {
29                options.push("rw");
30            }
31            options.push("relatime");
32
33            let line = format!(
34                "{} {} {} {} 0 0\n",
35                device,
36                path,
37                fs_type,
38                options.join(",")
39            );
40
41            content.push_str(&line);
42        }
43
44        Ok(content.into_bytes())
45    }
46}