gnunet-fuse

GNUnet file-sharing directory mounting via FUSE
Log | Files | Refs | Submodules | README | LICENSE

commit 7a7eac77c87972bf25a3afcc681cdb8f03ed8cee
parent 9df359914a71bbf3f944fc68ad59b0445a63688b
Author: David Barksdale <amatus.amongus@gmail.com>
Date:   Wed, 13 Jun 2007 04:44:48 +0000

Cleaned up options and added interrupt support

Diffstat:
MChangeLog | 4++++
Mconfigure.ac | 2+-
Mdirectory.c | 2+-
Mmain.c | 55++++++++++++++++++++++++++++++++++++++++++++++---------
Mread.c | 2+-
5 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +2007-06-12 David Barksdale <amatus@gnu.org> 0.6 +* Cleaned up fuse command line option passing (in a manner of speaking) +* Added an implicit "-o ro" so the mount shows up as read-only (for now) +* Added support for interrupting read operations 2007-06-10 David Barksdale <amatus@gnu.org> 0.5 * Added .uri.<file> files which read the uri of <file> 2007-06-08 David Barksdale <amatus@gnu.org> 0.4 diff --git a/configure.ac b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(gnunet-fuse, 0.5) +AC_INIT(gnunet-fuse, 0.6) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/directory.c b/directory.c @@ -40,7 +40,7 @@ static void dpcb(unsigned long long totalBytes, static int tt(void *cls) { (void)cls; - return OK; + return fuse_interrupted() ? SYSERR : OK; } struct dir_for_each_data diff --git a/main.c b/main.c @@ -35,11 +35,27 @@ static char *cfgFilename = DEFAULT_CLIENT_CONFIG_FILE; static char *cfgLogfile = "/tmp/gnunet_fuse.log"; unsigned int anonymity = 1; int uri_files = 0; +char **fuse_argv; +int fuse_argc; /* Root directory entry, currently used by the dirent cache when asked for / */ struct dirent *root_de; struct MUTEX *root_mutex; +int getopt_configure_argv(CommandLineProcessorContext *ctx, void *scls, + const char *cmdLineOption, const char *value) +{ + (void)ctx; + (void)scls; + (void)cmdLineOption; + + fuse_argv = REALLOC(fuse_argv, sizeof(char *) * (fuse_argc + 2)); + fuse_argv[fuse_argc] = (char *)value; + fuse_argc++; + fuse_argv[fuse_argc] = NULL; + return OK; +} + static struct fuse_operations fops = { .getattr = gn_getattr, @@ -60,19 +76,30 @@ static struct CommandLineOption gn_options[] = &gnunet_getopt_configure_set_uint, &anonymity }, { 'u', "uri-files", NULL, "Make .uri files visible", 0, &gnunet_getopt_configure_set_one, &uri_files }, + { 'x', "Xfuse", NULL, "Escape fuse option", 1, + &getopt_configure_argv, NULL }, COMMAND_LINE_OPTION_END, }; int main(int argc, char **argv) { - int i; + int i, ret; struct ECRS_URI *uri; + /* Initialize fuse options to specify a read-only filesystem (for now)*/ + fuse_argc = 3; + fuse_argv = MALLOC(sizeof(char *) * (fuse_argc + 1)); + fuse_argv[0] = argv[0]; + fuse_argv[1] = "-o"; + fuse_argv[2] = "ro"; + fuse_argv[3] = NULL; + /* Parse gnunet options */ i = GNUNET_init(argc, argv, "gnunet-fuse [OPTIONS] <URI> <PATH>", &cfgFilename, gn_options, &ectx, &cfg); if(i == -1) { + ret = -1; goto quit; } @@ -81,27 +108,37 @@ int main(int argc, char **argv) ectx = GE_create_context_logfile(ectx, GE_ALL, cfgLogfile, YES, 0); GE_setDefaultContext(ectx); - if(i >= argc) + /* There should be exactly two extra arguments */ + if(i + 2 != argc) { - GE_LOG(ectx, GE_ERROR | GE_BULK | GE_USER, - "give me a URI to mount\n"); + printf("You must specify a URI to mount and mountpoint\n"); + ret = -1; goto quit; } + + /* Set URI as our root directory entry */ uri = ECRS_stringToUri(ectx, argv[i]); if(uri == NULL || !ECRS_isFileUri(uri)) { - GE_LOG(ectx, GE_ERROR | GE_BULK | GE_USER, - "URI '%s' cannot be mounted\n", argv[i]); + printf("URI '%s' cannot be mounted\n", argv[i]); + ret = -1; goto quit; } gn_dirent_cache_init(); root_de = gn_dirent_new(G_DIR_SEPARATOR_S, uri, DE_DIR); ECRS_freeUri(uri); root_mutex = MUTEX_CREATE(0); - argv[i] = argv[0]; + + /* Add mount point as the last fuse option */ + fuse_argv = REALLOC(fuse_argv, sizeof(char *) * (fuse_argc + 2)); + fuse_argv[fuse_argc] = argv[i + 1]; + fuse_argc++; + fuse_argv[fuse_argc] = NULL; + GE_LOG(ectx, GE_BULK | GE_USER | GE_DEBUG, "calling fuse_main\n"); - return fuse_main(argc - i, argv + i, &fops, NULL); + ret = fuse_main(fuse_argc, fuse_argv, &fops, NULL); quit: + FREE(fuse_argv); GNUNET_fini(ectx, cfg); - return -1; + return ret; } diff --git a/read.c b/read.c @@ -66,7 +66,7 @@ static void dpcb(unsigned long long totalBytes, static int tt(void *cls) { (void)cls; - return OK; + return fuse_interrupted() ? SYSERR : OK; } int gn_read(const char *path, char *buf, size_t size, off_t offset,