We need BlockCache.
This commit is contained in:
parent
ed9ca7f62d
commit
00eaa64e7d
7 changed files with 428 additions and 33 deletions
|
@ -4,6 +4,7 @@ extern crate alloc;
|
|||
use easy_fs::{
|
||||
BlockDevice,
|
||||
EasyFileSystem,
|
||||
Inode,
|
||||
};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write, Seek, SeekFrom};
|
||||
|
@ -16,6 +17,7 @@ struct BlockFile(Mutex<File>);
|
|||
|
||||
impl BlockDevice for BlockFile {
|
||||
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
|
||||
println!("reading block {}", block_id);
|
||||
let mut file = self.0.lock().unwrap();
|
||||
file.seek(SeekFrom::Start((block_id * BLOCK_SZ) as u64))
|
||||
.expect("Error when seeking!");
|
||||
|
@ -23,6 +25,7 @@ impl BlockDevice for BlockFile {
|
|||
}
|
||||
|
||||
fn write_block(&self, block_id: usize, buf: &[u8]) {
|
||||
println!("writing block {}", block_id);
|
||||
let mut file = self.0.lock().unwrap();
|
||||
file.seek(SeekFrom::Start((block_id * BLOCK_SZ) as u64))
|
||||
.expect("Error when seeking!");
|
||||
|
@ -35,19 +38,23 @@ fn main() {
|
|||
}
|
||||
|
||||
fn easy_fs_pack() -> std::io::Result<()> {
|
||||
let block_file = BlockFile(Mutex::new(
|
||||
let block_file = Arc::new(BlockFile(Mutex::new(
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open("target/fs.img")?
|
||||
));
|
||||
/*
|
||||
let _efs = EasyFileSystem::create(
|
||||
Arc::new(block_file),
|
||||
)));
|
||||
EasyFileSystem::create(
|
||||
block_file.clone(),
|
||||
4096,
|
||||
1,
|
||||
);
|
||||
*/
|
||||
let _efs = EasyFileSystem::open(Arc::new(block_file));
|
||||
let efs = EasyFileSystem::open(block_file.clone());
|
||||
let mut root_inode = EasyFileSystem::root_inode(&efs);
|
||||
root_inode.create("filea");
|
||||
root_inode.create("fileb");
|
||||
for name in root_inode.ls() {
|
||||
println!("name");
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue