| 466 | } |
| 467 | |
| 468 | pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<(), SyscallError> { |
| 469 | let path: &Path = path.as_ref(); |
| 470 | |
| 471 | // Get the directory's parent |
| 472 | let parent = match path.parent() { |
| 473 | Some(parent) => parent, |
| 474 | None => { return Err(syscalls::SYSCALL_ERROR_PARAM); } |
| 475 | }; |
| 476 | |
| 477 | // Get the final part of the path |
| 478 | let new_dir_name = match path.file_name() { |
| 479 | Some(name) => name, |
| 480 | None => { return Err(syscalls::SYSCALL_ERROR_PARAM); } |
| 481 | }; |
| 482 | |
| 483 | // Open the parent directory for modifying |
| 484 | let f = OpenOptions::new().write(true).open(parent)?; |
| 485 | |
| 486 | // Send a MKDIR message |
| 487 | let bytes = new_dir_name.bytes(); |
| 488 | match f.rcall(message::MKDIR, |
| 489 | (bytes.len() as u64).into(), |
| 490 | MemoryHandle::from_u8_slice(bytes).into()) { |
| 491 | Err((err, _)) => Err(err), |
| 492 | Ok((message::OK, _, _)) => Ok(()), |
| 493 | _ => Err(syscalls::SYSCALL_ERROR_PARAM) |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /// Returns the canonical, absolute form of a path with all intermediate |
| 498 | /// components normalized and symbolic links resolved. |