Skip to content

Commit

Permalink
remove obsolete clone operations
Browse files Browse the repository at this point in the history
- according to POSIX standard, the position between file descriptors
  will be shared after a dup operation
  • Loading branch information
stlankes committed Jan 15, 2024
1 parent f4205b8 commit 7aa591a
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/fs/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::arch;
use crate::fd::{AccessPermission, IoError, ObjectInterface, OpenOption};
use crate::fs::{DirectoryEntry, FileAttr, NodeKind, VfsNode};

#[derive(Debug, Clone)]
#[derive(Debug)]
pub(crate) struct RomFileInner {
pub data: &'static [u8],
pub attr: FileAttr,
Expand All @@ -37,10 +37,10 @@ impl RomFileInner {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
struct RomFileInterface {
/// Position within the file
pos: SpinMutex<usize>,
pos: Arc<SpinMutex<usize>>,
/// File content
inner: Arc<RwSpinLock<RomFileInner>>,
}
Expand Down Expand Up @@ -78,7 +78,7 @@ impl ObjectInterface for RomFileInterface {
impl RomFileInterface {
pub fn new(inner: Arc<RwSpinLock<RomFileInner>>) -> Self {
Self {
pos: SpinMutex::new(0),
pos: Arc::new(SpinMutex::new(0)),
inner,
}
}
Expand All @@ -88,16 +88,7 @@ impl RomFileInterface {
}
}

impl Clone for RomFileInterface {
fn clone(&self) -> Self {
Self {
pos: SpinMutex::new(*self.pos.lock()),
inner: self.inner.clone(),
}
}
}

#[derive(Debug, Clone)]
#[derive(Debug)]
pub(crate) struct RamFileInner {
pub data: Vec<u8>,
pub attr: FileAttr,
Expand All @@ -112,10 +103,10 @@ impl RamFileInner {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RamFileInterface {
/// Position within the file
pos: SpinMutex<usize>,
pos: Arc<SpinMutex<usize>>,
/// File content
inner: Arc<RwSpinLock<RamFileInner>>,
}
Expand Down Expand Up @@ -176,7 +167,7 @@ impl ObjectInterface for RamFileInterface {
impl RamFileInterface {
pub fn new(inner: Arc<RwSpinLock<RamFileInner>>) -> Self {
Self {
pos: SpinMutex::new(0),
pos: Arc::new(SpinMutex::new(0)),
inner,
}
}
Expand All @@ -186,15 +177,6 @@ impl RamFileInterface {
}
}

impl Clone for RamFileInterface {
fn clone(&self) -> Self {
Self {
pos: SpinMutex::new(*self.pos.lock()),
inner: self.inner.clone(),
}
}
}

#[derive(Debug)]
pub(crate) struct RomFile {
data: Arc<RwSpinLock<RomFileInner>>,
Expand Down

0 comments on commit 7aa591a

Please sign in to comment.