WasmEdge icon indicating copy to clipboard operation
WasmEdge copied to clipboard

O_SYNC do not set.

Open Userzxcvbvnm opened this issue 8 months ago • 0 comments

Summary

Successfully set O_SYNC or O_DSYNC, but cannot print. I'm not sure whether this is a bug. If the test case set O_SYNC or O_DSYNC, wasmedge could not print Access mode: Synchronous Write or Access mode: Data Synchronization Write

Current State

WasmEdge print:

Get file descriptor of file subdir_2/subdir_1/subdir_4/subfile_2 succeed!
Access mode: Read Only
Enter function fd_fdstat_set_flags_00056_ZJtyU
Setting flags succeed!
After setting flags
Access mode: Read Only

Expected State

Get file descriptor of file subdir_2/subdir_1/subdir_4/subfile_2 succeed! Access mode: Read Only Enter function fd_fdstat_set_flags_00056_ZJtyU Setting flags succeed! After setting flags Access mode: Read Only Access mode: Synchronous Write

Reproduction steps

The test case is :


#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>


#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_00056_ZJtyU(int fd) {
    printf("Enter function fd_fdstat_set_flags_00056_ZJtyU\n");

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


    
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("subdir_2/subdir_1/subdir_4/subfile_2", O_RDONLY);

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

    
    print_flags(fd);
    fd_fdstat_set_flags_00056_ZJtyU(fd);
    printf("After setting flags\n");
    print_flags(fd);


    closebyfd(fd);

    return 0;
}


Steps to reproduce: (1)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

(2)Running wasm: (Before run the Wasm file, subdir_2/subdir_1/subdir_4/subfile_2 exists.) wasmedge --dir=. test.wasm

Screenshots

DESCRIPTION

Any logs you want to share for showing the specific issue

No response

Components

CLI

WasmEdge Version or Commit you used

0.13.5 and 0.13.3

Operating system information

Ubuntu 20.04

Hardware Architecture

x86_64

Compiler flags and options

No response

Userzxcvbvnm avatar Jun 24 '24 03:06 Userzxcvbvnm