You actually have to do very little command-line parsing: FUSE
understands a large number of command-line arguments, and parses
them itself. Most importantly, FUSE expects the mountpoint to be one
of the members of the
I'm simplifying things for myself by assuming that the root directory and mount point will be the last two arguments on the command line, with the root directory preceding the mount point. So, my command line parsing happens in two short sections. First, I do some sanity checking: I make sure I've got enough arguments on the command line, and that the last two arguments aren't options.
if ((argc < 3) || (argv[argc-2] == '-') || (argv[argc-1] == '-')) bb_usage();
A few lines later, I pull the root directory out of the argument list,
use the C library
realpath() function to translate it to
a canonicalized absolute pathname, and save it in my private data
(I'll be describing private data in the next section)
bb_data->rootdir = realpath(argv[argc-2], NULL); argv[argc-2] = argv[argc-1]; argv[argc-1] = NULL; argc--;
The last thing I do before turning control over to the FUSE library is to open the log file, and save its stream pointer in my private data as well.
Once I'm ready to start the filesystem, I call
fuse_main(). Its parameters are
argv (as modified by my
bb_oper struct containing pointers to my
re-implementations of the POSIX file operations, and a
struct bb_data, used for storing private data.
fuse_main() parses the rest of the command line,
mounts the directory specified on the command line, and performs other
initializations. Then, it calls an initialization function to
perform any initialization defined by my code.
points to my
bb_init() function, so it is what gets called.
bb_init() function is really small; all it does is
log the fact that it has been called.
Next: Private Data