mikros: Add mode to open operation

This commit is contained in:
pjht 2024-11-16 11:56:17 -06:00
parent 11c7f632a2
commit 7005510bc0
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
2 changed files with 61 additions and 2 deletions

View File

@ -11,6 +11,8 @@
mod errno; mod errno;
use serde::{Serialize, Serializer, ser::SerializeTupleVariant};
#[stable(feature = "mikros", since = "1.80.0")] #[stable(feature = "mikros", since = "1.80.0")]
pub use errno::Errno; pub use errno::Errno;
@ -74,3 +76,59 @@ pub mod prelude {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use super::ffi::{OsStrExt, OsStringExt}; pub use super::ffi::{OsStrExt, OsStringExt};
} }
#[unstable(feature = "rmp", issue = "none")]
impl Serialize for FileCreationMode {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::NoCreate => serializer.serialize_unit_variant("FileCreationMode", 0, "NoCreate"),
Self::Create => serializer.serialize_unit_variant("FileCreationMode", 1, "Create"),
Self::ForceCreate => serializer.serialize_unit_variant("FileCreationMode", 2, "ForceCreate"),
}
}
}
#[unstable(feature = "rmp", issue = "none")]
impl Serialize for FileWriteMode {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::Start => serializer.serialize_unit_variant("FileWriteMode", 0, "Start"),
Self::Truncate => serializer.serialize_unit_variant("FileWriteMode", 1, "Truncate"),
Self::Append => serializer.serialize_unit_variant("FileWriteMode", 2, "Append"),
}
}
}
#[unstable(feature = "rmp", issue = "none")]
impl Serialize for FileOpenMode {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::Read => serializer.serialize_unit_variant("FileOpenMode", 0, "Read"),
Self::Write(ref wr_mode, ref cr_mode) => {
let mut tv = serializer.serialize_tuple_variant("FileOpenMode", 1, "Write", 2)?;
tv.serialize_field(wr_mode)?;
tv.serialize_field(cr_mode)?;
tv.end()
},
Self::ReadWrite(ref wr_mode, ref cr_mode) => {
let mut tv = serializer.serialize_tuple_variant("FileOpenMode", 2, "ReadWrite", 2)?;
tv.serialize_field(wr_mode)?;
tv.serialize_field(cr_mode)?;
tv.end()
},
}
}
}

View File

@ -389,7 +389,8 @@ fn get_open_mode(&self) -> io::Result<FileOpenMode> {
impl File { impl File {
pub fn open(path: &Path, _opts: &OpenOptions) -> io::Result<File> { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
let open_mode = opts.get_open_mode()?;
let path = path.canonicalize()?; let path = path.canonicalize()?;
let vfs_pid = loop { let vfs_pid = loop {
if let Some(pid) = syscalls::try_get_registered(0) { if let Some(pid) = syscalls::try_get_registered(0) {
@ -397,7 +398,7 @@ pub fn open(path: &Path, _opts: &OpenOptions) -> io::Result<File> {
} }
}; };
let open_res: Result<(u64, u64), Errno> = postcard::from_bytes( let open_res: Result<(u64, u64), Errno> = postcard::from_bytes(
&rpc::send_call(vfs_pid, 2, 2, &postcard::to_allocvec(&path).unwrap()).get_return(), &rpc::send_call(vfs_pid, 2, 2, &postcard::to_allocvec(&(path, open_mode)).unwrap()).get_return(),
) )
.unwrap(); .unwrap();
let (fs_pid, fd) = open_res?; let (fs_pid, fd) = open_res?;