summaryrefslogtreecommitdiff
path: root/ayafs-core/src/block_device
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-12-01 19:42:13 -0800
committerChuyan Zhang <me@zcy.moe>2023-12-01 19:42:13 -0800
commit4c34414b26bf71e747ea3ecb2586645bab4aba52 (patch)
treeb569935a94c7fb3e0a23a19207f6545b4d7719c3 /ayafs-core/src/block_device
parentfd125947c9db0b33761414e65e919f73d9bf1815 (diff)
downloadmyfs-4c34414b26bf71e747ea3ecb2586645bab4aba52.tar.gz
myfs-4c34414b26bf71e747ea3ecb2586645bab4aba52.zip
Multiple bugfix, it works!
Diffstat (limited to 'ayafs-core/src/block_device')
-rw-r--r--ayafs-core/src/block_device/disk.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/ayafs-core/src/block_device/disk.rs b/ayafs-core/src/block_device/disk.rs
index d2beee9..9e9b6bc 100644
--- a/ayafs-core/src/block_device/disk.rs
+++ b/ayafs-core/src/block_device/disk.rs
@@ -2,22 +2,22 @@ use crate::block_device::{BlockDevice, BLOCK_SIZE};
use std::cell::RefCell;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
+use log::debug;
pub struct Disk {
+ #[allow(unused)]
disk_path: PathBuf,
device: RefCell<File>,
}
impl Disk {
pub fn new(disk_path: PathBuf) -> Self {
-
let device = File::options()
.read(true)
.write(true)
.open(disk_path.as_path())
.unwrap();
- // let device = File::open(disk_path.as_path()).unwrap();
Self {
disk_path,
device: RefCell::new(device),
@@ -27,6 +27,7 @@ impl Disk {
impl BlockDevice for Disk {
fn read(&self, block_id: usize, buffer: &mut [u8]) {
+ assert_eq!(buffer.len(), BLOCK_SIZE);
let mut device = self.device.borrow_mut();
device
.seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64))
@@ -34,9 +35,11 @@ impl BlockDevice for Disk {
device
.read_exact(buffer)
.expect("Failed to read 4096 bytes!");
+ debug!("disk::read block {}", block_id);
}
fn write(&self, block_id: usize, buffer: &[u8]) {
+ assert_eq!(buffer.len(), BLOCK_SIZE);
let mut device = self.device.borrow_mut();
device
.seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64))
@@ -44,5 +47,6 @@ impl BlockDevice for Disk {
device
.write_all(buffer)
.expect("Unable to write 4096 bytes!");
+ debug!("disk::write block {}", block_id);
}
}