mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 19:03:35 +04:00
fix(BlockCache): Vec as aligned buf
use a Vec allocated from buddy system to make sure it's well aligned
This commit is contained in:
parent
21bae8b034
commit
c94782fb4f
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user