Add dir_rpc support

This commit is contained in:
pjht 2024-09-26 11:28:36 -05:00
parent 51b08c6871
commit fa82e37faa
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
3 changed files with 49 additions and 4 deletions

22
Cargo.lock generated
View File

@ -62,6 +62,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"dev_driver_rpc", "dev_driver_rpc",
"devfs_rpc", "devfs_rpc",
"dir_rpc",
"fs_rpc", "fs_rpc",
"parking_lot", "parking_lot",
"syslog_rpc", "syslog_rpc",
@ -77,12 +78,26 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "dir_rpc"
version = "0.1.0"
dependencies = [
"parking_lot",
"postcard",
]
[[package]] [[package]]
name = "embedded-io" name = "embedded-io"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced"
[[package]]
name = "embedded-io"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
[[package]] [[package]]
name = "fs_rpc" name = "fs_rpc"
version = "0.1.0" version = "0.1.0"
@ -156,12 +171,13 @@ dependencies = [
[[package]] [[package]]
name = "postcard" name = "postcard"
version = "1.0.8" version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e"
dependencies = [ dependencies = [
"cobs", "cobs",
"embedded-io", "embedded-io 0.4.0",
"embedded-io 0.6.1",
"heapless", "heapless",
"serde", "serde",
] ]

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
dev_driver_rpc = { version = "0.1.0", path = "../dev_driver_rpc" } dev_driver_rpc = { version = "0.1.0", path = "../dev_driver_rpc" }
devfs_rpc = { version = "0.1.0", path = "devfs_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" } fs_rpc = { version = "0.1.0", path = "../fs_rpc" }
parking_lot = "0.12.3" parking_lot = "0.12.3"
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" } syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }

View File

@ -10,6 +10,7 @@ use parking_lot::RwLock;
struct Serv { struct Serv {
devices: Arc<RwLock<HashMap<String, u64>>>, devices: Arc<RwLock<HashMap<String, u64>>>,
syslog_client: syslog_rpc::Client, syslog_client: syslog_rpc::Client,
dirs: Arc<RwLock<Vec<(Vec<String>, usize)>>>,
} }
impl fs_rpc::Server for Serv { 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)?; let fd = dev_driver_rpc::Client::new(device_pid).open(path)?;
Ok((Some(device_pid), fd)) Ok((Some(device_pid), fd))
} }
fn open_dir(&self, _path: &std::path::Path, _mount_id: u64) -> Result<(Option<u64>, u64), ()> {
let entries = self.devices.read().keys().cloned().collect::<Vec<_>>();
self.dirs
.write()
.push((entries, 0));
let res = Ok((None, (self.dirs.read().len() - 1) as u64));
res
}
} }
impl devfs_rpc::Server for Serv { 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<Option<String>, ()> {
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() { fn main() {
let syslog_pid; let syslog_pid;
loop { loop {
@ -52,9 +78,11 @@ fn main() {
let serv = Serv { let serv = Serv {
devices: Arc::new(RwLock::new(HashMap::new())), devices: Arc::new(RwLock::new(HashMap::new())),
syslog_client, syslog_client,
dirs: Arc::new(RwLock::new(Vec::new())),
}; };
fs_rpc::register_server(Box::new(serv.clone())); 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; let vfs_pid;
loop { loop {
if let Some(pid) = syscalls::try_get_registered(0) { if let Some(pid) = syscalls::try_get_registered(0) {