Add basic umnount function

This commit is contained in:
pjht 2024-09-04 10:52:01 -05:00
parent adc2102dc1
commit 134bc41511
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 26 additions and 0 deletions

View File

@ -53,6 +53,14 @@ impl vfs_rpc::Server for Serv {
Ok((fs_pid, fd))
}
}
fn unmount(&self, path: &Path) -> Result<(), ()> {
if self.mount_list.write().remove(path).is_none() {
Err(())
} else {
Ok(())
}
}
}
fn main() {

View File

@ -15,6 +15,7 @@ pub trait Server: Send + Sync {
fn register_fs(&self, from: u64, kind: &str) -> Result<(), ()>;
fn mount(&self, dev: &Path, kind: &str, path: &Path) -> Result<(), ()>;
fn open(&self, path: &Path) -> Result<(u64, u64), ()>;
fn unmount(&self, path: &Path) -> Result<(), ()>;
}
#[derive(Copy, Clone)]
@ -51,6 +52,19 @@ impl Client {
)
.unwrap()
}
pub fn unmount(self, path: &Path) -> Result<(), ()> {
postcard::from_bytes(
&rpc::send_call(
self.0,
PROTO,
3,
&postcard::to_stdvec(path).unwrap(),
)
.get_return(),
)
.unwrap()
}
}
pub fn register_server(server: Box<dyn Server>) {
@ -78,5 +92,9 @@ fn callback(call: IncomingCall) {
let path = postcard::from_bytes(call.args()).unwrap();
let ret = postcard::to_stdvec(&server.open(path)).unwrap();
call.send_return(&ret);
} else if call.func == 3 {
let path = postcard::from_bytes(call.args()).unwrap();
let ret = postcard::to_stdvec(&server.unmount(path)).unwrap();
call.send_return(&ret);
}
}