From f5c4db98f9473a1de6863e121d1b7f61dd74d926 Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Mon, 8 Aug 2022 20:07:43 +0300 Subject: [PATCH] Devices: Add block devices --- ableos/src/devices/character_devs/dev_null.rs | 2 +- ableos/src/devices/character_devs/dev_unicode.rs | 2 +- ableos/src/devices/character_devs/dev_zero.rs | 2 +- ableos/src/devices/character_devs/mod.rs | 2 +- ableos/src/devices/dev_vterm.rs | 2 +- ableos/src/devices/mod.rs | 3 ++- ableos/src/driver_traits/serial.rs | 2 +- ableos/src/stdio.rs | 6 ++++-- kernel/src/device_interface/block.rs | 6 ++++++ kernel/src/device_interface/block/mod.rs | 1 - kernel/src/device_interface/mod.rs | 7 +++++-- 11 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 kernel/src/device_interface/block.rs delete mode 100644 kernel/src/device_interface/block/mod.rs diff --git a/ableos/src/devices/character_devs/dev_null.rs b/ableos/src/devices/character_devs/dev_null.rs index eef0d3bb..7688875f 100644 --- a/ableos/src/devices/character_devs/dev_null.rs +++ b/ableos/src/devices/character_devs/dev_null.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::CharacterDevice; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DevNull; diff --git a/ableos/src/devices/character_devs/dev_unicode.rs b/ableos/src/devices/character_devs/dev_unicode.rs index 839c1b79..995e0375 100644 --- a/ableos/src/devices/character_devs/dev_unicode.rs +++ b/ableos/src/devices/character_devs/dev_unicode.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::CharacterDevice; #[derive(Debug)] pub struct DevUnicode { diff --git a/ableos/src/devices/character_devs/dev_zero.rs b/ableos/src/devices/character_devs/dev_zero.rs index ad26d1d8..07508b51 100644 --- a/ableos/src/devices/character_devs/dev_zero.rs +++ b/ableos/src/devices/character_devs/dev_zero.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::CharacterDevice; #[derive(Debug)] pub struct DevZero; diff --git a/ableos/src/devices/character_devs/mod.rs b/ableos/src/devices/character_devs/mod.rs index 9a2f2948..f63a0640 100644 --- a/ableos/src/devices/character_devs/mod.rs +++ b/ableos/src/devices/character_devs/mod.rs @@ -2,4 +2,4 @@ pub mod dev_null; pub mod dev_unicode; pub mod dev_zero; -pub use kernel::device_interface::character::CharacterDevice; +pub use kernel::device_interface::CharacterDevice; diff --git a/ableos/src/devices/dev_vterm.rs b/ableos/src/devices/dev_vterm.rs index 8ea16546..e807cb46 100644 --- a/ableos/src/devices/dev_vterm.rs +++ b/ableos/src/devices/dev_vterm.rs @@ -3,7 +3,7 @@ use core::ops::Not; use core::sync::atomic::AtomicU32; use core::sync::atomic::Ordering; -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::CharacterDevice; use crate::pixel_format::Rgba64; diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index 2e618d07..52758fbf 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -10,7 +10,7 @@ pub use self::Device::*; use crate::devices::dev_vterm::VTerm; use character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero}; use hashbrown::HashMap; -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::{BlockDevice, CharacterDevice}; use spin::Lazy; pub static DEVICE_TABLE: Lazy> = @@ -19,6 +19,7 @@ pub static DEVICE_TABLE: Lazy> = // FIXME: This is a hack to hold a device. // #[derive(Debug)] pub enum Device { + Block(Box), Character(Box), Vterm(Box), } diff --git a/ableos/src/driver_traits/serial.rs b/ableos/src/driver_traits/serial.rs index 8e7aa15f..118f32f0 100644 --- a/ableos/src/driver_traits/serial.rs +++ b/ableos/src/driver_traits/serial.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::character::CharacterDevice; +use kernel::device_interface::CharacterDevice; pub struct Serial { pub base: usize, diff --git a/ableos/src/stdio.rs b/ableos/src/stdio.rs index b69b2eaf..c5b127d3 100644 --- a/ableos/src/stdio.rs +++ b/ableos/src/stdio.rs @@ -1,7 +1,7 @@ use { - crate::devices::Device::{Character, Vterm}, + crate::devices::Device::{Block, Character, Vterm}, core::fmt::{Arguments, Error, Write}, - kernel::device_interface::character::CharacterDevice, + kernel::device_interface::CharacterDevice, }; #[derive(Debug, Clone)] @@ -35,6 +35,7 @@ impl StdIo { } Ok(()) } + Block(_) => todo!(), } } @@ -54,6 +55,7 @@ impl StdIo { vterm.read_char().map(|c| buf.push(c)); println!("{}", buf); } + Block(_) => todo!(), } } } diff --git a/kernel/src/device_interface/block.rs b/kernel/src/device_interface/block.rs new file mode 100644 index 00000000..9a24cc37 --- /dev/null +++ b/kernel/src/device_interface/block.rs @@ -0,0 +1,6 @@ +//! Block device interface + +/// Block device interface +pub trait BlockDevice { + // TODO +} diff --git a/kernel/src/device_interface/block/mod.rs b/kernel/src/device_interface/block/mod.rs deleted file mode 100644 index 9d0f028e..00000000 --- a/kernel/src/device_interface/block/mod.rs +++ /dev/null @@ -1 +0,0 @@ -//! diff --git a/kernel/src/device_interface/mod.rs b/kernel/src/device_interface/mod.rs index 7fe7faaf..5306d1b4 100644 --- a/kernel/src/device_interface/mod.rs +++ b/kernel/src/device_interface/mod.rs @@ -1,4 +1,7 @@ //! Platform Agnostic Device -pub mod block; -pub mod character; +mod block; +mod character; + +pub use block::BlockDevice; +pub use character::CharacterDevice;