Commit 15313f98 authored by Jeremy Soller's avatar Jeremy Soller

Remove unnecessary dup implementations

parent 9570de21
......@@ -59,22 +59,6 @@ impl Scheme for DebugScheme {
Ok(id)
}
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let flags = {
let handles = handles();
*handles.get(&id).ok_or(Error::new(EBADF))?
};
let new_id = NEXT_ID.fetch_add(1, Ordering::SeqCst);
handles_mut().insert(new_id, flags);
Ok(new_id)
}
/// Read the file `number` into the `buffer`
///
/// Returns the number of bytes read
......
......@@ -19,7 +19,6 @@ include!(concat!(env!("OUT_DIR"), "/gen.rs"));
struct Handle {
path: &'static [u8],
flags: usize,
data: &'static [u8],
mode: u16,
seek: usize
......@@ -42,7 +41,7 @@ impl InitFsScheme {
}
impl Scheme for InitFsScheme {
fn open(&self, path: &[u8], flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
let path_utf8 = str::from_utf8(path).or(Err(Error::new(ENOENT)))?;
let path_trimmed = path_utf8.trim_matches('/');
......@@ -52,7 +51,6 @@ impl Scheme for InitFsScheme {
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.write().insert(id, Handle {
path: entry.0,
flags: flags,
data: (entry.1).0,
mode: if (entry.1).1 { MODE_DIR | 0o755 } else { MODE_FILE | 0o744 },
seek: 0
......@@ -65,29 +63,6 @@ impl Scheme for InitFsScheme {
Err(Error::new(ENOENT))
}
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let (path, flags, data, mode, seek) = {
let handles = self.handles.read();
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
(handle.path, handle.flags, handle.data, handle.mode, handle.seek)
};
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.write().insert(id, Handle {
path: path,
flags: flags,
data: data,
mode: mode,
seek: seek
});
Ok(id)
}
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
let mut handles = self.handles.write();
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
......
......@@ -48,14 +48,6 @@ impl Scheme for IrqScheme {
}
}
fn dup(&self, file: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
Ok(file)
}
fn read(&self, file: usize, buffer: &mut [u8]) -> Result<usize> {
// Ensures that the length of the buffer is larger than the size of a usize
if buffer.len() >= mem::size_of::<usize>() {
......
......@@ -64,28 +64,6 @@ impl Scheme for DiskScheme {
Ok(id)
}
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let (path, data, mode, seek) = {
let handles = self.handles.read();
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
(handle.path, handle.data.clone(), handle.mode, handle.seek)
};
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.write().insert(id, Handle {
path: path,
data: data,
mode: mode,
seek: seek
});
Ok(id)
}
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
let mut handles = self.handles.write();
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
......
......@@ -53,38 +53,6 @@ impl PipeScheme {
}
impl Scheme for PipeScheme {
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let mut pipes = pipes_mut();
let read_option = if let Some(pipe) = pipes.0.get(&id) {
Some(pipe.dup()?)
} else {
None
};
if let Some(pipe) = read_option {
let pipe_id = PIPE_NEXT_ID.fetch_add(1, Ordering::SeqCst);
pipes.0.insert(pipe_id, Arc::new(pipe));
return Ok(pipe_id);
}
let write_option = if let Some(pipe) = pipes.1.get(&id) {
Some(pipe.dup()?)
} else {
None
};
if let Some(pipe) = write_option {
let pipe_id = PIPE_NEXT_ID.fetch_add(1, Ordering::SeqCst);
pipes.1.insert(pipe_id, Arc::new(pipe));
return Ok(pipe_id);
}
Err(Error::new(EBADF))
}
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
// Clone to prevent deadlocks
let pipe = {
......@@ -186,16 +154,6 @@ impl PipeRead {
}
}
fn dup(&self) -> Result<Self> {
Ok(PipeRead {
scheme_id: self.scheme_id,
event_id: self.event_id,
flags: AtomicUsize::new(self.flags.load(Ordering::SeqCst)),
condition: self.condition.clone(),
vec: self.vec.clone()
})
}
fn fcntl(&self, cmd: usize, arg: usize) -> Result<usize> {
match cmd {
F_GETFL => Ok(self.flags.load(Ordering::SeqCst)),
......@@ -264,16 +222,6 @@ impl PipeWrite {
}
}
fn dup(&self) -> Result<Self> {
Ok(PipeWrite {
scheme_id: self.scheme_id,
event_id: self.event_id,
flags: AtomicUsize::new(self.flags.load(Ordering::SeqCst)),
condition: self.condition.clone(),
vec: self.vec.clone()
})
}
fn fcntl(&self, cmd: usize, arg: usize) -> Result<usize> {
match cmd {
F_GETFL => Ok(self.flags.load(Ordering::SeqCst)),
......
......@@ -127,23 +127,6 @@ impl Scheme for RootScheme {
}
}
fn dup(&self, file: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let mut handles = self.handles.write();
let inner = {
let inner = handles.get(&file).ok_or(Error::new(EBADF))?;
inner.clone()
};
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
handles.insert(id, inner);
Ok(id)
}
fn read(&self, file: usize, buf: &mut [u8]) -> Result<usize> {
let handle = {
let handles = self.handles.read();
......
......@@ -96,28 +96,6 @@ impl Scheme for SysScheme {
Err(Error::new(ENOENT))
}
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let (path, data, mode, seek) = {
let handles = self.handles.read();
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
(handle.path, handle.data.clone(), handle.mode, handle.seek)
};
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.write().insert(id, Handle {
path: path,
data: data,
mode: mode,
seek: seek
});
Ok(id)
}
fn read(&self, id: usize, buffer: &mut [u8]) -> Result<usize> {
let mut handles = self.handles.write();
let handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
......
......@@ -45,21 +45,6 @@ impl Scheme for TimeScheme {
Ok(id)
}
fn dup(&self, id: usize, buf: &[u8]) -> Result<usize> {
if ! buf.is_empty() {
return Err(Error::new(EINVAL));
}
let clock = {
let handles = self.handles.read();
*handles.get(&id).ok_or(Error::new(EBADF))?
};
let new_id = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.write().insert(new_id, clock);
Ok(new_id)
}
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
let clock = {
let handles = self.handles.read();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment