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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With