Skip to content

Commit

Permalink
Revises vectored I/O system (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Apr 16, 2024
1 parent 88659fc commit 44ee774
Show file tree
Hide file tree
Showing 26 changed files with 757 additions and 772 deletions.
24 changes: 12 additions & 12 deletions src/kernel/src/dev/camera.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{
errno::Errno,
fs::{
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, MakeDevError, MakeDevFlags,
Mode, OpenFlags, Uio, UioMut,
},
process::VThread,
ucred::{Gid, Uid},
use crate::errno::Errno;
use crate::fs::{
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, IoLen, IoVec, IoVecMut,
MakeDevError, MakeDevFlags, Mode, OpenFlags,
};
use crate::process::VThread;
use crate::ucred::{Gid, Uid};
use std::sync::Arc;
use thiserror::Error;

Expand Down Expand Up @@ -35,19 +33,21 @@ impl DeviceDriver for Camera {
fn read(
&self,
dev: &Arc<CharacterDevice>,
data: &mut UioMut,
off: Option<u64>,
buf: &mut [IoVecMut],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

#[allow(unused_variables)] // TODO: remove when implementing
fn write(
&self,
dev: &Arc<CharacterDevice>,
data: &mut Uio,
off: Option<u64>,
buf: &[IoVec],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

Expand Down
17 changes: 10 additions & 7 deletions src/kernel/src/dev/deci.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::errno::Errno;
use crate::fs::{
make_dev, CharacterDevice, DeviceDriver, DriverFlags, MakeDevError, MakeDevFlags, Mode,
OpenFlags, Uio, UioMut,
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoLen, IoVec, IoVecMut, MakeDevError,
MakeDevFlags, Mode, OpenFlags,
};
use crate::process::VThread;
use crate::ucred::{Gid, Uid};
use crate::{errno::Errno, process::VThread};
use std::sync::Arc;
use thiserror::Error;

Expand Down Expand Up @@ -32,19 +33,21 @@ impl DeviceDriver for Driver {
fn read(
&self,
dev: &Arc<CharacterDevice>,
data: &mut UioMut,
off: Option<u64>,
buf: &mut [IoVecMut],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

#[allow(unused_variables)] // TODO: remove when implementing
fn write(
&self,
dev: &Arc<CharacterDevice>,
data: &mut Uio,
off: Option<u64>,
buf: &[IoVec],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/kernel/src/dev/hid.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
errno::Errno,
fs::{CharacterDevice, DeviceDriver, IoCmd, UioMut},
process::VThread,
};
use crate::errno::Errno;
use crate::fs::{CharacterDevice, DeviceDriver, IoCmd, IoLen, IoVecMut};
use crate::process::VThread;
use std::sync::Arc;

#[derive(Debug)]
Expand All @@ -13,9 +11,10 @@ impl DeviceDriver for Hid {
fn read(
&self,
dev: &Arc<CharacterDevice>,
data: &mut UioMut,
off: Option<u64>,
buf: &mut [IoVecMut],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

Expand Down
18 changes: 9 additions & 9 deletions src/kernel/src/dev/random.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{
errno::Errno,
fs::{CharacterDevice, DefaultDeviceError, DeviceDriver, IoCmd, Uio, UioMut},
process::VThread,
};
use crate::errno::Errno;
use crate::fs::{CharacterDevice, DefaultDeviceError, DeviceDriver, IoCmd, IoLen, IoVec, IoVecMut};
use crate::process::VThread;
use std::sync::Arc;

#[derive(Debug)]
Expand All @@ -13,19 +11,21 @@ impl DeviceDriver for Random {
fn read(
&self,
dev: &Arc<CharacterDevice>,
data: &mut UioMut,
off: Option<u64>,
buf: &mut [IoVecMut],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

#[allow(unused_variables)] // TODO: remove when implementing
fn write(
&self,
dev: &Arc<CharacterDevice>,
data: &mut Uio,
off: Option<u64>,
buf: &[IoVec],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

Expand Down
17 changes: 10 additions & 7 deletions src/kernel/src/dev/ttyconsole.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::errno::{Errno, EPERM};
use crate::fs::{
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, MakeDevError, MakeDevFlags, Mode,
OpenFlags, Uio, UioMut,
make_dev, CharacterDevice, DeviceDriver, DriverFlags, IoCmd, IoLen, IoVec, IoVecMut,
MakeDevError, MakeDevFlags, Mode, OpenFlags,
};
use crate::process::VThread;
use crate::ucred::{Gid, Uid};
use crate::{errno::Errno, process::VThread};
use macros::Errno;
use std::sync::Arc;
use thiserror::Error;
Expand Down Expand Up @@ -35,19 +36,21 @@ impl DeviceDriver for TtyConsole {
fn read(
&self,
dev: &Arc<CharacterDevice>,
data: &mut UioMut,
off: Option<u64>,
buf: &mut [IoVecMut],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

#[allow(unused_variables)] // TODO: remove when implementing
fn write(
&self,
dev: &Arc<CharacterDevice>,
data: &mut Uio,
off: Option<u64>,
buf: &[IoVec],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
) -> Result<IoLen, Box<dyn Errno>> {
todo!()
}

Expand Down
20 changes: 9 additions & 11 deletions src/kernel/src/dmem/blockpool.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
use crate::errno::Errno;
use crate::fs::{DefaultFileBackendError, FileBackend, IoCmd, PollEvents, Stat, VFile};
use crate::process::VThread;
use std::sync::Arc;

#[derive(Debug)]
pub struct BlockPool {}

impl BlockPool {
pub fn new() -> Arc<Self> {
Arc::new(Self {})
pub fn new() -> Self {
Self {}
}
}

impl FileBackend for BlockPool {
fn is_seekable(&self) -> bool {
todo!()
}

#[allow(unused_variables)] // TODO: remove when implementing
fn ioctl(
self: &Arc<Self>,
file: &VFile,
cmd: IoCmd,
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
fn ioctl(&self, file: &VFile, cmd: IoCmd, td: Option<&VThread>) -> Result<(), Box<dyn Errno>> {
match cmd {
IoCmd::BPOOLEXPAND(args) => todo!(),
IoCmd::BPOOLSTATS(out) => todo!(),
Expand All @@ -28,11 +26,11 @@ impl FileBackend for BlockPool {
}

#[allow(unused_variables)] // TODO: remove when implementing
fn poll(self: &Arc<Self>, file: &VFile, events: PollEvents, td: &VThread) -> PollEvents {
fn poll(&self, file: &VFile, events: PollEvents, td: &VThread) -> PollEvents {
todo!()
}

fn stat(self: &Arc<Self>, _: &VFile, _: Option<&VThread>) -> Result<Stat, Box<dyn Errno>> {
fn stat(&self, _: &VFile, _: Option<&VThread>) -> Result<Stat, Box<dyn Errno>> {
let mut stat = Stat::zeroed();

stat.block_size = 0x10000;
Expand Down
10 changes: 6 additions & 4 deletions src/kernel/src/dmem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ impl DmemManager {

let flags = VFileFlags::from_bits_retain(flags) | VFileFlags::WRITE;

let fd = td
.proc()
.files()
.alloc(Arc::new(VFile::new(VFileType::Blockpool(bp), flags)));
let fd = td.proc().files().alloc(Arc::new(VFile::new(
VFileType::Blockpool,
flags,
None,
Box::new(bp),
)));

info!("Opened a blockpool at fd = {fd}");

Expand Down
22 changes: 12 additions & 10 deletions src/kernel/src/errno.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! This module contains errno used in a PS4 system. The value of each errno must be the same as the
//! PS4.
use std::convert::Infallible;
use std::error::Error;
use std::hint::unreachable_unchecked;
use std::num::NonZeroI32;

// This file contains errno used in a PS4 system. The value of each errno must be the same as the
// PS4.

macro_rules! error_numbers {
($($name:ident($num:expr) => $desc:literal,)*) => {
$(
Expand Down Expand Up @@ -127,7 +127,7 @@ error_numbers! {
}

/// An object that is mappable to PS4 errno.
pub trait Errno: Error {
pub trait Errno: Error + Send + Sync {
fn errno(&self) -> NonZeroI32;
}

Expand All @@ -143,14 +143,16 @@ impl<T: Errno + 'static> From<T> for Box<dyn Errno> {
}
}

impl Errno for Infallible {
fn errno(&self) -> NonZeroI32 {
// SAFETY: This is safe because Infallible type guarantee its value cannot be constructed,
// which imply this method cannot be called because it required a value of Infallible type.
unsafe { unreachable_unchecked() };
}
}

/// Get human readable text.
pub fn strerror(num: NonZeroI32) -> &'static str {
// This function is generated inside the macro `error_numbers!`.
strerror_impl(num)
}

impl Errno for Infallible {
fn errno(&self) -> NonZeroI32 {
match *self {}
}
}
Loading

0 comments on commit 44ee774

Please sign in to comment.