Repository navigation
fix: Correct rename, link-count and zero-length write edge cases - #32
Merged
krodak merged 4 commits intoOct 7, 2026
Merged
Conversation
path_rename("a", "a/b/c") detached "a" from the tree and returned success,
so the directory and everything in it were lost. Return EINVAL instead,
as POSIX rename does.
Co-authored-by: Peter Grayson <pete@jpgrayson.net>
fd_pwrite and fd_write with no bytes at an offset past EOF grew the file to that offset. POSIX says a zero-length write to a regular file has no other results, so return 0 bytes written and leave the file as it is. Co-authored-by: Peter Grayson <pete@jpgrayson.net>
path_link accepts any node but a directory, but only regular files kept a link count. A hard link to a symlink or to /dev/null left stat reporting nlink 1. Give every non-directory node a link count, and update it on link, unlink and replacing rename.
path_rename("f", "g"), with "g" a hard link to "f", removed "f" and lowered
the link count. POSIX says rename succeeds and does nothing else when both
names link the same file.
kateinoigakukun
approved these changes
Oct 7, 2026
Member
|
I think the latest wasi-testsuite covers more cases so it might be helpful to catch other issues as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four small fixes in
useMemoryFS. Each has its own commit and a regression test that fails onmain:"a"to"a/b/c") returned success and detached the directory, losing it and everything in it. It now returnsEINVAL, as POSIXrenamedoes.fd_pwriteandfd_writewith zero bytes at an offset past EOF grew the file to that offset. A zero-length write now leaves the file unchanged.statkept reportingnlink1. Every non-directory node now has a link count, updated on link, unlink and replacing rename.These came up while separating a storage-backend layer from the memory filesystem in our fork. I'll propose that layer separately. The directory-rename and zero-length-write fixes are adapted from Pete Grayson's work there, and those commits credit him.
Test Plan
mainbefore its fix.npm teston its own.npm run buildandnpm test: 187 passed (182 existing, 5 new), no failures or skips.npx prettier --check src/features/fd.ts test/fd.test.mjsandgit diff --check.