Use Errno as RPC error type
This commit is contained in:
parent
a451b4506b
commit
21120d4869
106
Cargo.lock
generated
106
Cargo.lock
generated
@ -32,9 +32,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 = "binread"
|
||||
@ -91,31 +91,11 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
|
||||
|
||||
[[package]]
|
||||
name = "const_format"
|
||||
version = "0.2.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673"
|
||||
dependencies = [
|
||||
"const_format_proc_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format_proc_macros"
|
||||
version = "0.2.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "critical-section"
|
||||
version = "1.1.2"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
|
||||
checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242"
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
@ -138,7 +118,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.72",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -149,38 +129,38 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.72",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.20.0"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7"
|
||||
checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b"
|
||||
dependencies = [
|
||||
"derive_builder_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.20.0"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d"
|
||||
checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.72",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_macro"
|
||||
version = "0.20.0"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b"
|
||||
checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc"
|
||||
dependencies = [
|
||||
"derive_builder_core",
|
||||
"syn 2.0.72",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -213,6 +193,12 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-io"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
|
||||
|
||||
[[package]]
|
||||
name = "file_rpc"
|
||||
version = "0.1.0"
|
||||
@ -278,9 +264,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.155"
|
||||
version = "0.2.159"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
||||
|
||||
[[package]]
|
||||
name = "libm"
|
||||
@ -331,13 +317,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "postcard"
|
||||
version = "1.0.8"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8"
|
||||
checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e"
|
||||
dependencies = [
|
||||
"cobs",
|
||||
"const_format",
|
||||
"embedded-io",
|
||||
"embedded-io 0.4.0",
|
||||
"embedded-io 0.6.1",
|
||||
"heapless",
|
||||
"postcard-derive",
|
||||
"serde",
|
||||
@ -345,9 +331,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "postcard-derive"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc4b01218787dd4420daf63875163a787a78294ad48a24e9f6fa8c6507759a79"
|
||||
checksum = "0239fa9c1d225d4b7eb69925c25c5e082307a141e470573fbbe3a817ce6a7a37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -365,18 +351,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.36"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[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",
|
||||
]
|
||||
@ -392,9 +378,9 @@ dependencies = [
|
||||
|
||||
[[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",
|
||||
]
|
||||
@ -419,22 +405,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.204"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12"
|
||||
version = "1.0.210"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.204"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
|
||||
version = "1.0.210"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.72",
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -477,9 +459,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.72"
|
||||
version = "2.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
|
||||
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -508,15 +490,9 @@ version = "0.6.0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
|
@ -20,6 +20,8 @@ x86_64 = "0.15.1"
|
||||
|
||||
[patch.crates-io]
|
||||
tock-registers = {path = "./tock-registers"}
|
||||
serde = { path = "../serde/serde" }
|
||||
serde_derive = { path = "../serde/serde_derive" }
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::os::mikros::Errno;
|
||||
|
||||
use crate::{
|
||||
ata_command::ReadDmaExtCommand,
|
||||
identify::IdentifyData,
|
||||
@ -26,6 +28,18 @@ pub enum AtaReadError {
|
||||
CommandError(#[allow(unused)] CommandIssueError),
|
||||
}
|
||||
|
||||
impl From<AtaReadError> for Errno {
|
||||
fn from(value: AtaReadError) -> Self {
|
||||
match value {
|
||||
AtaReadError::NotAligned
|
||||
| AtaReadError::SizeNotSectMult
|
||||
| AtaReadError::SizeTooBig
|
||||
| AtaReadError::ReadOffEnd => Self::EINVAL,
|
||||
AtaReadError::CommandError(_) => Self::EIO,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CommandIssueError> for AtaReadError {
|
||||
fn from(v: CommandIssueError) -> Self {
|
||||
Self::CommandError(v)
|
||||
|
60
src/main.rs
60
src/main.rs
@ -29,7 +29,7 @@ mod port;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
os::mikros::{address_space::ACTIVE_SPACE, ipc, syscalls},
|
||||
os::mikros::{address_space::ACTIVE_SPACE, ipc, syscalls, Errno},
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
@ -48,8 +48,8 @@ struct AhciState {
|
||||
}
|
||||
|
||||
impl dev_driver_rpc::Server for AhciState {
|
||||
fn open(&self, path: &Path) -> Result<u64, ()> {
|
||||
let port = *self.dev_port_map.get(path).ok_or(())?;
|
||||
fn open(&self, path: &Path) -> Result<u64, Errno> {
|
||||
let port = *self.dev_port_map.get(path).ok_or(Errno::ENOENT)?;
|
||||
let mut files = self.files.write();
|
||||
files.push((port, 0));
|
||||
Ok((files.len() - 1) as u64)
|
||||
@ -58,58 +58,66 @@ impl dev_driver_rpc::Server for AhciState {
|
||||
|
||||
impl file_rpc::Server for AhciState {
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn read(&self, fd: u64, len: usize) -> Result<std::borrow::Cow<'_, [u8]>, ()> {
|
||||
fn read(&self, fd: u64, len: usize) -> Result<std::borrow::Cow<'_, [u8]>, Errno> {
|
||||
let hba = self.hba.lock();
|
||||
let (port_no, pos) = self.files.read()[fd as usize];
|
||||
let port = hba.ports().get(port_no).ok_or(())?;
|
||||
let device = port.get_device().map_err(|_| ())?.ok_or(())?;
|
||||
let port = hba.ports().get(port_no).ok_or(Errno::ESTALE)?;
|
||||
let device = port
|
||||
.get_device()
|
||||
.map_err(|_| Errno::ESTALE)?
|
||||
.ok_or(Errno::ESTALE)?;
|
||||
let DeviceEnum::Ata(device) = device else {
|
||||
return Err(());
|
||||
return Err(Errno::ESTALE);
|
||||
};
|
||||
let mut buf = vec![0; len];
|
||||
device.read(pos as usize, &mut buf).map_err(|_| ())?;
|
||||
device.read(pos as usize, &mut buf)?;
|
||||
self.files.write()[fd as usize].1 += len as u64;
|
||||
Ok(buf.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(())
|
||||
}
|
||||
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn size(&self, fd: u64) -> Option<u64> {
|
||||
fn size(&self, fd: u64) -> Result<u64, Errno> {
|
||||
let hba = self.hba.lock();
|
||||
let port = hba.ports().get(fd as usize)?;
|
||||
let device = port.get_device().ok()??;
|
||||
let port = hba.ports().get(fd as usize).ok_or(Errno::ESTALE)?;
|
||||
let device = port
|
||||
.get_device()
|
||||
.map_err(|_| Errno::ESTALE)?
|
||||
.ok_or(Errno::ESTALE)?;
|
||||
let DeviceEnum::Ata(device) = device else {
|
||||
return None;
|
||||
return Err(Errno::ESTALE);
|
||||
};
|
||||
Some(device.capacity() as u64)
|
||||
Ok(device.capacity() as u64)
|
||||
}
|
||||
|
||||
fn dup(&self, fd: u64) -> Option<u64> {
|
||||
fn dup(&self, fd: u64) -> Result<u64, Errno> {
|
||||
let mut files = self.files.write();
|
||||
let file = files[fd as usize].clone();
|
||||
let file = files[fd as usize];
|
||||
files.push(file);
|
||||
Some((files.len() - 1) as u64)
|
||||
Ok((files.len() - 1) as u64)
|
||||
}
|
||||
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn seek(&self, fd: u64, pos: file_rpc::SeekFrom) -> u64 {
|
||||
fn seek(&self, fd: u64, pos: file_rpc::SeekFrom) -> Result<u64, Errno> {
|
||||
let mut files = self.files.write();
|
||||
let file = &mut files[fd as usize];
|
||||
match pos {
|
||||
file_rpc::SeekFrom::Start(offset) => {
|
||||
file.1 = offset;
|
||||
},
|
||||
}
|
||||
file_rpc::SeekFrom::End(_offset) => {
|
||||
todo!();
|
||||
//if offset <= 0 {
|
||||
// file.1 = file.len as u64 - (-offset) as u64;
|
||||
//}
|
||||
},
|
||||
}
|
||||
file_rpc::SeekFrom::Current(offset) => {
|
||||
if offset > 0 {
|
||||
//file.1 = u64::min(file.1 + offset as u64, file.len as u64);
|
||||
@ -122,9 +130,9 @@ impl file_rpc::Server for AhciState {
|
||||
file.1 -= offset;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
file.1
|
||||
Ok(file.1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,11 +266,13 @@ fn main() {
|
||||
|
||||
for dev in dev_port_map.keys() {
|
||||
let dev_name = dev.to_str().unwrap();
|
||||
devfs_rpc::Client::new(devfs_pid).register_dev(dev_name).unwrap();
|
||||
devfs_rpc::Client::new(devfs_pid)
|
||||
.register_dev(dev_name)
|
||||
.unwrap();
|
||||
syslog_client
|
||||
.send_text_binary_message(
|
||||
"blockdev",
|
||||
format!("New block device {}", dev_name),
|
||||
format!("New block device {dev_name}"),
|
||||
0,
|
||||
dev_name.as_bytes().to_vec(),
|
||||
)
|
||||
|
@ -37,7 +37,7 @@ pub enum CommandIssueError {
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum GetDeviceError {
|
||||
CommandIssueError(CommandIssueError),
|
||||
CommandIssueError(#[allow(unused)] CommandIssueError),
|
||||
AtaNewError(AtaNewError),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user