From 5e0be36d456ad254762ec9c72bbef87bd50847fb Mon Sep 17 00:00:00 2001 From: Stephen Marz Date: Fri, 13 Mar 2020 12:58:16 -0400 Subject: [PATCH] My fault, the mut's in let Some don't actually do anything. --- risc_v/ch9/src/block.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/risc_v/ch9/src/block.rs b/risc_v/ch9/src/block.rs index 2173a19..ecc690f 100755 --- a/risc_v/ch9/src/block.rs +++ b/risc_v/ch9/src/block.rs @@ -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) { 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 blk_request_size = size_of::(); 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) { 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 blk_request_size = size_of::(); 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 // given by the descriptor id. unsafe { - // println!("Size of Queue = {}, Descriptor = {}, Avail = {}, Used = {}", - // size_of::(), - // size_of::(), - // size_of::(), - // size_of::() - // ); - // println!("AL Dev {:p}", &(*bd.queue).used); let ref queue = &*bd.queue; 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]; bd.ack_used_idx = (bd.ack_used_idx + 1) % VIRTIO_RING_SIZE as u16; - let idx = elem.id as usize; - let _len = elem.len as usize; - // println!("Elem id = {}, Len = {}", idx, len); - // 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); + kfree(queue.desc[elem.id as usize].addr as *mut u8); + // TODO: Awaken the process that will need this I/O. This is + // the purpose of the waiting state. } } } @@ -371,7 +357,7 @@ pub fn pending(bd: &mut BlockDevice) { /// virtio determines that this is a block device, it sends it here. pub fn handle_interrupt(idx: usize) { unsafe { - if let Some(mut bdev) = BLOCK_DEVICES[idx].as_mut() { + if let Some(bdev) = BLOCK_DEVICES[idx].as_mut() { pending(bdev); } else {