From 9a21927ac4cdd497f3fbc84df3717748c4cb10a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Fri, 25 Apr 2008 13:57:45 +0200 Subject: - Added musicpath parsing Order is reversed, so usage is: ./mp3fs --- src/mp3_vnops.c | 31 ++++++++++++++++++++++++++----- src/mp3fs.c | 18 ------------------ 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/mp3_vnops.c b/src/mp3_vnops.c index b04f0dc..381e66d 100755 --- a/src/mp3_vnops.c +++ b/src/mp3_vnops.c @@ -11,9 +11,11 @@ #include +#include "debug.h" + #define MAXPATHLEN 100000 -char *musicpath = "/home/lulf/dev/mp3fs/music"; +char musicpath[MAXPATHLEN]; // = "/home/lulf/dev/mp3fs/music"; typedef void traverse_fn_t(char *, void *); @@ -202,6 +204,20 @@ static struct fuse_operations mp3_ops = { .read = mp3_read, }; +static int mp3fs_opt_proc (void *data, const char *arg, int key, + struct fuse_args *outargs) +{ + static bool musicpath_set = false; + + if (key == FUSE_OPT_KEY_NONOPT && !musicpath_set) { + /* The source directory isn't already set, let's do it */ + strcpy(musicpath, arg); + musicpath_set = true; + return (0); + } + return (1); +} + int mp3_run(int argc, char **argv) { @@ -211,11 +227,16 @@ mp3_run(int argc, char **argv) /* Update tables. */ if (argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s \n", argv[0]); return (-1); } + + struct fuse_args args = FUSE_ARGS_INIT (argc, argv); + + if (fuse_opt_parse(&args, NULL, NULL, mp3fs_opt_proc) != 0) + exit (1); -/* musicpath = argv[2];*/ - - return (fuse_main(argc, argv, &mp3_ops, NULL)); + DEBUG("musicpath: %s\n", musicpath); + + return (fuse_main(args.argc, args.argv, &mp3_ops, NULL)); } diff --git a/src/mp3fs.c b/src/mp3fs.c index b8f0ea1..3555d20 100755 --- a/src/mp3fs.c +++ b/src/mp3fs.c @@ -10,29 +10,11 @@ /* Prototypes. */ static int mp3fs_opt_proc (void *, const char *, int, struct fuse_args *); -/* Just for testing the argument parsing. TODO: fix something better */ -const char *sourcedir = NULL; - int main(int argc, char **argv) { -/* struct fuse_args args = FUSE_ARGS_INIT (argc, argv); - - if (fuse_opt_parse(&args, NULL, NULL, mp3fs_opt_proc) != 0) - exit (1);*/ - printf("Starting up mp3fs\n"); mp3_run(argc, argv); printf("Shutting down mp3fs\n"); } -static int mp3fs_opt_proc (void *data, const char *arg, int key, - struct fuse_args *outargs) -{ - if (key == FUSE_OPT_KEY_NONOPT && !sourcedir) { - /* The source directory isn't already set, let's do it */ - sourcedir = arg; - return (0); - } - return (-1); -} -- cgit v1.2.3