Skip to content

Commit

Permalink
Merge branch 'main' into vnops
Browse files Browse the repository at this point in the history
  • Loading branch information
SuchAFuriousDeath authored Feb 16, 2024
2 parents d3c928d + 7e2563a commit e8b3884
Show file tree
Hide file tree
Showing 23 changed files with 716 additions and 220 deletions.
15 changes: 15 additions & 0 deletions src/kernel/src/budget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ impl Budget {
}
}

#[derive(Debug)]
pub enum BudgetType {
DirectMemory = 1,
VirtualMemory = 2,
LockedMemory = 3,
CpuSet = 4,
FdFile = 5,
FdSocket = 6,
FdEqueue = 7,
FdPipe = 8,
FdDevice = 9,
Threads = 10,
FdIpcSocket = 11,
}

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProcType {
Expand Down
37 changes: 2 additions & 35 deletions src/kernel/src/dmem/blockpool.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::errno::{Errno, ENOTTY};
use crate::errno::Errno;
use crate::fs::{FileBackend, IoCmd, Stat, VFile};
use crate::process::VThread;
use macros::Errno;
use std::sync::Arc;
use thiserror::Error;

#[derive(Debug)]
pub struct BlockPool {}
Expand All @@ -14,14 +12,9 @@ impl FileBackend for BlockPool {
self: &Arc<Self>,
file: &VFile,
cmd: IoCmd,
data: &mut [u8],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
match cmd {
BLOCKPOOL_CMD1 => todo!("blockpool ioctl cmd 1"),
BLOCKPOOL_CMD2 => todo!("blockpool ioctl cmd 2"),
_ => Err(IoctlError::InvalidCommand(cmd).into()),
}
todo!()
}

fn stat(self: &Arc<Self>, _: &VFile, _: Option<&VThread>) -> Result<Stat, Box<dyn Errno>> {
Expand All @@ -33,29 +26,3 @@ impl FileBackend for BlockPool {
todo!()
}
}

#[derive(Debug, Error, Errno)]
pub enum IoctlError {
#[error("invalid command {0}")]
#[errno(ENOTTY)]
InvalidCommand(IoCmd),
}

pub const BLOCKPOOL_CMD1: IoCmd = IoCmd::iowr::<BlockpoolCmd1Arg>(0xa8, 1);
pub const BLOCKPOOL_CMD2: IoCmd = IoCmd::ior::<BlockpoolCmd2Arg>(0xa8, 2);

#[repr(C)]
struct BlockpoolCmd1Arg {
arg1: u64,
arg2: u64,
arg3: u64,
arg4: u64,
}

#[repr(C)]
struct BlockpoolCmd2Arg {
arg1: u32,
arg2: u32,
arg3: u32,
arg4: u32,
}
5 changes: 2 additions & 3 deletions src/kernel/src/fs/dev/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ impl crate::fs::VnodeBackend for VnodeBackend {
fn ioctl(
self: Arc<Self>,
#[allow(unused_variables)] vn: &Arc<Vnode>,
cmd: IoCmd,
data: &mut [u8],
td: Option<&VThread>,
#[allow(unused_variables)] cmd: IoCmd,
#[allow(unused_variables)] td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
let ref fs = self.fs;

Expand Down
70 changes: 38 additions & 32 deletions src/kernel/src/fs/file.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::{IoCmd, Offset, Stat, Uio, UioMut, Vnode};
use crate::dmem::BlockPool;
use crate::errno::Errno;
use crate::errno::{ENOTTY, ENXIO};
use crate::errno::{ENOTTY, ENXIO, EOPNOTSUPP};
use crate::kqueue::KernelQueue;
use crate::net::Socket;
use crate::process::VThread;
use crate::shm::Shm;
use bitflags::bitflags;
use macros::Errno;
use std::fmt::Debug;
Expand Down Expand Up @@ -34,7 +36,7 @@ impl VFile {
&mut self.flags
}

pub fn vnode(&self) -> Option<&Arc<Vnode>> {
pub fn vnode(&self) -> Option<Arc<Vnode>> {
todo!()
}

Expand Down Expand Up @@ -80,49 +82,48 @@ impl VFile {
}

fn read(&self, buf: &mut UioMut, td: Option<&VThread>) -> Result<usize, Box<dyn Errno>> {
match self.ty {
VFileType::Vnode(ref vn) => vn.read(self, buf, td),
VFileType::KernelQueue(ref kq) => kq.read(self, buf, td),
VFileType::Blockpool(ref bp) => bp.read(self, buf, td),
match &self.backend {
VFileType::Vnode(vn) => vn.read(self, buf, td),
VFileType::Socket(so) | VFileType::IpcSocket(so) => so.read(self, buf, td),
VFileType::KernelQueue(kq) => kq.read(self, buf, td),
VFileType::SharedMemory(shm) => shm.read(self, buf, td),
VFileType::Blockpool(bp) => bp.read(self, buf, td),
}
}

fn write(&self, buf: &mut Uio, td: Option<&VThread>) -> Result<usize, Box<dyn Errno>> {
match self.ty {
VFileType::Vnode(ref vn) => vn.write(self, buf, td),
VFileType::KernelQueue(ref kq) => kq.write(self, buf, td),
VFileType::Blockpool(ref bp) => bp.write(self, buf, td),
match &self.backend {
VFileType::Vnode(vn) => vn.write(self, buf, td),
VFileType::Socket(so) | VFileType::IpcSocket(so) => so.write(self, buf, td),
VFileType::KernelQueue(kq) => kq.write(self, buf, td),
VFileType::SharedMemory(shm) => shm.write(self, buf, td),
VFileType::Blockpool(bp) => bp.write(self, buf, td),
}
}

/// See `fo_ioctl` on the PS4 for a reference.
pub fn ioctl(
&self,
cmd: IoCmd,
data: &mut [u8],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
match self.ty {
VFileType::Vnode(ref vn) => vn.ioctl(self, cmd, data, td),
VFileType::KernelQueue(ref kq) => kq.ioctl(self, cmd, data, td),
VFileType::Blockpool(ref bp) => bp.ioctl(self, cmd, data, td),
pub fn ioctl(&self, cmd: IoCmd, td: Option<&VThread>) -> Result<(), Box<dyn Errno>> {
match &self.backend {
VFileType::Vnode(vn) => vn.ioctl(self, cmd, td),
VFileType::Socket(so) | VFileType::IpcSocket(so) => so.ioctl(self, cmd, td),
VFileType::KernelQueue(kq) => kq.ioctl(self, cmd, td),
VFileType::SharedMemory(shm) => shm.ioctl(self, cmd, td),
VFileType::Blockpool(bp) => bp.ioctl(self, cmd, td),
}
}

pub fn stat(&self, td: Option<&VThread>) -> Result<Stat, Box<dyn Errno>> {
match self.ty {
VFileType::Vnode(ref vn) => vn.stat(self, td),
VFileType::KernelQueue(ref kq) => kq.stat(self, td),
VFileType::Blockpool(ref bp) => bp.stat(self, td),
match &self.backend {
VFileType::Vnode(vn) => vn.stat(self, td),
VFileType::Socket(so) | VFileType::IpcSocket(so) => so.stat(self, td),
VFileType::KernelQueue(kq) => kq.stat(self, td),
VFileType::SharedMemory(shm) => shm.stat(self, td),
VFileType::Blockpool(bp) => bp.stat(self, td),
}
}

pub fn is_seekable(&self) -> bool {
match self.ty {
VFileType::Vnode(_) => true,
VFileType::KernelQueue(_) => false,
VFileType::Blockpool(_) => false,
}
matches!(self.backend, VFileType::Vnode(_))
}
}

Expand Down Expand Up @@ -150,11 +151,13 @@ impl Write for VFile {

/// Type of [`VFile`].
#[derive(Debug)]
#[rustfmt::skip]
pub enum VFileType {
Vnode(Arc<Vnode>), // DTYPE_VNODE = 1
Socket(Arc<Socket>), // DTYPE_SOCKET = 2,
KernelQueue(Arc<KernelQueue>), // DTYPE_KQUEUE = 5,
Blockpool(Arc<BlockPool>), // DTYPE_BPOOL = 17,
SharedMemory(Arc<Shm>), // DTYPE_SHM = 8,
IpcSocket(Arc<Socket>), // DTYPE_IPCSOCKET = 15,
Blockpool(Arc<BlockPool>), // DTYPE_BLOCKPOOL = 17,
}

bitflags! {
Expand Down Expand Up @@ -193,7 +196,6 @@ pub trait FileBackend: Debug + Send + Sync + 'static {
self: &Arc<Self>,
file: &VFile,
cmd: IoCmd,
data: &mut [u8],
td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
Err(Box::new(DefaultError::IoctlNotSupported))
Expand All @@ -216,4 +218,8 @@ pub enum DefaultError {
#[error("iocll is not supported")]
#[errno(ENOTTY)]
IoctlNotSupported,

#[error("operation is not supported")]
#[errno(EOPNOTSUPP)]
OperationNotSupported,
}
1 change: 0 additions & 1 deletion src/kernel/src/fs/host/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ impl crate::fs::VnodeBackend for VnodeBackend {
self: Arc<Self>,
#[allow(unused_variables)] vn: &Arc<Vnode>,
#[allow(unused_variables)] cmd: IoCmd,
#[allow(unused_variables)] data: &mut [u8],
#[allow(unused_variables)] td: Option<&VThread>,
) -> Result<(), Box<dyn Errno>> {
todo!()
Expand Down
Loading

0 comments on commit e8b3884

Please sign in to comment.