1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

My fault, the mut's in let Some don't actually do anything.

This commit is contained in:
Stephen Marz 2020-03-13 12:58:16 -04:00
parent efb26d6aa3
commit 5e0be36d45

View File

@ -246,7 +246,7 @@ pub fn fill_next_descriptor(bd: &mut BlockDevice, desc: Descriptor) -> u16 {
pub fn read(dev: usize, buffer: *mut u8, size: u32, offset: u64) { pub fn read(dev: usize, buffer: *mut u8, size: u32, offset: u64) {
unsafe { unsafe {
if let Some(mut bdev) = BLOCK_DEVICES[dev - 1].as_mut() { if let Some(bdev) = BLOCK_DEVICES[dev - 1].as_mut() {
let sector = offset / 512; let sector = offset / 512;
let blk_request_size = size_of::<Request>(); let blk_request_size = size_of::<Request>();
let blk_request = let blk_request =
@ -291,7 +291,7 @@ pub fn read(dev: usize, buffer: *mut u8, size: u32, offset: u64) {
pub fn write(dev: usize, buffer: *mut u8, size: u32, offset: u64) { pub fn write(dev: usize, buffer: *mut u8, size: u32, offset: u64) {
unsafe { unsafe {
if let Some(mut bdev) = BLOCK_DEVICES[dev - 1].as_mut() { if let Some(bdev) = BLOCK_DEVICES[dev - 1].as_mut() {
let sector = offset / 512; let sector = offset / 512;
let blk_request_size = size_of::<Request>(); let blk_request_size = size_of::<Request>();
let blk_request = let blk_request =
@ -342,27 +342,13 @@ pub fn pending(bd: &mut BlockDevice) {
// Here we need to check the used ring and then free the resources // Here we need to check the used ring and then free the resources
// given by the descriptor id. // given by the descriptor id.
unsafe { unsafe {
// println!("Size of Queue = {}, Descriptor = {}, Avail = {}, Used = {}",
// size_of::<virtio::Queue>(),
// size_of::<virtio::Descriptor>(),
// size_of::<virtio::Available>(),
// size_of::<virtio::Used>()
// );
// println!("AL Dev {:p}", &(*bd.queue).used);
let ref queue = &*bd.queue; let ref queue = &*bd.queue;
while bd.ack_used_idx != queue.used.idx { while bd.ack_used_idx != queue.used.idx {
// println!("ACK = {}, Used = {}", bd.ack_used_idx, queue.used.idx);
let ref elem = queue.used.ring[bd.ack_used_idx as usize]; let ref elem = queue.used.ring[bd.ack_used_idx as usize];
bd.ack_used_idx = (bd.ack_used_idx + 1) % VIRTIO_RING_SIZE as u16; bd.ack_used_idx = (bd.ack_used_idx + 1) % VIRTIO_RING_SIZE as u16;
let idx = elem.id as usize; kfree(queue.desc[elem.id as usize].addr as *mut u8);
let _len = elem.len as usize; // TODO: Awaken the process that will need this I/O. This is
// println!("Elem id = {}, Len = {}", idx, len); // the purpose of the waiting state.
// let ref desc = queue.desc[idx];
// Free the header.
// let addr = desc.addr as *const Request;
// println!("Status returned as {}", (*addr).status.status);
// println!("Freeing {:p}", addr);
kfree(queue.desc[idx].addr as *mut u8);
} }
} }
} }
@ -371,7 +357,7 @@ pub fn pending(bd: &mut BlockDevice) {
/// virtio determines that this is a block device, it sends it here. /// virtio determines that this is a block device, it sends it here.
pub fn handle_interrupt(idx: usize) { pub fn handle_interrupt(idx: usize) {
unsafe { unsafe {
if let Some(mut bdev) = BLOCK_DEVICES[idx].as_mut() { if let Some(bdev) = BLOCK_DEVICES[idx].as_mut() {
pending(bdev); pending(bdev);
} }
else { else {