Skip to content

Commit c441c1c

Browse files
authored
feat(storage): define storage device trait (#648)
* add storage device trait Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * fix warings Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * add get_namespaceid, get_blocksize Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * fix namespace_id Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * delete unnecessary comments Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * fix add_storage_device Signed-off-by: Koichi <koichi.imai.2@tier4.jp> * separate trait and amanger Signed-off-by: Koichi <koichi.imai.2@tier4.jp> --------- Signed-off-by: Koichi <koichi.imai.2@tier4.jp>
1 parent 9f8a3ae commit c441c1c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

awkernel_lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod mmio;
2626
pub mod net;
2727
pub mod priority_queue;
2828
pub mod sanity;
29+
pub mod storage;
2930
pub mod sync;
3031
pub mod time;
3132
pub mod timer;

awkernel_lib/src/storage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod storage_device;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use alloc::{borrow::Cow, vec::Vec};
2+
3+
#[derive(Debug, Clone, Copy)]
4+
pub enum StorageDeviceType {
5+
NVMe,
6+
SATA,
7+
USB,
8+
VirtIO,
9+
Memory,
10+
}
11+
12+
#[derive(Debug)]
13+
pub enum StorageDevError {
14+
IoError,
15+
InvalidCommand,
16+
DeviceNotReady,
17+
InvalidBlock,
18+
BufferTooSmall,
19+
NotSupported,
20+
}
21+
22+
pub trait StorageDevice: Send + Sync {
23+
fn device_id(&self) -> u64;
24+
25+
fn device_name(&self) -> Cow<'static, str>;
26+
27+
fn device_short_name(&self) -> Cow<'static, str>;
28+
29+
fn device_type(&self) -> StorageDeviceType;
30+
31+
fn irqs(&self) -> Vec<u16>;
32+
33+
fn interrupt(&self, irq: u16) -> Result<(), StorageDevError>;
34+
35+
fn block_size(&self) -> usize;
36+
37+
fn num_blocks(&self) -> u64;
38+
39+
fn read_blocks(&self, buf: &mut [u8], transfer_id: u16) -> Result<(), StorageDevError>;
40+
41+
fn write_blocks(&self, buf: &[u8], transfer_id: u16) -> Result<(), StorageDevError>;
42+
43+
fn flush(&self, _transfer_id: u16) -> Result<(), StorageDevError> {
44+
Ok(())
45+
}
46+
}

0 commit comments

Comments
 (0)