diff --git a/src/libos/src/fs/fs_ops/mod.rs b/src/libos/src/fs/fs_ops/mod.rs index abf6a46c..2202e7e3 100644 --- a/src/libos/src/fs/fs_ops/mod.rs +++ b/src/libos/src/fs/fs_ops/mod.rs @@ -5,7 +5,7 @@ pub use self::getcwd::do_getcwd; pub use self::mount::{ do_mount, do_mount_rootfs, do_umount, MountFlags, MountOptions, UmountFlags, }; -pub use self::statfs::{do_fstatfs, do_statfs, Statfs}; +pub use self::statfs::{do_fstatfs, do_statfs, fetch_host_statfs, Statfs}; pub use self::sync::do_sync; mod chdir; diff --git a/src/libos/src/fs/fs_ops/statfs.rs b/src/libos/src/fs/fs_ops/statfs.rs index 6da94bc4..00331f57 100644 --- a/src/libos/src/fs/fs_ops/statfs.rs +++ b/src/libos/src/fs/fs_ops/statfs.rs @@ -82,7 +82,10 @@ impl TryFrom for Statfs { let statfs = if info.magic == rcore_fs_unionfs::UNIONFS_MAGIC || info.magic == rcore_fs_sefs::SEFS_MAGIC as usize { - let mut host_statfs = host_statfs()?; + let mut host_statfs = { + let host_rootfs_dir = unsafe { format!("{}{}", INSTANCE_DIR, "/run/mount/__ROOT") }; + fetch_host_statfs(&host_rootfs_dir)? + }; host_statfs.f_type = info.magic; host_statfs } else { @@ -113,14 +116,30 @@ impl TryFrom for Statfs { } } -fn host_statfs() -> Result { +impl From for FsInfo { + fn from(statfs: Statfs) -> Self { + Self { + magic: statfs.f_type, + bsize: statfs.f_bsize, + frsize: statfs.f_frsize, + blocks: statfs.f_blocks, + bfree: statfs.f_bfree, + bavail: statfs.f_bavail, + files: statfs.f_files, + ffree: statfs.f_ffree, + namemax: statfs.f_namelen, + } + } +} + +pub fn fetch_host_statfs(path: &str) -> Result { extern "C" { fn occlum_ocall_statfs(ret: *mut i32, path: *const i8, buf: *mut Statfs) -> sgx_status_t; } let mut ret: i32 = 0; let mut statfs: Statfs = Default::default(); - let host_dir = unsafe { CString::new(INSTANCE_DIR.as_bytes()).unwrap() }; + let host_dir = CString::new(path.as_bytes()).unwrap(); let sgx_status = unsafe { occlum_ocall_statfs(&mut ret, host_dir.as_ptr(), &mut statfs) }; assert!(sgx_status == sgx_status_t::SGX_SUCCESS); assert!(ret == 0 || libc::errno() == Errno::EINTR as i32); diff --git a/src/libos/src/fs/hostfs.rs b/src/libos/src/fs/hostfs.rs index e58623ba..db055aaa 100644 --- a/src/libos/src/fs/hostfs.rs +++ b/src/libos/src/fs/hostfs.rs @@ -1,3 +1,4 @@ +use crate::fs::fs_ops::fetch_host_statfs; use alloc::string::String; use alloc::sync::{Arc, Weak}; use core::any::Any; @@ -39,8 +40,8 @@ impl FileSystem for HostFS { } fn info(&self) -> FsInfo { - warn!("HostFS: FsInfo is unimplemented"); - Default::default() + let statfs = fetch_host_statfs(&self.path.to_string_lossy()).unwrap(); + statfs.into() } }