Skip to content

Commit cb1f6f9

Browse files
committed
fs/mem: give fake blocksize/inode number to files
1 parent fca0d2d commit cb1f6f9

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ newlib = []
8282
## Enable stubbing result values for some system calls.
8383
##
8484
## For some system calls related to system options in which Hermit does not implement all possible options,
85-
## return 0 (success) instead of an error when the option is unknown.
86-
syscall-fake-success = []
85+
## return 0 (success) instead of an error when the option is unknown ; or return a convincing fake value.
86+
syscall-fake-values = []
8787

8888
#! ### Platform Features
8989

src/fs/mem.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use alloc::sync::Arc;
88
use alloc::vec::Vec;
99
use core::marker::PhantomData;
1010
use core::mem::MaybeUninit;
11+
#[cfg(feature = "syscall-fake-values")]
12+
use core::sync::atomic::{AtomicU64, Ordering};
1113
use core::{mem, ptr};
1214

1315
use align_address::Align;
@@ -36,6 +38,9 @@ impl RomFileInner {
3638
}
3739
}
3840

41+
#[cfg(feature = "syscall-fake-values")]
42+
static VFS_INO_NUM: AtomicU64 = AtomicU64::new(10_000);
43+
3944
pub struct RomFileInterface {
4045
/// Position within the file
4146
pos: Mutex<usize>,
@@ -306,6 +311,8 @@ impl RomFile {
306311
st_atim: t,
307312
st_mtim: t,
308313
st_ctim: t,
314+
#[cfg(feature = "syscall-fake-values")]
315+
st_ino: VFS_INO_NUM.fetch_add(1, Ordering::AcqRel),
309316
..Default::default()
310317
};
311318

@@ -361,6 +368,12 @@ impl RamFile {
361368
st_atim: t,
362369
st_mtim: t,
363370
st_ctim: t,
371+
#[cfg(feature = "syscall-fake-values")]
372+
st_nlink: 1,
373+
#[cfg(feature = "syscall-fake-values")]
374+
st_blksize: 4096,
375+
#[cfg(feature = "syscall-fake-values")]
376+
st_ino: VFS_INO_NUM.fetch_add(1, Ordering::AcqRel),
364377
..Default::default()
365378
};
366379

src/syscalls/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ pub extern "C" fn sys_fcntl(fd: i32, cmd: i32, arg: i32) -> i32 {
717717
.map_or_else(|e| -i32::from(e), |()| 0)
718718
},
719719
)
720-
} else if cfg!(feature = "syscall-fake-success") {
721-
warn!("[syscall-fake-success] Unknown fcntl flag {cmd} {arg}, returning 0");
720+
} else if cfg!(feature = "syscall-fake-values") {
721+
warn!("[syscall-fake-values] Unknown fcntl flag {cmd} {arg}, returning 0");
722722
0
723723
} else {
724724
-i32::from(Errno::Inval)

0 commit comments

Comments
 (0)