From f013aeb11ab59fcfe5d16b35aff28a5f96d7739d Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 31 Mar 2012 09:47:32 -0700 Subject: [PATCH] Add Metadata directory option. --- src/pifs.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/pifs.c b/src/pifs.c index 1127a1f..c5db84b 100644 --- a/src/pifs.c +++ b/src/pifs.c @@ -1,11 +1,24 @@ #define FUSE_USE_VERSION 26 #include #include +#include #include #include #include #include +struct options { + char *mdd; +} options; + +/** macro to define options */ +#define PIFS_OPT_KEY(t, p, v) { t, offsetof(struct options, p), v } + +static struct fuse_opt pifs_opts[] = +{ + PIFS_OPT_KEY("mdd=%s", mdd, 0), +}; + static int pifs_getattr(const char *path, struct stat *buf) { int ret = stat(path, buf); @@ -296,5 +309,28 @@ static struct fuse_operations pifs_ops = { int main (int argc, char *argv[]) { - return fuse_main(argc, argv, &pifs_ops, NULL); + int ret; + struct fuse_args args = FUSE_ARGS_INIT(argc, argv); + + memset(&options, 0, sizeof(struct options)); + if (fuse_opt_parse(&args, &options, pifs_opts, NULL) == -1) { + return -1; + } + + if (!options.mdd) { + fprintf(stderr, + "%s: Metadata directory must be specified with -o mdd=\n", + argv[0]); + return -1; + } + + if (access(options.mdd, R_OK | W_OK | X_OK) == -1) { + fprintf(stderr, "%s: Cannot access metadata directory '%s': %s\n", + argv[0], options.mdd, strerror(errno)); + return -1; + } + + ret = fuse_main(args.argc, args.argv, &pifs_ops, NULL); + fuse_opt_free_args(&args); + return ret; }