Skip to content

Commit df6b32f

Browse files
committed
partial proc fd file support
1 parent a120732 commit df6b32f

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • src/drivers/fs/proc/task

src/drivers/fs/proc/task/fd.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::drivers::fs::proc::{get_inode_id, procfs};
22
use crate::process::fd_table::Fd;
33
use crate::process::{TaskDescriptor, find_task_by_descriptor};
44
use crate::sched::current::current_task_shared;
5+
use alloc::borrow::ToOwned;
56
use alloc::boxed::Box;
67
use alloc::format;
78
use alloc::string::ToString;
@@ -11,6 +12,7 @@ use async_trait::async_trait;
1112
use libkernel::error::Result;
1213
use libkernel::error::{FsError, KernelError};
1314
use libkernel::fs::attr::FileAttr;
15+
use libkernel::fs::pathbuf::PathBuf;
1416
use 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,26 @@ 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: Find file type
171+
todo!(
172+
"Implement readlink for /proc/[pid]/fd/[fd] when fd doesn't refer to a file with an inode"
173+
)
174+
}
175+
} else {
176+
Err(FsError::NotFound.into())
177+
}
178+
} else {
179+
Err(KernelError::NotSupported)
180+
}
181+
}
154182
}

0 commit comments

Comments
 (0)