Move `Device` from sfs to vfs

master
WangRunji 7 years ago
parent 7a635c3142
commit 136f1a114e

@ -12,6 +12,8 @@ panic = 'abort' # prevent `_Unwind_Resume` link error
[dependencies] [dependencies]
spin = "0.4" spin = "0.4"
bit-set = { default-features = false, version = "0.5" } # default-features contains 'std' bit-set = { default-features = false, version = "0.5" } # default-features contains 'std'
[target.ucore.dependencies]
bitflags = "1.0" bitflags = "1.0"
[features] [features]

@ -265,7 +265,7 @@ impl IoBuf {
} }
// FIXME: Must block aligned // 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<usize> { fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Option<usize> {
let mut io_buf = IoBuf { let mut io_buf = IoBuf {
base: buf.as_mut_ptr(), base: buf.as_mut_ptr(),

@ -4,18 +4,11 @@ use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String};
use core::cell::{RefCell, RefMut}; use core::cell::{RefCell, RefMut};
use dirty::Dirty; use dirty::Dirty;
use super::structs::*; use super::structs::*;
use super::vfs; use super::vfs::{self, Device};
use core::mem::{uninitialized, size_of}; use core::mem::{uninitialized, size_of};
use core::slice; use core::slice;
use core::fmt::{Debug, Formatter, Error}; 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<usize>;
fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option<usize>;
}
trait DeviceExt: Device { trait DeviceExt: Device {
fn read_block(&mut self, id: BlockId, offset: usize, buf: &mut [u8]) -> vfs::Result<()> { fn read_block(&mut self, id: BlockId, offset: usize, buf: &mut [u8]) -> vfs::Result<()> {
debug_assert!(offset + buf.len() <= BLKSIZE); debug_assert!(offset + buf.len() <= BLKSIZE);

@ -4,6 +4,13 @@ use core::mem::size_of;
use core; use core;
use core::fmt::Debug; 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<usize>;
fn write_at(&mut self, offset: usize, buf: &[u8]) -> Option<usize>;
}
/// Abstract operations on a inode. /// Abstract operations on a inode.
pub trait INode: Debug { pub trait INode: Debug {
fn open(&mut self, flags: u32) -> Result<()>; fn open(&mut self, flags: u32) -> Result<()>;

Loading…
Cancel
Save