RedoxFS 0.5.0

Significant re-design to use copy-on-write and hashes for all data
This commit is contained in:
Jeremy Soller
2021-12-29 16:11:54 -07:00
committed by Jeremy Soller
parent c98e63af87
commit 731b97262b
27 changed files with 3837 additions and 1602 deletions
+6 -6
View File
@@ -3,8 +3,8 @@ use std::io::{Read, Seek, SeekFrom, Write};
use std::path::Path;
use syscall::error::{Error, Result, EIO};
use disk::Disk;
use BLOCK_SIZE;
use crate::disk::Disk;
use crate::BLOCK_SIZE;
macro_rules! try_disk {
($expr:expr) => {
@@ -25,7 +25,7 @@ pub struct DiskFile {
impl DiskFile {
pub fn open<P: AsRef<Path>>(path: P) -> Result<DiskFile> {
let file = try_disk!(OpenOptions::new().read(true).write(true).open(path));
Ok(DiskFile { file: file })
Ok(DiskFile { file })
}
pub fn create<P: AsRef<Path>>(path: P, size: u64) -> Result<DiskFile> {
@@ -35,18 +35,18 @@ impl DiskFile {
.create(true)
.open(path));
try_disk!(file.set_len(size));
Ok(DiskFile { file: file })
Ok(DiskFile { file })
}
}
impl Disk for DiskFile {
fn read_at(&mut self, block: u64, buffer: &mut [u8]) -> Result<usize> {
unsafe fn read_at(&mut self, block: u64, buffer: &mut [u8]) -> Result<usize> {
try_disk!(self.file.seek(SeekFrom::Start(block * BLOCK_SIZE)));
let count = try_disk!(self.file.read(buffer));
Ok(count)
}
fn write_at(&mut self, block: u64, buffer: &[u8]) -> Result<usize> {
unsafe fn write_at(&mut self, block: u64, buffer: &[u8]) -> Result<usize> {
try_disk!(self.file.seek(SeekFrom::Start(block * BLOCK_SIZE)));
let count = try_disk!(self.file.write(buffer));
Ok(count)