Skip to content

Commit

Permalink
Add FileHandle inode wrap for device indirection
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed May 27, 2024
1 parent 9de1519 commit a7087f5
Show file tree
Hide file tree
Showing 36 changed files with 278 additions and 247 deletions.
4 changes: 2 additions & 2 deletions cykusz-rs/src/arch/x86_64/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ pub extern "C" fn fast_syscall_handler(sys_frame: &mut SyscallFrame, regs: &mut
}
} else {
//logln!("syscall {:?} {:?}", regs, sys_frame);
logln_disabled!("syscall {}, ret: 0x{:x}", regs.rax, sys_frame.rip);
logln!("syscall {}, ret: 0x{:x}", regs.rax, sys_frame.rip);

let res = crate::kernel::syscall::syscall_handler(
regs.rax, regs.rdi, regs.rsi, regs.rdx, regs.r10, regs.r8, regs.r9,
);

logln_disabled!("done syscall {} = {:?}", regs.rax, res);
logln!("done syscall {} = {:?}", regs.rax, res);

crate::arch::signal::arch_sys_check_signals(res, sys_frame, regs);
}
Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/drivers/block/ahci/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::drivers::block::ahci::port::Port;
use crate::drivers::block::ahci::reg::*;
use crate::drivers::pci::PciHeader;
use crate::kernel::block::{register_blkdev, BlockDevice};

use crate::kernel::mm::VirtAddr;

pub struct AhciDevice {
Expand Down
2 changes: 0 additions & 2 deletions cykusz-rs/src/drivers/block/ahci/port/hba.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::arch::mm::virt::map_to_flags;

use crate::drivers::block::ahci::reg::*;
use crate::drivers::block::ata::request::DmaBuf;
use crate::drivers::block::ata::AtaCommand;

use crate::kernel::mm::allocate_order;
use crate::kernel::mm::virt::PageFlags;

Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/drivers/block/ahci/reg/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use mmio::VCell;

use crate::drivers::block::ahci::reg::FisRegH2D;
use crate::kernel::mm::PhysAddr;
use crate::kernel::utils::slice::ToBytesMut;

bitflags! {
pub struct HbaCmdHeaderFlags: u16 {
Expand Down
2 changes: 0 additions & 2 deletions cykusz-rs/src/drivers/block/ahci/reg/fis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use bit_field::BitField;
use mmio::VCell;

use crate::drivers::block::ata::AtaCommand;
use crate::kernel::mm::PhysAddr;
use crate::kernel::utils::slice::ToBytesMut;

#[repr(u8)]
#[derive(Copy, Clone)]
Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/drivers/block/ahci/reg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(unused)]

use bit_field::BitField;
use mmio::VCell;

pub use self::cmd::*;
pub use self::fis::*;
Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/drivers/block/ahci/reg/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use mmio::VCell;

use crate::drivers::block::ahci::reg::HbaCmdHeader;
use crate::kernel::mm::PhysAddr;
use crate::kernel::mm::VirtAddr;

bitflags! {
pub struct HbaPortISReg: u32 {
Expand Down
9 changes: 5 additions & 4 deletions cykusz-rs/src/drivers/pci/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use alloc::sync::Arc;
use alloc::vec::Vec;

use bit_field::BitField;

use crate::arch::idt::{add_shared_irq_handler, InterruptFn, SharedInterruptFn};
use crate::arch::int::{set_active_high, set_irq_dest, set_level_triggered};
use crate::arch::mm::{PhysAddr, VirtAddr};
use crate::kernel::mm::map_to_flags;
use crate::kernel::mm::virt::PageFlags;
use alloc::sync::Arc;
use alloc::vec::Vec;
use bit_field::BitField;

use crate::kernel::sync::Spin;

mod epci;
Expand Down
16 changes: 9 additions & 7 deletions cykusz-rs/src/drivers/ps2/kbd/handler.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use crate::drivers::ps2::{controller, Error};
use crate::kernel::sync::Spin;
use crate::kernel::utils::buffer::BufferQueue;
use alloc::string::String;
use alloc::sync::{Arc, Weak};

use spin::Once;

use syscall_defs::events::{Event, EventType};
use syscall_defs::poll::PollEventFlags;
use syscall_defs::time::Timeval;
use syscall_defs::OpenFlags;

use crate::drivers::ps2::{controller, Error};
use crate::kernel::device::dev_t::DevId;
use crate::kernel::device::Device;
use crate::kernel::fs::inode::INode;
use crate::kernel::fs::poll::PollTable;
use crate::kernel::fs::vfs::FsError;
use crate::kernel::sync::Spin;
use crate::kernel::timer::current_ns;
use crate::kernel::utils::buffer::BufferQueue;
use crate::kernel::utils::wait_queue::WaitQueueFlags;
use syscall_defs::events::{Event, EventType};
use syscall_defs::poll::PollEventFlags;
use syscall_defs::time::Timeval;
use syscall_defs::OpenFlags;

use super::scancode;

Expand Down
1 change: 1 addition & 0 deletions cykusz-rs/src/drivers/ps2/kbd/scancode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use syscall_defs::events::keys::KeyCode;

macro_rules! init_arr (
($a: ident, $([$k: expr, $v: expr]),+) => {
$($a[$k] = $v;)*
Expand Down
1 change: 1 addition & 0 deletions cykusz-rs/src/drivers/ps2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::hint::spin_loop;

use spin::Once;

use crate::kernel::sync::IrqGuard;
Expand Down
21 changes: 12 additions & 9 deletions cykusz-rs/src/drivers/ps2/mouse/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
use alloc::string::String;
use alloc::sync::{Arc, Weak};

use bit_field::BitField;
use spin::Once;

use syscall_defs::events::buttons::{ButtonCode, RelCode};
use syscall_defs::events::{Event, EventType};
use syscall_defs::poll::PollEventFlags;
use syscall_defs::time::Timeval;
use syscall_defs::OpenFlags;

use crate::drivers::ps2::{controller, Error};
use crate::kernel::device::dev_t::DevId;
use crate::kernel::device::Device;
Expand All @@ -8,15 +20,6 @@ use crate::kernel::sync::Spin;
use crate::kernel::timer::current_ns;
use crate::kernel::utils::buffer::BufferQueue;
use crate::kernel::utils::wait_queue::WaitQueueFlags;
use alloc::string::String;
use alloc::sync::{Arc, Weak};
use bit_field::BitField;
use spin::Once;
use syscall_defs::events::buttons::{ButtonCode, RelCode};
use syscall_defs::events::{Event, EventType};
use syscall_defs::poll::PollEventFlags;
use syscall_defs::time::Timeval;
use syscall_defs::OpenFlags;

struct MouseState {
state: Spin<State>,
Expand Down
4 changes: 2 additions & 2 deletions cykusz-rs/src/drivers/ps2/mouse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod handler;

use crate::arch::int;
use crate::drivers::ps2::{controller, Command, Error, PS};

mod handler;

#[repr(u8)]
#[allow(dead_code)]
#[derive(Debug, Copy, Clone)]
Expand Down
7 changes: 4 additions & 3 deletions cykusz-rs/src/drivers/random.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::kernel::device::Device;
use crate::kernel::fs::inode::INode;
use alloc::string::String;
use alloc::sync::{Arc, Weak};

use rand::{RngCore, SeedableRng};

use crate::kernel::device::dev_t::DevId;
use crate::kernel::device::Device;
use crate::kernel::fs::inode::INode;
use crate::kernel::sync::Spin;
use crate::kernel::timer::current_ns;
use rand::{RngCore, SeedableRng};

struct Random {
id: DevId,
Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/drivers/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::kernel::session::{sessions, Group};
use crate::kernel::signal::{SignalError, SignalResult};
use crate::kernel::sync::{Spin, SpinGuard};
use crate::kernel::task::Task;

use crate::kernel::tty::TerminalDevice;
use crate::kernel::utils::types::Prefault;
use crate::kernel::utils::wait_queue::{WaitQueue, WaitQueueFlags};
Expand Down
12 changes: 7 additions & 5 deletions cykusz-rs/src/drivers/video/fb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
use alloc::string::String;
use alloc::sync::{Arc, Weak};
use alloc::vec::Vec;

use bit_field::BitField;
use spin::Once;

use crate::arch::mm::VirtAddr;
use crate::arch::output::{register_video_driver, Color, ColorCode, ScreenChar, VideoDriver};
use crate::drivers::multiboot2::framebuffer_info::{FramebufferInfo, FramebufferType};
Expand All @@ -11,11 +18,6 @@ use crate::kernel::mm::{map_to_flags, virt, MappedAddr, PhysAddr, PAGE_SIZE};
use crate::kernel::sync::Spin;
use crate::kernel::timer::TimerObject;
use crate::kernel::utils::types::Align;
use alloc::string::String;
use alloc::sync::{Arc, Weak};
use alloc::vec::Vec;
use bit_field::BitField;
use spin::Once;

static FONT: &'static [u8] = &[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
10 changes: 7 additions & 3 deletions cykusz-rs/src/kernel/device/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub mod dev_t;

use crate::kernel::device::dev_t::DevId;
use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::sync::Arc;
use alloc::vec::Vec;
use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering;

use crate::kernel::device::dev_t::DevId;
use crate::kernel::fs::inode::INode;
use crate::kernel::sync::RwSpin;

pub mod dev_t;

pub trait Device: Send + Sync {
fn id(&self) -> dev_t::DevId;
fn name(&self) -> String;
Expand Down Expand Up @@ -67,3 +67,7 @@ pub fn register_device_listener(listener: Arc<dyn DeviceListener>) {
pub fn devices() -> &'static RwSpin<BTreeMap<DevId, Arc<dyn Device>>> {
&DEVICES
}

pub fn find_device(id: DevId) -> Option<Arc<dyn Device>> {
devices().read().get(&id).cloned()
}
62 changes: 0 additions & 62 deletions cykusz-rs/src/kernel/fs/devnode.rs

This file was deleted.

1 change: 1 addition & 0 deletions cykusz-rs/src/kernel/fs/ext2/disk/inode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(dead_code)]

use bit_field::BitField;

use crate::kernel::device::dev_t::DevId;

#[derive(Copy, Clone, PartialEq)]
Expand Down
16 changes: 11 additions & 5 deletions cykusz-rs/src/kernel/fs/ext2/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl INode for LockedExt2INode {
parent: DirEntryItem,
name: &str,
mode: Mode,
devid: DevId
devid: DevId,
) -> Result<INodeItem> {
let inode = self.create(parent, name, mode.into())?.inode();

Expand Down Expand Up @@ -1044,6 +1044,16 @@ impl INode for LockedExt2INode {
Some(Arc::new(SysDirEntIter::new(parent, self.self_ref())))
}

fn device_id(&self) -> Option<DevId> {
if ![FileType::Block, FileType::Char].contains(&self.ftype().ok()?) {
return None;
}

let id = self.node.read().d_inode().get_rdevid();

return if id != 0 { Some(id) } else { None };
}

fn sync(&self) -> Result<()> {
let mut pages = self.dirty_list.lock();

Expand All @@ -1060,10 +1070,6 @@ impl INode for LockedExt2INode {
return Ok(());
}

fn as_inode(&self) -> Option<Arc<dyn INode>> {
Some(self.self_ref())
}

fn as_cacheable(&self) -> Option<Arc<dyn CachedAccess>> {
if self.ftype().unwrap() == FileType::File {
Some(self.self_ref())
Expand Down
9 changes: 2 additions & 7 deletions cykusz-rs/src/kernel/fs/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use syscall_defs::{FileType, OpenFlags};
use syscall_defs::poll::PollEventFlags;

use crate::kernel::device::dev_t::DevId;
use crate::kernel::device::Device;
use crate::kernel::fs::dirent::DirEntryItem;
use crate::kernel::fs::filesystem::Filesystem;
use crate::kernel::fs::icache::{INodeItem, INodeItemInt};
Expand Down Expand Up @@ -135,8 +134,8 @@ pub trait INode: Send + Sync + DowncastSync {
None
}

fn device(&self) -> Result<Arc<dyn Device>> {
return Err(FsError::EntryNotFound);
fn device_id(&self) -> Option<DevId> {
None
}

fn ioctl(&self, _cmd: usize, _arg: usize) -> Result<usize> {
Expand All @@ -149,10 +148,6 @@ pub trait INode: Send + Sync + DowncastSync {

fn ref_update(&self, _new_ref: Weak<INodeItemInt>) {}

fn as_inode(&self) -> Option<Arc<dyn INode>> {
None
}

fn as_cacheable(&self) -> Option<Arc<dyn CachedAccess>> {
None
}
Expand Down
1 change: 0 additions & 1 deletion cykusz-rs/src/kernel/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::kernel::fs::vfs::{FsError, Result};
use crate::kernel::sched::current_task;

pub mod cache;
pub mod devnode;
pub mod dirent;
pub mod ext2;
pub mod filesystem;
Expand Down
Loading

0 comments on commit a7087f5

Please sign in to comment.