5

I'm new to FUSE and c and FSs and I'm messing with passthrough FS example which is given in the libfuse package. Can anyone give a hint where in the code it is commanded that FUSE mirror my root dir, please? Cause I found the two base functions - *xmp_init() and main() - pretty laconic.

Here they are:

static void *xmp_init(struct fuse_conn_info *conn,
              struct fuse_config *cfg)
{
    (void) conn;
    cfg->use_ino = 1;
    cfg->entry_timeout = 0;
    cfg->attr_timeout = 0;
    cfg->negative_timeout = 0;

    return NULL;
}

int main(int argc, char *argv[])
{
    umask(0);
    return fuse_main(argc, argv, &xmp_oper, NULL);
}

And other functions are just, like, implementations of libfuse interface...stuff. I need to make my own crippled FS, I need to modify passthrough.c so that mounted FS would be a white sheet and I could make use of implemented functions and manage files and stuff.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Sophour
  • 106
  • 9

2 Answers2

4

Try to read implementation of any fuse operation in the example and you will see it. There is no single place where this particular detail about mirroring of a root filesystem is hidden.

For example, let's check getattr fuse operation, which is similar to stat(2) system call, and is expected to return (via pointer) a stat structure of given file.

When some file is accessed in a fuse filesystem, a function implementing gettattr operation is called first, which makes implementation of this operation mandatory.

Looking at the implementation in the example:

static int xmp_getattr(const char *path, struct stat *stbuf,
           struct fuse_file_info *fi)
{
    (void) fi;
    int res;

    res = lstat(path, stbuf);
    if (res == -1)
        return -errno;

    return 0;
}

we see that all this code does is that it just calls lstat(2) with the same arguments.

So when you mount this example filesystem like this:

$ ./passthrough /tmp/example

and then try to list files there:

$ ls /tmp/example/

fuselib will call xmp_getattr() with path "/" because you are accessing the root of the fuse filesystem. Then the code in xmp_getattr() will just call ordinary syscall for the similar thing so that the root filesystem looks mirrored in /tmp/example mountpoint.

marbu
  • 1,939
  • 2
  • 16
  • 30
1

marbu's answer is correct. I will only clarify that the path argument passed to xmp_getattr() et.al. is relative to the mount point, thus /tmp/example/ is turned into /. You can compile passthrough with the -g flag and attach gdb on it after you've mounted it to inspect the arguments if you so wish.

n224576
  • 1,766
  • 2
  • 10
  • 3