Master - Name check & Duplicate code removed & Makefile modification
This commit is contained in:
committed by
Jeremy Soller
parent
e7cf569a1f
commit
e4ca510bc0
@@ -14,8 +14,8 @@ else
|
||||
endif
|
||||
|
||||
image.bin:
|
||||
dd if=/dev/zero of=image.bin bs=1048576 count=1024
|
||||
cargo build --release --bin redoxfs-mkfs
|
||||
dd if=/dev/zero of=image.bin bs=1048576 count=1024
|
||||
target/release/redoxfs-mkfs image.bin
|
||||
|
||||
mount: image.bin FORCE
|
||||
|
||||
+5
-9
@@ -1,28 +1,24 @@
|
||||
use alloc::{boxed::Box, vec};
|
||||
use core::{mem, ops, slice, str};
|
||||
|
||||
use crate::{BlockLevel, BlockTrait, Node, TreePtr, RECORD_LEVEL};
|
||||
use crate::{BlockLevel, BlockTrait, Node, TreePtr, RECORD_LEVEL, DIR_ENTRY_MAX_LENGTH};
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct DirEntry {
|
||||
node_ptr: TreePtr<Node>,
|
||||
name: [u8; 252],
|
||||
name: [u8; DIR_ENTRY_MAX_LENGTH],
|
||||
}
|
||||
|
||||
impl DirEntry {
|
||||
pub fn new(node_ptr: TreePtr<Node>, name: &str) -> Option<DirEntry> {
|
||||
pub fn new(node_ptr: TreePtr<Node>, name: &str) -> DirEntry {
|
||||
let mut entry = DirEntry {
|
||||
node_ptr,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if name.len() > entry.name.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
entry.name[..name.len()].copy_from_slice(name.as_bytes());
|
||||
|
||||
Some(entry)
|
||||
entry
|
||||
}
|
||||
|
||||
pub fn node_ptr(&self) -> TreePtr<Node> {
|
||||
@@ -54,7 +50,7 @@ impl Default for DirEntry {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
node_ptr: TreePtr::default(),
|
||||
name: [0; 252],
|
||||
name: [0; DIR_ENTRY_MAX_LENGTH],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ pub const RECORD_LEVEL: usize = 5;
|
||||
pub const RECORD_SIZE: u64 = BLOCK_SIZE << RECORD_LEVEL;
|
||||
pub const SIGNATURE: &[u8; 8] = b"RedoxFS\0";
|
||||
pub const VERSION: u64 = 6;
|
||||
pub const DIR_ENTRY_MAX_LENGTH: usize = 252;
|
||||
|
||||
pub static IS_UMT: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
pub use self::allocator::{AllocEntry, AllocList, Allocator, ALLOC_LIST_ENTRIES};
|
||||
|
||||
+25
-19
@@ -12,11 +12,7 @@ use syscall::error::{
|
||||
Error, Result, EEXIST, EINVAL, EIO, EISDIR, ENOENT, ENOSPC, ENOTDIR, ENOTEMPTY, ERANGE,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AllocEntry, AllocList, Allocator, BlockAddr, BlockData, BlockLevel, BlockPtr, BlockTrait,
|
||||
DirEntry, DirList, Disk, FileSystem, Header, Node, NodeLevel, RecordRaw, TreeData, TreePtr,
|
||||
ALLOC_LIST_ENTRIES, HEADER_RING,
|
||||
};
|
||||
use crate::{AllocEntry, AllocList, Allocator, BlockAddr, BlockData, BlockLevel, BlockPtr, BlockTrait, DirEntry, DirList, Disk, FileSystem, Header, Node, NodeLevel, RecordRaw, TreeData, TreePtr, ALLOC_LIST_ENTRIES, HEADER_RING, DIR_ENTRY_MAX_LENGTH};
|
||||
|
||||
pub struct Transaction<'a, D: Disk> {
|
||||
fs: &'a mut FileSystem<D>,
|
||||
@@ -569,12 +565,8 @@ impl<'a, D: Disk> Transaction<'a, D> {
|
||||
ctime: u64,
|
||||
ctime_nsec: u32,
|
||||
) -> Result<TreeData<Node>> {
|
||||
if name.contains(':') {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
|
||||
if self.find_node(parent_ptr, name).is_ok() {
|
||||
return Err(Error::new(EEXIST));
|
||||
if let Err(err) = self.check_name(&parent_ptr, &name){
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
@@ -605,13 +597,11 @@ impl<'a, D: Disk> Transaction<'a, D> {
|
||||
name: &str,
|
||||
node_ptr: TreePtr<Node>,
|
||||
) -> Result<()> {
|
||||
if name.contains(':') {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
if let Err(err) = self.check_name(&parent_ptr, &name){
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
if self.find_node(parent_ptr, name).is_ok() {
|
||||
return Err(Error::new(EEXIST));
|
||||
}
|
||||
let entry = DirEntry::new(node_ptr, name);
|
||||
|
||||
let mut parent = self.read_tree(parent_ptr)?;
|
||||
|
||||
@@ -619,8 +609,6 @@ impl<'a, D: Disk> Transaction<'a, D> {
|
||||
let links = node.data().links();
|
||||
node.data_mut().set_links(links + 1);
|
||||
|
||||
let entry = DirEntry::new(node_ptr, name).ok_or(Error::new(EINVAL))?;
|
||||
|
||||
let record_level = parent.data().record_level();
|
||||
let record_end = parent.data().size() / record_level.bytes();
|
||||
for record_offset in 0..record_end {
|
||||
@@ -795,6 +783,24 @@ impl<'a, D: Disk> Transaction<'a, D> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_name(&mut self,
|
||||
parent_ptr: &TreePtr<Node>,
|
||||
name: &str) -> Result<()> {
|
||||
if name.contains(':') {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
|
||||
if name.len() > DIR_ENTRY_MAX_LENGTH {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
|
||||
if self.find_node(parent_ptr.clone(), name).is_ok() {
|
||||
return Err(Error::new(EEXIST));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn node_record_ptr(
|
||||
&mut self,
|
||||
node: &TreeData<Node>,
|
||||
|
||||
Reference in New Issue
Block a user