diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 9fd8119..aefd349 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -10,7 +10,7 @@ pub struct FileHandle { inode: Arc, offset: u64, options: OpenOptions, - path: String, + pub path: String, } #[derive(Debug, Clone)] diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 49aebe5..895252c 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -776,12 +776,29 @@ impl Process { dirfd as isize, self.cwd, path, follow ); // hard code special path + let (fd_dir_path, fd_name) = split_path(&path); match path { "/proc/self/exe" => { return Ok(Arc::new(Pseudo::new(&self.exec_path, FileType::SymLink))); } _ => {} } + match fd_dir_path { + "/proc/self/fd" =>{ + let fd:u32= fd_name.parse::().unwrap(); + let fd_path= match self.files.get(&(fd as usize)).unwrap() { + FileLike::File(file) => Some(&file.path), + _ => None, + }; + info!("lookup_inode_at:BEG /proc/sefl/fd {}, path {}", fd, fd_path.unwrap()); + if(fd_path.is_some()) { + return Ok(Arc::new(Pseudo::new(fd_path.unwrap(), FileType::SymLink))); + } else { + {} + } + } + _ => {} + } let follow_max_depth = if follow { FOLLOW_MAX_DEPTH } else { 0 }; if dirfd == AT_FDCWD { @@ -1392,5 +1409,5 @@ impl FdSet { } } } - +//pathname is interpreted relative to the current working directory(CWD) const AT_FDCWD: usize = -100isize as usize;