mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
Fix #79.
This commit is contained in:
parent
5a362ba7cd
commit
bb9b32be61
@ -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