summary refs log tree commit diff
path: root/ripple/fossil/src
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r--ripple/fossil/src/bin/mount.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs
index de03a4b..aead582 100644
--- a/ripple/fossil/src/bin/mount.rs
+++ b/ripple/fossil/src/bin/mount.rs
@@ -109,6 +109,11 @@ impl Filesystem {
 	}
 }
 
+enum Handle {
+	File { contents: Vec<u8> },
+	_NonExhaustive,
+}
+
 impl fuser::Filesystem for Filesystem {
 	fn init(
 		&mut self,
@@ -167,35 +172,46 @@ impl fuser::Filesystem for Filesystem {
 		}
 	}
 
-	fn open(&mut self, _req: &fuser::Request<'_>, _ino: u64, _flags: i32, reply: fuser::ReplyOpen) {
-		reply.opened(0, 0);
+	fn open(&mut self, _req: &fuser::Request<'_>, ino: u64, _flags: i32, reply: fuser::ReplyOpen) {
+		match self.find(ino) {
+			Some(memtree::Node::File(f)) => {
+				let contents = self.store.read_blob(f.ident);
+				let fh = Box::new(Handle::File { contents });
+				reply.opened(Box::into_raw(fh) as u64, 0);
+			}
+			Some(_) => reply.error(EINVAL),
+			None => reply.error(ENOENT),
+		}
 	}
 
 	fn read(
 		&mut self,
 		_req: &fuser::Request<'_>,
-		ino: u64,
-		_fh: u64,
+		_ino: u64,
+		fh: u64,
 		offset: i64,
 		size: u32,
 		_flags: i32,
 		_lock_owner: Option<u64>,
 		reply: fuser::ReplyData,
 	) {
-		match self.find(ino) {
-			Some(memtree::Node::File(f)) => {
+		let fh = unsafe {
+			let ptr = fh as *mut Handle;
+			&*ptr
+		};
+
+		match fh {
+			Handle::File { contents } => {
 				let offset = offset as usize;
 				let size = size as usize;
 
-				let content = self.store.read_blob(f.ident);
-				let mut buffer = content.get(offset..).unwrap_or_default();
+				let mut buffer = contents.get(offset..).unwrap_or_default();
 				if buffer.len() > size {
 					buffer = &buffer[..size];
 				}
 				reply.data(buffer);
 			}
-			Some(_) => reply.error(EINVAL),
-			None => reply.error(ENOENT),
+			_ => reply.error(EINVAL),
 		}
 	}
 
@@ -218,12 +234,16 @@ impl fuser::Filesystem for Filesystem {
 		&mut self,
 		_req: &fuser::Request<'_>,
 		_ino: u64,
-		_fh: u64,
+		fh: u64,
 		_flags: i32,
 		_lock_owner: Option<u64>,
 		_flush: bool,
 		reply: fuser::ReplyEmpty,
 	) {
+		let _ = unsafe {
+			let ptr = fh as *mut Handle;
+			Box::from_raw(ptr)
+		};
 		reply.ok();
 	}