summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data.rs26
-rw-r--r--src/main.rs51
2 files changed, 76 insertions, 1 deletions
diff --git a/src/data.rs b/src/data.rs
index f652a13..6976352 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -14,3 +14,29 @@ pub fn get_data1() -> SimpleFsData {
1, vec!(("hello".to_string(),
SimpleFsData::File(2, "Hello, World!".to_string()))))
}
+
+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);
+ },
+ _ => (),
+ }
+}
+
+#[test]
+fn traverse() {
+ let mut result = String::new();
+ {
+ let mut f = |ref file: &SimpleFsData| {
+ match *file {
+ &SimpleFsData::File(_, ref s) => result += &s,
+ _ => (),
+ };
+ };
+ traverse_fs(get_data1(), &mut f);
+ }
+ assert_eq!("Hello, World!", result);
+}
diff --git a/src/main.rs b/src/main.rs
index 9ad2982..1fc8e53 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,17 +1,66 @@
extern crate fuse;
extern crate libc;
extern crate rafs;
+extern crate time;
use rafs::data::get_data1;
use rafs::data::SimpleFsData;
-use fuse::{Filesystem, Request, ReplyEntry, ReplyAttr, ReplyDirectory, ReplyData};
+use fuse::{Filesystem, Request, ReplyEntry, ReplyAttr, ReplyDirectory, ReplyData, FileAttr, FileType};
use libc::ENOENT;
use std::ffi::OsStr;
+use time::Timespec;
struct MemFs {
data: SimpleFsData,
}
+const CREATE_TIME: Timespec = Timespec { sec: 1494802762, nsec: 0 };
+
+fn getAttr(file: SimpleFsData) -> FileAttr {
+ fn fileAttr(ino: u64, len: usize) -> FileAttr {
+ FileAttr {
+ ino: ino,
+ size: len as u64,
+ blocks: 1,
+ atime: CREATE_TIME,
+ mtime: CREATE_TIME,
+ ctime: CREATE_TIME,
+ crtime: CREATE_TIME,
+ kind: FileType::RegularFile,
+ perm: 0o755,
+ nlink: 1,
+ uid: 501,
+ gid: 20,
+ rdev: 0,
+ flags: 0,
+ }
+ }
+
+ fn dirAttr(ino: u64, children: usize) -> FileAttr {
+ FileAttr {
+ ino: ino,
+ size: 0,
+ blocks: 1,
+ atime: CREATE_TIME,
+ mtime: CREATE_TIME,
+ ctime: CREATE_TIME,
+ crtime: CREATE_TIME,
+ kind: FileType::Directory,
+ perm: 0o755,
+ nlink: children as u32,
+ uid: 501,
+ gid: 20,
+ rdev: 0,
+ flags: 0,
+ }
+ }
+
+ match file {
+ SimpleFsData::File(ino, name) => fileAttr(ino, name.len()),
+ SimpleFsData::Directory(ino, children) => dirAttr(ino, children.len()),
+ }
+}
+
impl Filesystem for MemFs {
fn lookup(&mut self, _req: &Request, _parent: u64, _name: &OsStr,
reply: ReplyEntry) {