update SEFS crate, move sgx_impl to libos
This commit is contained in:
parent
a3483851a0
commit
4e8801850d
2
deps/sefs
vendored
2
deps/sefs
vendored
@ -1 +1 @@
|
||||
Subproject commit def861510944e13b99570d0d4cae5342ee729d2f
|
||||
Subproject commit 166616e5ade1a5c929f705fd1564ef0ea337ba72
|
1
src/libos/Cargo.lock
generated
1
src/libos/Cargo.lock
generated
@ -58,7 +58,6 @@ dependencies = [
|
||||
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rcore-fs 0.1.0",
|
||||
"sgx_tstd 1.0.6",
|
||||
"spin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"static_assertions 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -11,7 +11,7 @@ bitflags = "1.0"
|
||||
log = "0.4"
|
||||
lazy_static = { version = "1.1.0", features = ["spin_no_std"] } # Implies nightly
|
||||
rcore-fs = { path = "../../deps/sefs/rcore-fs" }
|
||||
rcore-fs-sefs = { path = "../../deps/sefs/rcore-fs-sefs", features = ["sgx"] }
|
||||
rcore-fs-sefs = { path = "../../deps/sefs/rcore-fs-sefs" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -2,7 +2,8 @@ use super::*;
|
||||
|
||||
use std::fmt;
|
||||
use rcore_fs::vfs::{INode, FileSystem, FsError};
|
||||
use rcore_fs_sefs::{SEFS, dev::sgx_impl::{SgxStorage, SgxTimeProvider}};
|
||||
use rcore_fs_sefs::{SEFS};
|
||||
use super::sgx_impl::SgxStorage;
|
||||
|
||||
lazy_static! {
|
||||
/// The root of file system
|
||||
@ -136,13 +137,12 @@ impl File for INodeFile {
|
||||
}
|
||||
|
||||
fn sync_all(&self) -> Result<(), Error> {
|
||||
self.inode.sync()?;
|
||||
self.inode.sync_all()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sync_data(&self) -> Result<(), Error> {
|
||||
// TODO: add sync_data to VFS
|
||||
self.inode.sync()?;
|
||||
self.inode.sync_data()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ mod file;
|
||||
mod file_table;
|
||||
mod pipe;
|
||||
mod inode_file;
|
||||
mod sgx_impl;
|
||||
|
||||
pub use self::file::{File, FileRef, SgxFile, StdinFile, StdoutFile};
|
||||
pub use self::file_table::{FileDesc, FileTable};
|
||||
@ -282,12 +283,7 @@ pub fn do_rename(oldpath: &str, newpath: &str) -> Result<(), Error> {
|
||||
let (new_dir_path, new_file_name) = split_path(&newpath);
|
||||
let old_dir_inode = current_process.lookup_inode(old_dir_path)?;
|
||||
let new_dir_inode = current_process.lookup_inode(new_dir_path)?;
|
||||
// TODO: merge `rename` and `move` in VFS
|
||||
if Arc::ptr_eq(&old_dir_inode, &new_dir_inode) {
|
||||
old_dir_inode.rename(old_file_name, new_file_name)?;
|
||||
} else {
|
||||
old_dir_inode.move_(old_file_name, &new_dir_inode, new_file_name)?;
|
||||
}
|
||||
old_dir_inode.move_(old_file_name, &new_dir_inode, new_file_name)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
85
src/libos/src/fs/sgx_impl.rs
Normal file
85
src/libos/src/fs/sgx_impl.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use std::boxed::Box;
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sgxfs::{OpenOptions, remove, SgxFile};
|
||||
use std::sync::SgxMutex as Mutex;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use rcore_fs::dev::TimeProvider;
|
||||
use rcore_fs::vfs::Timespec;
|
||||
use rcore_fs_sefs::dev::*;
|
||||
|
||||
pub struct SgxStorage {
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
impl SgxStorage {
|
||||
pub fn new(path: impl AsRef<Path>) -> Self {
|
||||
// assert!(path.as_ref().is_dir());
|
||||
SgxStorage { path: path.as_ref().to_path_buf() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Storage for SgxStorage {
|
||||
fn open(&self, file_id: usize) -> DevResult<Box<File>> {
|
||||
let mut path = self.path.to_path_buf();
|
||||
path.push(format!("{}", file_id));
|
||||
// TODO: key
|
||||
let key = [0u8; 16];
|
||||
let file = OpenOptions::new().read(true).update(true).open_ex(path, &key)
|
||||
.expect("failed to open SgxFile");
|
||||
Ok(Box::new(LockedFile(Mutex::new(file))))
|
||||
}
|
||||
|
||||
fn create(&self, file_id: usize) -> DevResult<Box<File>> {
|
||||
let mut path = self.path.to_path_buf();
|
||||
path.push(format!("{}", file_id));
|
||||
// TODO: key
|
||||
let key = [0u8; 16];
|
||||
let file = OpenOptions::new().write(true).update(true).open_ex(path, &key)
|
||||
.expect("failed to create SgxFile");
|
||||
Ok(Box::new(LockedFile(Mutex::new(file))))
|
||||
}
|
||||
|
||||
fn remove(&self, file_id: usize) -> DevResult<()> {
|
||||
let mut path = self.path.to_path_buf();
|
||||
path.push(format!("{}", file_id));
|
||||
remove(path).expect("failed to remove SgxFile");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LockedFile(Mutex<SgxFile>);
|
||||
|
||||
// `sgx_tstd::sgxfs::SgxFile` not impl Send ...
|
||||
unsafe impl Send for LockedFile {}
|
||||
unsafe impl Sync for LockedFile {}
|
||||
|
||||
impl File for LockedFile {
|
||||
fn read_at(&self, buf: &mut [u8], offset: usize) -> DevResult<usize> {
|
||||
let mut file = self.0.lock().unwrap();
|
||||
let offset = offset as u64;
|
||||
file.seek(SeekFrom::Start(offset)).expect("failed to seek SgxFile");
|
||||
let len = file.read(buf).expect("failed to read SgxFile");
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
fn write_at(&self, buf: &[u8], offset: usize) -> DevResult<usize> {
|
||||
let mut file = self.0.lock().unwrap();
|
||||
let offset = offset as u64;
|
||||
file.seek(SeekFrom::Start(offset)).expect("failed to seek SgxFile");
|
||||
let len = file.write(buf).expect("failed to write SgxFile");
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
fn set_len(&self, len: usize) -> DevResult<()> {
|
||||
// NOTE: do nothing ??
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn flush(&self) -> DevResult<()> {
|
||||
let mut file = self.0.lock().unwrap();
|
||||
file.flush().expect("failed to flush SgxFile");
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user