mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-02-01 18:11:51 -05:00
procfs bugfixes
This commit is contained in:
@@ -57,6 +57,7 @@ impl Inode for ProcRootInode {
|
||||
|
||||
Ok(Arc::new(ProcTaskInode::new(
|
||||
desc,
|
||||
false,
|
||||
InodeId::from_fsid_and_inodeid(self.id.fs_id(), get_inode_id(&[name])),
|
||||
)))
|
||||
}
|
||||
@@ -73,15 +74,17 @@ impl Inode for ProcRootInode {
|
||||
.iter()
|
||||
.filter(|(_, task)| task.upgrade().is_some())
|
||||
{
|
||||
// Use offset index as dirent offset.
|
||||
let name = desc.tgid().value().to_string();
|
||||
let inode_id =
|
||||
InodeId::from_fsid_and_inodeid(PROCFS_ID, ((desc.tgid().0 + 1) * 100) as u64);
|
||||
let inode_id = InodeId::from_fsid_and_inodeid(
|
||||
PROCFS_ID,
|
||||
get_inode_id(&[&desc.tgid().value().to_string()]),
|
||||
);
|
||||
let next_offset = (entries.len() + 1) as u64;
|
||||
entries.push(Dirent::new(
|
||||
name,
|
||||
inode_id,
|
||||
FileType::Directory,
|
||||
get_inode_id(&[&desc.tgid().value().to_string()]),
|
||||
next_offset,
|
||||
));
|
||||
}
|
||||
let current_task = current_task();
|
||||
@@ -94,6 +97,15 @@ impl Inode for ProcRootInode {
|
||||
FileType::Directory,
|
||||
(entries.len() + 1) as u64,
|
||||
));
|
||||
entries.push(Dirent::new(
|
||||
"thread-self".to_string(),
|
||||
InodeId::from_fsid_and_inodeid(
|
||||
PROCFS_ID,
|
||||
get_inode_id(&[¤t_task.descriptor().tid().value().to_string()]),
|
||||
),
|
||||
FileType::Directory,
|
||||
(entries.len() + 1) as u64,
|
||||
));
|
||||
|
||||
Ok(Box::new(SimpleDirStream::new(entries, start_offset)))
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ impl Inode for ProcFdInode {
|
||||
continue;
|
||||
}
|
||||
let fd_str = fd.to_string();
|
||||
let next_offset = (entries.len() + 1) as u64;
|
||||
entries.push(Dirent {
|
||||
id: InodeId::from_fsid_and_inodeid(
|
||||
self.id.fs_id(),
|
||||
@@ -89,7 +90,7 @@ impl Inode for ProcFdInode {
|
||||
&fd_str,
|
||||
]),
|
||||
),
|
||||
offset: fd as _,
|
||||
offset: next_offset,
|
||||
file_type: FileType::File,
|
||||
name: fd_str,
|
||||
});
|
||||
|
||||
@@ -22,10 +22,11 @@ pub struct ProcTaskInode {
|
||||
id: InodeId,
|
||||
attr: FileAttr,
|
||||
desc: TaskDescriptor,
|
||||
is_task_dir: bool,
|
||||
}
|
||||
|
||||
impl ProcTaskInode {
|
||||
pub fn new(desc: TaskDescriptor, inode_id: InodeId) -> Self {
|
||||
pub fn new(desc: TaskDescriptor, is_task_dir: bool, inode_id: InodeId) -> Self {
|
||||
Self {
|
||||
id: inode_id,
|
||||
attr: FileAttr {
|
||||
@@ -34,6 +35,7 @@ impl ProcTaskInode {
|
||||
..FileAttr::default()
|
||||
},
|
||||
desc,
|
||||
is_task_dir,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +56,10 @@ impl Inode for ProcTaskInode {
|
||||
return Ok(Arc::new(fd::ProcFdInode::new(self.desc, true, inode_id)));
|
||||
} else if name == "fd" {
|
||||
return Ok(Arc::new(fd::ProcFdInode::new(self.desc, false, inode_id)));
|
||||
} else if name == "task" && self.desc.tid().value() == self.desc.tgid().value() {
|
||||
} else if name == "task"
|
||||
&& self.desc.tid().value() == self.desc.tgid().value()
|
||||
&& !self.is_task_dir
|
||||
{
|
||||
return Ok(Arc::new(task::ProcTaskDirInode::new(
|
||||
self.desc.tgid(),
|
||||
inode_id,
|
||||
@@ -64,6 +69,7 @@ impl Inode for ProcTaskInode {
|
||||
Ok(Arc::new(ProcTaskFileInode::new(
|
||||
self.desc.tid(),
|
||||
file_type,
|
||||
self.is_task_dir,
|
||||
inode_id,
|
||||
)))
|
||||
} else {
|
||||
@@ -120,7 +126,7 @@ impl Inode for ProcTaskInode {
|
||||
FileType::Directory,
|
||||
7,
|
||||
));
|
||||
if self.desc.tid().value() == self.desc.tgid().value() {
|
||||
if self.desc.tid().value() == self.desc.tgid().value() && !self.is_task_dir {
|
||||
entries.push(Dirent::new(
|
||||
"task".to_string(),
|
||||
InodeId::from_fsid_and_inodeid(PROCFS_ID, get_inode_id(&[&initial_str, "task"])),
|
||||
|
||||
@@ -53,7 +53,7 @@ impl Inode for ProcTaskDirInode {
|
||||
);
|
||||
let desc = TaskDescriptor::from_tgid_tid(self.tgid, tid);
|
||||
find_task_by_descriptor(&desc).ok_or(FsError::NotFound)?;
|
||||
Ok(Arc::new(ProcTaskInode::new(desc, inode_id)))
|
||||
Ok(Arc::new(ProcTaskInode::new(desc, true, inode_id)))
|
||||
}
|
||||
|
||||
async fn readdir(&self, start_offset: u64) -> libkernel::error::Result<Box<dyn DirStream>> {
|
||||
|
||||
@@ -14,6 +14,7 @@ pub enum TaskFileType {
|
||||
Status,
|
||||
Comm,
|
||||
Cwd,
|
||||
Root,
|
||||
State,
|
||||
Stat,
|
||||
}
|
||||
@@ -28,6 +29,7 @@ impl TryFrom<&str> for TaskFileType {
|
||||
"state" => Ok(TaskFileType::State),
|
||||
"stat" => Ok(TaskFileType::Stat),
|
||||
"cwd" => Ok(TaskFileType::Cwd),
|
||||
"root" => Ok(TaskFileType::Root),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
@@ -38,10 +40,11 @@ pub struct ProcTaskFileInode {
|
||||
file_type: TaskFileType,
|
||||
attr: FileAttr,
|
||||
tid: Tid,
|
||||
process_stats: bool,
|
||||
}
|
||||
|
||||
impl ProcTaskFileInode {
|
||||
pub fn new(tid: Tid, file_type: TaskFileType, inode_id: InodeId) -> Self {
|
||||
pub fn new(tid: Tid, file_type: TaskFileType, process_stats: bool, inode_id: InodeId) -> Self {
|
||||
Self {
|
||||
id: inode_id,
|
||||
attr: FileAttr {
|
||||
@@ -50,11 +53,12 @@ impl ProcTaskFileInode {
|
||||
| TaskFileType::Comm
|
||||
| TaskFileType::State
|
||||
| TaskFileType::Stat => FileType::File,
|
||||
TaskFileType::Cwd => FileType::Symlink,
|
||||
TaskFileType::Cwd | TaskFileType::Root => FileType::Symlink,
|
||||
},
|
||||
mode: FilePermissions::from_bits_retain(0o444),
|
||||
..FileAttr::default()
|
||||
},
|
||||
process_stats,
|
||||
tid,
|
||||
file_type,
|
||||
}
|
||||
@@ -119,8 +123,15 @@ Threads:\t{tasks}\n",
|
||||
output.push_str(&format!("{} ", 0)); // cminflt
|
||||
output.push_str(&format!("{} ", 0)); // majflt
|
||||
output.push_str(&format!("{} ", 0)); // cmajflt
|
||||
output.push_str(&format!("{} ", task.process.utime.load(Ordering::Relaxed))); // utime
|
||||
output.push_str(&format!("{} ", task.process.stime.load(Ordering::Relaxed))); // stime
|
||||
if self.process_stats {
|
||||
output
|
||||
.push_str(&format!("{} ", task.process.utime.load(Ordering::Relaxed))); // utime
|
||||
output
|
||||
.push_str(&format!("{} ", task.process.stime.load(Ordering::Relaxed))); // stime
|
||||
} else {
|
||||
output.push_str(&format!("{} ", task.utime.load(Ordering::Relaxed))); // utime
|
||||
output.push_str(&format!("{} ", task.stime.load(Ordering::Relaxed))); // stime
|
||||
}
|
||||
output.push_str(&format!("{} ", 0)); // cutime
|
||||
output.push_str(&format!("{} ", 0)); // cstime
|
||||
output.push_str(&format!("{} ", *task.process.priority.lock_save_irq())); // priority
|
||||
@@ -162,6 +173,7 @@ Threads:\t{tasks}\n",
|
||||
output
|
||||
}
|
||||
TaskFileType::Cwd => task.cwd.lock_save_irq().clone().1.as_str().to_string(),
|
||||
TaskFileType::Root => task.root.lock_save_irq().1.as_str().to_string(),
|
||||
}
|
||||
} else {
|
||||
"State:\tGone\n".to_string()
|
||||
@@ -173,9 +185,13 @@ Threads:\t{tasks}\n",
|
||||
if let TaskFileType::Cwd = self.file_type {
|
||||
let tid = self.tid;
|
||||
let task_list = TASK_LIST.lock_save_irq();
|
||||
let id = task_list.iter().find(|(desc, _)| desc.tid() == tid);
|
||||
let task_details = if let Some((desc, _)) = id {
|
||||
find_task_by_descriptor(desc)
|
||||
let id = task_list
|
||||
.iter()
|
||||
.find(|(desc, _)| desc.tid() == tid)
|
||||
.map(|(desc, _)| *desc);
|
||||
drop(task_list);
|
||||
let task_details = if let Some(desc) = id {
|
||||
find_task_by_descriptor(&desc)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -185,6 +201,25 @@ Threads:\t{tasks}\n",
|
||||
} else {
|
||||
Err(FsError::NotFound.into())
|
||||
};
|
||||
} else if let TaskFileType::Root = self.file_type {
|
||||
let tid = self.tid;
|
||||
let task_list = TASK_LIST.lock_save_irq();
|
||||
let id = task_list
|
||||
.iter()
|
||||
.find(|(desc, _)| desc.tid() == tid)
|
||||
.map(|(desc, _)| *desc);
|
||||
drop(task_list);
|
||||
let task_details = if let Some(desc) = id {
|
||||
find_task_by_descriptor(&desc)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return if let Some(task) = task_details {
|
||||
let root = task.root.lock_save_irq();
|
||||
Ok(root.1.clone())
|
||||
} else {
|
||||
Err(FsError::NotFound.into())
|
||||
};
|
||||
}
|
||||
Err(KernelError::NotSupported)
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ async fn launch_init(mut opts: KOptions) {
|
||||
|
||||
// Now that the root fs has been mounted, set the real root inode as the
|
||||
// cwd and root.
|
||||
*task.cwd.lock_save_irq() = (VFS.root_inode(), PathBuf::new());
|
||||
*task.root.lock_save_irq() = (VFS.root_inode(), PathBuf::new());
|
||||
*task.cwd.lock_save_irq() = (VFS.root_inode(), PathBuf::from("/"));
|
||||
*task.root.lock_save_irq() = (VFS.root_inode(), PathBuf::from("/"));
|
||||
|
||||
let console = VFS
|
||||
.open(
|
||||
|
||||
Reference in New Issue
Block a user