fix TimeProvider. enable INodeFile

This commit is contained in:
WangRunji 2019-03-05 10:17:22 +08:00 committed by Tate Tian
parent 0105756897
commit d56378d96a
4 changed files with 41 additions and 25 deletions

2
deps/sefs vendored

@ -1 +1 @@
Subproject commit 62827eb7bb979f70fc2dad1d957ba19016214441
Subproject commit 9b475b0efdb5a262938d716f4f619e47b6ce3d7f

@ -8,7 +8,8 @@ lazy_static! {
/// The root of file system
pub static ref ROOT_INODE: Arc<INode> = {
let device = Box::new(SgxStorage::new("sefs"));
let sefs = SEFS::open(device, &SgxTimeProvider).expect("failed to open SEFS");
let sefs = SEFS::open(device, &time::OcclumTimeProvider)
.expect("failed to open SEFS");
sefs.root_inode()
};
}

@ -11,6 +11,7 @@ mod inode_file;
pub use self::file::{File, FileRef, SgxFile, StdinFile, StdoutFile};
pub use self::file_table::{FileDesc, FileTable};
pub use self::pipe::Pipe;
pub use self::inode_file::INodeFile;
pub const O_RDONLY: u32 = 0x00000000;
pub const O_WRONLY: u32 = 0x00000001;
@ -28,33 +29,33 @@ pub const O_CLOEXEC: u32 = 0x00080000;
pub type off_t = i64;
pub fn do_open(path: &str, flags: u32, mode: u32) -> Result<FileDesc, Error> {
let open_options = {
let mut open_options = fs_impl::OpenOptions::new();
if ((flags & O_TRUNC) != 0 || (flags & O_CREAT) != 0) {
open_options.write(true);
} else {
open_options.read(true);
}
open_options.update(true).binary(true);
open_options
};
let mut sgx_file = {
let key: sgx_key_128bit_t = [0 as uint8_t; 16];
// TODO: what if two processes open the same underlying SGX file?
let sgx_file = open_options
.open_ex(path, &key)
.map_err(|e| (Errno::ENOENT, "Failed to open the SGX-protected file"))?;
Arc::new(SgxMutex::new(sgx_file))
};
// let open_options = {
// let mut open_options = fs_impl::OpenOptions::new();
//
// if ((flags & O_TRUNC) != 0 || (flags & O_CREAT) != 0) {
// open_options.write(true);
// } else {
// open_options.read(true);
// }
// open_options.update(true).binary(true);
//
// open_options
// };
//
// let mut sgx_file = {
// let key: sgx_key_128bit_t = [0 as uint8_t; 16];
// // TODO: what if two processes open the same underlying SGX file?
// let sgx_file = open_options
// .open_ex(path, &key)
// .map_err(|e| (Errno::ENOENT, "Failed to open the SGX-protected file"))?;
// Arc::new(SgxMutex::new(sgx_file))
// };
let is_readable = (flags & O_WRONLY) == 0;
let is_writable = (flags & O_WRONLY != 0) || (flags & O_RDWR != 0);
let is_append = (flags & O_APPEND != 0);
let file_ref: Arc<Box<File>> = Arc::new(Box::new(SgxFile::new(
sgx_file,
let file_ref: Arc<Box<File>> = Arc::new(Box::new(INodeFile::open(
path,
is_readable,
is_writable,
is_append,

@ -1,4 +1,6 @@
use super::*;
use rcore_fs::dev::TimeProvider;
use rcore_fs::vfs::Timespec;
#[allow(non_camel_case_types)]
pub type time_t = i64;
@ -24,3 +26,15 @@ pub fn do_gettimeofday() -> timeval_t {
extern "C" {
fn ocall_gettimeofday(sec: *mut time_t, usec: *mut suseconds_t) -> sgx_status_t;
}
pub struct OcclumTimeProvider;
impl TimeProvider for OcclumTimeProvider {
fn current_time(&self) -> Timespec {
let time = do_gettimeofday();
Timespec {
sec: time.sec,
nsec: time.usec as i32 * 1000,
}
}
}