From 383b81411d41923b6df0a6b0615773bc4c7b774f Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 7 May 2018 12:55:13 +0800 Subject: [PATCH] Add info() for vfs::FileSystem. Add fs() for vfs::INode. --- src/sfs.rs | 10 ++++++++++ src/vfs.rs | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sfs.rs b/src/sfs.rs index c143ae2..ae02b9c 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -306,6 +306,9 @@ impl vfs::INode for INode { String::from(entry.name.as_ref()) }).collect()) } + fn fs(&self) -> Weak { + self.fs.clone() + } } impl Drop for INode { @@ -519,6 +522,13 @@ impl vfs::FileSystem for SimpleFileSystem { fn root_inode(&self) -> Ptr { self.get_inode(BLKN_ROOT) } + + fn info(&self) -> &'static vfs::FsInfo { + static INFO: vfs::FsInfo = vfs::FsInfo { + max_file_size: MAX_FILE_SIZE, + }; + &INFO + } } impl Drop for SimpleFileSystem { diff --git a/src/vfs.rs b/src/vfs.rs index b58e77e..be0c2a6 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -21,12 +21,12 @@ pub trait INode: Debug { fn sync(&mut self) -> Result<()>; // fn name_file(&mut self) -> Result<()>; // fn reclaim(&mut self) -> Result<()>; -// fn try_seek(&mut self, offset: u64) -> Result<()>; fn resize(&mut self, len: usize) -> Result<()>; fn create(&mut self, name: &'static str, type_: FileType) -> Result; fn lookup(&self, path: &'static str) -> Result; fn list(&self) -> Result>; // fn io_ctrl(&mut self, op: u32, data: &[u8]) -> Result<()>; + fn fs(&self) -> Weak; } #[derive(Debug, Eq, PartialEq)] @@ -42,12 +42,18 @@ pub enum FileType { File, Dir, } +#[derive(Debug)] +pub struct FsInfo { + pub max_file_size: usize, +} + pub type Result = core::result::Result; /// Abstract filesystem pub trait FileSystem { fn sync(&self) -> Result<()>; fn root_inode(&self) -> INodePtr; + fn info(&self) -> &'static FsInfo; // fn unmount(&self) -> Result<()>; // fn cleanup(&self); }