fix sys_open. import crate log.

This commit is contained in:
WangRunji 2019-03-05 18:46:20 +08:00 committed by Tate Tian
parent e41f65e132
commit 557eb7dc60
6 changed files with 41 additions and 26 deletions

2
deps/sefs vendored

@ -1 +1 @@
Subproject commit bffa92bb8d2571a15ab9e7d61e7330649fb74a7c
Subproject commit def861510944e13b99570d0d4cae5342ee729d2f

1
src/libos/Cargo.lock generated

@ -5,6 +5,7 @@ name = "Occlum"
version = "0.0.1"
dependencies = [
"lazy_static 1.1.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",
"rcore-fs-sefs 0.1.0",
"sgx_trts 1.0.6",

@ -7,6 +7,7 @@ name = "occlum_rs"
crate-type = ["staticlib"]
[dependencies]
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"] }

@ -67,9 +67,9 @@ impl File for INodeFile {
}
impl INodeFile {
pub fn open(path: &str, is_readable: bool, is_writable: bool, is_append: bool) -> Result<Self, Error> {
pub fn open(inode: Arc<INode>, is_readable: bool, is_writable: bool, is_append: bool) -> Result<Self, Error> {
Ok(INodeFile {
inode: ROOT_INODE.lookup(path)?,
inode,
offset: SgxMutex::new(0),
is_readable,
is_writable,

@ -11,7 +11,8 @@ 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 use self::inode_file::{INodeFile, ROOT_INODE};
use rcore_fs::vfs::{FsError, FileType, INode};
pub const O_RDONLY: u32 = 0x00000000;
pub const O_WRONLY: u32 = 0x00000001;
@ -29,33 +30,35 @@ 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))
// };
info!("open: path: {:?}, flags: {:?}, mode: {:#o}", path, flags, mode);
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 is_create = (flags & O_CREAT != 0);
let inode =
if is_create {
let (dir_path, file_name) = split_path(&path);
let dir_inode = ROOT_INODE.lookup(dir_path)?;
match dir_inode.find(file_name) {
Ok(file_inode) => {
// if flags.contains(OpenFlags::EXCLUSIVE) {
// return Err(SysError::EEXIST);
// }
file_inode
},
Err(FsError::EntryNotFound) => {
dir_inode.create(file_name, FileType::File, mode)?
}
Err(e) => return Err(Error::from(e)),
}
} else {
ROOT_INODE.lookup(&path)?
};
let file_ref: Arc<Box<File>> = Arc::new(Box::new(INodeFile::open(
path,
inode,
is_readable,
is_writable,
is_append,
@ -168,3 +171,11 @@ pub fn do_sync() -> Result<(), Error> {
extern "C" {
fn ocall_sync() -> sgx_status_t;
}
/// Split a `path` str to `(base_path, file_name)`
fn split_path(path: &str) -> (&str, &str) {
let mut split = path.trim_end_matches('/').rsplitn(2, '/');
let file_name = split.next().unwrap();
let dir_path = split.next().unwrap_or(".");
(dir_path, file_name)
}

@ -17,6 +17,8 @@ extern crate sgx_trts;
extern crate xmas_elf;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate rcore_fs;
extern crate rcore_fs_sefs;