From 136f1a114e7b1a5abf0b70aae780f66a1c892823 Mon Sep 17 00:00:00 2001 From: WangRunji Date: Sun, 6 May 2018 16:03:35 +0800 Subject: [PATCH] Move `Device` from sfs to vfs --- Cargo.toml | 2 ++ src/c_interface.rs | 2 +- src/sfs.rs | 9 +-------- src/vfs.rs | 7 +++++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0bc10e3..08b9800 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ panic = 'abort' # prevent `_Unwind_Resume` link error [dependencies] spin = "0.4" bit-set = { default-features = false, version = "0.5" } # default-features contains 'std' + +[target.ucore.dependencies] bitflags = "1.0" [features] diff --git a/src/c_interface.rs b/src/c_interface.rs index defd49a..7503cba 100644 --- a/src/c_interface.rs +++ b/src/c_interface.rs @@ -265,7 +265,7 @@ impl IoBuf { } // FIXME: Must block aligned -impl sfs::Device for Device { +impl vfs::Device for Device { fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option { let mut io_buf = IoBuf { base: buf.as_mut_ptr(), diff --git a/src/sfs.rs b/src/sfs.rs index f394794..53fa46d 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -4,18 +4,11 @@ use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String}; use core::cell::{RefCell, RefMut}; use dirty::Dirty; use super::structs::*; -use super::vfs; +use super::vfs::{self, Device}; use core::mem::{uninitialized, size_of}; use core::slice; use core::fmt::{Debug, Formatter, Error}; -/// Interface for SFS to read & write -/// TODO: use std::io::{Read, Write} -pub trait Device { - fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option; - fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option; -} - trait DeviceExt: Device { fn read_block(&mut self, id: BlockId, offset: usize, buf: &mut [u8]) -> vfs::Result<()> { debug_assert!(offset + buf.len() <= BLKSIZE); diff --git a/src/vfs.rs b/src/vfs.rs index 9be6ef5..0f0202d 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -4,6 +4,13 @@ use core::mem::size_of; use core; use core::fmt::Debug; +/// Interface for FS to read & write +/// TODO: use std::io::{Read, Write} +pub trait Device { + fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option; + fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option; +} + /// Abstract operations on a inode. pub trait INode: Debug { fn open(&mut self, flags: u32) -> Result<()>;