Fuse file system looks for /.Trash, /autorun.inf and /.xdg-volume-info files

I'm trying to write a minimum working example with fuse library. The desired file system should have only one read-only file. The problem is, when I initialize the fuse file system, it's trying to get the attributes of /.Trash, /autorun.inf and /.xdg-volume-info. After that it tries repeatedly to get the attributes of root directory and of the only file the file system has. After that it tries to get the attributes of the /autorun.inf and then freezes.


I'm using fuse 3.4.1, which I installed from source using meson build. I've already tried to run the example from the library called hello_fuse.c, but I get the same problem there. I followed this tutorial to write this code.


Readdir operation (reads the content of the directory):



static int do_readdir(const char *path, void *buffer, fuse_fill_dir_t filler,
                      off_t offset, fuse_file_info *fi, enum fuse_readdir_flags)
{
    std::cout << "do_readdir is called on " << path << std::endl;
    if (!dir_exists(path))
    {
        std::cout << "Entry doesn't exist" << std::endl
                  << std::endl;
        return -ENOENT;
    }
    filler(buffer, ".", nullptr, 0, FUSE_FILL_DIR_PLUS);
    filler(buffer, "..", nullptr, 0, FUSE_FILL_DIR_PLUS);
    if (strcmp(path, "/") == 0)
    {
        filler(buffer, "file_1.txt", nullptr, 0, FUSE_FILL_DIR_PLUS);
    }
    return 0;
}

Read operation (reads the content of the file)


static int do_read(const char *path, char *buffer, size_t size, off_t offset, fuse_file_info *fi)
{
    std::cout << "do_read is called on " << path << std::endl
              << std::endl;

    if (!file_exists(path))
    {
        std::cout << "Entry doesn't exist" << std::endl
                  << std::endl;
        return -ENOENT;
    }
    if (strlen(file_1_content) - offset < size)
    {
        size = strlen(file_1_content) - offset;
    }
    memcpy(buffer, file_1_content + offset, size);
    return size;
}

Get attributes operation (provides the attributes of the file system entry)


static int do_getattr(const char *path, struct stat *st, fuse_file_info *fi)
{
    std::cout << "do_getattr is called on " << path << std::endl
              << std::endl;
    bool not_exists = !file_exists(path) && !dir_exists(path);
    if (not_exists)
    {
        std::cout << "Entry doesn't exist" << std::endl
                  << std::endl;
        return -ENOENT;
    }
    st->st_uid = getuid();
    st->st_gid = getgid();
    st->st_atim.tv_sec = time(nullptr);
    st->st_mtim.tv_sec = time(nullptr);
    if (dir_exists(path))
    {
        st->st_mode = S_IFDIR | 0777;
        st->st_nlink = 2;
    }
    else
    {
        st->st_mode = S_IFREG | 0777;
        st->st_nlink = 1;
        st->st_size = strlen(file_1_content);
    }

    return 0;
}

Other code:

static struct fuse_operations operations = {
    getattr : do_getattr,
    read : do_read,
    readdir : do_readdir,
};

int main(int argc, char *argv[])
{
    std::cout << "Start mounting" << std::endl
              << std::endl;
    return fuse_main(argc, argv, &operations, nullptr);
}

Here's the output of the program:

Start mounting

do_getattr is called on /.Trash

Entry doesn't exist

do_getattr is called on /.xdg-volume-info

Entry doesn't exist

do_getattr is called on /

do_readdir is called on /
do_getattr is called on /autorun.inf

Entry doesn't exist

do_getattr is called on /file_1.txt

do_getattr is called on /

do_readdir is called on /
do_getattr is called on /

.........................

do_readdir is called on /
do_getattr is called on /autorun.inf

Entry doesn't exist

After the last line the program freezes.


The expected result is that the file system is mounted in some directory and I can, for instance, list the content of the directory and see the only read-only file there.

Upvotes: 0

Views: 1191

Answers (1)

jrcichra
jrcichra

Reputation: 345

For me, oh-my-zsh was the culprit. Using bash made the stat calls predictable.

Upvotes: 1

Related Questions