diff --git a/Cargo.lock b/Cargo.lock index e3f3b8a..c180b8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,7 @@ version = "0.1.0" dependencies = [ "dev_driver_rpc", "devfs_rpc", + "dir_rpc", "fs_rpc", "parking_lot", "syslog_rpc", @@ -77,12 +78,26 @@ dependencies = [ "serde", ] +[[package]] +name = "dir_rpc" +version = "0.1.0" +dependencies = [ + "parking_lot", + "postcard", +] + [[package]] name = "embedded-io" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "fs_rpc" version = "0.1.0" @@ -156,12 +171,13 @@ dependencies = [ [[package]] name = "postcard" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" dependencies = [ "cobs", - "embedded-io", + "embedded-io 0.4.0", + "embedded-io 0.6.1", "heapless", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 5e80301..ac6f68e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] dev_driver_rpc = { version = "0.1.0", path = "../dev_driver_rpc" } devfs_rpc = { version = "0.1.0", path = "devfs_rpc" } +dir_rpc = { version = "0.1.0", path = "../dir_rpc" } fs_rpc = { version = "0.1.0", path = "../fs_rpc" } parking_lot = "0.12.3" syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" } diff --git a/src/main.rs b/src/main.rs index 26480b1..6636c62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use parking_lot::RwLock; struct Serv { devices: Arc>>, syslog_client: syslog_rpc::Client, + dirs: Arc, usize)>>>, } impl fs_rpc::Server for Serv { @@ -23,6 +24,15 @@ impl fs_rpc::Server for Serv { let fd = dev_driver_rpc::Client::new(device_pid).open(path)?; Ok((Some(device_pid), fd)) } + + fn open_dir(&self, _path: &std::path::Path, _mount_id: u64) -> Result<(Option, u64), ()> { + let entries = self.devices.read().keys().cloned().collect::>(); + self.dirs + .write() + .push((entries, 0)); + let res = Ok((None, (self.dirs.read().len() - 1) as u64)); + res + } } impl devfs_rpc::Server for Serv { @@ -40,6 +50,22 @@ impl devfs_rpc::Server for Serv { } } +impl dir_rpc::Server for Serv { + fn next_entry(&self, fd: u64) -> Result, ()> { + let dirs = self.dirs.write(); + let &(ref entries, entry_no) = &dirs[fd as usize]; + if entry_no == entries.len() { + return Ok(None); + } + let entry = entries[entry_no].clone(); + std::mem::drop(dirs); + self.dirs.write()[fd as usize].1 += 1; + Ok(Some(entry)) + } + + fn close(&self, _fd: u64) {} +} + fn main() { let syslog_pid; loop { @@ -52,9 +78,11 @@ fn main() { let serv = Serv { devices: Arc::new(RwLock::new(HashMap::new())), syslog_client, + dirs: Arc::new(RwLock::new(Vec::new())), }; fs_rpc::register_server(Box::new(serv.clone())); - devfs_rpc::register_server(Box::new(serv)); + devfs_rpc::register_server(Box::new(serv.clone())); + dir_rpc::register_server(Box::new(serv)); let vfs_pid; loop { if let Some(pid) = syscalls::try_get_registered(0) {