summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/data.rs9
-rw-r--r--src/main.rs31
2 files changed, 31 insertions, 9 deletions
diff --git a/src/data.rs b/src/data.rs
index 6976352..0db499c 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -15,13 +15,14 @@ pub fn get_data1() -> SimpleFsData {
SimpleFsData::File(2, "Hello, World!".to_string()))))
}
-pub fn traverse_fs<F>(file: SimpleFsData, f: &mut F)
+pub fn traverse_fs<F>(file: &SimpleFsData, f: &mut F)
where F: FnMut(& SimpleFsData) {
f(&file);
match file {
- SimpleFsData::Directory(_, children) => for (_, file) in children {
- traverse_fs(file, f);
- },
+ &SimpleFsData::Directory(_, ref children) =>
+ for &(_, ref file) in children {
+ traverse_fs(&file, f);
+ },
_ => (),
}
}
diff --git a/src/main.rs b/src/main.rs
index 1fc8e53..89b1f4d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ extern crate rafs;
extern crate time;
use rafs::data::get_data1;
-use rafs::data::SimpleFsData;
+use rafs::data::{SimpleFsData, traverse_fs};
use fuse::{Filesystem, Request, ReplyEntry, ReplyAttr, ReplyDirectory, ReplyData, FileAttr, FileType};
use libc::ENOENT;
use std::ffi::OsStr;
@@ -15,8 +15,9 @@ struct MemFs {
}
const CREATE_TIME: Timespec = Timespec { sec: 1494802762, nsec: 0 };
+const TTL: Timespec = Timespec { sec: 1, nsec: 0 };
-fn getAttr(file: SimpleFsData) -> FileAttr {
+fn getAttr(file: &SimpleFsData) -> FileAttr {
fn fileAttr(ino: u64, len: usize) -> FileAttr {
FileAttr {
ino: ino,
@@ -56,15 +57,35 @@ fn getAttr(file: SimpleFsData) -> FileAttr {
}
match file {
- SimpleFsData::File(ino, name) => fileAttr(ino, name.len()),
- SimpleFsData::Directory(ino, children) => dirAttr(ino, children.len()),
+ &SimpleFsData::File(ino, ref name) => fileAttr(ino, name.len()),
+ &SimpleFsData::Directory(ino, ref children) => dirAttr(ino, children.len()),
}
}
impl Filesystem for MemFs {
fn lookup(&mut self, _req: &Request, _parent: u64, _name: &OsStr,
reply: ReplyEntry) {
- reply.error(ENOENT);
+ let mut result: Option<FileAttr> = None;
+ {
+ let mut f = |ref file: &SimpleFsData| {
+ match *file {
+ &SimpleFsData::Directory(i, ref children) =>
+ if i == _parent {
+ for &(ref name, ref file) in children {
+ if Some(name.as_str()) == _name.to_str() {
+ result = Some(getAttr(file));
+ }
+ };
+ },
+ _ => ()
+ };
+ };
+ traverse_fs(&self.data, &mut f);
+ }
+ match result {
+ Some(r) => reply.entry(&TTL, &r, 0),
+ None => reply.error(ENOENT)
+ }
}
fn getattr(&mut self, _req: &Request, _ino: u64, reply: ReplyAttr) {