This commit is contained in:
Yifan Wu 2022-05-27 23:42:53 -07:00
parent 5a362ba7cd
commit bb9b32be61

View File

@ -1,11 +1,13 @@
use super::{BlockDevice, BLOCK_SZ}; use super::{BlockDevice, BLOCK_SZ};
use alloc::collections::VecDeque; use alloc::collections::VecDeque;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec;
use alloc::vec::Vec;
use lazy_static::*; use lazy_static::*;
use spin::Mutex; use spin::Mutex;
pub struct BlockCache { pub struct BlockCache {
cache: [u8; BLOCK_SZ], cache: Vec<u8>,
block_id: usize, block_id: usize,
block_device: Arc<dyn BlockDevice>, block_device: Arc<dyn BlockDevice>,
modified: bool, modified: bool,
@ -14,7 +16,8 @@ pub struct BlockCache {
impl BlockCache { impl BlockCache {
/// Load a new BlockCache from disk. /// Load a new BlockCache from disk.
pub fn new(block_id: usize, block_device: Arc<dyn BlockDevice>) -> Self { pub fn new(block_id: usize, block_device: Arc<dyn BlockDevice>) -> Self {
let mut cache = [0u8; BLOCK_SZ]; // for alignment and move effciency
let mut cache = vec![0u8; BLOCK_SZ];
block_device.read_block(block_id, &mut cache); block_device.read_block(block_id, &mut cache);
Self { Self {
cache, cache,