Skip to content
Snippets Groups Projects
Commit e4ca510b authored by George Malandrakis's avatar George Malandrakis Committed by Jeremy Soller
Browse files

Master - Name check & Duplicate code removed & Makefile modification

parent e7cf569a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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};
......
......@@ -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>,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment