6 #include <uniconfroot.h>
7 #include <wvistreamlist.h>
8 #include <wvstringlist.h>
14 static bool want_to_die
= false;
16 #define FUSE_UMOUNT_CMD_ENV "_FUSE_UNMOUNT_CMD"
18 static void fuse_unmount()
20 if (!fuse
|| !fuse
->fs_unmounted
)
21 system(getenv(FUSE_UMOUNT_CMD_ENV
));
26 void sighandler_die(int signum
)
31 void sighandler_ignore(int signum
)
38 wvcon
->print("Usage: funfs <remote mount point> <local mount point> [options]\n"
39 "Supported options:\n"
40 "\t-d/--debug <1-9>\n"
42 "\t-k/--kernel-cache[=no] \tdefault: no\n"
43 "\t-m/--unmount[=no] \tdefault: yes\n"
49 int main(int argc
, char *argv
[])
51 WvLog::LogLevel lvl
= WvLog::Error
;
52 signal(SIGTERM
, sighandler_die
);
53 signal(SIGHUP
, sighandler_die
);
54 signal(SIGINT
, sighandler_die
);
55 signal(SIGUSR1
, sighandler_ignore
);
56 signal(SIGPIPE
, SIG_IGN
);
65 char *remotempoint
= NULL
;
66 char *localmpoint
= NULL
;
71 static struct option long_options
[] = {
75 {"kernel-cache", 2, 0, 'k'},
77 {"unmount", 2, 0, 'm'},
81 int opt
= getopt_long(argc
, argv
, "d:hk::m::p:s", long_options
, &option_index
);
86 if (opt
== '?' || opt
== ':')
93 int loglevel
= atoi(optarg
);
94 if (loglevel
< 1 || loglevel
> 9)
96 wvcon
->print("%s: Invalid debug level.\n", argv
[0]);
99 lvl
= (WvLog::LogLevel
)(loglevel
- 1);
110 cache
= !strstr(optarg
, "no");
119 if (!port
|| port
< 1 || port
> 65536)
121 wvcon
->print("%s: Invalid port %s\n", argv
[0], optarg
);
131 umount
= !strstr(optarg
, "no");
141 if (argc
- optind
< 2 - !!slave
)
145 else if (argc
- optind
> 2)
148 wvcon
->print("%s: Unrecognized paramater(s): ", argv
[0]);
149 while (optind
< argc
)
150 wvcon
->print("%s ", argv
[optind
++]);
156 remotempoint
= argv
[optind
++];
160 localmpoint
= argv
[optind
++];
163 system(WvString("fusermount -u %s 2>/dev/null", localmpoint
));
165 const char *params
[11];
168 WvString
strlvl(lvl
);
169 WvString
strport(port
);
171 params
[next
++] = "fusermount";
173 params
[next
++] = "-c";
174 params
[next
++] = localmpoint
;
175 params
[next
++] = argv
[0];
176 params
[next
++] = remotempoint
;
177 params
[next
++] = "--slave";
178 params
[next
++] = "--debug";
179 params
[next
++] = strlvl
;
180 params
[next
++] = "--port";
181 params
[next
++] = strport
;
182 params
[next
++] = NULL
;
184 execvp("fusermount", (char* const*)params
);
186 fprintf(stderr
, "%s: fusermount: %s\n", argv
[0], strerror(errno
));
192 WvLogConsole
logdisp(2, lvl
);
195 lst
.split(remotempoint
, ":", 2);
197 if (lst
.count() != 2)
199 wvcon
->print("funfs: Bad mount point %s: expected format 'host:/path'\n",
204 UniConfRoot
cfg("temp");
206 UniConf funfscfg
= cfg
["FunFS"];
207 funfscfg
["Hostname"].set(lst
.popstr());
208 funfscfg
["Remote Mount Point"].set(lst
.popstr());
209 funfscfg
["Port"].setint(port
);
210 funfscfg
["Local Mount Point"].set(localmpoint
);
212 UniConf cachefscfg
= cfg
["CacheFS"];
213 cachefscfg
["Cache Root"].set("cache");
214 cachefscfg
["Cache Size"].setint(5 * 1024); // Megabytes
216 cachefscfg
["DB Location"].set("%s/%s", cachefscfg
["Cache Root"].get(),
219 mkdirp(cachefscfg
["DB Location"].get());
220 system(WvString("rm -f %s/*", cachefscfg
["DB Location"].get()));
222 cachefscfg
["Meta Root"].set("%s/meta/%s/%s", cachefscfg
["Cache Root"].get(),
223 funfscfg
["Hostname"].get(), funfscfg
["Remote Mount Point"].get());
224 cachefscfg
["Data Root"].set("%s/data/%s/%s", cachefscfg
["Cache Root"].get(),
225 funfscfg
["Hostname"].get(), funfscfg
["Remote Mount Point"].get());
227 UniConf fusecfg
= cfg
["WvFuse"];
228 fusecfg
["DB Location"].set(cachefscfg
["DB Location"].get());
230 FunFS
*funfs
= new FunFS(funfscfg
);
232 fuse
= new WvFuse(new CacheFS(funfs
, cachefscfg
), fusecfg
);
233 WvIStreamList::globallist
.append(fuse
, false);
235 while (fuse
->isok() && funfs
->isok() && !want_to_die
)
237 WvIStreamList::globallist
.select(-1);
240 WvIStreamList::globallist
.zap();
241 system(WvString("rm -f %s/*", cachefscfg
["DB Location"].get()));
242 rmdir(cachefscfg
["DB Location"].get());