From 29e818afaa7f29ecba49aba4f934a6034f66a02c Mon Sep 17 00:00:00 2001 From: gjz010 Date: Thu, 13 Jun 2019 21:04:52 +0800 Subject: [PATCH] Added INode::create2() which allows creating devicefile with argument. Default INode::create2() and INode::create() implements each other so (perhaps) no worry about compatability. Implemented INode::create2() for SFS. --- rcore-fs-sfs/src/lib.rs | 4 +++- rcore-fs/src/vfs.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rcore-fs-sfs/src/lib.rs b/rcore-fs-sfs/src/lib.rs index 2acb580..1587313 100644 --- a/rcore-fs-sfs/src/lib.rs +++ b/rcore-fs-sfs/src/lib.rs @@ -498,7 +498,7 @@ impl vfs::INode for INodeImpl { } self._resize(len) } - fn create(&self, name: &str, type_: vfs::FileType, _mode: u32) -> vfs::Result> { + fn create2(&self, name: &str, type_: vfs::FileType, _mode: u32, data: usize)->vfs::Result>{ let info = self.metadata()?; if info.type_ != vfs::FileType::Dir { return Err(FsError::NotDir); @@ -517,6 +517,7 @@ impl vfs::INode for INodeImpl { vfs::FileType::File => self.fs.new_inode_file()?, vfs::FileType::SymLink => self.fs.new_inode_symlink()?, vfs::FileType::Dir => self.fs.new_inode_dir(self.id)?, + vfs::FileType::CharDevice => self.fs.new_inode_chardevice(data)?, _ => return Err(vfs::FsError::InvalidParam), }; @@ -533,6 +534,7 @@ impl vfs::INode for INodeImpl { Ok(inode) } + fn link(&self, name: &str, other: &Arc) -> vfs::Result<()> { let info = self.metadata()?; if info.type_ != vfs::FileType::Dir { diff --git a/rcore-fs/src/vfs.rs b/rcore-fs/src/vfs.rs index 083ce7d..0aa974a 100644 --- a/rcore-fs/src/vfs.rs +++ b/rcore-fs/src/vfs.rs @@ -32,7 +32,14 @@ pub trait INode: Any + Sync + Send { fn resize(&self, len: usize) -> Result<()>; /// Create a new INode in the directory - fn create(&self, name: &str, type_: FileType, mode: u32) -> Result>; + fn create(&self, name: &str, type_: FileType, mode: u32) -> Result>{ + self.create2(name, type_, mode, 0) + } + + /// Create a new INode in the directory, with a data field for usages like device file. + fn create2(&self, name: &str, type_: FileType, mode: u32, data: usize) -> Result>{ + self.create(name, type_, mode) + } /// Create a hard link `name` to `other` fn link(&self, name: &str, other: &Arc) -> Result<()>;