Add mode to open operation

This commit is contained in:
pjht 2024-11-16 11:53:37 -06:00
parent 04f3574bc1
commit 2df5db760e
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -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,
};
@ -13,7 +13,7 @@ const PROTO: u16 = 3;
pub trait Server: Send + Sync {
fn mount(&self, dev: &Path) -> Result<u64, Errno>;
fn open(&self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), Errno>;
fn open(&self, path: &Path, mode: FileOpenMode, mount_id: u64) -> Result<(Option<u64>, u64), Errno>;
fn open_dir(&self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), Errno>;
}
@ -33,13 +33,13 @@ impl Client {
.unwrap()
}
pub fn open(self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), Errno> {
pub fn open(self, path: &Path, mode: FileOpenMode, mount_id: u64) -> Result<(Option<u64>, u64), Errno> {
postcard::from_bytes(
&rpc::send_call(
self.0,
PROTO,
1,
&postcard::to_stdvec(&(path, mount_id)).unwrap(),
&postcard::to_stdvec(&(path, mode, mount_id)).unwrap(),
)
.get_return(),
)
@ -78,8 +78,8 @@ fn callback(call: IncomingCall) {
let ret = postcard::to_stdvec(&server.mount(dev)).unwrap();
call.send_return(&ret);
} else if call.func == 1 {
let (path, mount_id) = postcard::from_bytes(call.args()).unwrap();
let ret = postcard::to_stdvec(&server.open(path, mount_id)).unwrap();
let (path, mode, mount_id) = postcard::from_bytes(call.args()).unwrap();
let ret = postcard::to_stdvec(&server.open(path, mode, mount_id)).unwrap();
call.send_return(&ret);
} else if call.func == 2 {
let (path, mount_id) = postcard::from_bytes(call.args()).unwrap();