zzjas opened issue #2973:
Test Case
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> int main() { int fd = open("non_empty_file.txt", O_RDWR); struct stat fs; printf("Before fallocate:\n"); fstat(fd, &fs); printf("size is: %lld\n", (long long) fs.st_size); int r = posix_fallocate(fd, 0, 0); printf("posix_fallocate returns %d\n", r); if(r != 0) { printf("error is: %s\n", strerror(r)); } printf("After fallocate:\n"); fstat(fd, &fs); printf("size is: %lld\n", (long long) fs.st_size); }
non_empty_file.txt Hello, this is a file with some text in it.
Steps to Reproduce
Compile the C program with the clang from wasi-sdk and run it with wasmtime on macOS.
Expected Results
For posix_fallocate(int fd, off_t offset, off_t len), POSIX manual says "If the size of the file is less than offset+len, then the file is increased to this size; otherwise the file size is left unchanged."
Actual Results
When offset+len < file size, wasmtime will keep the file size unchanged on Linux(Ubuntu), but will truncate the file on macOS(Mojave).
Versions and Environment
Wasmtime version or commit: 0.26.0
Operating system: Mac OS X 10.14.6
Architecture: x86
CC: @deian
zzjas labeled issue #2973:
Test Case
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> int main() { int fd = open("non_empty_file.txt", O_RDWR); struct stat fs; printf("Before fallocate:\n"); fstat(fd, &fs); printf("size is: %lld\n", (long long) fs.st_size); int r = posix_fallocate(fd, 0, 0); printf("posix_fallocate returns %d\n", r); if(r != 0) { printf("error is: %s\n", strerror(r)); } printf("After fallocate:\n"); fstat(fd, &fs); printf("size is: %lld\n", (long long) fs.st_size); }
non_empty_file.txt Hello, this is a file with some text in it.
Steps to Reproduce
Compile the C program with the clang from wasi-sdk and run it with wasmtime on macOS.
Expected Results
For posix_fallocate(int fd, off_t offset, off_t len), POSIX manual says "If the size of the file is less than offset+len, then the file is increased to this size; otherwise the file size is left unchanged."
Actual Results
When offset+len < file size, wasmtime will keep the file size unchanged on Linux(Ubuntu), but will truncate the file on macOS(Mojave).
Versions and Environment
Wasmtime version or commit: 0.26.0
Operating system: Mac OS X 10.14.6
Architecture: x86
CC: @deian
sunfishcode commented on issue #2973:
Thanks for the report! It seems there isn't a non-racy way to implement this aspect of
posix_fallocate
on macOS. I expect we'll need to removeposix_fallocate
from WASI entirely. I've [filed an issue in wasi-filesystem[(https://github.com/WebAssembly/wasi-filesystem/issues/19) to track this.
sunfishcode edited a comment on issue #2973:
Thanks for the report! It seems there isn't a non-racy way to implement this aspect of
posix_fallocate
on macOS. I expect we'll need to removeposix_fallocate
from WASI entirely. I've filed an issue in wasi-filesystem to track this.
Last updated: Nov 22 2024 at 17:03 UTC