From ff62de072261c2ee49ea817c51c5ec7c6e74775f Mon Sep 17 00:00:00 2001 From: Direktor799 Date: Sat, 28 May 2022 11:25:55 +0800 Subject: [PATCH] fix(BlockCache): Vec as aligned buf use a Vec allocated from buddy system to make sure it's well aligned --- 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 4b90294..1b3b969 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,