diff options
author | Chuyan Zhang <me@zcy.moe> | 2023-11-30 02:15:06 -0800 |
---|---|---|
committer | Chuyan Zhang <me@zcy.moe> | 2023-11-30 02:15:06 -0800 |
commit | 1eac97eea4ec0bcef0be061a2cba93a584355283 (patch) | |
tree | d98fb1f6e3811286a0733c9df21e467590635ad2 /src/block_device | |
parent | b3db8a5a710aa0890c80241ffb3fd9792bf1cbe7 (diff) | |
download | myfs-1eac97eea4ec0bcef0be061a2cba93a584355283.tar.gz myfs-1eac97eea4ec0bcef0be061a2cba93a584355283.zip |
Add real disk i/o, add mkfs.aya (not yet implemented)
Diffstat (limited to 'src/block_device')
-rw-r--r-- | src/block_device/memory_disk.rs | 33 | ||||
-rw-r--r-- | src/block_device/mod.rs | 8 |
2 files changed, 0 insertions, 41 deletions
diff --git a/src/block_device/memory_disk.rs b/src/block_device/memory_disk.rs deleted file mode 100644 index 0639d3e..0000000 --- a/src/block_device/memory_disk.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::block_device::{BlockDevice, BLOCK_SIZE}; -use std::cell::RefCell; - -#[repr(C)] -pub struct MemoryDisk { - /// Emulating a block device with a segment of RAM, - /// which is 64MiB == 4KiB per block * 16384 blocks - pub arena: RefCell<Vec<u8>>, -} - -impl MemoryDisk { - pub fn new(block_number: usize) -> Self { - Self { - arena: RefCell::new(vec![0u8; BLOCK_SIZE * block_number]), - } - } -} - -impl BlockDevice for MemoryDisk { - fn read(&self, block_id: usize, buffer: &mut [u8]) { - let block_front = block_id * BLOCK_SIZE; - let block_back = block_front + BLOCK_SIZE; - let arena = self.arena.borrow(); - buffer.copy_from_slice(&arena[block_front..block_back]); - } - - fn write(&self, block_id: usize, buffer: &[u8]) { - let block_front = block_id * BLOCK_SIZE; - let block_back = block_front + BLOCK_SIZE; - let mut arena = self.arena.borrow_mut(); - arena[block_front..block_back].copy_from_slice(buffer); - } -} diff --git a/src/block_device/mod.rs b/src/block_device/mod.rs deleted file mode 100644 index a8fd8b7..0000000 --- a/src/block_device/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -/// Abstracts for block devices. -/// Currently only a mock memory disk. -pub mod memory_disk; -pub const BLOCK_SIZE: usize = 4096; -pub trait BlockDevice { - fn read(&self, block_id: usize, buffer: &mut [u8]); - fn write(&self, block_id: usize, buffer: &[u8]); -} |