diff --git a/makefile b/makefile index 73930b0df9a366e92cfea028cbb94d10d427cb77..7dbfd036ecb74da3145ed05011da315d3bfa27f1 100644 --- a/makefile +++ b/makefile @@ -74,7 +74,7 @@ hexdump: coredump: hexdump $(BIN_FILE) -C -run: build qemu +run: qemu k210: @cp src/linker-k210.ld src/linker.ld diff --git a/src/device/block.rs b/src/device/block.rs index ae3a37693f61701cae8210c3c670ae867bf80a24..c95f4074800c85c0a5ed59071b01a169e98c1a77 100644 --- a/src/device/block.rs +++ b/src/device/block.rs @@ -1,3 +1,6 @@ +use core::borrow::Borrow; + +use alloc::boxed::Box; use alloc::sync::Arc; use alloc::vec; use alloc::vec::Vec; @@ -18,11 +21,11 @@ pub struct BlockDeviceContainer (Vec<Arc<Mutex<FAT32>>>); pub struct VirtIOBlock(VirtIOBlk<'static>); impl BlockDevice for VirtIOBlock { - fn read_block(&self, sector_offset: usize, buf: &mut [u8]) { + fn read_block(&mut self, sector_offset: usize, buf: &mut [u8]) { self.0.read_block(sector_offset, buf).expect("读å–失败") } - fn write_block(&self, sector_offset: usize, buf: &mut [u8]) { + fn write_block(&mut self, sector_offset: usize, buf: &mut [u8]) { self.0.read_block(sector_offset, buf).expect("写入失败") } } @@ -31,7 +34,7 @@ impl BlockDeviceContainer { pub fn add(&mut self, virtio: usize) { // 创建å˜å‚¨è®¾å¤‡ let device = VirtIOBlk::new(unsafe {&mut *(virtio as *mut VirtIOHeader)}).expect("failed to create blk driver"); - let block_device = Arc::new(Mutex::new(VirtIOBlock(device))); + let block_device:Arc<Mutex<Box<dyn BlockDevice>>> = Arc::new(Mutex::new(Box::new(VirtIOBlock(device)))); let disk_device = Arc::new(Mutex::new(FAT32::new(block_device))); // device.lock().write_block_nb(block_id, buf, resp) // 识别分区 diff --git a/src/device/mod.rs b/src/device/mod.rs index 284009008c39678162ae8badd2eb45931337659a..6ac16eb312d296ac91b3027d623a89bc2e45830c 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -4,9 +4,9 @@ pub use block::BLK_CONTROL; pub use block::SECTOR_SIZE; pub trait BlockDevice { - fn read_block(&self, sector_offset: usize, buf: &mut [u8]); + fn read_block(&mut self, sector_offset: usize, buf: &mut [u8]); - fn write_block(&self, sector_offset: usize, buf: &mut [u8]); + fn write_block(&mut self, sector_offset: usize, buf: &mut [u8]); } pub fn init() { diff --git a/src/fs/fat32/mod.rs b/src/fs/fat32/mod.rs index 2b77107c8465f22cc5b92df28f60bc5230867955..23fafc72dec645cab405ae83892a4b3f7d96ffd9 100644 --- a/src/fs/fat32/mod.rs +++ b/src/fs/fat32/mod.rs @@ -1,6 +1,6 @@ use core::{cell::RefCell, mem::size_of}; -use alloc::{sync::Arc, rc::Rc, string::String}; +use alloc::{sync::Arc, rc::Rc, string::String, boxed::Box}; use crate::{sync::mutex::Mutex, device::{SECTOR_SIZE, BLK_CONTROL, BlockDevice}, fs::{fat32::{long_file::FAT32longFileItem, short_file::FAT32shortFileItem}, filetree::FileTreeNodeRaw}}; @@ -28,16 +28,16 @@ pub enum FAT32FileItemAttr { pub struct FAT32 { // pub device: Arc<Mutex<VirtIOBlk<'a>>>, - pub device: Arc<Mutex<dyn BlockDevice>>, + pub device: Arc<Mutex<Box<dyn BlockDevice>>>, pub bpb: FAT32BPB, } impl Partition for FAT32 { fn read_sector(&self, sector_offset: usize, buf: &mut [u8]) { let mut output = vec![0; SECTOR_SIZE]; - let t = self.device.lock(); + // let t = self.device.lock(); + self.device.lock().read_block(sector_offset, &mut output); - t. buf.copy_from_slice(&output[..buf.len()]); } @@ -78,7 +78,7 @@ impl Partition for FAT32 { /// ç›®å‰ä»…æ”¯æŒæŒ‚载文件系统 impl FAT32 { // 创建新的FAT32表项 device_id: 为设备id ç›®å‰æ”¯æŒæ–‡ä»¶ç³»ç»Ÿ éœ€è¦æ‰‹åŠ¨è¯»å–bpb - pub fn new(device: Arc<Mutex<dyn BlockDevice>>) -> Self { + pub fn new(device: Arc<Mutex<Box<dyn BlockDevice>>>) -> Self { let fat32 = FAT32 { device, bpb: Default::default() diff --git a/src/main.rs b/src/main.rs index 663349902d8ee0da757ed495141ff00fc89124b3..f7b09de83c816968ce5304665e606cc46fb84ec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,8 +123,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { // }; - // - + // let mut words = String::new(); // read_line_display(&mut words); // info!("I say {}", words);