Fuse fixes, file read/write implemented
This commit is contained in:
+4
-67
@@ -1,9 +1,8 @@
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use collections::{String, Vec};
|
||||
use collections::borrow::ToOwned;
|
||||
use collections::Vec;
|
||||
|
||||
use system::error::{Result, Error, EEXIST, EISDIR, ENOENT, ENOSPC, ENOTDIR, ENOTEMPTY, EPERM};
|
||||
use system::error::{Result, Error, EEXIST, EISDIR, ENOENT, ENOSPC, ENOTDIR, ENOTEMPTY};
|
||||
|
||||
use super::{Disk, ExNode, Extent, Header, Node};
|
||||
|
||||
@@ -142,7 +141,7 @@ impl FileSystem {
|
||||
self.find_node(name, parent.1.next)
|
||||
}
|
||||
|
||||
fn path_nodes(&mut self, path: &str, nodes: &mut Vec<(u64, Node)>) -> Result<(u64, Node)> {
|
||||
pub fn path_nodes(&mut self, path: &str, nodes: &mut Vec<(u64, Node)>) -> Result<(u64, Node)> {
|
||||
let mut block = self.header.1.root;
|
||||
nodes.push(try!(self.node(block)));
|
||||
|
||||
@@ -221,7 +220,7 @@ impl FileSystem {
|
||||
let mut replace_option = None;
|
||||
let mut parent = try!(self.node(parent_block));
|
||||
for mut extent in parent.1.extents.iter_mut() {
|
||||
if block >= extent.block && block + length <= extent.block + length/512 {
|
||||
if block >= extent.block && block + length <= extent.block + extent.length/512 {
|
||||
//Inside
|
||||
removed = true;
|
||||
|
||||
@@ -423,66 +422,4 @@ impl FileSystem {
|
||||
Ok(size)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mkdir(&mut self, path: &str) -> Result<usize> {
|
||||
let mut nodes = Vec::new();
|
||||
match self.path_nodes(path, &mut nodes) {
|
||||
Ok(_node) => Err(Error::new(EEXIST)),
|
||||
Err(err) => if err.errno == ENOENT {
|
||||
let mut last_part = String::new();
|
||||
for part in path.split('/') {
|
||||
if ! part.is_empty() {
|
||||
last_part = part.to_owned();
|
||||
}
|
||||
}
|
||||
if ! last_part.is_empty() {
|
||||
if let Some(parent) = nodes.last() {
|
||||
self.create_node(Node::MODE_DIR, &last_part, parent.0).and(Ok(0))
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
} else {
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rmdir(&mut self, path: &str) -> Result<usize> {
|
||||
let mut nodes = Vec::new();
|
||||
let child = try!(self.path_nodes(path, &mut nodes));
|
||||
if let Some(parent) = nodes.last() {
|
||||
if child.1.is_dir() {
|
||||
if let Ok(child_name) = child.1.name() {
|
||||
self.remove_node(Node::MODE_DIR, child_name, parent.0).and(Ok(0))
|
||||
} else {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(ENOTDIR))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlink(&mut self, path: &str) -> Result<usize> {
|
||||
let mut nodes = Vec::new();
|
||||
let child = try!(self.path_nodes(path, &mut nodes));
|
||||
if let Some(parent) = nodes.last() {
|
||||
if ! child.1.is_dir() {
|
||||
if let Ok(child_name) = child.1.name() {
|
||||
self.remove_node(Node::MODE_FILE, child_name, parent.0).and(Ok(0))
|
||||
} else {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EISDIR))
|
||||
}
|
||||
} else {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user