@@ -2,6 +2,7 @@ use crate::drivers::fs::proc::{get_inode_id, procfs};
22use crate :: process:: fd_table:: Fd ;
33use crate :: process:: { TaskDescriptor , find_task_by_descriptor} ;
44use crate :: sched:: current:: current_task_shared;
5+ use alloc:: borrow:: ToOwned ;
56use alloc:: boxed:: Box ;
67use alloc:: format;
78use alloc:: string:: ToString ;
@@ -11,6 +12,7 @@ use async_trait::async_trait;
1112use libkernel:: error:: Result ;
1213use libkernel:: error:: { FsError , KernelError } ;
1314use libkernel:: fs:: attr:: FileAttr ;
15+ use libkernel:: fs:: pathbuf:: PathBuf ;
1416use libkernel:: fs:: {
1517 DirStream , Dirent , FileType , Filesystem , Inode , InodeId , SimpleDirStream , SimpleFile ,
1618} ;
@@ -115,7 +117,11 @@ impl ProcFdFile {
115117 Self {
116118 id : inode_id,
117119 attr : FileAttr {
118- file_type : FileType :: File ,
120+ file_type : if fd_info {
121+ FileType :: File
122+ } else {
123+ FileType :: Symlink
124+ } ,
119125 // Define appropriate file attributes for fdinfo file.
120126 ..FileAttr :: default ( )
121127 } ,
@@ -151,4 +157,23 @@ impl SimpleFile for ProcFdFile {
151157 Err ( KernelError :: NotSupported )
152158 }
153159 }
160+
161+ async fn readlink ( & self ) -> Result < PathBuf > {
162+ if !self . fd_info {
163+ if let Some ( task) = find_task_by_descriptor ( & self . desc ) {
164+ let Some ( file) = task. fd_table . lock_save_irq ( ) . get ( Fd ( self . fd ) ) else {
165+ return Err ( FsError :: NotFound . into ( ) ) ;
166+ } ;
167+ if let Some ( path) = file. path ( ) {
168+ Ok ( path. to_owned ( ) )
169+ } else {
170+ todo ! ( ) ;
171+ }
172+ } else {
173+ Err ( FsError :: NotFound . into ( ) )
174+ }
175+ } else {
176+ Err ( KernelError :: NotSupported )
177+ }
178+ }
154179}
0 commit comments