diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/debug.h | 10 | ||||
-rwxr-xr-x | src/mp3_vnops.c | 31 | ||||
-rwxr-xr-x | src/mp3fs.c | 18 |
4 files changed, 37 insertions, 24 deletions
@@ -1,5 +1,5 @@ CFLAGS = -Wall -std=c99 -D_BSD_SOURCE -I/usr/local/include/ -Iinclude/ \ - `pkg-config fuse --cflags` + `pkg-config fuse --cflags` -DDEBUGGING LD_ADD = -L/usr/local/lib -lid3 \ `pkg-config fuse --libs` diff --git a/include/debug.h b/include/debug.h new file mode 100644 index 0000000..5b780bc --- /dev/null +++ b/include/debug.h @@ -0,0 +1,10 @@ +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#ifdef DEBUGGING +# define DEBUG(...) fprintf (stderr, __VA_ARGS__) +#else +# define DEBUG(...) +#endif + +#endif diff --git a/src/mp3_vnops.c b/src/mp3_vnops.c index 8348064..29069c0 100755 --- a/src/mp3_vnops.c +++ b/src/mp3_vnops.c @@ -13,7 +13,9 @@ #include <id3.h> #include <mp3fs.h> -char *musicpath = "/home/lulf/dev/mp3fs/music"; +#include <debug.h> + +char musicpath[MAXPATHLEN]; // = "/home/lulf/dev/mp3fs/music"; static int mp3_getattr (const char *path, struct stat *stbuf) { @@ -108,6 +110,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) { @@ -117,11 +133,16 @@ mp3_run(int argc, char **argv) /* Update tables. */ if (argc < 2) { - fprintf(stderr, "Usage: %s <mountpoint> <musicfolder>\n", argv[0]); + fprintf(stderr, "Usage: %s <musicfolder> <mountpoint>\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); -} |