# VFS-mutation syscalls (brintos/linux#5): mkdirat / chmod / chown / rename / fsync.
# These returned ENOSYS before the wasm32 kernel wired them. GNU `mv` masks a
# broken rename (copy-then-delete fallback) and no shell tool calls fsync, so the
# syscalls are exercised at the C boundary by the data/vfs-probe payload, which
# prints one `VFS-<name> OK|FAIL` line each. data payloads install 0644; the wasm
# exec bit is set on a private copy (chmod itself is one of the wired syscalls).
. "$BST_LIB"

probe=${TMPDIR:-/tmp}/bst-vfs-probe.$$
cp "$BST_DATA/vfs-probe" "$probe" 2>/dev/null && chmod +x "$probe" 2>/dev/null || {
  bst_notok vfs/stage "cannot stage $BST_DATA/vfs-probe"; exit 0; }

out=$("$probe" 2>&1)
rm -f "$probe"

# One assertion per ticket syscall. The four wired upstream must pass; chown is a
# known upstream gap (brintos/linux#5: no ownership model on the virtio-fs backend)
# and reports its actual state so a future wiring flips this suite green.
check_out vfs/mkdirat "VFS-mkdirat OK" printf '%s\n' "$out"
check_out vfs/fsync   "VFS-fsync OK"   printf '%s\n' "$out"
check_out vfs/chmod   "VFS-chmod OK"   printf '%s\n' "$out"
check_out vfs/rename  "VFS-rename OK"  printf '%s\n' "$out"
check_out vfs/chown   "VFS-chown OK"   printf '%s\n' "$out"
