|
@@ -38,7 +38,7 @@ mod syscall;
|
|
|
|
|
|
/// @brief 进程文件类型
|
|
/// @brief 进程文件类型
|
|
/// @usage 用于定义进程文件夹下的各类文件类型
|
|
/// @usage 用于定义进程文件夹下的各类文件类型
|
|
-#[derive(Debug)]
|
|
|
|
|
|
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
#[repr(u8)]
|
|
#[repr(u8)]
|
|
pub enum ProcFileType {
|
|
pub enum ProcFileType {
|
|
///展示进程状态信息
|
|
///展示进程状态信息
|
|
@@ -49,6 +49,9 @@ pub enum ProcFileType {
|
|
ProcKmsg = 2,
|
|
ProcKmsg = 2,
|
|
/// 可执行路径
|
|
/// 可执行路径
|
|
ProcExe = 3,
|
|
ProcExe = 3,
|
|
|
|
+ ProcSelf = 4,
|
|
|
|
+ ProcFdDir = 5,
|
|
|
|
+ ProcFdFile = 6,
|
|
//todo: 其他文件类型
|
|
//todo: 其他文件类型
|
|
///默认文件类型
|
|
///默认文件类型
|
|
Default,
|
|
Default,
|
|
@@ -61,6 +64,9 @@ impl From<u8> for ProcFileType {
|
|
1 => ProcFileType::ProcMeminfo,
|
|
1 => ProcFileType::ProcMeminfo,
|
|
2 => ProcFileType::ProcKmsg,
|
|
2 => ProcFileType::ProcKmsg,
|
|
3 => ProcFileType::ProcExe,
|
|
3 => ProcFileType::ProcExe,
|
|
|
|
+ 4 => ProcFileType::ProcSelf,
|
|
|
|
+ 5 => ProcFileType::ProcFdDir,
|
|
|
|
+ 6 => ProcFileType::ProcFdFile,
|
|
_ => ProcFileType::Default,
|
|
_ => ProcFileType::Default,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -73,7 +79,9 @@ pub struct InodeInfo {
|
|
pid: RawPid,
|
|
pid: RawPid,
|
|
///文件类型
|
|
///文件类型
|
|
ftype: ProcFileType,
|
|
ftype: ProcFileType,
|
|
- //其他需要传入的信息在此定义
|
|
|
|
|
|
+ /// 文件描述符
|
|
|
|
+ fd: i32,
|
|
|
|
+ // 其他需要传入的信息在此定义
|
|
}
|
|
}
|
|
|
|
|
|
/// @brief procfs的inode名称的最大长度
|
|
/// @brief procfs的inode名称的最大长度
|
|
@@ -304,8 +312,13 @@ impl ProcFSInode {
|
|
return Ok(0);
|
|
return Ok(0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fn open_self(&self, _pdata: &mut ProcfsFilePrivateData) -> Result<i64, SystemError> {
|
|
|
|
+ let pid = ProcessManager::current_pid().data();
|
|
|
|
+ return Ok(pid.to_string().as_bytes().len() as _);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 读取exe文件
|
|
// 读取exe文件
|
|
- fn read_link(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
|
|
|
|
|
|
+ fn read_exe_link(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
|
|
// 判断是否有记录pid信息,有的话就是当前进程的exe文件,没有则是当前进程的exe文件
|
|
// 判断是否有记录pid信息,有的话就是当前进程的exe文件,没有则是当前进程的exe文件
|
|
let pid = self.fdata.pid;
|
|
let pid = self.fdata.pid;
|
|
let pcb = if pid == RawPid::from(0) {
|
|
let pcb = if pid == RawPid::from(0) {
|
|
@@ -320,6 +333,31 @@ impl ProcFSInode {
|
|
Ok(len)
|
|
Ok(len)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// read current task pid dynamically
|
|
|
|
+ fn read_self_link(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
|
|
|
|
+ let pid = ProcessManager::current_pid().data();
|
|
|
|
+ let pid_bytes = pid.to_string();
|
|
|
|
+ let len = pid_bytes.len().min(buf.len());
|
|
|
|
+ buf[..len].copy_from_slice(&pid_bytes.as_bytes()[..len]);
|
|
|
|
+ Ok(len)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn read_fd_link(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
|
|
|
|
+ let fd = self.fdata.fd;
|
|
|
|
+ let fd_table = ProcessManager::current_pcb().fd_table();
|
|
|
|
+ let fd_table = fd_table.read();
|
|
|
|
+ let file = fd_table.get_file_by_fd(fd);
|
|
|
|
+ if let Some(file) = file {
|
|
|
|
+ let inode = file.inode();
|
|
|
|
+ let path = inode.absolute_path().unwrap();
|
|
|
|
+ let len = path.len().min(buf.len());
|
|
|
|
+ buf[..len].copy_from_slice(&path.as_bytes()[..len]);
|
|
|
|
+ Ok(len)
|
|
|
|
+ } else {
|
|
|
|
+ return Err(SystemError::EBADF);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/// proc文件系统读取函数
|
|
/// proc文件系统读取函数
|
|
fn proc_read(
|
|
fn proc_read(
|
|
&self,
|
|
&self,
|
|
@@ -402,6 +440,7 @@ impl ProcFS {
|
|
fdata: InodeInfo {
|
|
fdata: InodeInfo {
|
|
pid: RawPid::new(0),
|
|
pid: RawPid::new(0),
|
|
ftype: ProcFileType::Default,
|
|
ftype: ProcFileType::Default,
|
|
|
|
+ fd: -1,
|
|
},
|
|
},
|
|
dname: DName::default(),
|
|
dname: DName::default(),
|
|
})));
|
|
})));
|
|
@@ -421,34 +460,31 @@ impl ProcFS {
|
|
|
|
|
|
// 创建meminfo文件
|
|
// 创建meminfo文件
|
|
let inode = result.root_inode();
|
|
let inode = result.root_inode();
|
|
- let binding = inode.create(
|
|
|
|
- "meminfo",
|
|
|
|
- FileType::File,
|
|
|
|
- ModeType::from_bits_truncate(0o444),
|
|
|
|
- );
|
|
|
|
- if let Ok(meminfo) = binding {
|
|
|
|
- let meminfo_file = meminfo
|
|
|
|
- .as_any_ref()
|
|
|
|
- .downcast_ref::<LockedProcFSInode>()
|
|
|
|
- .unwrap();
|
|
|
|
- meminfo_file.0.lock().fdata.pid = RawPid::new(0);
|
|
|
|
- meminfo_file.0.lock().fdata.ftype = ProcFileType::ProcMeminfo;
|
|
|
|
- } else {
|
|
|
|
- panic!("create meminfo error");
|
|
|
|
- }
|
|
|
|
|
|
+ let meminfo = inode
|
|
|
|
+ .create(
|
|
|
|
+ "meminfo",
|
|
|
|
+ FileType::File,
|
|
|
|
+ ModeType::from_bits_truncate(0o444),
|
|
|
|
+ )
|
|
|
|
+ .expect("create meminfo error");
|
|
|
|
+ let meminfo_file = meminfo
|
|
|
|
+ .as_any_ref()
|
|
|
|
+ .downcast_ref::<LockedProcFSInode>()
|
|
|
|
+ .unwrap();
|
|
|
|
+ meminfo_file.0.lock().fdata.pid = RawPid::new(0);
|
|
|
|
+ meminfo_file.0.lock().fdata.ftype = ProcFileType::ProcMeminfo;
|
|
|
|
|
|
// 创建kmsg文件
|
|
// 创建kmsg文件
|
|
- let binding = inode.create("kmsg", FileType::File, ModeType::from_bits_truncate(0o444));
|
|
|
|
- if let Ok(kmsg) = binding {
|
|
|
|
- let kmsg_file = kmsg
|
|
|
|
- .as_any_ref()
|
|
|
|
- .downcast_ref::<LockedProcFSInode>()
|
|
|
|
- .unwrap();
|
|
|
|
- kmsg_file.0.lock().fdata.pid = RawPid::new(1);
|
|
|
|
- kmsg_file.0.lock().fdata.ftype = ProcFileType::ProcKmsg;
|
|
|
|
- } else {
|
|
|
|
- panic!("create ksmg error");
|
|
|
|
- }
|
|
|
|
|
|
+ let kmsg = inode
|
|
|
|
+ .create("kmsg", FileType::File, ModeType::from_bits_truncate(0o444))
|
|
|
|
+ .expect("create kmsg error");
|
|
|
|
+ let kmsg_file = kmsg
|
|
|
|
+ .as_any_ref()
|
|
|
|
+ .downcast_ref::<LockedProcFSInode>()
|
|
|
|
+ .unwrap();
|
|
|
|
+ kmsg_file.0.lock().fdata.pid = RawPid::new(1);
|
|
|
|
+ kmsg_file.0.lock().fdata.ftype = ProcFileType::ProcKmsg;
|
|
|
|
+
|
|
// 这个文件是用来欺骗Aya框架识别内核版本
|
|
// 这个文件是用来欺骗Aya框架识别内核版本
|
|
/* On Ubuntu LINUX_VERSION_CODE doesn't correspond to info.release,
|
|
/* On Ubuntu LINUX_VERSION_CODE doesn't correspond to info.release,
|
|
* but Ubuntu provides /proc/version_signature file, as described at
|
|
* but Ubuntu provides /proc/version_signature file, as described at
|
|
@@ -460,36 +496,30 @@ impl ProcFS {
|
|
* In the above, 5.4.8 is what kernel is actually expecting, while
|
|
* In the above, 5.4.8 is what kernel is actually expecting, while
|
|
* uname() call will return 5.4.0 in info.release.
|
|
* uname() call will return 5.4.0 in info.release.
|
|
*/
|
|
*/
|
|
- let binding = inode.create("version_signature", FileType::File, ModeType::S_IRUGO);
|
|
|
|
- if let Ok(version_signature) = binding {
|
|
|
|
- let version_signature = version_signature
|
|
|
|
- .as_any_ref()
|
|
|
|
- .downcast_ref::<LockedProcFSInode>()
|
|
|
|
- .unwrap();
|
|
|
|
- version_signature.0.lock().fdata.ftype = ProcFileType::Default;
|
|
|
|
- version_signature.0.lock().data = "DragonOS 6.0.0-generic 6.0.0\n"
|
|
|
|
- .to_string()
|
|
|
|
- .as_bytes()
|
|
|
|
- .to_vec();
|
|
|
|
- } else {
|
|
|
|
- panic!("create version_signature error");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let self_dir = inode
|
|
|
|
- .create("self", FileType::Dir, ModeType::from_bits_truncate(0o555))
|
|
|
|
|
|
+ let version_signature = inode
|
|
|
|
+ .create("version_signature", FileType::File, ModeType::S_IRUGO)
|
|
|
|
+ .expect("create version_signature error");
|
|
|
|
+ let version_signature = version_signature
|
|
|
|
+ .as_any_ref()
|
|
|
|
+ .downcast_ref::<LockedProcFSInode>()
|
|
.unwrap();
|
|
.unwrap();
|
|
-
|
|
|
|
- let binding = self_dir.create("exe", FileType::SymLink, ModeType::S_IRUGO);
|
|
|
|
- if let Ok(exe) = binding {
|
|
|
|
- let exe_file = exe
|
|
|
|
- .as_any_ref()
|
|
|
|
- .downcast_ref::<LockedProcFSInode>()
|
|
|
|
- .unwrap();
|
|
|
|
- exe_file.0.lock().fdata.pid = RawPid::new(0);
|
|
|
|
- exe_file.0.lock().fdata.ftype = ProcFileType::ProcExe;
|
|
|
|
- } else {
|
|
|
|
- panic!("create exe error");
|
|
|
|
- }
|
|
|
|
|
|
+ version_signature.0.lock().fdata.ftype = ProcFileType::Default;
|
|
|
|
+ version_signature.0.lock().data = b"DragonOS 6.0.0-generic 6.0.0\n".to_vec();
|
|
|
|
+
|
|
|
|
+ let self_file = inode
|
|
|
|
+ .create_with_data(
|
|
|
|
+ "self",
|
|
|
|
+ FileType::SymLink,
|
|
|
|
+ ModeType::from_bits_truncate(0o555),
|
|
|
|
+ 0,
|
|
|
|
+ )
|
|
|
|
+ .expect("create self error");
|
|
|
|
+ let self_file = self_file
|
|
|
|
+ .as_any_ref()
|
|
|
|
+ .downcast_ref::<LockedProcFSInode>()
|
|
|
|
+ .unwrap();
|
|
|
|
+ self_file.0.lock().fdata.pid = RawPid::new(2);
|
|
|
|
+ self_file.0.lock().fdata.ftype = ProcFileType::ProcSelf;
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -498,16 +528,16 @@ impl ProcFS {
|
|
/// @usage 在进程中调用并创建进程对应文件
|
|
/// @usage 在进程中调用并创建进程对应文件
|
|
pub fn register_pid(&self, pid: RawPid) -> Result<(), SystemError> {
|
|
pub fn register_pid(&self, pid: RawPid) -> Result<(), SystemError> {
|
|
// 获取当前inode
|
|
// 获取当前inode
|
|
- let inode: Arc<dyn IndexNode> = self.root_inode();
|
|
|
|
|
|
+ let inode = self.root_inode();
|
|
// 创建对应进程文件夹
|
|
// 创建对应进程文件夹
|
|
- let pid_dir: Arc<dyn IndexNode> = inode.create(
|
|
|
|
|
|
+ let pid_dir = inode.create(
|
|
&pid.to_string(),
|
|
&pid.to_string(),
|
|
FileType::Dir,
|
|
FileType::Dir,
|
|
ModeType::from_bits_truncate(0o555),
|
|
ModeType::from_bits_truncate(0o555),
|
|
)?;
|
|
)?;
|
|
// 创建相关文件
|
|
// 创建相关文件
|
|
// status文件
|
|
// status文件
|
|
- let status_binding: Arc<dyn IndexNode> = pid_dir.create(
|
|
|
|
|
|
+ let status_binding = pid_dir.create(
|
|
"status",
|
|
"status",
|
|
FileType::File,
|
|
FileType::File,
|
|
ModeType::from_bits_truncate(0o444),
|
|
ModeType::from_bits_truncate(0o444),
|
|
@@ -520,7 +550,7 @@ impl ProcFS {
|
|
status_file.0.lock().fdata.ftype = ProcFileType::ProcStatus;
|
|
status_file.0.lock().fdata.ftype = ProcFileType::ProcStatus;
|
|
|
|
|
|
// exe文件
|
|
// exe文件
|
|
- let exe_binding: Arc<dyn IndexNode> = pid_dir.create_with_data(
|
|
|
|
|
|
+ let exe_binding = pid_dir.create_with_data(
|
|
"exe",
|
|
"exe",
|
|
FileType::SymLink,
|
|
FileType::SymLink,
|
|
ModeType::from_bits_truncate(0o444),
|
|
ModeType::from_bits_truncate(0o444),
|
|
@@ -533,6 +563,10 @@ impl ProcFS {
|
|
exe_file.0.lock().fdata.pid = pid;
|
|
exe_file.0.lock().fdata.pid = pid;
|
|
exe_file.0.lock().fdata.ftype = ProcFileType::ProcExe;
|
|
exe_file.0.lock().fdata.ftype = ProcFileType::ProcExe;
|
|
|
|
|
|
|
|
+ // fd dir
|
|
|
|
+ let fd = pid_dir.create("fd", FileType::Dir, ModeType::from_bits_truncate(0o555))?;
|
|
|
|
+ let fd = fd.as_any_ref().downcast_ref::<LockedProcFSInode>().unwrap();
|
|
|
|
+ fd.0.lock().fdata.ftype = ProcFileType::ProcFdDir;
|
|
//todo: 创建其他文件
|
|
//todo: 创建其他文件
|
|
|
|
|
|
return Ok(());
|
|
return Ok(());
|
|
@@ -548,6 +582,7 @@ impl ProcFS {
|
|
// 删除进程文件夹下文件
|
|
// 删除进程文件夹下文件
|
|
pid_dir.unlink("status")?;
|
|
pid_dir.unlink("status")?;
|
|
pid_dir.unlink("exe")?;
|
|
pid_dir.unlink("exe")?;
|
|
|
|
+ pid_dir.rmdir("fd")?;
|
|
|
|
|
|
// 查看进程文件是否还存在
|
|
// 查看进程文件是否还存在
|
|
// let pf= pid_dir.find("status").expect("Cannot find status");
|
|
// let pf= pid_dir.find("status").expect("Cannot find status");
|
|
@@ -559,6 +594,43 @@ impl ProcFS {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+impl LockedProcFSInode {
|
|
|
|
+ fn dynamical_find_fd(&self, fd: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
|
|
|
|
+ // ::log::info!("ProcFS: Dynamically opening fd files for current process.");
|
|
|
|
+ let fd = fd.parse::<i32>().map_err(|_| SystemError::EINVAL)?;
|
|
|
|
+ let pcb = ProcessManager::current_pcb();
|
|
|
|
+ let fd_table = pcb.fd_table();
|
|
|
|
+ let fd_table = fd_table.read();
|
|
|
|
+ let file = fd_table.get_file_by_fd(fd);
|
|
|
|
+ if file.is_some() {
|
|
|
|
+ let _ = self.unlink(&fd.to_string());
|
|
|
|
+ let fd_file = self.create(
|
|
|
|
+ &fd.to_string(),
|
|
|
|
+ FileType::SymLink,
|
|
|
|
+ ModeType::from_bits_truncate(0o444),
|
|
|
|
+ )?;
|
|
|
|
+ let fd_file_proc = fd_file
|
|
|
|
+ .as_any_ref()
|
|
|
|
+ .downcast_ref::<LockedProcFSInode>()
|
|
|
|
+ .unwrap();
|
|
|
|
+ fd_file_proc.0.lock().fdata.fd = fd;
|
|
|
|
+ fd_file_proc.0.lock().fdata.ftype = ProcFileType::ProcFdFile;
|
|
|
|
+ return Ok(fd_file);
|
|
|
|
+ } else {
|
|
|
|
+ return Err(SystemError::ENOENT);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn dynamical_list_fd(&self) -> Result<Vec<String>, SystemError> {
|
|
|
|
+ // ::log::info!("ProcFS: Dynamically listing fd files for current process");
|
|
|
|
+ let pcb = ProcessManager::current_pcb();
|
|
|
|
+ let fd_table = pcb.fd_table();
|
|
|
|
+ let fd_table = fd_table.read();
|
|
|
|
+ let res = fd_table.iter().map(|(fd, _)| fd.to_string()).collect();
|
|
|
|
+ return Ok(res);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
impl IndexNode for LockedProcFSInode {
|
|
impl IndexNode for LockedProcFSInode {
|
|
fn open(
|
|
fn open(
|
|
&self,
|
|
&self,
|
|
@@ -567,6 +639,7 @@ impl IndexNode for LockedProcFSInode {
|
|
) -> Result<(), SystemError> {
|
|
) -> Result<(), SystemError> {
|
|
// 加锁
|
|
// 加锁
|
|
let mut inode: SpinLockGuard<ProcFSInode> = self.0.lock();
|
|
let mut inode: SpinLockGuard<ProcFSInode> = self.0.lock();
|
|
|
|
+ let proc_ty = inode.fdata.ftype;
|
|
|
|
|
|
// 如果inode类型为文件夹,则直接返回成功
|
|
// 如果inode类型为文件夹,则直接返回成功
|
|
if let FileType::Dir = inode.metadata.file_type {
|
|
if let FileType::Dir = inode.metadata.file_type {
|
|
@@ -574,22 +647,36 @@ impl IndexNode for LockedProcFSInode {
|
|
}
|
|
}
|
|
let mut private_data = ProcfsFilePrivateData::new();
|
|
let mut private_data = ProcfsFilePrivateData::new();
|
|
// 根据文件类型获取相应数据
|
|
// 根据文件类型获取相应数据
|
|
- let file_size = match inode.fdata.ftype {
|
|
|
|
|
|
+ let file_size = match proc_ty {
|
|
ProcFileType::ProcStatus => inode.open_status(&mut private_data)?,
|
|
ProcFileType::ProcStatus => inode.open_status(&mut private_data)?,
|
|
ProcFileType::ProcMeminfo => inode.open_meminfo(&mut private_data)?,
|
|
ProcFileType::ProcMeminfo => inode.open_meminfo(&mut private_data)?,
|
|
ProcFileType::ProcExe => inode.open_exe(&mut private_data)?,
|
|
ProcFileType::ProcExe => inode.open_exe(&mut private_data)?,
|
|
ProcFileType::Default => inode.data.len() as i64,
|
|
ProcFileType::Default => inode.data.len() as i64,
|
|
- _ => {
|
|
|
|
- todo!()
|
|
|
|
- }
|
|
|
|
|
|
+ ProcFileType::ProcSelf => inode.open_self(&mut private_data)?,
|
|
|
|
+ _ => 0,
|
|
};
|
|
};
|
|
*data = FilePrivateData::Procfs(private_data);
|
|
*data = FilePrivateData::Procfs(private_data);
|
|
// 更新metadata里面的文件大小数值
|
|
// 更新metadata里面的文件大小数值
|
|
inode.metadata.size = file_size;
|
|
inode.metadata.size = file_size;
|
|
|
|
+ drop(inode);
|
|
|
|
+ return Ok(());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ fn rmdir(&self, name: &str) -> Result<(), SystemError> {
|
|
|
|
+ let mut guard = self.0.lock();
|
|
|
|
+ if guard.metadata.file_type != FileType::Dir {
|
|
|
|
+ return Err(SystemError::ENOTDIR);
|
|
|
|
+ }
|
|
|
|
+ let name = DName::from(name);
|
|
|
|
+ guard.children.remove(&name);
|
|
return Ok(());
|
|
return Ok(());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fn parent(&self) -> Result<Arc<dyn IndexNode>, SystemError> {
|
|
|
|
+ let parent = self.0.lock().parent.upgrade().ok_or(SystemError::ENOENT)?;
|
|
|
|
+ return Ok(parent as Arc<dyn IndexNode>);
|
|
|
|
+ }
|
|
|
|
+
|
|
fn close(&self, mut data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
|
|
fn close(&self, mut data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
|
|
let guard: SpinLockGuard<ProcFSInode> = self.0.lock();
|
|
let guard: SpinLockGuard<ProcFSInode> = self.0.lock();
|
|
// 如果inode类型为文件夹,则直接返回成功
|
|
// 如果inode类型为文件夹,则直接返回成功
|
|
@@ -613,32 +700,29 @@ impl IndexNode for LockedProcFSInode {
|
|
return Err(SystemError::EINVAL);
|
|
return Err(SystemError::EINVAL);
|
|
}
|
|
}
|
|
// 加锁
|
|
// 加锁
|
|
- let inode: SpinLockGuard<ProcFSInode> = self.0.lock();
|
|
|
|
|
|
+ let inode = self.0.lock();
|
|
|
|
|
|
// 检查当前inode是否为一个文件夹,如果是的话,就返回错误
|
|
// 检查当前inode是否为一个文件夹,如果是的话,就返回错误
|
|
if inode.metadata.file_type == FileType::Dir {
|
|
if inode.metadata.file_type == FileType::Dir {
|
|
return Err(SystemError::EISDIR);
|
|
return Err(SystemError::EISDIR);
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取数据信息
|
|
|
|
- let mut private_data = match &*data {
|
|
|
|
- FilePrivateData::Procfs(p) => p.clone(),
|
|
|
|
- _ => {
|
|
|
|
- panic!("ProcFS: FilePrivateData mismatch!");
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
// 根据文件类型读取相应数据
|
|
// 根据文件类型读取相应数据
|
|
match inode.fdata.ftype {
|
|
match inode.fdata.ftype {
|
|
- ProcFileType::ProcStatus => {
|
|
|
|
- return inode.proc_read(offset, len, buf, &mut private_data)
|
|
|
|
- }
|
|
|
|
- ProcFileType::ProcMeminfo => {
|
|
|
|
- return inode.proc_read(offset, len, buf, &mut private_data)
|
|
|
|
|
|
+ ProcFileType::ProcStatus | ProcFileType::ProcMeminfo => {
|
|
|
|
+ // 获取数据信息
|
|
|
|
+ let mut private_data = match &*data {
|
|
|
|
+ FilePrivateData::Procfs(p) => p.clone(),
|
|
|
|
+ _ => {
|
|
|
|
+ panic!("ProcFS: FilePrivateData mismatch!");
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ return inode.proc_read(offset, len, buf, &mut private_data);
|
|
}
|
|
}
|
|
- ProcFileType::ProcExe => return inode.read_link(buf),
|
|
|
|
- ProcFileType::ProcKmsg => (),
|
|
|
|
- ProcFileType::Default => (),
|
|
|
|
|
|
+ ProcFileType::ProcExe => return inode.read_exe_link(buf),
|
|
|
|
+ ProcFileType::ProcSelf => return inode.read_self_link(buf),
|
|
|
|
+ ProcFileType::ProcFdFile => return inode.read_fd_link(buf),
|
|
|
|
+ _ => (),
|
|
};
|
|
};
|
|
|
|
|
|
// 默认读取
|
|
// 默认读取
|
|
@@ -677,7 +761,6 @@ impl IndexNode for LockedProcFSInode {
|
|
fn metadata(&self) -> Result<Metadata, SystemError> {
|
|
fn metadata(&self) -> Result<Metadata, SystemError> {
|
|
let inode = self.0.lock();
|
|
let inode = self.0.lock();
|
|
let metadata = inode.metadata.clone();
|
|
let metadata = inode.metadata.clone();
|
|
-
|
|
|
|
return Ok(metadata);
|
|
return Ok(metadata);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -751,6 +834,7 @@ impl IndexNode for LockedProcFSInode {
|
|
fdata: InodeInfo {
|
|
fdata: InodeInfo {
|
|
pid: RawPid::new(0),
|
|
pid: RawPid::new(0),
|
|
ftype: ProcFileType::Default,
|
|
ftype: ProcFileType::Default,
|
|
|
|
+ fd: -1,
|
|
},
|
|
},
|
|
dname: name.clone(),
|
|
dname: name.clone(),
|
|
})));
|
|
})));
|
|
@@ -829,23 +913,32 @@ impl IndexNode for LockedProcFSInode {
|
|
}
|
|
}
|
|
|
|
|
|
fn find(&self, name: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
|
|
fn find(&self, name: &str) -> Result<Arc<dyn IndexNode>, SystemError> {
|
|
- let inode = self.0.lock();
|
|
|
|
-
|
|
|
|
- if inode.metadata.file_type != FileType::Dir {
|
|
|
|
|
|
+ if self.0.lock().metadata.file_type != FileType::Dir {
|
|
return Err(SystemError::ENOTDIR);
|
|
return Err(SystemError::ENOTDIR);
|
|
}
|
|
}
|
|
|
|
|
|
match name {
|
|
match name {
|
|
"" | "." => {
|
|
"" | "." => {
|
|
- return Ok(inode.self_ref.upgrade().ok_or(SystemError::ENOENT)?);
|
|
|
|
|
|
+ return Ok(self
|
|
|
|
+ .0
|
|
|
|
+ .lock()
|
|
|
|
+ .self_ref
|
|
|
|
+ .upgrade()
|
|
|
|
+ .ok_or(SystemError::ENOENT)?);
|
|
}
|
|
}
|
|
|
|
|
|
".." => {
|
|
".." => {
|
|
- return Ok(inode.parent.upgrade().ok_or(SystemError::ENOENT)?);
|
|
|
|
|
|
+ return Ok(self.0.lock().parent.upgrade().ok_or(SystemError::ENOENT)?);
|
|
}
|
|
}
|
|
|
|
+
|
|
name => {
|
|
name => {
|
|
|
|
+ if self.0.lock().fdata.ftype == ProcFileType::ProcFdDir {
|
|
|
|
+ return self.dynamical_find_fd(name);
|
|
|
|
+ }
|
|
// 在子目录项中查找
|
|
// 在子目录项中查找
|
|
- return Ok(inode
|
|
|
|
|
|
+ return Ok(self
|
|
|
|
+ .0
|
|
|
|
+ .lock()
|
|
.children
|
|
.children
|
|
.get(&DName::from(name))
|
|
.get(&DName::from(name))
|
|
.ok_or(SystemError::ENOENT)?
|
|
.ok_or(SystemError::ENOENT)?
|
|
@@ -897,9 +990,14 @@ impl IndexNode for LockedProcFSInode {
|
|
return Err(SystemError::ENOTDIR);
|
|
return Err(SystemError::ENOTDIR);
|
|
}
|
|
}
|
|
|
|
|
|
- let mut keys: Vec<String> = Vec::new();
|
|
|
|
|
|
+ let mut keys = Vec::new();
|
|
keys.push(String::from("."));
|
|
keys.push(String::from("."));
|
|
keys.push(String::from(".."));
|
|
keys.push(String::from(".."));
|
|
|
|
+
|
|
|
|
+ if self.0.lock().fdata.ftype == ProcFileType::ProcFdDir {
|
|
|
|
+ return self.dynamical_list_fd();
|
|
|
|
+ }
|
|
|
|
+
|
|
keys.append(
|
|
keys.append(
|
|
&mut self
|
|
&mut self
|
|
.0
|
|
.0
|