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

fd_allocate on Windows #19

Closed
sunfishcode opened this issue Jan 26, 2021 · 2 comments · Fixed by #64
Closed

fd_allocate on Windows #19

sunfishcode opened this issue Jan 26, 2021 · 2 comments · Fixed by #64

Comments

@sunfishcode
Copy link
Member

I have not found a way to implement fd_allocate on Windows in a non-racy way. SetFileInformationByHandle and SetEndOfFile can change a file's size, but will also silently truncate a file if it happens to be longer than the requested length. WriteFile can change a file's size, but needs to write at least one byte in order to do so.

One option would be to remove fd_allocate from WASI. Use cases where fd_allocate is being used to increase a file's size may be able to use filestat_set_size or pwrite themselves. It may make sense to have wasi-libc provide an optional emulated version of posix_fallocate that works in terms of fileestat_set_size -- it would be racy, but some applications would be ok with that, and applications are in a better position to make that determination than WASI implementations.

Another option would be to specify that fd_allocate can truncate files. This would differ from posix_fallocate, but would be more portable. It may make sense for wasi-libc to provide an optional emulated version of posix_fallocate which checks the file length and adjusts the requested length before calling fd_allocate -- it would be racy, but as above, some applications would be ok with that.

@sunfishcode
Copy link
Member Author

There doesn't appear to be a way to implement fd_allocate in a non-racy way on macOS either.

yamt added a commit to yamt/toywasm that referenced this issue Oct 3, 2022
@yamt
Copy link

yamt commented Oct 4, 2022

One option would be to remove fd_allocate from WASI.

it makes sense as the functionality is rarely used at best.

otherwise, another option would be to provide an api w/o changing the size instead.
say, fd_preallocate.

  • fallocate with FALLOC_FL_KEEP_SIZE for linux
  • probably fcntl F_PREALLOCATE for macOS
  • for platforms w/o the functionality, an no-op implementation is not too bad. (at least it would be safer than fd_allocate.)

sunfishcode added a commit that referenced this issue Oct 10, 2022
There does not appear to be a way to implement `allocate` in a non-racy
way on Windows or macOS.

Fixes #19.
sunfishcode added a commit that referenced this issue Oct 19, 2022
* Remove `allocate`.

There does not appear to be a way to implement `allocate` in a non-racy
way on Windows or macOS.

Fixes #19.

* Update wasi-filesystem.abi.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants