Playing with fuse option parsing.
This commit is contained in:
6
config.h
6
config.h
@@ -1 +1,7 @@
|
||||
/*
|
||||
Copyright (c) 2010 Matthias Blankertz <matthias@blankertz.org>
|
||||
|
||||
This work is licensed under the Open Software License ("OSL") v. 3.0.
|
||||
*/
|
||||
|
||||
#define FUSE_USE_VERSION 28
|
||||
|
||||
63
tcfs.c
63
tcfs.c
@@ -1,20 +1,73 @@
|
||||
/*
|
||||
Copyright (c) 2010 Matthias Blankertz <matthias@blankertz.org>
|
||||
|
||||
This work is licensed under the Open Software License ("OSL") v. 3.0.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <fuse.h>
|
||||
#include <fuse_opt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
struct options {
|
||||
char *base;
|
||||
} options;
|
||||
|
||||
int is_audio_file(const char *path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcfs_getattr(const char *path, struct stat *stbuf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *tcfs_init(struct fuse_conn_info *conn)
|
||||
{
|
||||
printf("tcfs_init: proto_major %u, proto_minor %u, async_read %u, max_write %u, max_readahead %u, capable %u, want %u, base \"%s\"\n",
|
||||
conn->proto_major, conn->proto_minor, conn->async_read, conn->max_write, conn->max_readahead, conn->capable, conn->want, options.base);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct fuse_operations tcfs_oper = {
|
||||
.getattr = NULL,
|
||||
.readdir = NULL,
|
||||
.open = NULL,
|
||||
.read = NULL
|
||||
.init = tcfs_init
|
||||
};
|
||||
|
||||
enum {
|
||||
KEY_VERSION,
|
||||
KEY_HELP
|
||||
};
|
||||
|
||||
static struct fuse_opt tcfs_opts[] = {
|
||||
{ "base=%s", offsetof(struct options, base), 0},
|
||||
FUSE_OPT_KEY("-V", KEY_VERSION),
|
||||
FUSE_OPT_KEY("--version", KEY_VERSION),
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return fuse_main(argc, argv, &tcfs_oper, NULL);
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
||||
|
||||
memset(&options, 0, sizeof(struct options));
|
||||
|
||||
if(fuse_opt_parse(&args, &options, tcfs_opts, NULL) == -1)
|
||||
return -1;
|
||||
|
||||
if(!options.base) {
|
||||
fprintf(stderr, "Base directory must be specified!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fuse_main(args.argc, args.argv, &tcfs_oper, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user