Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic support to inode in filestat_get (for #3583 and #3239) #3765

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/wasi/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub const MAX_SYMLINKS: u32 = 128;
pub struct Inode(u64);

impl Inode {
fn as_u64(&self) -> u64 {
pub fn as_u64(&self) -> u64 {
self.0
}
}
Expand Down
11 changes: 7 additions & 4 deletions lib/wasi/src/syscalls/wasi/path_filestat_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ pub(crate) fn path_filestat_get_internal(
path_string,
flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0,
)?;
if file_inode.is_preopened {
Ok(*file_inode.stat.read().unwrap().deref())
let st_ino = file_inode.ino().as_u64();
let mut stat = if file_inode.is_preopened {
*file_inode.stat.read().unwrap().deref()
} else {
let guard = file_inode.read();
state.fs.get_stat_for_kind(guard.deref())
}
state.fs.get_stat_for_kind(guard.deref())?
};
stat.st_ino = st_ino;
Ok(stat)
}
Binary file added tests/wasi-wast/wasi/snapshot1/inode.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/wasi-wast/wasi/snapshot1/inode.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
;; This file was generated by https://github.com/wasmerio/wasi-tests

(wasi_test "inode.wasm"
(preopens "test_fs")
(assert_return (i64.const 0))
(assert_stdout "all done\n")
)
31 changes: 31 additions & 0 deletions tests/wasi-wast/wasi/tests/inode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// WASI:
// dir: test_fs

use std::fs;
use std::io;
#[cfg(target = "wasi")]
use std::os::wasi::fs::MetadataExt;

// `test_fs` will be implicit.
// this need experimentat MetadataExt
// this program does nothing in native
// it only tests things in wasi
fn main() {
#[cfg(target = "wasi")]
{
let meta1 = fs::metadata("test_fs/hamlet/act1/scene1.txt").expect("could not find src file");
let meta2 = fs::metadata("test_fs/hamlet/act1/scene2.txt").expect("could not find src file");
if meta1.dev() == meta2.dev() && meta1.ino() == meta2.ino() {
println!("Warning, different files from same folder have same dev/inod");
}
let meta3 = fs::metadata("test_fs/hamlet/act2/scene1.txt").expect("could not find src file");
if meta1.dev() == meta3.dev() && meta1.ino() == meta3.ino() {
println!("Warning, different files from different folder with same name have same dev/inod");
}
let meta4 = fs::metadata("test_fs/hamlet/act1/../act1/scene1.txt").expect("could not find src file");
if meta1.dev() != meta4.dev() || meta1.ino() != meta4.ino() {
println!("Warning, same files have different dev/inod");
}
}
println!("all done");
}