gnunet-fuse

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

commit 9df359914a71bbf3f944fc68ad59b0445a63688b
parent 475ed1ce3a0579a3ec8aac8ea71482af6fe54b88
Author: David Barksdale <amatus.amongus@gmail.com>
Date:   Sun, 10 Jun 2007 05:19:15 +0000

Added .uri.<file> files which read the uri of <file>

Diffstat:
MChangeLog | 2++
Mconfigure.ac | 2+-
Mgnfs.h | 1+
Mmain.c | 3+++
Mreaddir.c | 29+++++++++++++++++++++++++++--
Mspecial_file.c | 44++++++++++++++++++++++++++++++++++----------
6 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,5 @@ +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 * Added .uri files which read the uri of the containing directory 2007-05-30 David Barksdale <amatus@gnu.org> 0.3 diff --git a/configure.ac b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(gnunet-fuse, 0.4) +AC_INIT(gnunet-fuse, 0.5) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/gnfs.h b/gnfs.h @@ -52,6 +52,7 @@ typedef int (*gn_dir_for_each_callback)(struct dirent *de, extern struct GC_Configuration *cfg; extern struct GE_Context *ectx; extern unsigned int anonymity; +extern int uri_files; extern struct dirent *root_de; extern struct MUTEX *root_mutex; diff --git a/main.c b/main.c @@ -34,6 +34,7 @@ struct GE_Context *ectx; static char *cfgFilename = DEFAULT_CLIENT_CONFIG_FILE; static char *cfgLogfile = "/tmp/gnunet_fuse.log"; unsigned int anonymity = 1; +int uri_files = 0; /* Root directory entry, currently used by the dirent cache when asked for / */ struct dirent *root_de; @@ -57,6 +58,8 @@ static struct CommandLineOption gn_options[] = { 'a', "anonymity", "LEVEL", "set the desired LEVEL of sender-anonymity", 1, &gnunet_getopt_configure_set_uint, &anonymity }, + { 'u', "uri-files", NULL, "Make .uri files visible", 0, + &gnunet_getopt_configure_set_one, &uri_files }, COMMAND_LINE_OPTION_END, }; diff --git a/readdir.c b/readdir.c @@ -34,6 +34,7 @@ struct readdir_callback_data { fuse_fill_dir_t filler; void *buf; + const char *prefix; }; static int readdir_callback(struct dirent *de, const gchar *filename, @@ -48,7 +49,18 @@ static int readdir_callback(struct dirent *de, const gchar *filename, if(isRoot) return OK; - d->filler(d->buf, filename, NULL, 0); + if(d->prefix != NULL) + { + char *buf = MALLOC(strlen(d->prefix) + strlen(filename) + 1); + + sprintf(buf, "%s%s", d->prefix, filename); + d->filler(d->buf, buf, NULL, 0); + FREE(buf); + } + else + { + d->filler(d->buf, filename, NULL, 0); + } return OK; } @@ -81,9 +93,22 @@ int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, } filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); - filler(buf, URI_FILE, NULL, 0); + if(uri_files) + { + filler(buf, URI_FILE, NULL, 0); + d.filler = filler; + d.buf = buf; + d.prefix = ".uri."; + ret = gn_directory_for_each(de, readdir_callback, &d); + if(ret == -1) + { + ret = -ENOENT; + goto out; + } + } d.filler = filler; d.buf = buf; + d.prefix = NULL; ret = gn_directory_for_each(de, readdir_callback, &d); if(ret == -1) ret = -ENOENT; diff --git a/special_file.c b/special_file.c @@ -26,27 +26,51 @@ char *gn_get_special_file(const char *path) { struct dirent *de; - char *parent, *buf = NULL; - int len; + char *buf = NULL, *file, *parent; - len = strlen(path); - if(len >= URI_LEN && strcmp(&path[len - URI_LEN], URI_FILE) == 0) + /* Break path into parent and file (dirname and basename kinda) */ + parent = STRDUP(path); + file = strrchr(parent, G_DIR_SEPARATOR); + if(file == NULL) + goto out; + file[0] = '\0'; + file++; + + /* Check for special file name */ + if(strcmp(file, URI_FILE) == 0) { char *uri; - parent = STRDUP(path); - parent[len - URI_LEN - 1] = '\0'; + /* Return URI of the 'current' directory */ de = gn_dirent_find(parent); - FREE(parent); if(de == NULL) - return NULL; + goto out; + uri = ECRS_uriToString(de->de_uri); + gn_dirent_put(de); + buf = MALLOC(strlen(uri) + 2); + strcpy(buf, uri); + FREE(uri); + strcat(buf, "\n"); + } + else if(strncmp(file, URI_FILE ".", URI_LEN + 1) == 0) + { + char *uri, *actual_file = MALLOC(strlen(path)); + + /* Return URI of the file named after the .uri. */ + sprintf(actual_file, "%s" G_DIR_SEPARATOR_S "%s", parent, + &file[URI_LEN + 1]); + de = gn_dirent_find(actual_file); + FREE(actual_file); + if(de == NULL) + goto out; uri = ECRS_uriToString(de->de_uri); gn_dirent_put(de); - buf = MALLOC(strlen(uri) + 1); + buf = MALLOC(strlen(uri) + 2); strcpy(buf, uri); FREE(uri); strcat(buf, "\n"); } - /* else if next case */ +out: + FREE(parent); return buf; }