Skip to content

Commit

Permalink
add traversal for Root inode
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed May 22, 2024
1 parent 2527d7b commit 8bc7267
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/wasix/src/syscalls/wasi/path_create_directory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{path::PathBuf, str::FromStr};

use super::*;
use crate::syscalls::*;

Expand Down Expand Up @@ -57,13 +59,7 @@ pub(crate) fn path_create_directory_internal(
let env = ctx.data();
let (memory, state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };
let working_dir = state.fs.get_fd(fd)?;
{
let guard = working_dir.inode.read();
if let Kind::Root { .. } = guard.deref() {
trace!("root has no rights to create a directories");
return Err(Errno::Access);
}
}

if !working_dir.rights.contains(Rights::PATH_CREATE_DIRECTORY) {
trace!("working directory (fd={fd}) has no rights to create a directory");
return Err(Errno::Access);
Expand Down Expand Up @@ -149,9 +145,17 @@ pub(crate) fn path_create_directory_internal(
cur_dir_inode = new_inode;
}
}
Kind::Root { .. } => {
trace!("the root node can no create a directory");
return Err(Errno::Access);
Kind::Root { entries } => {
match comp.borrow() {
"." | ".." => continue,
_ => (),
}
if let Some(child) = entries.get(comp) {
cur_dir_inode = child.clone();
} else {
trace!("the root node can no create a directory");
return Err(Errno::Access);
}
}
_ => {
trace!("path is not a directory");
Expand Down

0 comments on commit 8bc7267

Please sign in to comment.