Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions awkernel_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod mmio;
pub mod net;
pub mod priority_queue;
pub mod sanity;
pub mod storage;
pub mod sync;
pub mod time;
pub mod timer;
Expand Down
1 change: 1 addition & 0 deletions awkernel_lib/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod storage_device;
46 changes: 46 additions & 0 deletions awkernel_lib/src/storage/storage_device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use alloc::{borrow::Cow, vec::Vec};

#[derive(Debug, Clone, Copy)]
pub enum StorageDeviceType {
NVMe,
SATA,
USB,
VirtIO,
Memory,
}

#[derive(Debug)]
pub enum StorageDevError {
IoError,
InvalidCommand,
DeviceNotReady,
InvalidBlock,
BufferTooSmall,
NotSupported,
}

pub trait StorageDevice: Send + Sync {
fn device_id(&self) -> u64;

fn device_name(&self) -> Cow<'static, str>;

fn device_short_name(&self) -> Cow<'static, str>;

fn device_type(&self) -> StorageDeviceType;

fn irqs(&self) -> Vec<u16>;

fn interrupt(&self, irq: u16) -> Result<(), StorageDevError>;

fn block_size(&self) -> usize;

fn num_blocks(&self) -> u64;

fn read_blocks(&self, buf: &mut [u8], transfer_id: u16) -> Result<(), StorageDevError>;

fn write_blocks(&self, buf: &[u8], transfer_id: u16) -> Result<(), StorageDevError>;

fn flush(&self, _transfer_id: u16) -> Result<(), StorageDevError> {
Ok(())
}
}