From 5ee3138d3d53b0b002190ea4768be11876561823 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:42:54 +0200 Subject: [PATCH 1/4] Fix cargo test Rustc complained about being unable to infer the type for [] --- src/allocator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 71c2939491..f4e306bc88 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -329,7 +329,7 @@ fn allocator_test() { } else if level == 10 { assert_eq!(alloc.levels[level], [1024]); } else { - assert_eq!(alloc.levels[level], []); + assert_eq!(alloc.levels[level], [0u64; 0]); } } @@ -343,6 +343,6 @@ fn allocator_test() { assert_eq!(alloc.levels.len(), 11); for level in 0..alloc.levels.len() { - assert_eq!(alloc.levels[level], []); + assert_eq!(alloc.levels[level], [0u64; 0]); } } From dc507f7e2a0cf1b2b4f9bfb5d76aae0a78595f6c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:43:51 +0200 Subject: [PATCH 2/4] Remove unreachable dup impl --- src/mount/redox/resource.rs | 22 ---------------------- src/mount/redox/scheme.rs | 24 ------------------------ 2 files changed, 46 deletions(-) diff --git a/src/mount/redox/resource.rs b/src/mount/redox/resource.rs index 8d59693c36..bf556e7638 100644 --- a/src/mount/redox/resource.rs +++ b/src/mount/redox/resource.rs @@ -24,8 +24,6 @@ pub trait Resource { fn uid(&self) -> u32; - fn dup(&self) -> Result>>; - fn set_path(&mut self, path: &str); fn read(&mut self, buf: &mut [u8], offset: u64, tx: &mut Transaction) -> Result; @@ -176,16 +174,6 @@ impl Resource for DirResource { self.uid } - fn dup(&self) -> Result>> { - Ok(Box::new(DirResource { - path: self.path.clone(), - parent_ptr_opt: self.parent_ptr_opt, - node_ptr: self.node_ptr, - data: self.data.clone(), - uid: self.uid, - })) - } - fn set_path(&mut self, path: &str) { self.path = path.to_string(); } @@ -375,16 +363,6 @@ impl Resource for FileResource { self.uid } - fn dup(&self) -> Result>> { - Ok(Box::new(FileResource { - path: self.path.clone(), - parent_ptr_opt: self.parent_ptr_opt, - node_ptr: self.node_ptr, - flags: self.flags, - uid: self.uid, - })) - } - fn set_path(&mut self, path: &str) { self.path = path.to_string(); } diff --git a/src/mount/redox/scheme.rs b/src/mount/redox/scheme.rs index bef17cfc99..f64f58d03b 100644 --- a/src/mount/redox/scheme.rs +++ b/src/mount/redox/scheme.rs @@ -452,30 +452,6 @@ impl SchemeMut for FileScheme { } /* Resource operations */ - #[allow(unused_variables)] - fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result { - // println!("Dup {}", old_id); - - if !buf.is_empty() { - return Err(Error::new(EINVAL)); - } - - let resource = if let Some(old_resource) = self.files.get(&old_id) { - old_resource.dup()? - } else { - return Err(Error::new(EBADF)); - }; - - self.fmap - .get_mut(&resource.node_ptr().id()) - .ok_or(Error::new(EBADFD))? - .open_fds += 1; - let id = self.next_id.fetch_add(1, Ordering::SeqCst); - self.files.insert(id, resource); - - Ok(id) - } - fn read(&mut self, id: usize, buf: &mut [u8], offset: u64, _fcntl_flags: u32) -> Result { // println!("Read {}, {:X} {}", id, buf.as_ptr() as usize, buf.len()); let file = self.files.get_mut(&id).ok_or(Error::new(EBADF))?; From 22f759aa4f459e9e40328644f2036624a3e169a0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:51:10 +0200 Subject: [PATCH 3/4] Rustc now allows many derives for packed structs --- src/allocator.rs | 29 +---------------------------- src/block.rs | 7 +------ src/dir.rs | 9 +-------- src/record.rs | 7 +------ 4 files changed, 4 insertions(+), 48 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index f4e306bc88..286695c2bf 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -172,6 +172,7 @@ impl Allocator { } #[repr(C, packed)] +#[derive(Clone, Copy, Default, Debug)] pub struct AllocEntry { /// The index of the first block this [`AllocEntry`] refers to index: Le, @@ -210,34 +211,6 @@ impl AllocEntry { } } -impl Clone for AllocEntry { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for AllocEntry {} - -impl Default for AllocEntry { - fn default() -> Self { - Self { - index: 0.into(), - count: 0.into(), - } - } -} - -impl fmt::Debug for AllocEntry { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let index = self.index(); - let count = self.count(); - f.debug_struct("AllocEntry") - .field("index", &index) - .field("count", &count) - .finish() - } -} - /// A node in the allocation chain. #[repr(C, packed)] pub struct AllocList { diff --git a/src/block.rs b/src/block.rs index b66a66d2f1..5e677ec7ec 100644 --- a/src/block.rs +++ b/src/block.rs @@ -286,6 +286,7 @@ impl fmt::Debug for BlockPtr { } #[repr(C, packed)] +#[derive(Clone)] pub struct BlockRaw([u8; BLOCK_SIZE as usize]); unsafe impl BlockTrait for BlockRaw { @@ -298,12 +299,6 @@ unsafe impl BlockTrait for BlockRaw { } } -impl Clone for BlockRaw { - fn clone(&self) -> Self { - Self(self.0) - } -} - impl ops::Deref for BlockRaw { type Target = [u8]; fn deref(&self) -> &[u8] { diff --git a/src/dir.rs b/src/dir.rs index 63846516b2..f9a23c1c7d 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -4,6 +4,7 @@ use core::{mem, ops, slice, str}; use crate::{BlockLevel, BlockTrait, Node, TreePtr, DIR_ENTRY_MAX_LENGTH, RECORD_LEVEL}; #[repr(C, packed)] +#[derive(Clone, Copy)] pub struct DirEntry { node_ptr: TreePtr, name: [u8; DIR_ENTRY_MAX_LENGTH], @@ -38,14 +39,6 @@ impl DirEntry { } } -impl Clone for DirEntry { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for DirEntry {} - impl Default for DirEntry { fn default() -> Self { Self { diff --git a/src/record.rs b/src/record.rs index 6a9556b89d..e7815a42c0 100644 --- a/src/record.rs +++ b/src/record.rs @@ -4,6 +4,7 @@ use core::ops; use crate::{BlockLevel, BlockTrait, RECORD_LEVEL}; //TODO: this is a box to prevent stack overflows +#[derive(Clone)] pub struct RecordRaw(Box<[u8]>); unsafe impl BlockTrait for RecordRaw { @@ -16,12 +17,6 @@ unsafe impl BlockTrait for RecordRaw { } } -impl Clone for RecordRaw { - fn clone(&self) -> Self { - Self(self.0.clone()) - } -} - impl ops::Deref for RecordRaw { type Target = [u8]; fn deref(&self) -> &[u8] { From 7e3915deb6f34eba642ca439a1b98bb333972ebf Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:53:28 +0200 Subject: [PATCH 4/4] Use Iterator::all in two places --- src/block.rs | 7 +------ src/dir.rs | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/block.rs b/src/block.rs index 5e677ec7ec..a429ce089f 100644 --- a/src/block.rs +++ b/src/block.rs @@ -169,12 +169,7 @@ unsafe impl BlockTrait for BlockList { impl BlockList { pub fn is_empty(&self) -> bool { - for ptr in self.ptrs.iter() { - if !ptr.is_null() { - return false; - } - } - true + self.ptrs.iter().all(|ptr| ptr.is_null()) } } diff --git a/src/dir.rs b/src/dir.rs index f9a23c1c7d..d65a5d9f4a 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -68,12 +68,7 @@ unsafe impl BlockTrait for DirList { impl DirList { pub fn is_empty(&self) -> bool { - for entry in self.entries.iter() { - if !entry.node_ptr().is_null() { - return false; - } - } - true + self.entries.iter().all(|entry| entry.node_ptr().is_null()) } }