From 6e8c80d3285a64c933150447f846277dcb62a6b4 Mon Sep 17 00:00:00 2001 From: Ben Pig Chu Date: Thu, 20 Dec 2018 14:26:32 +0800 Subject: [PATCH] panicless default fs implement --- kernel/src/fs.rs | 20 ++++++++++---------- kernel/src/syscall.rs | 5 +++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/kernel/src/fs.rs b/kernel/src/fs.rs index 10f85fe..0603a0d 100644 --- a/kernel/src/fs.rs +++ b/kernel/src/fs.rs @@ -108,16 +108,16 @@ lazy_static! { // TODO: better way to provide default impl? macro_rules! impl_inode { () => { - fn info(&self) -> Result { unimplemented!() } - fn sync(&self) -> Result<()> { unimplemented!() } - fn resize(&self, _len: usize) -> Result<()> { unimplemented!() } - fn create(&self, _name: &str, _type_: FileType) -> Result> { unimplemented!() } - fn unlink(&self, _name: &str) -> Result<()> { unimplemented!() } - fn link(&self, _name: &str, _other: &Arc) -> Result<()> { unimplemented!() } - fn rename(&self, _old_name: &str, _new_name: &str) -> Result<()> { unimplemented!() } - fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { unimplemented!() } - fn find(&self, _name: &str) -> Result> { unimplemented!() } - fn get_entry(&self, _id: usize) -> Result { unimplemented!() } + fn info(&self) -> Result { Err(FsError::NotSupported) } + fn sync(&self) -> Result<()> { Ok(()) } + fn resize(&self, _len: usize) -> Result<()> { Err(FsError::NotSupported) } + fn create(&self, _name: &str, _type_: FileType) -> Result> { Err(FsError::NotDir) } + fn unlink(&self, _name: &str) -> Result<()> { Err(FsError::NotDir) } + fn link(&self, _name: &str, _other: &Arc) -> Result<()> { Err(FsError::NotDir) } + fn rename(&self, _old_name: &str, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn move_(&self, _old_name: &str, _target: &Arc, _new_name: &str) -> Result<()> { Err(FsError::NotDir) } + fn find(&self, _name: &str) -> Result> { Err(FsError::NotDir) } + fn get_entry(&self, _id: usize) -> Result { Err(FsError::NotDir) } fn fs(&self) -> Arc { unimplemented!() } fn as_any_ref(&self) -> &Any { self } }; diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 4d82415..00971e3 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), } } @@ -286,7 +286,8 @@ pub type SysResult = Result; #[repr(i32)] #[derive(Debug)] pub enum SysError { - // ucore compatible error code, which is a modified version of the ones used in linux + // 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 // name conversion E_XXXXX -> SysError::Xxxxx // see https://github.com/oscourse-tsinghua/ucore_plus/blob/master/ucore/src/libs-user-ucore/common/error.h // we only add current used errors here