#define DIR_TRIGGER 2
static fmt_e format_index = OUTFMT_OGG;
+static long long cachesize_value = CACHE_DEFAULT_SIZE;
+static long num_threads_value = 1;
char *quality = NULL;
FMDB *db_state = NULL;
};
struct thread_work global_work;
-#define MOUNT_OPT_CHAR(n) char *n
-#define MOUNT_OPT_LLD(n) long long n
-#define MOUNT_OPT_INT(n) int n
-#define FUSE_MOUNT_OPT_CHAR(n) {"--"#n"=%s", offsetof(struct mount_opts, n), 1}
-#define FUSE_MOUNT_OPT_LLD(n) {"--"#n"=%lld", offsetof(struct mount_opts, n), 1}
-#define FUSE_MOUNT_OPT_INT(n) {"--"#n"=%d", offsetof(struct mount_opts, n), 1}
+#define MOUNT_OPT(n) char *n
+#define FUSE_MOUNT_OPT(n) {"--"#n"=%s", offsetof(struct mount_opts, n), 1}
struct mount_opts
{
- MOUNT_OPT_CHAR(config_file);
- MOUNT_OPT_CHAR(basedir);
- MOUNT_OPT_CHAR(cachedir);
- MOUNT_OPT_CHAR(db_file);
- MOUNT_OPT_CHAR(format);
- MOUNT_OPT_CHAR(quality);
- MOUNT_OPT_CHAR(logfile);
- MOUNT_OPT_LLD(cachesize);
- MOUNT_OPT_INT(num_threads);
+ MOUNT_OPT(config_file);
+ MOUNT_OPT(basedir);
+ MOUNT_OPT(cachedir);
+ MOUNT_OPT(db_file);
+ MOUNT_OPT(format);
+ MOUNT_OPT(quality);
+ MOUNT_OPT(logfile);
+ MOUNT_OPT(cachesize);
+ MOUNT_OPT(num_threads);
};
struct mount_opts mo;
pthread_once_t once_control = PTHREAD_ONCE_INIT;
static const struct fuse_opt fm_mount_opts[] = {
- FUSE_MOUNT_OPT_CHAR(config_file),
- FUSE_MOUNT_OPT_CHAR(basedir),
- FUSE_MOUNT_OPT_CHAR(cachedir),
- FUSE_MOUNT_OPT_CHAR(db_file),
- FUSE_MOUNT_OPT_CHAR(format),
- FUSE_MOUNT_OPT_CHAR(quality),
- FUSE_MOUNT_OPT_CHAR(logfile),
- FUSE_MOUNT_OPT_LLD(cachesize),
- FUSE_MOUNT_OPT_INT(num_threads),
+ FUSE_MOUNT_OPT(config_file),
+ FUSE_MOUNT_OPT(basedir),
+ FUSE_MOUNT_OPT(cachedir),
+ FUSE_MOUNT_OPT(db_file),
+ FUSE_MOUNT_OPT(format),
+ FUSE_MOUNT_OPT(quality),
+ FUSE_MOUNT_OPT(logfile),
+ FUSE_MOUNT_OPT(cachesize),
+ FUSE_MOUNT_OPT(num_threads),
FUSE_OPT_END
};
pthread_mutex_init(&dir_state.lock, &attr);
pthread_mutex_init(&global_work.lock, &attr);
pthread_cond_init(&global_work.cv, NULL);
- bg_thread = malloc(mo.num_threads * sizeof(pthread_t));
+ bg_thread = malloc(num_threads_value * sizeof(pthread_t));
if (!bg_thread)
{
MAINLOG0((logfile, "%s: Failed to malloc thread space for thread descriptors\n", __func__));
db_close(db_state);
}
- threadcount = malloc(mo.num_threads * sizeof(int));
+ threadcount = malloc(num_threads_value * sizeof(int));
if (!threadcount)
{
MAINLOG0((logfile, "%s: Failed to malloc thread space for thread numbers\n", __func__));
db_close(db_state);
}
- for (i = 0; i < mo.num_threads; i++)
+ for (i = 0; i < num_threads_value; i++)
{
threadcount[i] = i;
error = pthread_create(&bg_thread[i], NULL, bg_handler, &threadcount[i]);
pthread_mutex_unlock(&global_work.lock);
- if (mo.num_threads > 1)
+ if (num_threads_value > 1)
{
tmp_path = strdup(flac_path);
current_dir = dirname(tmp_path);
}
pthread_mutex_unlock(&dir_state.lock);
free(tmp_path);
- } /* mo.num_threads > 1 */
+ } /* num_threads_value > 1 */
pthread_mutex_lock(&global_work.lock);
MAINLOG1((logfile, "%s: signal, %d files in queue\n", dbgname, global_work.num_todo));
logfile = stderr;
- mo.cachesize = CACHE_DEFAULT_SIZE;
- mo.num_threads = 1;
fuse_opt_parse(&args, &mo, fm_mount_opts, NULL);
if (mo.logfile)
return EINVAL;
}
- if (mo.cachesize < CACHE_MIN_SIZE)
+ /* Convert strings into useful integers */
+ if (mo.cachesize)
+ {
+ error = parse_string_to_long_long(mo.cachesize, &cachesize_value);
+ if (error)
+ {
+ MAINLOG0((logfile, "Unable to parse cachesize value: %s\n", mo.cachesize));
+ return EINVAL;
+ }
+ }
+
+ if (mo.num_threads)
+ {
+ error = parse_string_to_long(mo.cachesize, &num_threads_value);
+ if (error)
+ {
+ MAINLOG0((logfile, "Unable to parse num_threads value: %s\n", mo.num_threads));
+ return EINVAL;
+ }
+ }
+
+ if (cachesize_value < CACHE_MIN_SIZE)
{
MAINLOG0((logfile, "Cache size %lld is too small; minimum allowed is %lld\n",
- mo.cachesize, CACHE_MIN_SIZE));
+ cachesize_value, CACHE_MIN_SIZE));
return EINVAL;
}
return 1;
}
- error = cache_init(db_state, mo.cachedir, mo.cachesize);
+ error = cache_init(db_state, mo.cachedir, cachesize_value);
if (error)
{
MAINLOG0((logfile, "Failed to init cache %s, error %d\n", mo.cachedir, error));