gnunet-fuse

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

commit aced3911edbe1c1605fbca574d47091784d4939b
parent 11dba0f1a415dd65376c974e44d4e49aaee34e4c
Author: Mauricio Günther <mauricio@140774ce-b5e7-0310-ab8b-a85725594a96>
Date:   Wed, 28 Mar 2012 14:20:59 +0000

working changes
his line, and those below, will be ignored--

M    ext/gnunet-fuse.c
M    ext/gnunet-fuse.h
M    ext/readdir.c


Diffstat:
Msrc/ext/gnunet-fuse.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/ext/gnunet-fuse.h | 17++++++++++-------
Msrc/ext/readdir.c | 37++++++-------------------------------
3 files changed, 71 insertions(+), 60 deletions(-)

diff --git a/src/ext/gnunet-fuse.c b/src/ext/gnunet-fuse.c @@ -26,20 +26,14 @@ #define FUSE_USE_VERSION 26 #define TESTING GNUNET_YES -#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) -#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) - #include "gnunet-fuse.h" #include <gnunet/gnunet_container_lib.h> #include <gnunet/gnunet_crypto_lib.h> - static int ret; - - /* Context for the command. */ struct CommandContext { @@ -82,27 +76,35 @@ static struct fuse_operations fops = { }; + + struct GNUNET_FUSE_path_info * create_path_info (const char *path, const struct GNUNET_FS_Uri *uri) { struct GNUNET_FUSE_path_info * pi; + /* check if path or uri are NULL, if yes, abort */ GNUNET_assert (NULL != path); GNUNET_assert (NULL != uri); pi = GNUNET_malloc (sizeof (struct GNUNET_FUSE_path_info)); pi->path = strdup (path); - //FIX - //pi->source = strdup (uri); + pi->uri = GNUNET_FS_uri_dup(uri); return pi; + } void delete_path_info (struct GNUNET_FUSE_path_info *pi) { + /* free path */ GNUNET_free (pi->path); - // FIX free uri + + /* free uri */ + GNUNET_FS_uri_destroy (pi->uri); + + /* free pi */ GNUNET_free (pi); } @@ -113,9 +115,12 @@ int cleanup_path_info (void *cls, struct GNUNET_FUSE_path_info *pi = value; delete_path_info (pi); + return 0; } + + /** * Main function that will be run by the scheduler. * @@ -132,31 +137,28 @@ run (void *cls, { int argc; struct GNUNET_FUSE_path_info *pi; - struct GNUNET_FS_Uri *uri; + const struct GNUNET_FS_Uri *uri; + char *emsg; + ret = 0; - //char * test= GNUNET_malloc(500); - //GNUNET_free (test); - //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ERROR\n-d option for mountpoint required %s\n", test); if (NULL == source) { - printf("ERROR\n-s option for URI missing\n"); + printf("\n-s option for URI missing\n\n"); ret = 1; return; } if (NULL == directory) { - printf("ERROR\n-d option for mountpoint missing\n"); + printf("\n-d option for mountpoint missing\n\n"); ret = 2; return; } - printf("%s\n", directory); /* checking for muti- or singlethreading */ - if (GNUNET_YES == TESTING) { argc = 5; @@ -174,23 +176,54 @@ run (void *cls, a[3] = "-f"; a[4] = "-d"; } - /* create MultiHashMap */ + + + /* parse source string to uri */ + uri = GNUNET_FS_uri_parse(source, &emsg); + + /* check if uri is valid entry */ + if (NULL == uri) + { + printf("\n%s\n\n", emsg); + ret = 3; + return; + } + + + + /* create MultiHashMap, setting len arbitrarily to 10 */ map = GNUNET_CONTAINER_multihashmap_create (10); GNUNET_HashCode path_hash; - char * path = "/"; + char*path = "/" ; + + /* create hashkey */ GNUNET_CRYPTO_hash (path, strlen (path), &path_hash); /* new path */ - // FIX parse source string to uri + + /* print content of variable source, just for personal interest */ + printf("%s\n", source); + + /*check if content of uri isn't NULL, otherwise call abort... */ + GNUNET_assert (NULL != uri); + + /** Mapping path and uri. Store it in struct pi. + * fuse gives us "/" as default. + */ pi = create_path_info (path, uri); + + /* after having used uri, you must free it */ + GNUNET_FS_uri_destroy (uri); + + /* check if your put was successfull */ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(map, &path_hash, pi, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); /* main function of fuse */ fuse_main(argc, a, &fops, NULL); + /* after fuse operations iterate and destroy multihashmap map */ GNUNET_CONTAINER_multihashmap_iterate(map, &cleanup_path_info, NULL); - GNUNET_CONTAINER_multihashmap_destroy(map); } @@ -219,7 +252,7 @@ main (int argc, char *const *argv) return (GNUNET_OK == GNUNET_PROGRAM_run2(argc, argv, - "gnunet-fuse -s URI [-- FUSE-OPTIONS] DIRECTORYNAME", //"gnunet-fuse [options [value]]", + "gnunet-fuse -s URI [-- FUSE-OPTIONS] DIRECTORYNAME", gettext_noop ("fuse"), options, &run, NULL, GNUNET_YES)) ? ret : 1; diff --git a/src/ext/gnunet-fuse.h b/src/ext/gnunet-fuse.h @@ -2,7 +2,8 @@ * gnfs.h - types and stuff * * Created on: Mar 16, 2012 - * Author: mg + * Author: Mauricio Günther + * * * * @@ -35,6 +36,7 @@ #include "gnunet/gnunet_os_lib.h" #include "gnunet/gnunet_program_lib.h" #include "gnunet/gnunet_resolver_service.h" +#include "gnunet/gnunet_fs_service.h" #include "gnunet/gnunet_scheduler_lib.h" #include <fuse.h> @@ -42,8 +44,8 @@ /* Variables from commandline for gnunet-fuse */ -static char *source; -static char *directory; +char *source; +char *directory; struct GNUNET_CONTAINER_MultiHashMap *map; @@ -52,10 +54,11 @@ struct GNUNET_CONTAINER_MultiHashMap *map; struct GNUNET_FUSE_path_info { /* uri to corresponding path */ - struct GNUNET_FS_Uri *uri; + const struct GNUNET_FS_Uri *uri; /* pathname */ char* path; - +/* source to corresponding path, needs to be parsed to uri */ + char* source; /*name of temporary file */ char* tmpfile; /*file attributes*/ @@ -63,10 +66,10 @@ struct GNUNET_FUSE_path_info }; struct GNUNET_FUSE_path_info * -create_path_info (path, uri); +create_path_info (const char *path, const struct GNUNET_FS_Uri *uri); void -delet_path_info (struct GNUNET_FUSE_path_info *pi); +delete_path_info (struct GNUNET_FUSE_path_info *pi); /* FUSE function files */ int gn_getattr(const char *path, struct stat *stbuf); diff --git a/src/ext/readdir.c b/src/ext/readdir.c @@ -2,7 +2,7 @@ * reddir.c - FUSE read directory function * * Created on: Mar 14, 2012 - * Author: mg, Christian Grothoff, Matthias Wachs, + * Author: MG, Christian Grothoff, Matthias Wachs, * Krista Bennett, James Blackwell, Igor Wronsky * * Read directory @@ -27,22 +27,15 @@ * Introduced in version 2.3 */ -//#include <string.h> -//#include <errno.h> -//#include <glib.h> -//#include <GNUnet/gnunet_ecrs_lib.h> - #include <sys/types.h> #include <sys/mman.h> #include <fcntl.h> #include <unistd.h> - -#include <fuse.h> - #include <gnunet-fuse.h> #include <gnunet/gnunet_fs_service.h> #include <gnunet/gnunet_container_lib.h> #include "gnunet/gnunet_crypto_lib.h" +#include <fuse.h> static int ret; @@ -174,14 +167,8 @@ return NULL; void readdir_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { - - enum GNUNET_FS_DownloadOptions options; - - - - if (NULL == uri) { FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg); @@ -238,11 +225,12 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, GNUNET_HashCode path_hash; GNUNET_CRYPTO_hash (path, strlen (path), &path_hash); + /* NOTE: Path can be like /.Trash/1000/files for the trash directory */ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(map, &path_hash)) { /* new path */ - path_info = create_path_info (path, NULL); - GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(map, &path_hash, path_info, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + //path_info = create_path_info (path, NULL); + //GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(map, &path_hash, path_info, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); } else { @@ -250,7 +238,7 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, path_info = GNUNET_CONTAINER_multihashmap_get (map, &path_hash); } - GNUNET_assert (path_info != NULL); + //GNUNET_assert (path_info != NULL); #if 0 r = GNUNET_malloc (sizeof (struct GNUNET_FUSE_path_info)); @@ -303,16 +291,3 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, filler(buf, "..", NULL, 0); return 0; } - - - - - - - - - - - - -