use the error code specified in ucore_os_lab instead of ucore_plus

toolchain_update
Ben Pig Chu 6 years ago
parent 6e8c80d328
commit 364497e379

@ -53,7 +53,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> i32 {
}; };
match ret { match ret {
Ok(code) => code, 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); info!("close: fd: {:?}", fd);
match process().files.remove(&fd) { match process().files.remove(&fd) {
Some(_) => Ok(0), 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); info!("dup: {} {}", fd1, fd2);
let file = get_file(fd1)?; let file = get_file(fd1)?;
if process().files.contains_key(&fd2) { if process().files.contains_key(&fd2) {
return Err(SysError::Badf); return Err(SysError::Inval);
} }
process().files.insert(fd2, file.clone()); process().files.insert(fd2, file.clone());
Ok(0) Ok(0)
@ -278,7 +278,7 @@ fn sys_putc(c: char) -> SysResult {
} }
fn get_file(fd: usize) -> Result<&'static Arc<Mutex<File>>, SysError> { fn get_file(fd: usize) -> Result<&'static Arc<Mutex<File>>, SysError> {
process().files.get(&fd).ok_or(SysError::Badf) process().files.get(&fd).ok_or(SysError::Inval)
} }
pub type SysResult = Result<i32, SysError>; pub type SysResult = Result<i32, SysError>;
@ -286,23 +286,23 @@ pub type SysResult = Result<i32, SysError>;
#[repr(i32)] #[repr(i32)]
#[derive(Debug)] #[derive(Debug)]
pub enum SysError { pub enum SysError {
// ucore_plus compatible error code, which is a modified version of the ones used in linux // ucore compatible error code
// note that ucore_os_lab use another error code table // 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 // 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 // we only add current used errors here
Noent = 2,// No such file or directory Inval = 3,// Invalid argument, also Invaild fd number.
Badf = 9,// Invaild fd number Nomem = 4,// Out of memory, also used as no device space in ucore
Nomem = 12,// Out of memory, also used as no device space in ucore Noent = 16,// No such file or directory
Exist = 17,// File exists Isdir = 17,// Fd is a directory
Xdev = 18,// Cross-device link Notdir = 18,// Fd is not a directory
Notdir = 20,// Fd is not a directory Xdev = 19,// Cross-device link
Isdir = 21,// Fd is a directory Unimp = 20,// Not implemented
Inval = 22,// Invalid argument. Exists = 23,// File exists
Unimp = 35,// Not implemented operation Notempty = 24,// Directory is not empty
#[allow(dead_code)] #[allow(dead_code)]
Unknown = 65535,// A really really unknown error. Unspcified = 1,// A really really unknown error.
} }
impl From<FsError> for SysError { impl From<FsError> for SysError {
@ -313,12 +313,12 @@ impl From<FsError> for SysError {
FsError::IsDir => SysError::Isdir, FsError::IsDir => SysError::Isdir,
FsError::NotDir => SysError::Notdir, FsError::NotDir => SysError::Notdir,
FsError::EntryNotFound => SysError::Noent, FsError::EntryNotFound => SysError::Noent,
FsError::EntryExist => SysError::Exist, FsError::EntryExist => SysError::Exists,
FsError::NotSameFs => SysError::Xdev, FsError::NotSameFs => SysError::Xdev,
FsError::InvalidParam => SysError::Inval, FsError::InvalidParam => SysError::Inval,
FsError::NoDeviceSpace => SysError::Nomem, FsError::NoDeviceSpace => SysError::Nomem,
FsError::DirRemoved => SysError::Noent, 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, FsError::WrongFs => SysError::Inval,
} }
} }

Loading…
Cancel
Save