From 09772171880308a12216da47825b1717d4c45a01 Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 4 Oct 2024 12:35:22 -0500 Subject: [PATCH] Use Errno as RPC error type --- Cargo.lock | 51 ++++++++++++++++++++++++++++----------------------- Cargo.toml | 4 ++++ src/main.rs | 32 ++++++++++++++++---------------- 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ded565..921bf80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" @@ -58,9 +58,9 @@ checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "dashmap" -version = "6.0.1" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804c8821570c3f8b70230c2ba75ffa5c0f9a4189b9a432b6656c536712acae28" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if", "crossbeam-utils", @@ -171,9 +171,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" @@ -193,9 +193,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "parking_lot" @@ -237,6 +240,12 @@ dependencies = [ "vfs_rpc", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "postcard" version = "1.0.10" @@ -282,18 +291,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] @@ -312,22 +321,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.209" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +version = "1.0.210" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +version = "1.0.210" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.79", ] [[package]] @@ -373,9 +378,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -409,9 +414,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "uuid" diff --git a/Cargo.toml b/Cargo.toml index 498ce1a..e449f18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,7 @@ vfs_rpc = { version = "0.1.0", path = "../vfs/vfs_rpc" } # lto = true # opt-level = "z" # codegen-units=1 + +[patch.crates-io] +serde = { path = "../serde/serde" } +serde_derive = { path = "../serde/serde_derive" } diff --git a/src/main.rs b/src/main.rs index 98793e6..a708a96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use std::{ fs::File, io::{Read, Seek, SeekFrom}, - os::mikros::{ipc, syscalls}, + os::mikros::{ipc, syscalls, Errno}, path::Path, sync::{atomic::{AtomicU64, Ordering}, Arc}, }; @@ -55,8 +55,8 @@ struct Serv { } impl dev_driver_rpc::Server for Serv { - fn open(&self, path: &std::path::Path) -> Result { - let part = *(self.parts.get(path.to_str().unwrap()).ok_or(())?); + fn open(&self, path: &std::path::Path) -> Result { + let part = *(self.parts.get(path.to_str().unwrap()).ok_or(Errno::EBADF)?); Ok(self.open_files.insert(OpenFile { drive_file: part.0, offset: part.1, @@ -67,35 +67,35 @@ impl dev_driver_rpc::Server for Serv { } impl file_rpc::Server for Serv { - fn read(&self, fd: u64, len: usize) -> Result, ()> { - let file = &*self.open_files.get(fd as usize).ok_or(())?; + fn read(&self, fd: u64, len: usize) -> Result, Errno> { + let file = &*self.open_files.get(fd as usize).ok_or(Errno::EBADF)?; if file.pos.load(Ordering::Relaxed).saturating_add(len as u64) > file.part_len as u64 { - return Err(()); + return Err(Errno::EINVAL); } let file_client = file_rpc::Client::new(file.drive_file.0); - file_client.seek(file.drive_file.1, file_rpc::SeekFrom::Start(file.offset + file.pos.load(Ordering::Relaxed))); + file_client.seek(file.drive_file.1, file_rpc::SeekFrom::Start(file.offset + file.pos.load(Ordering::Relaxed)))?; Ok(file_client .read(file.drive_file.1, len)? .into()) } - fn write(&self, _fd: u64, _data: &[u8]) -> Result<(), ()> { + fn write(&self, _fd: u64, _data: &[u8]) -> Result<(), Errno> { todo!() } - fn close(&self, _fd: u64) {} + fn close(&self, _fd: u64) -> Result<(), Errno> { Ok(()) } - fn size(&self, fd: u64) -> Option { - Some(self.open_files.get(fd as usize)?.part_len as u64) + fn size(&self, fd: u64) -> Result { + Ok(self.open_files.get(fd as usize).ok_or(Errno::EBADF)?.part_len as u64) } - fn dup(&self, fd: u64) -> Option { - let file = self.open_files.get(fd as usize)?.clone(); - self.open_files.insert(file).map(|x| x as u64) + fn dup(&self, fd: u64) -> Result { + let file = self.open_files.get(fd as usize).ok_or(Errno::EBADF)?.clone(); + self.open_files.insert(file).map(|x| x as u64).ok_or(Errno::ENOMEM) } - fn seek(&self, fd: u64, pos: file_rpc::SeekFrom) -> u64 { + fn seek(&self, fd: u64, pos: file_rpc::SeekFrom) -> Result { let file = &*self.open_files.get(fd as usize).unwrap(); match pos { file_rpc::SeekFrom::Start(offset) => { @@ -119,7 +119,7 @@ impl file_rpc::Server for Serv { } }, } - file.pos.load(Ordering::Relaxed) + Ok(file.pos.load(Ordering::Relaxed)) } }