     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33

    // mod sdcard;
    mod virtio_blk;

    // pub use sdcard::SDCardWrapper;
    pub use virtio_blk::VirtIOBlock;

    use crate::board::BlockDeviceImpl;
    use alloc::sync::Arc;
    use crate::fs::easy_fs::BlockDevice;
    use lazy_static::*;

    lazy_static! {
        pub static ref BLOCK_DEVICE: Arc<dyn BlockDevice> = {
            kprintln!("[KERN] drivers::block::lazy_static!BLOCK_DEVICE begin");
            Arc::new(BlockDeviceImpl::new())
        };
    }

    #[allow(unused)]
    pub fn block_device_test() {
        let block_device = BLOCK_DEVICE.clone();
        let mut write_buffer = [0u8; 512];
        let mut read_buffer = [0u8; 512];
        for i in 0..512 {
            for byte in write_buffer.iter_mut() {
                *byte = i as u8;
            }
            block_device.write_block(i as usize, &write_buffer);
            block_device.read_block(i as usize, &mut read_buffer);
            assert_eq!(write_buffer, read_buffer);
        }
        println!("block device test passed!");
    }