From 7005510bc0282c62a4accd7aa8a6f7c8bcb9478d Mon Sep 17 00:00:00 2001 From: pjht Date: Sat, 16 Nov 2024 11:56:17 -0600 Subject: [PATCH] mikros: Add mode to open operation --- library/std/src/os/mikros/mod.rs | 58 ++++++++++++++++++++++++++++ library/std/src/sys/pal/mikros/fs.rs | 5 ++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/mikros/mod.rs b/library/std/src/os/mikros/mod.rs index 07f8179b5e7..fad0564f867 100644 --- a/library/std/src/os/mikros/mod.rs +++ b/library/std/src/os/mikros/mod.rs @@ -11,6 +11,8 @@ mod errno; +use serde::{Serialize, Serializer, ser::SerializeTupleVariant}; + #[stable(feature = "mikros", since = "1.80.0")] pub use errno::Errno; @@ -74,3 +76,59 @@ pub mod prelude { #[stable(feature = "rust1", since = "1.0.0")] pub use super::ffi::{OsStrExt, OsStringExt}; } + +#[unstable(feature = "rmp", issue = "none")] +impl Serialize for FileCreationMode { + #[inline] + fn serialize(&self, serializer: S) -> Result + 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(&self, serializer: S) -> Result + 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(&self, serializer: S) -> Result + 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() + }, + + } + } +} diff --git a/library/std/src/sys/pal/mikros/fs.rs b/library/std/src/sys/pal/mikros/fs.rs index 28cbf02d51a..58081f3a276 100644 --- a/library/std/src/sys/pal/mikros/fs.rs +++ b/library/std/src/sys/pal/mikros/fs.rs @@ -389,7 +389,8 @@ fn get_open_mode(&self) -> io::Result { impl File { - pub fn open(path: &Path, _opts: &OpenOptions) -> io::Result { + pub fn open(path: &Path, opts: &OpenOptions) -> io::Result { + let open_mode = opts.get_open_mode()?; let path = path.canonicalize()?; let vfs_pid = loop { if let Some(pid) = syscalls::try_get_registered(0) { @@ -397,7 +398,7 @@ pub fn open(path: &Path, _opts: &OpenOptions) -> io::Result { } }; 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(); let (fs_pid, fd) = open_res?;