Add mode to open operation
This commit is contained in:
parent
3c651c22e9
commit
58fcd0213e
12
src/lib.rs
12
src/lib.rs
@ -1,7 +1,7 @@
|
||||
#![allow(clippy::result_unit_err)]
|
||||
|
||||
use std::{
|
||||
os::mikros::{ipc::rpc::{self, IncomingCall}, Errno},
|
||||
os::mikros::{ipc::rpc::{self, IncomingCall}, Errno, FileOpenMode},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@ static SERVER: RwLock<Option<Box<dyn Server>>> = RwLock::new(None);
|
||||
const PROTO: u16 = 0;
|
||||
|
||||
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)]
|
||||
@ -23,9 +23,9 @@ impl Client {
|
||||
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(
|
||||
&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()
|
||||
}
|
||||
@ -45,8 +45,8 @@ fn callback(call: IncomingCall) {
|
||||
let server_lock = SERVER.read();
|
||||
let server = server_lock.as_ref().unwrap();
|
||||
if call.func == 0 {
|
||||
let path = postcard::from_bytes(call.args()).unwrap();
|
||||
let ret = postcard::to_stdvec(&server.open(path)).unwrap();
|
||||
let (path, mode) = postcard::from_bytes(call.args()).unwrap();
|
||||
let ret = postcard::to_stdvec(&server.open(path, mode)).unwrap();
|
||||
call.send_return(&ret);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user