Remove unreachable dup impls

Dup calls with an empty path never reach scheme implementations
This commit is contained in:
bjorn3
2025-03-30 17:51:07 +02:00
parent 83c8234808
commit 8286249ff7
10 changed files with 1 additions and 69 deletions
-24
View File
@@ -57,30 +57,6 @@ impl SchemeMut for LogScheme {
Ok(id)
}
fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<usize> {
if !buf.is_empty() {
return Err(Error::new(EINVAL));
}
let context = {
let handle = self.handles.get(&old_id).ok_or(Error::new(EBADF))?;
handle.context.clone()
};
let id = self.next_id;
self.next_id += 1;
self.handles.insert(
id,
LogHandle {
context,
bufs: BTreeMap::new(),
},
);
Ok(id)
}
fn read(&mut self, id: usize, _buf: &mut [u8], _offset: u64, _flags: u32) -> Result<usize> {
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
-6
View File
@@ -8,7 +8,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyControlTerm {
pty: Rc<RefCell<Pty>>,
flags: usize,
@@ -28,10 +27,6 @@ impl PtyControlTerm {
}
impl Resource for PtyControlTerm {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
Rc::downgrade(&self.pty)
}
@@ -45,7 +40,6 @@ impl Resource for PtyControlTerm {
}
fn read(&mut self, buf: &mut [u8]) -> Result<Option<usize>> {
self.notified_read = false;
let mut pty = self.pty.borrow_mut();
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyPgrp {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyPgrp {
}
impl Resource for PtyPgrp {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-1
View File
@@ -7,7 +7,6 @@ use syscall::flag::EventFlags;
use crate::pty::Pty;
pub trait Resource {
fn boxed_clone(&self) -> Box<dyn Resource>;
fn pty(&self) -> Weak<RefCell<Pty>>;
fn flags(&self) -> usize;
+1 -3
View File
@@ -64,9 +64,7 @@ impl SchemeBlock for PtyScheme {
let handle: Box<dyn Resource> = {
let old_handle = self.handles.get(&old_id).ok_or(Error::new(EBADF))?;
if buf.is_empty() {
old_handle.boxed_clone()
} else if buf == b"pgrp" {
if buf == b"pgrp" {
Box::new(PtyPgrp::new(old_handle.pty(), old_handle.flags()))
} else if buf == b"termios" {
Box::new(PtyTermios::new(old_handle.pty(), old_handle.flags()))
-6
View File
@@ -8,7 +8,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtySubTerm {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -28,10 +27,6 @@ impl PtySubTerm {
}
impl Resource for PtySubTerm {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
@@ -49,7 +44,6 @@ impl Resource for PtySubTerm {
}
fn read(&mut self, buf: &mut [u8]) -> Result<Option<usize>> {
self.notified_read = false;
if let Some(pty_lock) = self.pty.upgrade() {
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyTermios {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyTermios {
}
impl Resource for PtyTermios {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-5
View File
@@ -9,7 +9,6 @@ use crate::pty::Pty;
use crate::resource::Resource;
/// Read side of a pipe
#[derive(Clone)]
pub struct PtyWinsize {
pty: Weak<RefCell<Pty>>,
flags: usize,
@@ -25,10 +24,6 @@ impl PtyWinsize {
}
impl Resource for PtyWinsize {
fn boxed_clone(&self) -> Box<dyn Resource> {
Box::new(self.clone())
}
fn pty(&self) -> Weak<RefCell<Pty>> {
self.pty.clone()
}
-6
View File
@@ -247,12 +247,6 @@ impl SchemeSync for Scheme {
fn unlink(&mut self, path: &str, ctx: &CallerCtx) -> Result<()> {
self.remove_dentry(path, ctx.uid, ctx.gid, false)
}
fn dup(&mut self, old_inode: usize, _buf: &[u8], _ctx: &CallerCtx) -> Result<OpenResult> {
Ok(OpenResult::ThisScheme {
number: old_inode,
flags: NewFdFlags::POSITIONED,
})
}
fn read(
&mut self,
inode: usize,
-8
View File
@@ -10,14 +10,6 @@ impl SchemeMut for ZeroScheme {
Ok(0)
}
fn dup(&mut self, _file: usize, buf: &[u8]) -> Result<usize> {
if !buf.is_empty() {
return Err(Error::new(EINVAL));
}
Ok(0)
}
fn read(&mut self, _file: usize, buf: &mut [u8], _offset: u64, _flags: u32) -> Result<usize> {
match self.0 {
Ty::Null => Ok(0),