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

Access mode of O_TRUNC and O_CREAT. #4891

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

Access mode of O_TRUNC and O_CREAT. #4891

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

Userzxcvbvnm commented Jun 24, 2024

Describe the bug

wasmer fd_fdstat_get bug?
Getting the access mode different from others.

Steps to reproduce

(1)The test case is :


#include <stdio.h>
#include <stdlib.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_set_flags_00065_ZJtyU(int fd) {
    printf("Enter function fd_fdstat_set_flags_00065_ZJtyU\n");

    int flags = fcntl(fd, F_GETFL);
    flags = flags | O_SYNC;
    
    if (fcntl(fd, F_SETFL, flags) == -1) {
        printf("Setting flags failed!\n");
    } else {
        printf("Setting flags succeed!\n");
    }
}


    
void print_flags(int fd){
    int flags1 = fcntl(fd, F_GETFL);
    int access_mode1 = flags1 & O_ACCMODE;
    if (access_mode1 == O_RDONLY) {
        printf("Access mode: Read Only\n");
    }
    if (access_mode1 == O_WRONLY) {
        printf("Access mode: Write Only\n");
    }
    if (access_mode1 == O_RDWR) {
        printf("Access mode: Read/Write\n");
    }
    if (flags1 & O_TRUNC) {
        printf("Access mode: O_TRUNC\n");
    }
    if (flags1 & O_APPEND) {
        printf("Access mode: O_APPEND\n");
    }
    if (flags1 & O_CREAT) {
        printf("Access mode: O_CREAT\n");
    }
    if (flags1 & O_EXCL) {
        printf("Access mode: O_EXCL\n");
    }
    if (flags1 & O_NONBLOCK) {
        printf("Access mode: Non-blocking\n");
    }
    if (flags1 & O_SYNC) {
        printf("Access mode: Synchronous Write\n");
    }
    if (flags1 & O_DSYNC) {
        printf("Access mode: Data Synchronization Write\n");
    }
}
    
int main() {
    
    int fd = get_fd("hardfile_2", O_WRONLY | O_TRUNC | O_CREAT);

    if (fd == -1) {
        return 1;
    }

    
    print_flags(fd);
    fd_fdstat_set_flags_00065_ZJtyU(fd);
    printf("After setting flags\n");
    print_flags(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, hardfile_2 exists and it is a hard link file points to subdir_3/subfile_3, and subdir_3/subfile_3 exists.)
wasmer run --dir=. test.wasm

Expected behavior

print:

Get file descriptor of file hardfile_2 succeed!
Access mode: Write Only
Access mode: O_TRUNC
Access mode: O_CREAT
Enter function fd_fdstat_set_flags_00065_ZJtyU
Setting flags succeed!
After setting flags
Access mode: Write Only
Access mode: O_TRUNC
Access mode: O_CREAT
Access mode: Synchronous Write

wasmer do not print "Access mode: O_TRUNC" and "Access mode: O_CREAT".
I'm not sure whether this is a bug.

Actual behavior

wasmer print:

Get file descriptor of file hardfile_2 succeed!
Access mode: Read/Write
Enter function fd_fdstat_set_flags_00065_ZJtyU
Setting flags succeed!
After setting flags
Access mode: Read/Write
Access mode: Synchronous Write

Additional context

Ubuntu 20.04
x86_64
wasmer-4.3.1 and 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