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

Read directory bug ? #4347

Open
Userzxcvbvnm opened this issue Dec 8, 2023 · 2 comments
Open

Read directory bug ? #4347

Userzxcvbvnm opened this issue Dec 8, 2023 · 2 comments
Labels
bug Something isn't working 📦 lib-cli About wasmer-cli 📦 lib-vfs About wasmer-vfs 🕵️ needs investigation The issue/PR needs further investigation priority-medium Medium priority issue
Milestone

Comments

@Userzxcvbvnm
Copy link
Contributor

Describe the bug

Data/mydir is a directory, and there is a file Data/mydir/test.txt.

The c file is uploaded as
test-c.txt

The wasm file is uploaded as
test-wasm.txt

Steps to reproduce

Change Data/mydir into 0600 (rw- --- ---)
using command wasmer run --dir=./Data test.wasm

Expected behavior

Print:

.
..
test.txt

wamr,wasmedge and native (gcc test.c -o test and ./test) print this message.

Actual behavior

Print:

Enter fd_readdir.
opendir: Permission denied

Additional context

Ubuntu 20.04 (x86_64)
wasmer v4.2.2

@Michael-F-Bryan Michael-F-Bryan added bug Something isn't working 📦 lib-vfs About wasmer-vfs labels Dec 12, 2023
@Michael-F-Bryan
Copy link
Contributor

This looks like it might be an issue with how you are mapping directories because --dir ./Data will mount the directory to one location, while the WASI app's current directory is set to /.

Can you try mounting ./Data with --mapdir /data:./Data and updating your code to iterate over /data/mydir? We tried running with --dir ./Data just then and it errored out saying you need to use an absolute path, so maybe also try running --dir $(pwd)/Data and update the paths in your code accordingly?


For context, this is the contents of test-c.txt:

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


int fd_readdir(const char *path) {
    printf("Enter fd_readdir.\n");

    DIR *directory;
    struct dirent *entry;

    directory = opendir(path);

    if (directory == NULL) {
        perror("opendir");
        return 1;
    }

    while ((entry = readdir(directory)) != NULL) {
        printf("%s\n", entry->d_name);
    }

    closedir(directory);
    printf("Leave fd_readdir.\n");
    return 0;
}


int main() {
    const char *dirPath = "Data/mydir";
    fd_readdir(dirPath);
    return 0;
}

@Michael-F-Bryan Michael-F-Bryan added 🕵️ needs investigation The issue/PR needs further investigation 📦 lib-cli About wasmer-cli priority-medium Medium priority issue labels Dec 12, 2023
@Michael-F-Bryan Michael-F-Bryan added this to the v4.4 milestone Dec 12, 2023
@Userzxcvbvnm
Copy link
Contributor Author

Userzxcvbvnm commented Dec 12, 2023

Thanks for your reply! We tried to execute it in two ways:
(1)Modify the C file code into :

const char *dirPath = "data/mydir";

and using command wasmer run --mapdir /data:./Data test.wasm
It prints:

Enter fd_readdir.
opendir: Operation not permitted

(2)Modify the C file code into :

const char *dirPath = "$(pwd)/Data/mydir";

and using command wasmer run --dir=$(pwd)/Data test.wasm
It prints:

Enter fd_readdir.
opendir: Operation not permitted

And the permission of mydir is changed into 0600 before execution, just as we mentioned initially.
Maybe it is related to permission?

@syrusakbary syrusakbary modified the milestones: v4.5, backlog Sep 12, 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-cli About wasmer-cli 📦 lib-vfs About wasmer-vfs 🕵️ needs investigation The issue/PR needs further investigation priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants