diff --git a/rcore-fs-sfs/src/lib.rs b/rcore-fs-sfs/src/lib.rs index 0b61166..1bd0f0d 100644 --- a/rcore-fs-sfs/src/lib.rs +++ b/rcore-fs-sfs/src/lib.rs @@ -406,6 +406,21 @@ impl INodeImpl { child.nlinks_inc(); Ok(()) } + + pub fn call_ioctl(&self, request: u32, data: *mut u8) -> Result<(), IOCTLError> { + if self.metadata().unwrap().type_ != vfs::FileType::CharDevice { + return Err(IOCTLError::NotCharDevice); + } + let device_inodes = self.fs.device_inodes.read(); + let device_inode = device_inodes.get(&self.device_inode_id); + match device_inode { + Some(x) => { x.ioctl(request, data) } + None => { + warn!("cannot find corresponding device inode in call_inoctl"); + Err(IOCTLError::NotCharDevice) + } + } + } } impl vfs::INode for INodeImpl { @@ -836,13 +851,6 @@ impl SimpleFileSystem { self.device_inodes.write().insert(device_inode_id, device_inode); } - pub fn get_device_inode(&self, device_inode_id: usize) -> vfs::Result> { - match self.device_inodes.read().get(&device_inode_id) { - Some(x) => Ok(Arc::clone(x)), - None => Err(FsError::DeviceError) - } - } - /// Create a new INode struct, then insert it to self.inodes /// Private used for load or create INode fn _new_inode(&self, id: INodeId, disk_inode: Dirty) -> Arc { diff --git a/rcore-fs-sfs/src/structs.rs b/rcore-fs-sfs/src/structs.rs index fd84e98..b8e09e9 100644 --- a/rcore-fs-sfs/src/structs.rs +++ b/rcore-fs-sfs/src/structs.rs @@ -55,7 +55,23 @@ pub trait DeviceINode : Any + Sync + Send{ } */ -pub type DeviceINode = vfs::INode; +// pub type DeviceINode = vfs::INode; +pub trait DeviceINode : vfs::INode { + fn ioctl(&self, request: u32, data: *mut u8) -> Result<(), IOCTLError>; +} + +impl DeviceINode { + fn ioctl(&self, request: u32, data: *mut u8) -> Result<(), IOCTLError> { + Ok(()) + } +} + +pub enum IOCTLError { + NotValidFD = 9, // EBADF + NotValidMemory = 14, // EFAULT + NotValidParam = 22, // EINVAL + NotCharDevice = 25, // ENOTTY +} #[repr(C)] pub struct IndirectBlock {