I am trying to implement a FUSE filesystem, and after reading around. I think I have found out how to implement it. I would state out what my idea is of the implementation. Please let me know if it is right or wrong.
One implements the operations that is required to be implemented by the filesystem using whatever functions one sees fit (say xmp_getattributes
for getattr
function) and then maps those functions to the corresponding functions in a struct of type fuse_operations
static struct fuse_operations xmp_oper =
{
.getattr = xmp_getattributes,
//more declarations...
};
Now, if I have used a class ExFuse
to implement a FUSE filesystem and I have a method ExFuse::getAttributes
which does the job of getattr
in the implementation. Then, my declaration would change as
static struct fuse_operations xmp_oper =
{
.getattr = ExFuse::getAttributes,
//more declarations...
};
Am I correct? Also, is there any other way of implementing FUSE in C++ which is better than the static struct
declaration?
if I have used a class
ExFuse
to implement a FUSE filesystem and I have a methodExFuse::getAttributes
which does the job ofgetattr
in the implementation. Then, my declaration would change as
static struct fuse_operations xmp_oper =
{
.getattr = ExFuse::getAttributes,
//more declarations...
};
This is wrong. FUSE expects a pointer to function, but ExFuse::getAttributes
is a pointer to member method (since you didn't explicitly say that it was a static method, I can only assume it's a member method). They are not the same thing.
You either need to use plain functions, or static methods.
is there any other way of implementing FUSE in C++ which is better than the static struct declaration?
I'm afraid not. FUSE is written in C and expects you to stick to the "C way". This gives you very little leeway to use C++ paradigms as far as the public interface is concerned (of course, you can do pretty much what you want in the private implementation, as long as you don't throw, but this won't help you writing the interface to FUSE).