diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 00971e3..4f60ca2 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -53,7 +53,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> i32 { }; match ret { Ok(code) => code, - Err(err) => (err as i32), + Err(err) => -(err as i32), } } @@ -96,7 +96,7 @@ fn sys_close(fd: usize) -> SysResult { info!("close: fd: {:?}", fd); match process().files.remove(&fd) { Some(_) => Ok(0), - None => Err(SysError::Badf), + None => Err(SysError::Inval), } } @@ -133,7 +133,7 @@ fn sys_dup(fd1: usize, fd2: usize) -> SysResult { info!("dup: {} {}", fd1, fd2); let file = get_file(fd1)?; if process().files.contains_key(&fd2) { - return Err(SysError::Badf); + return Err(SysError::Inval); } process().files.insert(fd2, file.clone()); Ok(0) @@ -278,7 +278,7 @@ fn sys_putc(c: char) -> SysResult { } fn get_file(fd: usize) -> Result<&'static Arc>, SysError> { - process().files.get(&fd).ok_or(SysError::Badf) + process().files.get(&fd).ok_or(SysError::Inval) } pub type SysResult = Result; @@ -286,23 +286,23 @@ pub type SysResult = Result; #[repr(i32)] #[derive(Debug)] pub enum SysError { - // ucore_plus compatible error code, which is a modified version of the ones used in linux - // note that ucore_os_lab use another error code table + // ucore compatible error code + // note that ucore_plus use another error code table, which is a modified version of the ones used in linux // name conversion E_XXXXX -> SysError::Xxxxx - // see https://github.com/oscourse-tsinghua/ucore_plus/blob/master/ucore/src/libs-user-ucore/common/error.h + // see https://github.com/oscourse-tsinghua/ucore_os_lab/blob/master/labcodes/lab8/libs/error.h // we only add current used errors here - Noent = 2,// No such file or directory - Badf = 9,// Invaild fd number - Nomem = 12,// Out of memory, also used as no device space in ucore - Exist = 17,// File exists - Xdev = 18,// Cross-device link - Notdir = 20,// Fd is not a directory - Isdir = 21,// Fd is a directory - Inval = 22,// Invalid argument. - Unimp = 35,// Not implemented operation + Inval = 3,// Invalid argument, also Invaild fd number. + Nomem = 4,// Out of memory, also used as no device space in ucore + Noent = 16,// No such file or directory + Isdir = 17,// Fd is a directory + Notdir = 18,// Fd is not a directory + Xdev = 19,// Cross-device link + Unimp = 20,// Not implemented + Exists = 23,// File exists + Notempty = 24,// Directory is not empty #[allow(dead_code)] - Unknown = 65535,// A really really unknown error. + Unspcified = 1,// A really really unknown error. } impl From for SysError { @@ -313,12 +313,12 @@ impl From for SysError { FsError::IsDir => SysError::Isdir, FsError::NotDir => SysError::Notdir, FsError::EntryNotFound => SysError::Noent, - FsError::EntryExist => SysError::Exist, + FsError::EntryExist => SysError::Exists, FsError::NotSameFs => SysError::Xdev, FsError::InvalidParam => SysError::Inval, FsError::NoDeviceSpace => SysError::Nomem, FsError::DirRemoved => SysError::Noent, - FsError::DirNotEmpty => SysError::Isdir,// It should be E_NOTEMPTY in linux, but in ucore it is equal to E_Isdir + FsError::DirNotEmpty => SysError::Notempty, FsError::WrongFs => SysError::Inval, } }