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

Open with O_APPEND, but do not print the correct offset value. #4902

Open
Userzxcvbvnm opened this issue Jun 26, 2024 · 0 comments
Open

Open with O_APPEND, but do not print the correct offset value. #4902

Userzxcvbvnm opened this issue Jun 26, 2024 · 0 comments
Assignees
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-high High priority issue

Comments

@Userzxcvbvnm
Copy link
Contributor

Describe the bug

Read directory failed.

Steps to reproduce

(1)The test case is :



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/uio.h>
#include <fcntl.h>

int get_fd(const char *filename, int flags) {
    int fd = open(filename, flags);
    
    if (fd == -1) {
        printf("Get file descriptor of file %s failed!\n", filename);
        return -1;
    } else {
        printf("Get file descriptor of file %s succeed!\n", filename);
        return fd;
    }
}

void closebyfd(int fd) {
    if (close(fd) == -1) {
        printf("Close the file %d by descriptor failed!\n", fd);
    }
}

void fd_write_00019_WOtrt(int fd) {
    printf("Enter function fd_write_00019_WOtrt\n");
    
    
    struct iovec iov[2];
    iov[0].iov_base = "v0AXE";
    iov[0].iov_len = 5;
    iov[1].iov_base = "v0AXE";
    iov[1].iov_len = 5;

    off_t offset = lseek(fd, 0, SEEK_CUR);
    printf("File current offset before write: %lld\n", (long long)offset);
    ssize_t numBytes = writev(fd, iov, 2);
    offset = lseek(fd, 0, SEEK_CUR);
    printf("File current offset after write: %lld\n", (long long)offset);


    if (numBytes == -1) {
        printf("Write to file descriptor failed!\n");
    } else {
        printf("Write to file descriptor successful. Number of bytes written: %zd\n", numBytes);
    }
}

int main() {
    int fd = get_fd("subdir_1/subfile_1", O_WRONLY | O_APPEND);
    if (fd == -1) {
        return -1;
    }

    fd_write_00019_WOtrt(fd);

    closebyfd(fd);

    return 0;
}


(2)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

(3)Running wasm:
(Before run the Wasm file, file subdir_1/subfile_1 exists, and the file size is 45.)
wasmer run --dir=. test.wasm

Expected behavior

print:

Get file descriptor of file subdir_1/subfile_1 succeed!
Enter function fd_write_00019_WOtrt
File current offset before write: 0
File current offset after write: 55
Write to file descriptor successful. Number of bytes written: 10

And this is what wasmtime, WAMR and WasmEdge do.

Actual behavior

wasmer print:

Get file descriptor of file subdir_1/subfile_1 succeed!
Enter function fd_write_00019_WOtrt
File current offset before write: 0
File current offset after write: 10
Write to file descriptor successful. Number of bytes written: 10

Although wasmer print offset after write is 10, the file size after writing is 55, it is written from the end of the file. Thus, the offset is expected to be 55 rather than 10.

Additional context

Ubuntu 20.04
x86_64
wasmer-4.2.2

@maminrayej maminrayej added bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-high High priority issue labels Jun 27, 2024
@maminrayej maminrayej self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs priority-high High priority issue
Projects
None yet
Development

No branches or pull requests

2 participants