Skip to content
Newer
Older
100644 421 lines (375 sloc) 13.9 KB
4d4d90b @hzeller o More legalese
authored Sep 23, 2012
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 Sep 8, 2012
3 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce634 @hzeller o Remove some trailing whitespaces
authored Sep 24, 2012
4 //
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
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 Sep 25, 2012
20 #include <fuse/fuse.h>
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored Sep 15, 2012
21
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
22 #include <dirent.h>
23 #include <errno.h>
b698853 @hzeller o README updates.
authored Sep 15, 2012
24 #include <fcntl.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
25 #include <limits.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
26 #include <sndfile.h> // for sf_version_string
27 #include <stdarg.h>
b698853 @hzeller o README updates.
authored Sep 16, 2012
28 #include <stdio.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
29 #include <stdlib.h>
b698853 @hzeller o README updates.
authored Sep 16, 2012
30 #include <string.h>
31 #include <sys/stat.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
32 #include <sys/syscall.h> // need to call gettid syscall.
b698853 @hzeller o README updates.
authored Sep 16, 2012
33 #include <sys/time.h>
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
34 #include <sys/types.h>
49eca7f @hzeller o add syslog as preparation for parameter handling.
authored Sep 16, 2012
35 #include <syslog.h>
b698853 @hzeller o README updates.
authored Sep 16, 2012
36 #include <unistd.h>
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
37
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored Sep 16, 2012
38 #include "folve-filesystem.h"
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 13, 2012
39 #include "status-server.h"
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored Sep 22, 2012
40 #include "util.h"
e9c07dd @hzeller o add documentation
authored Sep 8, 2012
41
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 6, 2012
42 static const char kStatusFileName[] = "/folve-status.html";
43
6c6dedb @hzeller o Some readme tweaks and readability improvements.
authored Sep 16, 2012
44 // Compilation unit variables to communicate with the fuse callbacks.
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
45 static struct FolveRuntime {
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
46 FolveRuntime() : fs(NULL), mount_point(NULL),
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
47 status_port(-1), refresh_time(10), parameter_error(false),
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
48 readdir_dump_file(NULL), status_server(NULL) {}
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 16, 2012
49 FolveFilesystem *fs;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
50 const char *mount_point;
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
51 int status_port;
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
52 int refresh_time;
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored Sep 22, 2012
53 bool parameter_error;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
54 FILE *readdir_dump_file;
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
55 StatusServer *status_server;
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 17, 2012
56 } folve_rt;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
57
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
58 // Logger that only prints to stderr; used for
59 class ReaddirLogger {
60 public:
939d805 @hzeller o write relative time from startup.
authored Oct 6, 2012
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 Oct 6, 2012
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 Oct 6, 2012
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 Oct 6, 2012
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 Oct 6, 2012
82
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
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 Oct 6, 2012
89
90 private:
91 const double start_time_;
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
92 folve::Mutex io_mutex_;
93 } rlog;
94
7c7bda6 @hzeller o attempt to create a sndfile for every file, if that fails, fall
authored Sep 10, 2012
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 Sep 9, 2012
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 Sep 21, 2012
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 Sep 9, 2012
105 }
106
7c7bda6 @hzeller o attempt to create a sndfile for every file, if that fails, fall
authored Sep 11, 2012
107 // Essentially lstat(). Just forward to the original filesystem (this
73093dc @hzeller o Keep open file-descriptor.
authored Sep 8, 2012
108 // will by lying: our convolved files are of different size...)
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
109 static int folve_getattr(const char *path, struct stat *stbuf) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
110 if (folve_rt.status_server && strcmp(path, kStatusFileName) == 0) {
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 Sep 12, 2012
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 Sep 18, 2012
118 int result = folve_rt.fs->StatByFilename(path, stbuf);
369a0a7 @hzeller o Writing is not possible. Show permissions as readonly.
authored Sep 20, 2012
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 Oct 6, 2012
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 Sep 21, 2012
126 if (result == -1)
127 return -errno;
4b54970 @hzeller o Also, debug stat() calls with -R option.
authored Oct 6, 2012
128 } else {
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
129 rlog.Log("FOLVE-Stat %s\n", path);
369a0a7 @hzeller o Writing is not possible. Show permissions as readonly.
authored Sep 21, 2012
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 Sep 9, 2012
133 return 0;
134 }
135
73093dc @hzeller o Keep open file-descriptor.
authored Sep 9, 2012
136 // readdir(). Just forward to original filesystem.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
137 static int folve_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
138 off_t offset, struct fuse_file_info *fi) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
139 if (folve_rt.status_server && strcmp(path, "/") == 0) {
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 Sep 9, 2012
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 Sep 29, 2012
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 Oct 6, 2012
157 rlog.Log("LIST %s\n", path);
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
158
bf030af @hzeller o use readdir_r() - looks like readdir is indeed not really multi-thread
authored Sep 29, 2012
159 while (readdir_r(dp, entry_buf, &de) == 0 && de != NULL) {
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
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 Sep 11, 2012
164 const char *entry_name = de->d_name;
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
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 Oct 6, 2012
166 if (filler(buf, entry_name, &st, 0)) {
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
167 rlog.Log("DONE (%s)\n", de->d_name);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
168 break;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
169 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
170 }
bf030af @hzeller o use readdir_r() - looks like readdir is indeed not really multi-thread
authored Sep 29, 2012
171 free(entry_buf);
79d07ba @hzeller o Make readdir logging thread safe.
authored Oct 6, 2012
172 rlog.Log("DONE %s\n", path).Flush();
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
173 closedir(dp);
174 return 0;
175 }
176
73093dc @hzeller o Keep open file-descriptor.
authored Sep 9, 2012
177 // readlink(): forward to original filesystem.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
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 Sep 9, 2012
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 Sep 17, 2012
189 static int folve_open(const char *path, struct fuse_file_info *fi) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
190 if (folve_rt.status_server && strcmp(path, kStatusFileName) == 0) {
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 Sep 9, 2012
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 Sep 9, 2012
201 // The file-handle has the neat property to be 64 bit - so we can actually
b698853 @hzeller o README updates.
authored Sep 16, 2012
202 // stuff a pointer to our file handler object in there :)
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored Sep 10, 2012
203 // (Yay, someone was thinking while developing that API).
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored Sep 21, 2012
204 FileHandler *handler = folve_rt.fs->GetOrCreateHandler(path);
680f590 @hzeller o report opening error.
authored Sep 13, 2012
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 Sep 9, 2012
209 }
210
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
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 Sep 14, 2012
213 return reinterpret_cast<FileHandler *>(fi->fh)->Read(buf, size, offset);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
214 }
215
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
216 static int folve_release(const char *path, struct fuse_file_info *fi) {
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
217 if (folve_rt.status_server && strcmp(path, kStatusFileName) == 0) {
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 Sep 14, 2012
222 return 0;
9a8ea56 @hzeller o add infrastructure to provide Stat() output of currently open
authored Sep 12, 2012
223 }
224
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
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 Sep 14, 2012
227 return reinterpret_cast<FileHandler *>(fi->fh)->Stat(result);
73093dc @hzeller o Keep open file-descriptor.
authored Sep 9, 2012
228 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
229
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
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 Sep 17, 2012
233 snprintf(ident, ident_len, "folve[%d]", getpid());
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
234 openlog(ident, LOG_CONS|LOG_PERROR, LOG_USER);
ec3ae89 @hzeller o Print out version string of used libraries.
authored Oct 5, 2012
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 Sep 18, 2012
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 Sep 22, 2012
240 if (folve::IsDebugLogEnabled()) {
5830c5a @hzeller o Switch logging to syslog()
authored Sep 17, 2012
241 syslog(LOG_INFO, "Debug logging enabled (-D)");
242 }
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
243
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
244 if (folve_rt.status_port > 0) {
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
245 // Need to start status server after we're daemonized.
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
246 folve_rt.status_server = new StatusServer(folve_rt.fs);
247 if (folve_rt.status_server->Start(folve_rt.status_port)) {
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
248 syslog(LOG_INFO, "HTTP status server on port %d; refresh=%d",
249 folve_rt.status_port, folve_rt.refresh_time);
30b49d6 @hzeller Provide html status as well as /folve-status.html
authored Oct 7, 2012
250 folve_rt.status_server->set_meta_refresh(folve_rt.refresh_time);
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
251 } else {
252 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 Sep 18, 2012
253 folve_rt.status_port);
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
254 }
255 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
256
a90d922 @hzeller o Separate sanitizing of config subdirectories.
authored Oct 4, 2012
257 folve_rt.fs->SetupInitialConfig();
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
258 return NULL;
259 }
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
260
0a3400d @hzeller o Write when we're exiting.
authored Sep 16, 2012
261 static void folve_destroy(void *) {
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
262 if (folve_rt.readdir_dump_file) {
263 fclose(folve_rt.readdir_dump_file);
264 }
db66f7d @hzeller o print which directory is serviced.
authored Sep 17, 2012
265 syslog(LOG_INFO, "Exiting.");
0a3400d @hzeller o Write when we're exiting.
authored Sep 17, 2012
266 }
267
b698853 @hzeller o README updates.
authored Sep 16, 2012
268 static int usage(const char *prg) {
8fb28ec @hzeller Making README.md more readable thanks to wordsmithing input from
authored Sep 24, 2012
269 printf("usage: %s [options] <original-dir> <mount-point-dir>\n", prg);
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
270 printf("Options: (in sequence of usefulness)\n"
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored Oct 4, 2012
271 "\t-C <cfg-dir> : Convolver base configuration directory.\n"
272 "\t Sub-directories name the different filters.\n"
1971a4a @hzeller o No more radio buttons.
authored Sep 23, 2012
273 "\t Select on the HTTP status page.\n"
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
274 "\t-p <port> : Port to run the HTTP status server on.\n"
436f57d @hzeller o Have a default refresh time of 10 seconds.
authored Sep 22, 2012
275 "\t-r <refresh> : Seconds between refresh of status page;\n"
276 "\t Default is %d seconds; switch off with -1.\n"
f9b9bc9 @hzeller o gapless not experimental anymore.
authored Sep 21, 2012
277 "\t-g : Gapless convolving alphabetically adjacent files.\n"
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored Oct 6, 2012
278 "\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 Sep 24, 2012
279 "\t-D : Moderate volume Folve debug messages to syslog,\n"
280 "\t and some more detailed configuration info in UI\n"
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
281 "\t-f : Operate in foreground; useful for debugging.\n"
8fb28ec @hzeller Making README.md more readable thanks to wordsmithing input from
authored Sep 25, 2012
282 "\t-o <mnt-opt> : other generic mount parameters passed to FUSE.\n"
4b54970 @hzeller o Also, debug stat() calls with -R option.
authored Oct 6, 2012
283 "\t-d : High volume FUSE debug log. Implies -f.\n"
284 "\t-R <file> : Debug readdir() & stat() calls. Output to file.\n",
436f57d @hzeller o Have a default refresh time of 10 seconds.
authored Sep 22, 2012
285 folve_rt.refresh_time);
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored Sep 10, 2012
286 return 1;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
287 }
288
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
289 struct FolveConfig {
290 FolveConfig() : base_dir(NULL), config_dir(NULL), port(-1) {}
291 const char *base_dir;
292 const char *mount_point;
293 const char *config_dir;
294 int port;
295 };
296
297 enum {
298 FOLVE_OPT_PORT = 42,
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored Oct 7, 2012
299 FOLVE_OPT_PREBUFFER,
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
300 FOLVE_OPT_REFRESH_TIME,
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
301 FOLVE_OPT_CONFIG,
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
302 FOLVE_OPT_DEBUG,
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
303 FOLVE_OPT_DEBUG_READDIR,
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored Sep 21, 2012
304 FOLVE_OPT_GAPLESS,
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
305 };
306
307 int FolveOptionHandling(void *data, const char *arg, int key,
308 struct fuse_args *outargs) {
df18f63 @hzeller o Make path-names to filters and base-directory absolute
authored Sep 22, 2012
309 char realpath_buf[PATH_MAX]; // running as daemon, need absolute names.
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
310 FolveRuntime *rt = (FolveRuntime*) data;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
311 switch (key) {
312 case FUSE_OPT_KEY_NONOPT:
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
313 // First non-opt: our underlying dir.
314 if (rt->fs->underlying_dir().empty()) {
cf1b0e0 @hzeller o README demo tweaking
authored Sep 22, 2012
315 const char *base_dir = realpath(arg, realpath_buf);
316 if (base_dir != NULL) {
317 rt->fs->set_underlying_dir(base_dir);
318 } else {
319 fprintf(stderr, "Invalid base path '%s': %s\n",
320 arg, strerror(errno));
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored Sep 23, 2012
321 rt->parameter_error = true;
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
322 }
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
323 return 0; // we consumed this.
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
324 } else {
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
325 rt->mount_point = strdup(arg); // remmber as FYI
326 return 1; // .. but leave it to fuse
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
327 }
328 case FOLVE_OPT_PORT:
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
329 rt->status_port = atoi(arg + 2); // strip "-p"
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
330 return 0;
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored Oct 7, 2012
331 case FOLVE_OPT_PREBUFFER: {
332 char *end;
333 const double value = strtod(arg + 2, &end);
334 if (*end != '\0') {
335 fprintf(stderr, "Invalid number %s\n", arg + 2);
336 rt->parameter_error= true;
337 } else if (value > 16) {
338 fprintf(stderr, "-b %.1f out of range. More than 16MB prebuffer. "
339 "That is a lot!\n",
340 value);
341 rt->parameter_error= true;
342 } else {
343 rt->fs->set_pre_buffer_size(value * (1 << 20));
344 }
345 return 0;
346 }
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
347 case FOLVE_OPT_REFRESH_TIME:
348 rt->refresh_time = atoi(arg + 2); // strip "-r"
349 return 0;
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
350 case FOLVE_OPT_CONFIG: {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored Oct 4, 2012
351 const char *config_dir = realpath(arg + 2, realpath_buf); // strip "-C"
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
352 if (config_dir != NULL) {
31096bb @hzeller o remove option -c and add -C: give a base directory for all filters.
authored Oct 4, 2012
353 rt->fs->SetBaseConfigDir(config_dir);
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
354 } else {
39fece1 @hzeller o remove debug ui feature. Not really used and disabled for a while.
authored Oct 6, 2012
355 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 Sep 23, 2012
356 rt->parameter_error = true;
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
357 }
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
358 return 0;
cf1b0e0 @hzeller o README demo tweaking
authored Sep 23, 2012
359 }
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
360 case FOLVE_OPT_DEBUG:
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored Sep 22, 2012
361 folve::EnableDebugLog(true);
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
362 return 0;
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
363 case FOLVE_OPT_DEBUG_READDIR:
364 rt->readdir_dump_file = fopen(arg + 2, "w");
939d805 @hzeller o write relative time from startup.
authored Oct 6, 2012
365 rlog.WriteInit();
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
366 return 0;
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored Sep 21, 2012
367 case FOLVE_OPT_GAPLESS:
368 rt->fs->set_gapless_processing(true);
369 return 0;
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
370 }
371 return 1;
372 }
373
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
374 int main(int argc, char *argv[]) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored Sep 15, 2012
375 const char *progname = argv[0];
8b18938 @hzeller o some comment changes. Ready to do some flac handling.
authored Sep 10, 2012
376 if (argc < 4) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored Sep 16, 2012
377 return usage(progname);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
378 }
49eca7f @hzeller o add syslog as preparation for parameter handling.
authored Sep 17, 2012
379
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
380 folve_rt.fs = new FolveFilesystem();
381
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
382 static struct fuse_opt folve_options[] = {
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
383 FUSE_OPT_KEY("-p ", FOLVE_OPT_PORT),
fea3d55 @hzeller o Initial implementation of pre-buffering thread.
authored Oct 7, 2012
384 FUSE_OPT_KEY("-b ", FOLVE_OPT_PREBUFFER),
a372a03 @hzeller o Make meta-refresh configurable.
authored Sep 22, 2012
385 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 Oct 4, 2012
386 FUSE_OPT_KEY("-C ", FOLVE_OPT_CONFIG),
5830c5a @hzeller o Switch logging to syslog()
authored Sep 18, 2012
387 FUSE_OPT_KEY("-D", FOLVE_OPT_DEBUG),
4e69b5b @hzeller o Provide a way to see what readdir() yields. Some media servers
authored Oct 6, 2012
388 FUSE_OPT_KEY("-R ", FOLVE_OPT_DEBUG_READDIR),
08bbf28 @hzeller o First shot at gapless. Works pretty well for my test-case.
authored Sep 21, 2012
389 FUSE_OPT_KEY("-g", FOLVE_OPT_GAPLESS),
cca212e @hzeller o document compile error with old version of fuse.
authored Sep 24, 2012
390 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 Sep 17, 2012
391 };
392 struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
ee675fe @hzeller o Provide a way to select between different filter diretories.
authored Sep 18, 2012
393 fuse_opt_parse(&args, &folve_rt, folve_options, FolveOptionHandling);
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
394
fa525ee @hzeller o If we find problems in the options, complain and exit.
authored Sep 23, 2012
395 if (folve_rt.parameter_error || !folve_rt.fs->CheckInitialized()) {
1e9ff21 @hzeller o main: report if parameters are not directories.
authored Sep 16, 2012
396 return usage(progname);
397 }
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
398
399 struct fuse_operations folve_operations;
400 memset(&folve_operations, 0, sizeof(folve_operations));
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 14, 2012
401
0a3400d @hzeller o Write when we're exiting.
authored Sep 17, 2012
402 // Start/stop. Will write to syslog and start auxiliary http service.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
403 folve_operations.init = folve_init;
0a3400d @hzeller o Write when we're exiting.
authored Sep 17, 2012
404 folve_operations.destroy = folve_destroy;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 14, 2012
405
406 // Basic operations to make navigation work.
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
407 folve_operations.readdir = folve_readdir;
408 folve_operations.readlink = folve_readlink;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 14, 2012
409
410 // open() and close() file.
38cdeb1 @hzeller o whitespace changes.
authored Sep 20, 2012
411 folve_operations.open = folve_open;
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
412 folve_operations.release = folve_release;
8d1fbe7 @hzeller o Move fuse-convolve.c to fuse-convolve.cc. Make filter-interface
authored Sep 14, 2012
413
414 // Actual workhorse: reading a file and returning predicted file-size
0330f76 @hzeller o Only start status server after we're daemonized, otherwise
authored Sep 17, 2012
415 folve_operations.read = folve_read;
416 folve_operations.fgetattr = folve_fgetattr;
417 folve_operations.getattr = folve_getattr;
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
418
27c44cd @hzeller o Use fuse option handling to extract our flags and options.
authored Sep 17, 2012
419 return fuse_main(args.argc, args.argv, &folve_operations, NULL);
98a5725 @hzeller o Start implementation. Just a basic forwarding filesystem for
authored Sep 9, 2012
420 }
Something went wrong with that request. Please try again.