Compare commits
No commits in common. "b78fffd9b0358cf2e64755e3a2e08ff286773a67" and "334a5698eb666529ff01230122896fdd6b89dad6" have entirely different histories.
b78fffd9b0
...
334a5698eb
@ -139,42 +139,6 @@ pub enum Errno {
|
||||
EWRZERO = 137,
|
||||
}
|
||||
|
||||
use serde::de::{self, Deserialize, Deserializer, Unexpected};
|
||||
|
||||
use crate::fmt;
|
||||
|
||||
#[unstable(feature = "mikros_internals", issue = "none")]
|
||||
impl<'de> Deserialize<'de> for crate::os::mikros::Errno {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_i32(ErrnoVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct ErrnoVisitor;
|
||||
|
||||
impl<'de> de::Visitor<'de> for ErrnoVisitor {
|
||||
type Value = crate::os::mikros::Errno;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("errno")
|
||||
}
|
||||
|
||||
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
use crate::convert::TryFrom;
|
||||
if let Ok(errno) = Errno::try_from(v) {
|
||||
Ok(errno)
|
||||
} else {
|
||||
Err(E::invalid_value(Unexpected::Signed(v as i64), &self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "mikros", since = "1.80.0")]
|
||||
impl TryFrom<i32> for Errno {
|
||||
type Error = i32;
|
||||
@ -525,10 +489,3 @@ fn from(error: crate::io::Error) -> Self {
|
||||
Self::from(error.kind())
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "mikros", since = "1.80.0")]
|
||||
impl From<Errno> for crate::io::Error {
|
||||
fn from(error: Errno) -> Self {
|
||||
Self::from_raw_os_error(error)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
use crate::hash::{Hash, Hasher};
|
||||
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
|
||||
use crate::os::mikros::ipc::rpc;
|
||||
use crate::os::mikros::{Errno, syscalls};
|
||||
use crate::os::mikros::syscalls;
|
||||
use crate::path::{Path, PathBuf};
|
||||
use crate::sys::time::SystemTime;
|
||||
use crate::sys::unsupported;
|
||||
@ -43,16 +43,9 @@ pub struct FileAttr {
|
||||
size: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ReadDir {
|
||||
path: PathBuf,
|
||||
fs_pid: u64,
|
||||
fd: u64,
|
||||
}
|
||||
pub struct ReadDir(!);
|
||||
|
||||
pub struct DirEntry {
|
||||
path: PathBuf,
|
||||
}
|
||||
pub struct DirEntry(!);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OpenOptions {}
|
||||
@ -176,46 +169,35 @@ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ReadDir {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for ReadDir {
|
||||
type Item = io::Result<DirEntry>;
|
||||
|
||||
fn next(&mut self) -> Option<io::Result<DirEntry>> {
|
||||
let msg_data =
|
||||
&rpc::send_call(self.fs_pid, 7, 0, &postcard::to_allocvec(&self.fd).unwrap())
|
||||
.get_return();
|
||||
let entry_res: Result<Option<String>, Errno> = postcard::from_bytes(msg_data).unwrap();
|
||||
let entry_name = match entry_res.transpose()? {
|
||||
Ok(val) => val,
|
||||
Err(e) => return Some(Err(e.into())),
|
||||
};
|
||||
let mut entry_path = self.path.clone();
|
||||
entry_path.push(entry_name);
|
||||
Some(Ok(DirEntry { path: entry_path }))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ReadDir {
|
||||
fn drop(&mut self) {
|
||||
let _ = &rpc::send_call(self.fs_pid, 7, 1, &postcard::to_allocvec(&self.fd).unwrap())
|
||||
.get_return();
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DirEntry {
|
||||
pub fn path(&self) -> PathBuf {
|
||||
self.path.clone()
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn file_name(&self) -> OsString {
|
||||
self.path.file_name().unwrap().to_owned()
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> io::Result<FileAttr> {
|
||||
unsupported()
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn file_type(&self) -> io::Result<FileType> {
|
||||
unsupported()
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,21 +221,22 @@ pub fn open(path: &Path, _opts: &OpenOptions) -> io::Result<File> {
|
||||
break pid;
|
||||
}
|
||||
};
|
||||
let open_res: Result<(u64, u64), Errno> = postcard::from_bytes(
|
||||
let open_res: Result<(u64, u64), ()> = postcard::from_bytes(
|
||||
&rpc::send_call(vfs_pid, 2, 2, &postcard::to_allocvec(path).unwrap()).get_return(),
|
||||
)
|
||||
.unwrap();
|
||||
let (fs_pid, fd) = open_res?;
|
||||
let (fs_pid, fd) =
|
||||
open_res.map_err(|_| io::Error::new(io::ErrorKind::NotFound, "No such file"))?;
|
||||
Ok(Self { fs_pid, fd })
|
||||
}
|
||||
|
||||
pub fn file_attr(&self) -> io::Result<FileAttr> {
|
||||
let size_res: Result<u64, Errno> = postcard::from_bytes(
|
||||
let size_res: Option<u64> = postcard::from_bytes(
|
||||
&rpc::send_call(self.fs_pid, 1, 3, &postcard::to_allocvec(&self.fd).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap();
|
||||
let size = size_res?;
|
||||
let size = size_res.unwrap_or(0);
|
||||
Ok(FileAttr { size })
|
||||
}
|
||||
|
||||
@ -277,8 +260,8 @@ pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
&postcard::to_allocvec(&(self.fd, buf.len())).unwrap(),
|
||||
)
|
||||
.get_return();
|
||||
let read_res: Result<&[u8], Errno> = postcard::from_bytes(msg_data).unwrap();
|
||||
let read_data = read_res?;
|
||||
let read_res: Result<&[u8], ()> = postcard::from_bytes(msg_data).unwrap();
|
||||
let read_data = read_res.unwrap();
|
||||
let copy_len = usize::min(read_data.len(), buf.len());
|
||||
buf[0..copy_len].copy_from_slice(&read_data[0..copy_len]);
|
||||
Ok(copy_len)
|
||||
@ -300,20 +283,20 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
&postcard::to_allocvec(&(self.fd, cursor.capacity())).unwrap(),
|
||||
)
|
||||
.get_return();
|
||||
let read_res: Result<&[u8], Errno> = postcard::from_bytes(msg_data).unwrap();
|
||||
let read_data = read_res?;
|
||||
let read_res: Result<&[u8], ()> = postcard::from_bytes(msg_data).unwrap();
|
||||
let read_data = read_res.unwrap();
|
||||
let copy_len = usize::min(read_data.len(), cursor.capacity());
|
||||
cursor.append(&read_data[0..copy_len]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
let write_res: Result<(), Errno> = postcard::from_bytes(
|
||||
let write_res: Result<(), ()> = postcard::from_bytes(
|
||||
&rpc::send_call(self.fs_pid, 1, 1, &postcard::to_allocvec(&(self.fd, buf)).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap();
|
||||
write_res?;
|
||||
write_res.unwrap();
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
@ -335,17 +318,17 @@ pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
|
||||
SeekFrom::End(offset) => postcard::to_allocvec(&(self.fd, 1u8, offset)).unwrap(),
|
||||
SeekFrom::Current(offset) => postcard::to_allocvec(&(self.fd, 2u8, offset)).unwrap(),
|
||||
};
|
||||
let seek_res: Result<u64, Errno> =
|
||||
let seek_res: u64 =
|
||||
postcard::from_bytes(&rpc::send_call(self.fs_pid, 1, 8, &args).get_return()).unwrap();
|
||||
Ok(seek_res?)
|
||||
Ok(seek_res)
|
||||
}
|
||||
|
||||
pub fn duplicate(&self) -> io::Result<File> {
|
||||
let msg_data =
|
||||
&rpc::send_call(self.fs_pid, 1, 4, &postcard::to_allocvec(&self.fd).unwrap())
|
||||
.get_return();
|
||||
let dup_res: Result<u64, Errno> = postcard::from_bytes(msg_data).unwrap();
|
||||
let dup_data = dup_res?;
|
||||
let dup_res: Option<u64> = postcard::from_bytes(msg_data).unwrap();
|
||||
let dup_data = dup_res.unwrap();
|
||||
Ok(Self { fs_pid: self.fs_pid, fd: dup_data })
|
||||
}
|
||||
|
||||
@ -381,18 +364,8 @@ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn readdir(path: &Path) -> io::Result<ReadDir> {
|
||||
let vfs_pid = loop {
|
||||
if let Some(pid) = syscalls::try_get_registered(0) {
|
||||
break pid;
|
||||
}
|
||||
};
|
||||
let open_res: Result<(u64, u64), Errno> = postcard::from_bytes(
|
||||
&rpc::send_call(vfs_pid, 2, 6, &postcard::to_allocvec(path).unwrap()).get_return(),
|
||||
)
|
||||
.unwrap();
|
||||
let (fs_pid, fd) = open_res?;
|
||||
Ok(ReadDir { path: path.to_owned(), fs_pid, fd })
|
||||
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn unlink(_p: &Path) -> io::Result<()> {
|
||||
|
@ -3,7 +3,6 @@
|
||||
pub use crate::ffi::OsString as EnvKey;
|
||||
use crate::ffi::{CString, OsStr, OsString};
|
||||
use crate::num::NonZero;
|
||||
use crate::os::mikros::Errno;
|
||||
use crate::os::mikros::ipc::rpc;
|
||||
use crate::path::Path;
|
||||
use crate::sys::fs::File;
|
||||
@ -129,7 +128,7 @@ pub fn spawn(
|
||||
};
|
||||
let stdio = [stdin, stdout, stderr];
|
||||
let path = Path::new(&self.program);
|
||||
let binary = crate::fs::read(path)?;
|
||||
let binary = crate::fs::read(path).unwrap();
|
||||
let (space, entry) = crate::os::mikros::loader::Loader::load(&binary);
|
||||
let args_owned = self
|
||||
.args
|
||||
@ -139,12 +138,8 @@ pub fn spawn(
|
||||
let args = args_owned.iter().map(|arg| arg.to_bytes_with_nul()).collect::<Vec<&[u8]>>();
|
||||
let pid = super::syscalls::new_process(entry as _, space, args.as_slice()).unwrap();
|
||||
if let Some(vfs_pid) = syscalls::try_get_registered(0) {
|
||||
let res: Result<(), Errno> = postcard::from_bytes(
|
||||
&rpc::send_call(vfs_pid, 2, 4, &postcard::to_allocvec(&(pid, stdio)).unwrap())
|
||||
.get_return(),
|
||||
)
|
||||
.unwrap();
|
||||
res?;
|
||||
let _ = &rpc::send_call(vfs_pid, 2, 4, &postcard::to_allocvec(&(pid, stdio)).unwrap())
|
||||
.get_return();
|
||||
};
|
||||
syscalls::wake_new(pid).unwrap();
|
||||
Ok((Process { dummy: () }, StdioPipes { stdin: None, stdout: None, stderr: None }))
|
||||
|
Loading…
Reference in New Issue
Block a user