Skip to content

Commit

Permalink
remove code duplication, sys_mkdir reuses fs:create_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed May 26, 2024
1 parent ae7115f commit 3de7906
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,8 @@ pub unsafe fn create_file(
}

/// Creates a new, empty directory at the provided path
pub fn create_dir(path: &str) -> Result<(), IoError> {
FILESYSTEM
.get()
.unwrap()
.mkdir(path, AccessPermission::from_bits(0o777).unwrap())
pub fn create_dir(path: &str, mode: AccessPermission) -> Result<(), IoError> {
FILESYSTEM.get().unwrap().mkdir(path, mode)
}

/// Returns an vector with all the entries within a directory.
Expand Down
6 changes: 1 addition & 5 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,7 @@ pub unsafe extern "C" fn sys_mkdir(name: *const u8, mode: u32) -> i32 {
return -crate::errno::EINVAL;
};

fs::FILESYSTEM
.get()
.unwrap()
.mkdir(name, mode)
.map_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap(), |_| 0)
crate::fs::create_dir(name, mode).map_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap(), |_| 0)
}

#[hermit_macro::system]
Expand Down

0 comments on commit 3de7906

Please sign in to comment.