add sys_rmdir. fix sys_sync, sys_unlink.
This commit is contained in:
parent
694fb32a35
commit
002d1f1dd2
@ -248,9 +248,7 @@ pub fn do_dup3(old_fd: FileDesc, new_fd: FileDesc, flags: u32) -> Result<FileDes
|
||||
}
|
||||
|
||||
pub fn do_sync() -> Result<(), Error> {
|
||||
unsafe {
|
||||
ocall_sync();
|
||||
}
|
||||
ROOT_INODE.fs().sync()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -299,6 +297,21 @@ pub fn do_mkdir(path: &str, mode: usize) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn do_rmdir(path: &str) -> Result<(), Error> {
|
||||
let current_ref = process::get_current();
|
||||
let current_process = current_ref.lock().unwrap();
|
||||
info!("rmdir: path: {:?}", path);
|
||||
|
||||
let (dir_path, file_name) = split_path(&path);
|
||||
let dir_inode = current_process.lookup_inode(dir_path)?;
|
||||
let file_inode = dir_inode.find(file_name)?;
|
||||
if file_inode.metadata()?.type_ != FileType::Dir {
|
||||
return Err(Error::new(ENOTDIR, "rmdir on not directory"));
|
||||
}
|
||||
dir_inode.unlink(file_name)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn do_link(oldpath: &str, newpath: &str) -> Result<(), Error> {
|
||||
let current_ref = process::get_current();
|
||||
let current_process = current_ref.lock().unwrap();
|
||||
@ -318,6 +331,10 @@ pub fn do_unlink(path: &str) -> Result<(), Error> {
|
||||
|
||||
let (dir_path, file_name) = split_path(&path);
|
||||
let dir_inode = current_process.lookup_inode(dir_path)?;
|
||||
let file_inode = dir_inode.find(file_name)?;
|
||||
if file_inode.metadata()?.type_ == FileType::Dir {
|
||||
return Err(Error::new(EISDIR, "unlink on directory"));
|
||||
}
|
||||
dir_inode.unlink(file_name)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ pub extern "C" fn dispatch_syscall(
|
||||
SYS_CHDIR => do_chdir(arg0 as *mut i8),
|
||||
SYS_RENAME => do_rename(arg0 as *const i8, arg1 as *const i8),
|
||||
SYS_MKDIR => do_mkdir(arg0 as *const i8, arg1 as usize),
|
||||
SYS_RMDIR => do_rmdir(arg0 as *const i8),
|
||||
SYS_LINK => do_link(arg0 as *const i8, arg1 as *const i8),
|
||||
SYS_UNLINK => do_unlink(arg0 as *const i8),
|
||||
|
||||
@ -508,7 +509,7 @@ fn do_getcwd(buf: *mut u8, size: usize) -> Result<isize, Error> {
|
||||
}
|
||||
safe_buf[..cwd.len()].copy_from_slice(cwd.as_bytes());
|
||||
safe_buf[cwd.len()] = 0;
|
||||
Ok(0)
|
||||
Ok(buf as isize)
|
||||
}
|
||||
|
||||
fn do_chdir(path: *const i8) -> Result<isize, Error> {
|
||||
@ -530,6 +531,12 @@ fn do_mkdir(path: *const i8, mode: usize) -> Result<isize, Error> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn do_rmdir(path: *const i8) -> Result<isize, Error> {
|
||||
let path = clone_cstring_safely(path)?.to_string_lossy().into_owned();
|
||||
fs::do_rmdir(&path)?;
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn do_link(oldpath: *const i8, newpath: *const i8) -> Result<isize, Error> {
|
||||
let oldpath = clone_cstring_safely(oldpath)?.to_string_lossy().into_owned();
|
||||
let newpath = clone_cstring_safely(newpath)?.to_string_lossy().into_owned();
|
||||
|
Loading…
Reference in New Issue
Block a user