fix ioctl bug

master
gaotianyu1350 6 years ago
parent 0bc5a7dcfd
commit 958fd0844e

@ -406,21 +406,6 @@ 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 {
@ -707,6 +692,21 @@ impl vfs::INode for INodeImpl {
fn as_any_ref(&self) -> &Any { fn as_any_ref(&self) -> &Any {
self self
} }
fn ioctl(&self, request: u32, data: *mut u8) -> Result<(), vfs::IOCTLError> {
if self.metadata().unwrap().type_ != vfs::FileType::CharDevice {
return Err(vfs::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(vfs::IOCTLError::NotCharDevice)
}
}
}
} }
impl Drop for INodeImpl { impl Drop for INodeImpl {

@ -55,23 +55,7 @@ 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 {

@ -32,6 +32,7 @@ pub trait INode: Any + Sync + Send {
/// this is used to implement dynamics cast /// this is used to implement dynamics cast
/// simply return self in the implement of the function /// simply return self in the implement of the function
fn as_any_ref(&self) -> &Any; fn as_any_ref(&self) -> &Any;
fn ioctl(&self, request: u32, data: *mut u8) -> result::Result<(), IOCTLError>;
} }
impl INode { impl INode {
@ -111,6 +112,14 @@ impl INode {
} }
Ok(result) Ok(result)
} }
}
pub enum IOCTLError {
NotValidFD = 9, // EBADF
NotValidMemory = 14, // EFAULT
NotValidParam = 22, // EINVAL
NotCharDevice = 25, // ENOTTY
} }
/// Metadata of INode /// Metadata of INode

Loading…
Cancel
Save