From bb9b32be61c103ca397b7f99bf2e791f436b7382 Mon Sep 17 00:00:00 2001 From: Yifan Wu Date: Fri, 27 May 2022 23:42:53 -0700 Subject: [PATCH] Fix #79. --- easy-fs/src/block_cache.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/easy-fs/src/block_cache.rs b/easy-fs/src/block_cache.rs index 4b90294a..1b3b9697 100644 --- a/easy-fs/src/block_cache.rs +++ b/easy-fs/src/block_cache.rs @@ -1,11 +1,13 @@ use super::{BlockDevice, BLOCK_SZ}; use alloc::collections::VecDeque; use alloc::sync::Arc; +use alloc::vec; +use alloc::vec::Vec; use lazy_static::*; use spin::Mutex; pub struct BlockCache { - cache: [u8; BLOCK_SZ], + cache: Vec, block_id: usize, block_device: Arc, modified: bool, @@ -14,7 +16,8 @@ pub struct BlockCache { impl BlockCache { /// Load a new BlockCache from disk. pub fn new(block_id: usize, block_device: Arc) -> 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); Self { cache,