Add mode to open operation

This commit is contained in:
pjht 2024-11-16 11:54:17 -06:00
parent 230adf0ee0
commit bb2f570131
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,6 @@
use std::{
collections::HashMap,
os::mikros::{ipc, syscalls, Errno},
os::mikros::{ipc, syscalls, Errno, FileOpenMode},
path::{Path, PathBuf},
};
@ -36,7 +36,7 @@ impl vfs_rpc::Server for Serv {
Ok(())
}
fn open(&self, path: &Path) -> Result<(u64, u64), Errno> {
fn open(&self, path: &Path, mode: FileOpenMode) -> Result<(u64, u64), Errno> {
if !path.is_absolute() {
return Err(Errno::EINVAL);
}
@ -49,7 +49,7 @@ impl vfs_rpc::Server for Serv {
.map(|(a, b)| (a.clone(), *b))
.unwrap();
let (override_pid, fd) =
fs_rpc::Client::new(fs_pid).open(path.strip_prefix(mount_path).unwrap(), mount_id)?;
fs_rpc::Client::new(fs_pid).open(path.strip_prefix(mount_path).unwrap(), mode, mount_id)?;
if let Some(override_pid) = override_pid {
Ok((override_pid, fd))
} else {

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