Use SEFS at /, HostFS at /host, and RamFS at /tmp
This commit is contained in:
parent
7f229cef50
commit
8cda63ab3a
@ -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<INode> = {
|
||||
// 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<dyn FileSystem>, 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
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user