Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/drivers/fs/proc/task/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::drivers::fs::proc::{get_inode_id, procfs};
use crate::process::fd_table::Fd;
use crate::process::{TaskDescriptor, find_task_by_descriptor};
use crate::sched::current::current_task_shared;
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::ToString;
Expand All @@ -11,6 +12,7 @@ use async_trait::async_trait;
use libkernel::error::Result;
use libkernel::error::{FsError, KernelError};
use libkernel::fs::attr::FileAttr;
use libkernel::fs::pathbuf::PathBuf;
use libkernel::fs::{
DirStream, Dirent, FileType, Filesystem, Inode, InodeId, SimpleDirStream, SimpleFile,
};
Expand Down Expand Up @@ -115,7 +117,11 @@ impl ProcFdFile {
Self {
id: inode_id,
attr: FileAttr {
file_type: FileType::File,
file_type: if fd_info {
FileType::File
} else {
FileType::Symlink
},
// Define appropriate file attributes for fdinfo file.
..FileAttr::default()
},
Expand Down Expand Up @@ -151,4 +157,26 @@ impl SimpleFile for ProcFdFile {
Err(KernelError::NotSupported)
}
}

async fn readlink(&self) -> Result<PathBuf> {
if !self.fd_info {
if let Some(task) = find_task_by_descriptor(&self.desc) {
let Some(file) = task.fd_table.lock_save_irq().get(Fd(self.fd)) else {
return Err(FsError::NotFound.into());
};
if let Some(path) = file.path() {
Ok(path.to_owned())
} else {
// TODO: Find file type
todo!(
"Implement readlink for /proc/[pid]/fd/[fd] when fd doesn't refer to a file with an inode"
)
}
} else {
Err(FsError::NotFound.into())
}
} else {
Err(KernelError::NotSupported)
}
}
}