One more piece of information on using FUSE that's very helpful is how it lets you store and access data that you've defined.
FUSE has a struct fuse_context
which contains a
little bit of extra information about a filesystem. One very useful
field in this struct
is
void* private_data
, a pointer to arbitrary data
stored by your filesystem.
From inside any FUSE operation, it's possible to obtain the context by
calling fuse_get_context()
; this means we can use
fuse_get_context()->private_data
to get the private data.
We can see how to use this by looking at my log_msg()
function. Here it is:
void log_msg(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(BB_DATA->logfile, format, ap);
}
It uses a macro I defined:
#define BB_DATA ((struct bb_state *) fuse_get_context()->private_data)
to obtain the private data field and cast it to a
struct bb_state *
.
You can see how I created the struct bb_struct
by
looking at params.h
where I defined the
struct
:
struct bb_state {
FILE *logfile;
char *rootdir;
};
It has two fields: the FILE*
for the log file, and
the path to the directory we're accessing through BBFS.
I malloc()
the structure and set the values of the
fields in my main()
function (see last section) so
they'll be available to me later.
Next: Extra Information About Unclear Functions