From fd125947c9db0b33761414e65e919f73d9bf1815 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Thu, 30 Nov 2023 12:01:11 -0800 Subject: Refactor workspace --- ayafs/src/block_device/disk.rs | 47 ------------------------------------------ 1 file changed, 47 deletions(-) delete mode 100644 ayafs/src/block_device/disk.rs (limited to 'ayafs/src/block_device/disk.rs') diff --git a/ayafs/src/block_device/disk.rs b/ayafs/src/block_device/disk.rs deleted file mode 100644 index 3f0b018..0000000 --- a/ayafs/src/block_device/disk.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::cell::RefCell; -use std::fs::File; -use std::io::{Read, Seek, SeekFrom, Write}; -use std::path::{Path, PathBuf}; -use crate::block_device::{BLOCK_SIZE, BlockDevice}; - -pub struct Disk { - disk_path: PathBuf, - device: RefCell, -} - -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), - } - } -} - -impl BlockDevice for Disk { - fn read(&self, block_id: usize, buffer: &mut [u8]) { - let mut device = self.device.borrow_mut(); - device - .seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64)) - .expect("Unable to seek!"); - device - .read_exact(buffer) - .expect("Failed to read 4096 bytes!"); - } - - fn write(&self, block_id: usize, buffer: &[u8]) { - let mut device = self.device.borrow_mut(); - device - .seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64)) - .expect("Unable to seek!"); - device - .write_all(buffer) - .expect("Unable to write 4096 bytes!"); - } -} \ No newline at end of file -- cgit v1.2.3-70-g09d2