Skip to content

Commit

Permalink
add queue to block
Browse files Browse the repository at this point in the history
  • Loading branch information
yodalee committed May 9, 2023
1 parent e2c5336 commit 2252f8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn init_disk() {
Ok(block) => unsafe {
DISK = Some(block);
},
Err(()) => panic!("Error: Disk initialization"),
Err(_err) => panic!("Error: Disk initialization"),
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/virtio/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::header::VirtioHeader;
use super::queue::VirtioQueue;
use super::Error;

use bitflags::bitflags;

Expand All @@ -11,21 +13,24 @@ use bitflags::bitflags;
/// ref: 5.2 Block Device
pub struct VirtioBlock {
header: &'static mut VirtioHeader,
queue: VirtioQueue,
}

impl VirtioBlock {
pub fn new(header: &'static mut VirtioHeader) -> Result<Self, ()> {
pub fn new(header: &'static mut VirtioHeader) -> Result<Self, Error> {
header.begin_init(|features| {
let features = BlockFeatures::from_bits_truncate(features);
let disable_features = BlockFeatures::RO
| BlockFeatures::CONFIG_WCE
| BlockFeatures::RING_EVENT_IDX
| BlockFeatures::RING_INDIRECT_DESC;
(features - disable_features).bits()
}).ok();
})?;

let queue = VirtioQueue::new(header, 0, 8)?;
header.end_init();

Ok(Self { header })
Ok(Self { header, queue })
}
}

Expand Down

0 comments on commit 2252f8b

Please sign in to comment.