Add support for '/proc/[pid]/root'
This commit is contained in:
parent
65271ce190
commit
9a76ca1888
@ -3,14 +3,20 @@ use super::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FsView {
|
||||
root: String,
|
||||
cwd: String,
|
||||
}
|
||||
|
||||
impl FsView {
|
||||
pub fn new() -> FsView {
|
||||
Self {
|
||||
cwd: "/".to_owned(),
|
||||
}
|
||||
let root = String::from("/");
|
||||
let cwd = root.clone();
|
||||
Self { root, cwd }
|
||||
}
|
||||
|
||||
/// Get the root directory
|
||||
pub fn root(&self) -> &str {
|
||||
&self.root
|
||||
}
|
||||
|
||||
/// Get the current working directory.
|
||||
@ -203,8 +209,8 @@ impl FsView {
|
||||
|
||||
impl Default for FsView {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cwd: "/".to_owned(),
|
||||
}
|
||||
let root = String::from("/");
|
||||
let cwd = root.clone();
|
||||
Self { root, cwd }
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ impl LockedPidDirINode {
|
||||
// fd
|
||||
let fd_inode = LockedProcFdDirINode::new(&file.process_ref, file.this.upgrade().unwrap());
|
||||
file.entries.insert(String::from("fd"), fd_inode);
|
||||
// root
|
||||
let root_inode = ProcRootSymINode::new(&file.process_ref);
|
||||
file.entries.insert(String::from("root"), root_inode);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -166,6 +170,22 @@ impl ProcINode for ProcCwdSymINode {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProcRootSymINode(ProcessRef);
|
||||
|
||||
impl ProcRootSymINode {
|
||||
pub fn new(process_ref: &ProcessRef) -> Arc<dyn INode> {
|
||||
Arc::new(SymLink::new(Self(Arc::clone(process_ref))))
|
||||
}
|
||||
}
|
||||
|
||||
impl ProcINode for ProcRootSymINode {
|
||||
fn generate_data_in_bytes(&self) -> vfs::Result<Vec<u8>> {
|
||||
let main_thread = self.0.main_thread().ok_or(FsError::EntryNotFound)?;
|
||||
let fs = main_thread.fs().lock().unwrap();
|
||||
Ok(fs.root().to_owned().into_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FdSymINode(FileRef);
|
||||
|
||||
impl FdSymINode {
|
||||
|
@ -66,6 +66,16 @@ static int test_readlink_from_proc_self_cwd() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_readlink_from_proc_self_root() {
|
||||
char root_buf[PATH_MAX] = { 0 };
|
||||
const char *proc_root = "/proc/self/root";
|
||||
|
||||
if (test_readlink_from_procfs(proc_root, root_buf, PATH_MAX, "/") < 0) {
|
||||
THROW_ERROR("failed to call test_readlink_from_procfs");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_read_from_proc_self_cmdline() {
|
||||
char absolute_path[PATH_MAX] = { 0 };
|
||||
const char *proc_cmdline = "/proc/self/cmdline";
|
||||
@ -126,6 +136,7 @@ static int test_read_from_proc_cpuinfo() {
|
||||
static test_case_t test_cases[] = {
|
||||
TEST_CASE(test_readlink_from_proc_self_exe),
|
||||
TEST_CASE(test_readlink_from_proc_self_cwd),
|
||||
TEST_CASE(test_readlink_from_proc_self_root),
|
||||
TEST_CASE(test_read_from_proc_self_cmdline),
|
||||
TEST_CASE(test_read_from_proc_meminfo),
|
||||
TEST_CASE(test_read_from_proc_cpuinfo),
|
||||
|
Loading…
Reference in New Issue
Block a user