add call ioctl for inodeimpl

master
gaotianyu1350 6 years ago
parent 83c218aadb
commit 4ed2ad6967

@ -406,6 +406,21 @@ impl INodeImpl {
child.nlinks_inc(); child.nlinks_inc();
Ok(()) 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 { impl vfs::INode for INodeImpl {
@ -836,13 +851,6 @@ impl SimpleFileSystem {
self.device_inodes.write().insert(device_inode_id, device_inode); self.device_inodes.write().insert(device_inode_id, device_inode);
} }
pub fn get_device_inode(&self, device_inode_id: usize) -> vfs::Result<Arc<DeviceINode>> {
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 /// Create a new INode struct, then insert it to self.inodes
/// Private used for load or create INode /// Private used for load or create INode
fn _new_inode(&self, id: INodeId, disk_inode: Dirty<DiskINode>) -> Arc<INodeImpl> { fn _new_inode(&self, id: INodeId, disk_inode: Dirty<DiskINode>) -> Arc<INodeImpl> {

@ -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)] #[repr(C)]
pub struct IndirectBlock { pub struct IndirectBlock {

Loading…
Cancel
Save