Add mode to open operation

This commit is contained in:
pjht 2024-11-16 11:54:35 -06:00
parent 3c651c22e9
commit 58fcd0213e
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -1,7 +1,7 @@
#![allow(clippy::result_unit_err)] #![allow(clippy::result_unit_err)]
use std::{ use std::{
os::mikros::{ipc::rpc::{self, IncomingCall}, Errno}, os::mikros::{ipc::rpc::{self, IncomingCall}, Errno, FileOpenMode},
path::Path, path::Path,
}; };
@ -12,7 +12,7 @@ static SERVER: RwLock<Option<Box<dyn Server>>> = RwLock::new(None);
const PROTO: u16 = 0; const PROTO: u16 = 0;
pub trait Server: Send + Sync { pub trait Server: Send + Sync {
fn open(&self, path: &Path) -> Result<u64, Errno>; fn open(&self, path: &Path, mode: FileOpenMode) -> Result<u64, Errno>;
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -23,9 +23,9 @@ impl Client {
Self(pid) Self(pid)
} }
pub fn open(self, path: &Path) -> Result<u64, Errno> { pub fn open(self, path: &Path, mode: FileOpenMode) -> Result<u64, Errno> {
postcard::from_bytes( postcard::from_bytes(
&rpc::send_call(self.0, PROTO, 0, &postcard::to_stdvec(path).unwrap()).get_return(), &rpc::send_call(self.0, PROTO, 0, &postcard::to_stdvec(&(path, mode)).unwrap()).get_return(),
) )
.unwrap() .unwrap()
} }
@ -45,8 +45,8 @@ fn callback(call: IncomingCall) {
let server_lock = SERVER.read(); let server_lock = SERVER.read();
let server = server_lock.as_ref().unwrap(); let server = server_lock.as_ref().unwrap();
if call.func == 0 { if call.func == 0 {
let path = postcard::from_bytes(call.args()).unwrap(); let (path, mode) = postcard::from_bytes(call.args()).unwrap();
let ret = postcard::to_stdvec(&server.open(path)).unwrap(); let ret = postcard::to_stdvec(&server.open(path, mode)).unwrap();
call.send_return(&ret); call.send_return(&ret);
} }
} }