-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathmod.rs
More file actions
90 lines (78 loc) · 2.15 KB
/
mod.rs
File metadata and controls
90 lines (78 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! ProcFS - 进程文件系统
//!
//! 实现 Linux 兼容的 /proc 文件系统
use alloc::{sync::Arc, vec::Vec};
use system_error::SystemError;
use crate::{libs::once::Once, process::ProcessManager};
use super::vfs::mount::{MountFlags, MountPath};
use super::vfs::InodeMode;
mod cmdline;
mod cpuinfo;
pub mod klog;
pub mod kmsg;
mod kmsg_file;
mod uptime;
mod loadavg;
mod meminfo;
mod mounts;
mod net;
mod pid;
pub mod root;
mod self_;
mod stat;
mod sys;
mod syscall;
pub(super) mod template;
mod thread_self;
mod utils;
mod version;
mod version_signature;
mod vmstat;
// 重新导出 ProcFS
pub use root::ProcFS;
/// procfs 的 inode 名称的最大长度
pub(super) const PROCFS_MAX_NAMELEN: usize = 64;
/// procfs 的块大小
pub(super) const PROCFS_BLOCK_SIZE: u64 = 512;
/// 供 template 使用的 Builder trait
pub(super) use template::Builder;
/// procfs 文件私有数据
#[derive(Debug, Clone)]
pub struct ProcfsFilePrivateData {
pub data: Vec<u8>,
}
impl ProcfsFilePrivateData {
pub fn new() -> Self {
ProcfsFilePrivateData { data: Vec::new() }
}
}
impl Default for ProcfsFilePrivateData {
fn default() -> Self {
Self::new()
}
}
/// 初始化 ProcFS
pub fn procfs_init() -> Result<(), SystemError> {
static INIT: Once = Once::new();
let mut result = None;
INIT.call_once(|| {
::log::info!("Initializing ProcFS...");
// 创建 procfs 实例
let procfs: Arc<ProcFS> = ProcFS::new();
let root_inode = ProcessManager::current_mntns().root_inode();
// procfs 挂载
let mntfs = root_inode
.mkdir("proc", InodeMode::from_bits_truncate(0o755))
.expect("Unable to create /proc")
.mount(procfs, MountFlags::empty())
.expect("Failed to mount at /proc");
let ino = root_inode.metadata().unwrap().inode_id;
let mount_path = Arc::new(MountPath::from("/proc"));
ProcessManager::current_mntns()
.add_mount(Some(ino), mount_path, mntfs)
.expect("Failed to add mount for /proc");
::log::info!("ProcFS mounted at /proc");
result = Some(Ok(()));
});
return result.unwrap();
}