Merge branch 'misc_improvements' into 'master'
Couple of misc improvements See merge request redox-os/redoxfs!88
This commit is contained in:
+3
-30
@@ -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<u64>,
|
||||
@@ -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 {
|
||||
@@ -329,7 +302,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 +316,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]);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-12
@@ -169,12 +169,7 @@ unsafe impl<T> BlockTrait for BlockList<T> {
|
||||
|
||||
impl<T> BlockList<T> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +281,7 @@ impl<T> fmt::Debug for BlockPtr<T> {
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone)]
|
||||
pub struct BlockRaw([u8; BLOCK_SIZE as usize]);
|
||||
|
||||
unsafe impl BlockTrait for BlockRaw {
|
||||
@@ -298,12 +294,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] {
|
||||
|
||||
+2
-14
@@ -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<Node>,
|
||||
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 {
|
||||
@@ -75,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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ pub trait Resource<D: Disk> {
|
||||
|
||||
fn uid(&self) -> u32;
|
||||
|
||||
fn dup(&self) -> Result<Box<dyn Resource<D>>>;
|
||||
|
||||
fn set_path(&mut self, path: &str);
|
||||
|
||||
fn read(&mut self, buf: &mut [u8], offset: u64, tx: &mut Transaction<D>) -> Result<usize>;
|
||||
@@ -176,16 +174,6 @@ impl<D: Disk> Resource<D> for DirResource {
|
||||
self.uid
|
||||
}
|
||||
|
||||
fn dup(&self) -> Result<Box<dyn Resource<D>>> {
|
||||
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<D: Disk> Resource<D> for FileResource {
|
||||
self.uid
|
||||
}
|
||||
|
||||
fn dup(&self) -> Result<Box<dyn Resource<D>>> {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -452,30 +452,6 @@ impl<D: Disk> SchemeMut for FileScheme<D> {
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
#[allow(unused_variables)]
|
||||
fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||
// 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<usize> {
|
||||
// println!("Read {}, {:X} {}", id, buf.as_ptr() as usize, buf.len());
|
||||
let file = self.files.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
+1
-6
@@ -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] {
|
||||
|
||||
Reference in New Issue
Block a user