diff --git a/src/main.rs b/src/main.rs index 40ab03c..cf783ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,12 @@ -use std::{fs::File, io::{Read, Seek}, os::mikros::{ipc, syscalls}, path::PathBuf, sync::Arc, usize}; +use std::{ + fs::File, + io::{Read, Seek}, + os::mikros::{ipc, syscalls}, + path::PathBuf, + sync::Arc, +}; use parking_lot::RwLock; -use syslog_rpc::{BinaryMessage, Message}; use tar::Archive; #[derive(Clone)] @@ -14,12 +19,16 @@ impl fs_rpc::Server for Serv { fn mount(&self, dev: &std::path::Path) -> Result { let archive = File::open(dev).map_err(|_| ())?; let mut archive = Archive::new(archive); - let entries = archive.entries_with_seek().unwrap().map(|entry| { - let entry = entry.unwrap(); - let path = entry.path().unwrap().into_owned(); - let file_offset = entry.raw_file_position(); - (path, file_offset, entry.size() as usize) - }).collect(); + let entries = archive + .entries_with_seek() + .unwrap() + .map(|entry| { + let entry = entry.unwrap(); + let path = entry.path().unwrap().into_owned(); + let file_offset = entry.raw_file_position(); + (path, file_offset, entry.size() as usize) + }) + .collect(); self.mounts.write().push((archive.into_inner(), entries)); Ok((self.mounts.read().len() - 1) as u64) } @@ -27,8 +36,15 @@ impl fs_rpc::Server for Serv { fn open(&self, path: &std::path::Path, mount_id: u64) -> Result<(Option, u64), ()> { let mounts = self.mounts.read(); let mount = &mounts[mount_id as usize]; - let (&file_offset, &file_size) = mount.1.iter().find(|(entry_path, _offset, _size)| entry_path == path).map(|(_x, y, z)| (y, z)).ok_or(())?; - self.files.write().push((mount_id as usize, file_offset, file_size)); + let (&file_offset, &file_size) = mount + .1 + .iter() + .find(|(entry_path, _offset, _size)| entry_path == path) + .map(|(_x, y, z)| (y, z)) + .ok_or(())?; + self.files + .write() + .push((mount_id as usize, file_offset, file_size)); Ok((None, (self.files.read().len() - 1) as u64)) } } @@ -41,10 +57,12 @@ impl file_rpc::Server for Serv { return Ok(Vec::new()); }; let mounts = self.mounts.read(); - let mount = &mounts[mount_id as usize]; - (&mount.0).seek(std::io::SeekFrom::Start(file_offset + pos)).unwrap(); + let mount = &mounts[mount_id]; + (&mount.0) + .seek(std::io::SeekFrom::Start(file_offset + pos)) + .unwrap(); let mut buf = vec![0; read_len]; - let read_bytes = (&mount.0).read(&mut buf).map_err(|_| ()) ?; + let read_bytes = (&mount.0).read(&mut buf).map_err(|_| ())?; buf.truncate(read_bytes); Ok(buf) } @@ -83,14 +101,14 @@ fn main() { break; } } - syslog_rpc::Client::new(syslog_pid).send_message(Message { - from: "tarfs".to_string(), - text: Some("Tar archive fs initialized".to_string()), - binary: Some(BinaryMessage { - kind: 0, - data: vec![], - }), - }).unwrap(); + syslog_rpc::Client::new(syslog_pid) + .send_text_binary_message( + "tarfs".to_string(), + "Tar archive fs initialized".to_string(), + 0, + [], + ) + .unwrap(); loop { ipc::process_messages() }