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_WRONLY | * bug get with Read/Write #4889

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

Open with O_WRONLY | * bug get with Read/Write #4889

Userzxcvbvnm opened this issue Jun 23, 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

wasmer fail to print the file size of hard link file.

Steps to reproduce

(1)The test case is :


#include <stdio.h>
#include <fcntl.h>
#include <unistd.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_fdstat_get_00002_yBbmO(int fd) {
    printf("Enter function fd_fdstat_get_00002_yBbmO\n");

    int flags = fcntl(fd, F_GETFL);
    if (flags == -1) {
        printf("Error getting file descriptor flags\n");
        return;
    }

    printf("File descriptor flags: %d\n", flags);

    int access_mode = flags & O_ACCMODE;

    
    if (access_mode == O_RDONLY) {
        printf("Access mode: Read Only\n");
    }
    if (access_mode == O_WRONLY) {
        printf("Access mode: Write Only\n");
    }
    if (access_mode == O_RDWR) {
        printf("Access mode: Read/Write\n");
    }
    if (flags & O_TRUNC) {
        printf("Flag: O_TRUNC\n");
    }
    if (flags & O_APPEND) {
        printf("Flag: O_APPEND\n");
    }
    if (flags & O_CREAT) {
        printf("Flag: O_CREAT\n");
    }
    if (flags & O_NONBLOCK) {
        printf("Flag: Non-blocking\n");
    }
    if (flags & O_SYNC) {
        printf("Flag: Synchronous Write\n");
    }
    if (flags & O_DSYNC) {
        printf("Flag: Data Synchronization Write\n");
    }
}

int main() {
    int fd = get_fd("subdir_1/subdir_2/subdir_3/subdir_4/subfile_2", O_WRONLY);
    if (fd == -1) {
        return -1;
    }

    fd_fdstat_get_00002_yBbmO(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, subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 exists.)
wasmer run --dir=. test.wasm

Expected behavior

print:

Get file descriptor of file subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 succeed!
Enter function fd_fdstat_get_00002_yBbmO
File descriptor flags: 268435456
Access mode: Write Only

This is what wasmtime, WAMR and WasmEdge do.

Actual behavior

wasmer print:

Get file descriptor of file subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 succeed!
Enter function fd_fdstat_get_00002_yBbmO
File descriptor flags: 335544320
Access mode: Read/Write

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 24, 2024
@maminrayej maminrayej self-assigned this Jun 24, 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