From 8cda63ab3ab0ba906e71f1a726c7ba2ea68b571f Mon Sep 17 00:00:00 2001 From: "Tate, Hongliang Tian" Date: Fri, 19 Jul 2019 10:25:33 +0000 Subject: [PATCH] Use SEFS at /, HostFS at /host, and RamFS at /tmp --- src/libos/src/fs/inode_file.rs | 43 +++++++++++++++++++------------- src/libos/src/process/process.rs | 6 +++-- test/Makefile | 3 ++- test/mkdir/main.c | 4 +-- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/libos/src/fs/inode_file.rs b/src/libos/src/fs/inode_file.rs index 765921fe..8c242eb9 100644 --- a/src/libos/src/fs/inode_file.rs +++ b/src/libos/src/fs/inode_file.rs @@ -1,5 +1,5 @@ -use rcore_fs::vfs::{FileSystem, FsError, INode}; -use rcore_fs_mountfs::MountFS; +use rcore_fs::vfs::{FileSystem, FileType, FsError, INode}; +use rcore_fs_mountfs::{MountFS, MNode}; use rcore_fs_ramfs::RamFS; use rcore_fs_sefs::SEFS; use std::fmt; @@ -11,29 +11,36 @@ use super::*; lazy_static! { /// The root of file system pub static ref ROOT_INODE: Arc = { - // ramfs as rootfs - let rootfs = MountFS::new(RamFS::new()); - let root = rootfs.root_inode(); - - // sefs + // Mount SEFS at / let device = Box::new(SgxStorage::new("sefs")); let sefs = SEFS::open(device, &time::OcclumTimeProvider) .expect("failed to open SEFS"); + let rootfs = MountFS::new(sefs); + let root = rootfs.root_inode(); - // mount sefs at /test - let bin = root.create("test", FileType::Dir, 0o777) - .expect("failed to mkdir: /test"); - bin.mount(sefs) - .expect("failed to mount SEFS"); + fn mount_default_fs(fs: Arc, root: &MNode, mount_at: &str) -> Result<(), Error> { + let mount_dir = match root.find(false, mount_at) { + Ok(existing_dir) => { + if existing_dir.metadata()?.type_ != FileType::Dir { + return errno!(EIO, "not a directory"); + } + existing_dir + } + Err(_) => { + root.create(mount_at, FileType::Dir, 0o777)? + } + }; + mount_dir.mount(fs); + Ok(()) + } - // HostFS let hostfs = HostFS::new("."); + mount_default_fs(hostfs, &root, "host") + .expect("failed to mount HostFS at /host"); - // mount HostFS at /host - let host = root.create("host", FileType::Dir, 0o777) - .expect("failed to mkdir: /host"); - host.mount(hostfs) - .expect("failed to mount HostFS"); + let ramfs = RamFS::new(); + mount_default_fs(ramfs, &root, "tmp") + .expect("failed to mount RamFS at /tmp"); root }; diff --git a/src/libos/src/process/process.rs b/src/libos/src/process/process.rs index 7eed7c04..3545c969 100644 --- a/src/libos/src/process/process.rs +++ b/src/libos/src/process/process.rs @@ -13,7 +13,7 @@ lazy_static! { pgid: 1, tgid: 0, exit_status: 0, - cwd: "/test".to_owned(), // FIXME: hack for test + cwd: "/".to_owned(), clear_child_tid: None, parent: None, children: Vec::new(), @@ -99,7 +99,9 @@ impl Process { self.cwd = path.to_owned(); } else { // relative - self.cwd += "/"; + if !self.cwd.ends_with("/") { + self.cwd += "/"; + } self.cwd += path; } } diff --git a/test/Makefile b/test/Makefile index 857acef2..c59f0aae 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,7 +4,8 @@ PROJECT_DIR := $(realpath $(CUR_DIR)/../) # Dependencies: need to be compiled but not to run by any Makefile target TEST_DEPS := dev_null # Tests: need to be compiled and run by test-% target -TESTS := empty argv hello_world malloc mmap file getpid spawn pipe time truncate readdir mkdir link tls pthread uname rlimit client server server_epoll unix_socket cout hostfs cpuid rdtsc +#TESTS := empty argv hello_world malloc mmap file getpid spawn pipe time truncate readdir mkdir link tls pthread uname rlimit client server server_epoll unix_socket cout hostfs cpuid rdtsc +TESTS := hello_world file readdir mkdir link hostfs # Benchmarks: need to be compiled and run by bench-% target BENCHES := spawn_and_exit_latency pipe_throughput unix_socket_throughput diff --git a/test/mkdir/main.c b/test/mkdir/main.c index 8239e0e6..4ce33b3b 100644 --- a/test/mkdir/main.c +++ b/test/mkdir/main.c @@ -17,14 +17,14 @@ int main(int argc, const char* argv[]) { return -1; } - const char expect_cwd[] = "/test"; + const char expect_cwd[] = "/"; if(strcmp(buf, expect_cwd)) { printf("incorrect cwd \"%s\". expect \"%s\".\n", buf, expect_cwd); return -1; } const char DIR_NAME[] = "test_dir"; - const char DIR_PATH[] = "/test/test_dir"; + const char DIR_PATH[] = "/test_dir"; const int DIR_MODE = 0664; ret = mkdir(DIR_NAME, DIR_MODE); if(ret < 0) {