Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 422 lines (376 sloc) 14.228 kB
4d4d90b @hzeller o More legalese
authored
1 // Folve - A fuse filesystem that convolves audio files on-the-fly.
2 //
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
3 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce634 @hzeller o Remove some trailing whitespaces
authored
4 //
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 // Use latest version.
19 #define FUSE_USE_VERSION 26
49a4cd9 @hzeller o Provide an INSTALL.md that explains how to compile on older systems.
authored
20 #include <fuse/fuse.h>
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
21
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
22 #include <dirent.h>
23 #include <errno.h>
b698853 @hzeller o README updates.
authored
24 #include <fcntl.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
25 #include <limits.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored
26 #include <sndfile.h> // for sf_version_string
27 #include <stdarg.h>
b698853 @hzeller o README updates.
authored
28 #include <stdio.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
29 #include <stdlib.h>
b698853 @hzeller o README updates.
authored
30 #include <string.h>
31 #include <sys/stat.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored
32 #include <sys/syscall.h> // need to call gettid syscall.
b698853 @hzeller o README updates.
authored
33 #include <sys/time.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored
34 #include <sys/types.h>
49eca7f @hzeller o add syslog as preparation for parameter handling.
authored
35 #include <syslog.h>
b698853 @hzeller o README updates.
authored
36 #include <unistd.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
37
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
38 #include "folve-filesystem.h"
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
39 #include "status-server.h"
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
40 #include "util.h"
e9c07dd @hzeller o add documentation
authored
41
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
42 static const char kStatusFileName[] = "/folve-status.html";
43
6c6dedb @hzeller o Some readme tweaks and readability improvements.
authored
44 // Compilation unit variables to communicate with the fuse callbacks.
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
45 static struct FolveRuntime {
a372a03 @hzeller o Make meta-refresh configurable.
authored
46 FolveRuntime() : fs(NULL), mount_point(NULL),
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
47 status_port(-1), refresh_time(10), parameter_error(false),
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
48 readdir_dump_file(NULL), status_server(NULL) {}
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
49 FolveFilesystem *fs;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
50 const char *mount_point;
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
51 int status_port;
a372a03 @hzeller o Make meta-refresh configurable.
authored
52 int refresh_time;
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored
53 bool parameter_error;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
54 FILE *readdir_dump_file;
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
55 StatusServer *status_server;
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
56 } folve_rt;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
57
79d07ba @hzeller o Make readdir logging thread safe.
authored
58 // Logger that only prints to stderr; used for
59 class ReaddirLogger {
60 public:
939d805 @hzeller o write relative time from startup.
authored
61 ReaddirLogger() : start_time_(folve::CurrentTime()) {}
62
63 void WriteInit() {
64 if (!folve_rt.readdir_dump_file) return;
65 fprintf (folve_rt.readdir_dump_file, "%-11s %-8s: <log>\n",
66 "# time", " tid");
67 fflush(folve_rt.readdir_dump_file);
68 }
69
79d07ba @hzeller o Make readdir logging thread safe.
authored
70 ReaddirLogger &Log(const char *fmt, ...)
71 __attribute__ ((format (printf, 2, 3))) {
72 if (!folve_rt.readdir_dump_file) return *this;
939d805 @hzeller o write relative time from startup.
authored
73 fprintf (folve_rt.readdir_dump_file, "%011.6f %08lx: ",
74 folve::CurrentTime() - start_time_, syscall(SYS_gettid));
79d07ba @hzeller o Make readdir logging thread safe.
authored
75 va_list ap;
76 va_start(ap, fmt);
77 folve::MutexLock l(&io_mutex_);
78 vfprintf(folve_rt.readdir_dump_file, fmt, ap);
79 va_end(ap);
80 return *this;
81 }
939d805 @hzeller o write relative time from startup.
authored
82
79d07ba @hzeller o Make readdir logging thread safe.
authored
83 void Flush() {
84 if (folve_rt.readdir_dump_file) {
85 folve::MutexLock l(&io_mutex_);
86 fflush(folve_rt.readdir_dump_file);
87 }
88 }
939d805 @hzeller o write relative time from startup.
authored
89
90 private:
91 const double start_time_;
79d07ba @hzeller o Make readdir logging thread safe.
authored
92 folve::Mutex io_mutex_;
93 } rlog;
94
7c7bda6 @hzeller o attempt to create a sndfile for every file, if that fails, fall
authored
95 static char *concat_path(char *buf, const char *a, const char *b) {
96 strcpy(buf, a);
97 strcat(buf, b);
98 return buf;
99 }
100
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
101 // Given a relative path from the root of the mounted file-system, get the
102 // original file from the source filesystem.
103 static const char *assemble_orig_path(char *buf, const char *path) {
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
104 return concat_path(buf, folve_rt.fs->underlying_dir().c_str(), path);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
105 }
106
7c7bda6 @hzeller o attempt to create a sndfile for every file, if that fails, fall
authored
107 // Essentially lstat(). Just forward to the original filesystem (this
73093dc @hzeller o Keep open file-descriptor.
authored
108 // will by lying: our convolved files are of different size...)
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
109 static int folve_getattr(const char *path, struct stat *stbuf) {
c6994d4 @hzeller o Allow port-less status serving at /folve-status.html
authored
110 if (strcmp(path, kStatusFileName) == 0) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
111 FileHandler *status = folve_rt.status_server->CreateStatusFileHandler();
112 status->Stat(stbuf);
113 delete status;
114 return 0;
115 }
9a8ea56 @hzeller o add infrastructure to provide Stat() output of currently open
authored
116 // If this is a currently open filename, we might be able to output a better
117 // estimate.
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
118 int result = folve_rt.fs->StatByFilename(path, stbuf);
369a0a7 @hzeller o Writing is not possible. Show permissions as readonly.
authored
119 if (result != 0) {
120 char path_buf[PATH_MAX];
121 result = lstat(assemble_orig_path(path_buf, path), stbuf);
79d07ba @hzeller o Make readdir logging thread safe.
authored
122 rlog.Log("STAT %s mode=%03o %s %s %s", path,
123 stbuf->st_mode & 0777, S_ISDIR(stbuf->st_mode) ? "DIR" : "",
124 (result == -1) ? strerror(errno) : "",
125 ctime(&stbuf->st_mtime)); // ctime ends with \n, so put that last
369a0a7 @hzeller o Writing is not possible. Show permissions as readonly.
authored
126 if (result == -1)
127 return -errno;
4b54970 @hzeller o Also, debug stat() calls with -R option.
authored
128 } else {
79d07ba @hzeller o Make readdir logging thread safe.
authored
129 rlog.Log("FOLVE-Stat %s\n", path);
369a0a7 @hzeller o Writing is not possible. Show permissions as readonly.
authored
130 }
131 // Whatever write mode was there before: now things are readonly.
132 stbuf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
133 return 0;
134 }
135
73093dc @hzeller o Keep open file-descriptor.
authored
136 // readdir(). Just forward to original filesystem.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
137 static int folve_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
138 off_t offset, struct fuse_file_info *fi) {
c6994d4 @hzeller o Allow port-less status serving at /folve-status.html
authored
139 if (strcmp(path, "/") == 0) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
140 struct stat st;
141 memset(&st, 0, sizeof(st));
142 filler(buf, kStatusFileName + 1, &st, 0);
143 }
144
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
145 DIR *dp;
146 struct dirent *de;
147 char path_buf[PATH_MAX];
148
149 dp = opendir(assemble_orig_path(path_buf, path));
150 if (dp == NULL)
151 return -errno;
152
bf030af @hzeller o use readdir_r() - looks like readdir is indeed not really multi-thread
authored
153 // Entry size is a bit shaky to calculate, but this should be the upper bound.
154 const size_t entry_size = sizeof(struct dirent) + PATH_MAX;
155 struct dirent *entry_buf = (struct dirent *) malloc(entry_size);
156
79d07ba @hzeller o Make readdir logging thread safe.
authored
157 rlog.Log("LIST %s\n", path);
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
158
bf030af @hzeller o use readdir_r() - looks like readdir is indeed not really multi-thread
authored
159 while (readdir_r(dp, entry_buf, &de) == 0 && de != NULL) {
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
160 struct stat st;
161 memset(&st, 0, sizeof(st));
162 st.st_ino = de->d_ino;
163 st.st_mode = de->d_type << 12;
7c7bda6 @hzeller o attempt to create a sndfile for every file, if that fails, fall
authored
164 const char *entry_name = de->d_name;
79d07ba @hzeller o Make readdir logging thread safe.
authored
165 rlog.Log("ITEM %s%s%s\n", path, strlen(path) > 1 ? "/" : "", de->d_name);
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
166 if (filler(buf, entry_name, &st, 0)) {
79d07ba @hzeller o Make readdir logging thread safe.
authored
167 rlog.Log("DONE (%s)\n", de->d_name);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
168 break;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
169 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
170 }
bf030af @hzeller o use readdir_r() - looks like readdir is indeed not really multi-thread
authored
171 free(entry_buf);
79d07ba @hzeller o Make readdir logging thread safe.
authored
172 rlog.Log("DONE %s\n", path).Flush();
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
173 closedir(dp);
174 return 0;
175 }
176
73093dc @hzeller o Keep open file-descriptor.
authored
177 // readlink(): forward to original filesystem.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
178 static int folve_readlink(const char *path, char *buf, size_t size) {
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
179 char path_buf[PATH_MAX];
180 const int result = readlink(assemble_orig_path(path_buf, path),
181 buf, size - 1);
182 if (result == -1)
183 return -errno;
184
185 buf[result] = '\0';
186 return 0;
187 }
188
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
189 static int folve_open(const char *path, struct fuse_file_info *fi) {
c6994d4 @hzeller o Allow port-less status serving at /folve-status.html
authored
190 if (strcmp(path, kStatusFileName) == 0) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
191 fi->fh = (uint64_t) folve_rt.status_server->CreateStatusFileHandler();
192 return 0;
193 }
194
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored
195 // We want to be allowed to only return part of the requested data in read().
196 // That way, we can separate reading the ID3-tags from
197 // decoding of the music stream - that way indexing should be fast.
198 // Setting the flag 'direct_io' allows us to return partial results.
199 fi->direct_io = 1;
200
e9c07dd @hzeller o add documentation
authored
201 // The file-handle has the neat property to be 64 bit - so we can actually
b698853 @hzeller o README updates.
authored
202 // stuff a pointer to our file handler object in there :)
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored
203 // (Yay, someone was thinking while developing that API).
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
204 FileHandler *handler = folve_rt.fs->GetOrCreateHandler(path);
680f590 @hzeller o report opening error.
authored
205 if (handler == NULL)
206 return -errno;
207 fi->fh = (uint64_t) handler;
208 return 0;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
209 }
210
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
211 static int folve_read(const char *path, char *buf, size_t size, off_t offset,
212 struct fuse_file_info *fi) {
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
213 return reinterpret_cast<FileHandler *>(fi->fh)->Read(buf, size, offset);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
214 }
215
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
216 static int folve_release(const char *path, struct fuse_file_info *fi) {
c6994d4 @hzeller o Allow port-less status serving at /folve-status.html
authored
217 if (strcmp(path, kStatusFileName) == 0) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
218 delete reinterpret_cast<FileHandler *>(fi->fh);
219 } else {
220 folve_rt.fs->Close(path, reinterpret_cast<FileHandler *>(fi->fh));
221 }
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
222 return 0;
9a8ea56 @hzeller o add infrastructure to provide Stat() output of currently open
authored
223 }
224
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
225 static int folve_fgetattr(const char *path, struct stat *result,
226 struct fuse_file_info *fi) {
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
227 return reinterpret_cast<FileHandler *>(fi->fh)->Stat(result);
73093dc @hzeller o Keep open file-descriptor.
authored
228 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
229
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
230 static void *folve_init(struct fuse_conn_info *conn) {
231 const int ident_len = 20;
232 char *ident = (char*) malloc(ident_len); // openlog() keeps reference. Leaks.
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
233 snprintf(ident, ident_len, "folve[%d]", getpid());
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
234 openlog(ident, LOG_CONS|LOG_PERROR, LOG_USER);
ec3ae89 @hzeller o Print out version string of used libraries.
authored
235 syslog(LOG_INFO, "Version " FOLVE_VERSION " started "
236 "(with fuse=%d.%d; sndfile=%s). ",
237 FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION, sf_version_string());
238 syslog(LOG_INFO, "Serving '%s' on mount point '%s'",
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
239 folve_rt.fs->underlying_dir().c_str(), folve_rt.mount_point);
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
240 if (folve::IsDebugLogEnabled()) {
5830c5a @hzeller o Switch logging to syslog()
authored
241 syslog(LOG_INFO, "Debug logging enabled (-D)");
242 }
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
243
c6994d4 @hzeller o Allow port-less status serving at /folve-status.html
authored
244 // Status server is always used - it serves the status as an HTML file.
245 folve_rt.status_server = new StatusServer(folve_rt.fs);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
246 if (folve_rt.status_port > 0) {
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
247 // Need to start status server after we're daemonized.
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
248 if (folve_rt.status_server->Start(folve_rt.status_port)) {
a372a03 @hzeller o Make meta-refresh configurable.
authored
249 syslog(LOG_INFO, "HTTP status server on port %d; refresh=%d",
250 folve_rt.status_port, folve_rt.refresh_time);
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored
251 folve_rt.status_server->set_meta_refresh(folve_rt.refresh_time);
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
252 } else {
253 syslog(LOG_ERR, "Couldn't start HTTP server on port %d\n",
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
254 folve_rt.status_port);
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
255 }
256 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
257
a90d922 @hzeller o Separate sanitizing of config subdirectories.
authored
258 folve_rt.fs->SetupInitialConfig();
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
259 return NULL;
260 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
261
0a3400d @hzeller o Write when we're exiting.
authored
262 static void folve_destroy(void *) {
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
263 if (folve_rt.readdir_dump_file) {
264 fclose(folve_rt.readdir_dump_file);
265 }
db66f7d @hzeller o print which directory is serviced.
authored
266 syslog(LOG_INFO, "Exiting.");
0a3400d @hzeller o Write when we're exiting.
authored
267 }
268
b698853 @hzeller o README updates.
authored
269 static int usage(const char *prg) {
8fb28ec @hzeller Making README.md more readable thanks to wordsmithing input from
authored
270 printf("usage: %s [options] <original-dir> <mount-point-dir>\n", prg);
5830c5a @hzeller o Switch logging to syslog()
authored
271 printf("Options: (in sequence of usefulness)\n"
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
272 "\t-C <cfg-dir> : Convolver base configuration directory.\n"
273 "\t Sub-directories name the different filters.\n"
1971a4a @hzeller o No more radio buttons.
authored
274 "\t Select on the HTTP status page.\n"
5830c5a @hzeller o Switch logging to syslog()
authored
275 "\t-p <port> : Port to run the HTTP status server on.\n"
436f57d @hzeller o Have a default refresh time of 10 seconds.
authored
276 "\t-r <refresh> : Seconds between refresh of status page;\n"
277 "\t Default is %d seconds; switch off with -1.\n"
f9b9bc9 @hzeller o gapless not experimental anymore.
authored
278 "\t-g : Gapless convolving alphabetically adjacent files.\n"
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
279 "\t-b <MebiByte>: Pre-buffer files by given MB. Experimental.\n"
20e139c @hzeller o Less cluttered output in UI if -D is not set.
authored
280 "\t-D : Moderate volume Folve debug messages to syslog,\n"
281 "\t and some more detailed configuration info in UI\n"
5830c5a @hzeller o Switch logging to syslog()
authored
282 "\t-f : Operate in foreground; useful for debugging.\n"
8fb28ec @hzeller Making README.md more readable thanks to wordsmithing input from
authored
283 "\t-o <mnt-opt> : other generic mount parameters passed to FUSE.\n"
4b54970 @hzeller o Also, debug stat() calls with -R option.
authored
284 "\t-d : High volume FUSE debug log. Implies -f.\n"
285 "\t-R <file> : Debug readdir() & stat() calls. Output to file.\n",
436f57d @hzeller o Have a default refresh time of 10 seconds.
authored
286 folve_rt.refresh_time);
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored
287 return 1;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
288 }
289
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
290 struct FolveConfig {
291 FolveConfig() : base_dir(NULL), config_dir(NULL), port(-1) {}
292 const char *base_dir;
293 const char *mount_point;
294 const char *config_dir;
295 int port;
296 };
297
298 enum {
299 FOLVE_OPT_PORT = 42,
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
300 FOLVE_OPT_PREBUFFER,
a372a03 @hzeller o Make meta-refresh configurable.
authored
301 FOLVE_OPT_REFRESH_TIME,
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
302 FOLVE_OPT_CONFIG,
5830c5a @hzeller o Switch logging to syslog()
authored
303 FOLVE_OPT_DEBUG,
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
304 FOLVE_OPT_DEBUG_READDIR,
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
305 FOLVE_OPT_GAPLESS,
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
306 };
307
308 int FolveOptionHandling(void *data, const char *arg, int key,
309 struct fuse_args *outargs) {
df18f63 @hzeller o Make path-names to filters and base-directory absolute
authored
310 char realpath_buf[PATH_MAX]; // running as daemon, need absolute names.
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
311 FolveRuntime *rt = (FolveRuntime*) data;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
312 switch (key) {
313 case FUSE_OPT_KEY_NONOPT:
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
314 // First non-opt: our underlying dir.
315 if (rt->fs->underlying_dir().empty()) {
cf1b0e0 @hzeller o README demo tweaking
authored
316 const char *base_dir = realpath(arg, realpath_buf);
317 if (base_dir != NULL) {
318 rt->fs->set_underlying_dir(base_dir);
319 } else {
320 fprintf(stderr, "Invalid base path '%s': %s\n",
321 arg, strerror(errno));
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored
322 rt->parameter_error = true;
cf1b0e0 @hzeller o README demo tweaking
authored
323 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
324 return 0; // we consumed this.
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
325 } else {
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
326 rt->mount_point = strdup(arg); // remmber as FYI
327 return 1; // .. but leave it to fuse
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
328 }
329 case FOLVE_OPT_PORT:
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
330 rt->status_port = atoi(arg + 2); // strip "-p"
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
331 return 0;
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
332 case FOLVE_OPT_PREBUFFER: {
333 char *end;
334 const double value = strtod(arg + 2, &end);
335 if (*end != '\0') {
336 fprintf(stderr, "Invalid number %s\n", arg + 2);
337 rt->parameter_error= true;
338 } else if (value > 16) {
339 fprintf(stderr, "-b %.1f out of range. More than 16MB prebuffer. "
340 "That is a lot!\n",
341 value);
342 rt->parameter_error= true;
343 } else {
344 rt->fs->set_pre_buffer_size(value * (1 << 20));
345 }
346 return 0;
347 }
a372a03 @hzeller o Make meta-refresh configurable.
authored
348 case FOLVE_OPT_REFRESH_TIME:
349 rt->refresh_time = atoi(arg + 2); // strip "-r"
350 return 0;
cf1b0e0 @hzeller o README demo tweaking
authored
351 case FOLVE_OPT_CONFIG: {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
352 const char *config_dir = realpath(arg + 2, realpath_buf); // strip "-C"
cf1b0e0 @hzeller o README demo tweaking
authored
353 if (config_dir != NULL) {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
354 rt->fs->SetBaseConfigDir(config_dir);
cf1b0e0 @hzeller o README demo tweaking
authored
355 } else {
39fece1 @hzeller o remove debug ui feature. Not really used and disabled for a while.
authored
356 fprintf(stderr, "Invalid config dir '%s': %s\n", arg + 2, strerror(errno));
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored
357 rt->parameter_error = true;
cf1b0e0 @hzeller o README demo tweaking
authored
358 }
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
359 return 0;
cf1b0e0 @hzeller o README demo tweaking
authored
360 }
5830c5a @hzeller o Switch logging to syslog()
authored
361 case FOLVE_OPT_DEBUG:
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
362 folve::EnableDebugLog(true);
5830c5a @hzeller o Switch logging to syslog()
authored
363 return 0;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
364 case FOLVE_OPT_DEBUG_READDIR:
365 rt->readdir_dump_file = fopen(arg + 2, "w");
939d805 @hzeller o write relative time from startup.
authored
366 rlog.WriteInit();
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
367 return 0;
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
368 case FOLVE_OPT_GAPLESS:
369 rt->fs->set_gapless_processing(true);
370 return 0;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
371 }
372 return 1;
373 }
374
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
375 int main(int argc, char *argv[]) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
376 const char *progname = argv[0];
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored
377 if (argc < 4) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
378 return usage(progname);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
379 }
49eca7f @hzeller o add syslog as preparation for parameter handling.
authored
380
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
381 folve_rt.fs = new FolveFilesystem();
382
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
383 static struct fuse_opt folve_options[] = {
5830c5a @hzeller o Switch logging to syslog()
authored
384 FUSE_OPT_KEY("-p ", FOLVE_OPT_PORT),
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored
385 FUSE_OPT_KEY("-b ", FOLVE_OPT_PREBUFFER),
a372a03 @hzeller o Make meta-refresh configurable.
authored
386 FUSE_OPT_KEY("-r ", FOLVE_OPT_REFRESH_TIME),
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored
387 FUSE_OPT_KEY("-C ", FOLVE_OPT_CONFIG),
5830c5a @hzeller o Switch logging to syslog()
authored
388 FUSE_OPT_KEY("-D", FOLVE_OPT_DEBUG),
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored
389 FUSE_OPT_KEY("-R ", FOLVE_OPT_DEBUG_READDIR),
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored
390 FUSE_OPT_KEY("-g", FOLVE_OPT_GAPLESS),
cca212e @hzeller o document compile error with old version of fuse.
authored
391 FUSE_OPT_END // This fails to compile for fuse <= 2.8.1; get >= 2.8.4
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
392 };
393 struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored
394 fuse_opt_parse(&args, &folve_rt, folve_options, FolveOptionHandling);
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
395
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored
396 if (folve_rt.parameter_error || !folve_rt.fs->CheckInitialized()) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored
397 return usage(progname);
398 }
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
399
400 struct fuse_operations folve_operations;
401 memset(&folve_operations, 0, sizeof(folve_operations));
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
402
0a3400d @hzeller o Write when we're exiting.
authored
403 // Start/stop. Will write to syslog and start auxiliary http service.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
404 folve_operations.init = folve_init;
0a3400d @hzeller o Write when we're exiting.
authored
405 folve_operations.destroy = folve_destroy;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
406
407 // Basic operations to make navigation work.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
408 folve_operations.readdir = folve_readdir;
409 folve_operations.readlink = folve_readlink;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
410
411 // open() and close() file.
38cdeb1 @hzeller o whitespace changes.
authored
412 folve_operations.open = folve_open;
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
413 folve_operations.release = folve_release;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored
414
415 // Actual workhorse: reading a file and returning predicted file-size
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored
416 folve_operations.read = folve_read;
417 folve_operations.fgetattr = folve_fgetattr;
418 folve_operations.getattr = folve_getattr;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
419
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored
420 return fuse_main(args.argc, args.argv, &folve_operations, NULL);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored
421 }
Something went wrong with that request. Please try again.