gnunet-fuse

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

commit a03089799bd8f48223e0dd163a08dbe79c776c5f
parent 59ed22771b8e0818e049aecb00dfce2e554a5268
Author: Mauricio Günther <mauricio@140774ce-b5e7-0310-ab8b-a85725594a96>
Date:   Mon, 19 Mar 2012 15:04:30 +0000

--changes


Diffstat:
Asrc/ext/getattr.c | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/ext/gnunet-fuse.c | 68++++++++++++--------------------------------------------------------
Asrc/ext/mkdir.c | 25+++++++++++++++++++++++++
Asrc/ext/mknod.c | 23+++++++++++++++++++++++
Asrc/ext/open.c | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ext/read.c | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ext/readdir.c | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ext/release.c | 29+++++++++++++++++++++++++++++
Asrc/ext/rename.c | 22++++++++++++++++++++++
Asrc/ext/rmdir.c | 21+++++++++++++++++++++
Asrc/ext/truncate.c | 20++++++++++++++++++++
Asrc/ext/unlink.c | 21+++++++++++++++++++++
Asrc/ext/utimens.c | 25+++++++++++++++++++++++++
Asrc/ext/write.c | 26++++++++++++++++++++++++++
14 files changed, 789 insertions(+), 56 deletions(-)

diff --git a/src/ext/getattr.c b/src/ext/getattr.c @@ -0,0 +1,132 @@ +/* + * getattr.c - FUSE getattr function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * + * Get file attributes. + * + * Similar to stat(). The 'st_dev' and 'st_blksize' fields are + * ignored. The 'st_ino' field is ignored except if the 'use_ino' + * mount option is given. + */ + +#include <sys/stat.h> +#include <string.h> +#include <errno.h> +#include <fuse.h> +#include <gnunet-fuse.h> + +int gn_getattr(const char *path, struct stat *stbuf) +{ + int ret = 0; + GNUNET_break (0); + memset(stbuf, 0, sizeof(struct stat)); + + if(strcmp(path, "/") == 0) + { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + } + else if(strcmp(path, directory) == 0) + { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 1; + } + else if(strcmp(path, "/probe/mal") == 0) + { + stbuf->st_mode = S_IFREG | 0444; + stbuf->st_nlink = 1; + stbuf->st_size = strlen("/probe/mal/inhalt"); + } + else return -ENOENT; + + return ret; + + + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* +static const char *archive_path = "/"; +static const char *archive_str = "/Archive\n"; + +static const char *britney_path = "/Britney Spears"; +static const char *britney_str = "Britney Spears\n"; + +static const char *britney_br_path = "/Britney Spears/Britney"; +static const char *britney_br_str = "Britney\n"; + +static const char *b_br_1_path = "/Britney Spears/Britney/I'm a Slave 4 U"; + static const char *b_br_1_str = "3:23 U\n"; + + +int gn_getattr(const char *path, struct stat *stbuf) +{ + +int res = 0; + + memset(stbuf, 0, sizeof(struct stat)); + + if(strcmp(path, "/") == 0) { //attr. fuer parent vz + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 3; + } + + else if(strcmp(path, britney_path) == 0) { //attr. fuer unterverzeichnis Britney + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 3; + } + + else if(strcmp(path, britney_br_path) == 0) { //Attribute fuer UnterUnterverzeichnis Britney + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 1; + + } + else if(strcmp(path, b_br_1_path) == 0 ){ //Songnummer 1 + stbuf->st_mode = S_IFREG | 0444; + stbuf->st_nlink = 1; + stbuf->st_size = strlen(b_br_1_str); + } + + else res = -ENOENT; + + return res; +} + +*/ diff --git a/src/ext/gnunet-fuse.c b/src/ext/gnunet-fuse.c @@ -29,30 +29,11 @@ #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/platform.h> -#include <gnunet/gnunet_util_lib.h> -#include <gnunet/gnunet_fs_service.h> -#include <sys/stat.h> -#include <string.h> -#include <errno.h> -#include <fuse.h> -#include <gnunet-fuse.h> - -#include "gnunet/gnunet_common.h" -#include "gnunet/gnunet_configuration_lib.h" -#include "gnunet/gnunet_crypto_lib.h" -#include "gnunet/gnunet_directories.h" -#include "gnunet/gnunet_getopt_lib.h" -#include "gnunet/gnunet_os_lib.h" -#include "gnunet/gnunet_program_lib.h" -#include "gnunet/gnunet_resolver_service.h" -#include "gnunet/gnunet_scheduler_lib.h" -#include <gcrypt.h> +#include "gnunet-fuse.h" static int ret; -static char *source; -static char *directory; + /* Context for the command. */ struct CommandContext @@ -76,45 +57,19 @@ struct CommandContext // calling fuse operations -/* -int gn_open(const char *path, struct fuse_file_info *fi) -{ - return 0; -} -int gn_read(const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *fi) -{ - return -2; -} - -int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) -{ - return -2; -} - -int gn_getattr(const char *path, struct stat *stbuf) -{ - return 0; -} -*/ /*struct with renamed fuseoperations*/ static struct fuse_operations fops = { - .mkdir = gn_mkdir, - .mknod = gn_mknod, - - - - .release = gn_release, - .rename = gn_rename, - .rmdir = gn_rmdir, - .truncate = gn_truncate, - .unlink = gn_unlink, - .utimens = gn_utimens, - .write = gn_write, - + // .mkdir = gn_mkdir, + // .mknod = gn_mknod, + // .release = gn_release, + // .rename = gn_rename, + // .rmdir = gn_rmdir, + // .truncate = gn_truncate, + // .unlink = gn_unlink, + // .utimens = gn_utimens, + // .write = gn_write, .getattr = gn_getattr, .readdir = gn_readdir, .open = gn_open, @@ -156,6 +111,7 @@ run (void *cls, return; } +/* checking for muti- or singlethreading */ if (GNUNET_YES == TESTING) { diff --git a/src/ext/mkdir.c b/src/ext/mkdir.c @@ -0,0 +1,25 @@ +/* + * mkdir.c - FUSE mkdir function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * + * Create a directory + * + * Note that the mode argument may not have the type specification + * bits set, i.e. S_ISDIR(mode) can be false. To obtain the + * correct directory type bits use mode|S_IFDIR + * */ + +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> + + +int gn_mkdir(const char *path, mode_t mode) +{ + return 0; +} diff --git a/src/ext/mknod.c b/src/ext/mknod.c @@ -0,0 +1,23 @@ +/* + * mknod.c - FUSE mknod function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * + * Create a file node + * + * This is called for creation of all non-directory, non-symlink + * nodes. If the filesystem defines a create() method, then for + * regular files that will be called instead. + */ + +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> + +int gn_mknod(const char *path, mode_t mode, dev_t rdev) +{ + return 0; +} diff --git a/src/ext/open.c b/src/ext/open.c @@ -0,0 +1,108 @@ +/* + * open.c - FUSE open function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * File open operation + * + * No creation (O_CREAT, O_EXCL) and by default also no + * truncation (O_TRUNC) flags will be passed to open(). If an + * application specifies O_TRUNC, fuse first calls truncate() + * and then open(). Only if 'atomic_o_trunc' has been + * specified and kernel version is 2.6.24 or later, O_TRUNC is + * passed on to open. + * + * Unless the 'default_permissions' mount option is given, + * open should check if the operation is permitted for the + * given flags. Optionally open may also return an arbitrary + * filehandle in the fuse_file_info structure, which will be + * passed to all file operations. + * + * Changed in version 2.2 + */ + +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> +#include <gnunet-fuse.h> + + + +int gn_open(const char *path, struct fuse_file_info *fi) +{ + + + if (strcmp(path, directory) | strcmp(path, "/") == 0) + return 0; + + else if ((fi->flags & 3) != O_RDONLY) + return -EACCES; + + + else return 0; + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* +static const char *archive_path = "/"; +static const char *archive_str = "/Archive\n"; + +static const char *britney_path = "/Britney Spears"; +static const char *britney_str = "Britney Spears\n"; + +static const char *britney_br_path = "/Britney Spears/Britney"; +static const char *britney_br_str = "Britney\n"; + +static const char *b_br_1_path = "/Britney Spears/Britney/I'm a Slave 4 U"; + static const char *b_br_1_str = "3:23 U\n"; + + + if((strcmp(path, archive_path) | strcmp(path, britney_path) | strcmp(path, britney_br_path))==0) + // return -ENOENT; + return 0; + + else if ( (fi->flags & 3) != O_RDONLY ) + return -EACCES; + + else return 0; + + + +*/ diff --git a/src/ext/read.c b/src/ext/read.c @@ -0,0 +1,176 @@ +/* + * read.c - FUSE read function + * + * Created on: Mar 14, 2012 + * Author: mg + * + + Read data from an open file + * + * Read should return exactly the number of bytes requested except + * on EOF or error, otherwise the rest of the data will be + * substituted with zeroes. An exception to this is when the + * 'direct_io' mount option is specified, in which case the return + * value of the read system call will reflect the return value of + * this operation. + * + * Changed in version 2.2 + */ + +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <fuse.h> +#include <gnunet-fuse.h> + + + + +int gn_read(const char *path, char *buf, size_t size, off_t offset, + struct fuse_file_info *fi) +{ + size_t len; + if (strcmp(path, directory) == 0) + { + len = strlen(directory); + + if (offset < len) + { + if (offset + size > len) + size = len - offset; + memcpy(buf, "/" + offset, size); + } + else + size = 0; + + return size; + } + + + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* + * + * + +static const char *archive_path = "/"; +static const char *archive_str = "/Archive\n"; + +static const char *britney_path = "/Britney Spears"; +static const char *britney_str = "Britney Spears\n"; + +static const char *britney_br_path = "/Britney Spears/Britney"; +static const char *britney_br_str = "Britney\n"; + +static const char *b_br_1_path = "/Britney Spears/Britney/I'm a Slave 4 U"; + static const char *b_br_1_str = "3:23 U\n"; + + + + +size_t len; + (void) fi; + + + if (strcmp(path, archive_path) == 0) + { + len = strlen(archive_str); + if (offset < len) + { + if (offset + size > len) + size = len - offset; + memcpy(buf, archive_str + offset, size); + } + else + size = 0; + + return size; + } + + + else if(strcmp(path, britney_path) == 0) + { + len = strlen(britney_str); + if (offset < len) { + if (offset + size > len) + size = len - offset; + memcpy(buf, britney_str + offset, size); + } + else + size = 0; + + return size; + } + + else if(strcmp(path, britney_br_path) == 0) // ab hier das verzeichnis britney spears + { + len = strlen(britney_br_str); + if (offset < len) { + if (offset + size > len) + size = len - offset; + memcpy(buf, britney_br_str + offset, size); + } + else + size = 0; + + return size; + } + + else if(strcmp(path, b_br_1_path) == 0) // ab hier album Britney-Lied1 + { + len = strlen(b_br_1_str); + if (offset < len) + { + if (offset + size > len) + size = len - offset; + memcpy(buf, b_br_1_str + offset, size); + } + else + size = 0; + + return size; + } + else return -ENOENT; + +*/ diff --git a/src/ext/readdir.c b/src/ext/readdir.c @@ -0,0 +1,149 @@ +/* + * reddir.c - FUSE read directory function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Read directory + * + * This supersedes the old getdir() interface. New applications + * should use this. + * + * The filesystem may choose between two modes of operation: + * + * 1) The readdir implementation ignores the offset parameter, and + * passes zero to the filler function's offset. The filler + * function will not return '1' (unless an error happens), so the + * whole directory is read in a single readdir operation. This + * works just like the old getdir() method. + * + * 2) The readdir implementation keeps track of the offsets of the + * directory entries. It uses the offset parameter and always + * passes non-zero offset to the filler function. When the buffer + * is full (or an error happens) the filler function will return + * '1'. + * + * Introduced in version 2.3 + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +//#include <glib.h> +#include <fuse.h> +//#include <GNUnet/gnunet_ecrs_lib.h> +#include <gnunet-fuse.h> + + + + + +int gn_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi) +{ + + static char* track = "directory/mal"; + int len = strlen(directory); + + + if (strcmp(path, "/") == 0) + { + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + filler(buf, directory+1, NULL, 0); + return 0; + } + else if (strcmp(path, directory) == 0) // mounted directory with content + { + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + filler(buf, track+len, NULL, 0); // path to directory mal + return 0; + } + + else return -ENOENT; + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* + +static const char *archive_path = "/"; +static const char *archive_str = "/Archive\n"; + +static const char *britney_path = "/Britney Spears"; +static const char *britney_str = "Britney Spears\n"; + +static const char *britney_br_path = "/Britney Spears/Britney"; +static const char *britney_br_str = "Britney\n"; + +static const char *b_br_1_path = "/Britney Spears/Britney/I'm a Slave 4 U"; + static const char *b_br_1_str = "3:23 U\n"; + + + +if(strcmp(path, "/") == 0) + { + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + + filler(buf, britney_path + 1, NULL, 0); + //filler(buf, metallica_path + 1, NULL, 0); + return 0; + } + + else if(strcmp(path, "/Britney Spears") == 0) + { + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + //filler(buf, britney_omt_path + 16, NULL, 0); + filler(buf, britney_br_path + 16, NULL, 0); + return 0; + } + + else if(strcmp(path, britney_br_path) == 0) // ab hier das album britney + { + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + filler(buf, b_br_1_path + 24 , NULL, 0); + + return 0; + } + + else return -ENOENT; + + + +*/ diff --git a/src/ext/release.c b/src/ext/release.c @@ -0,0 +1,29 @@ +/* + * release.c - FUSE release function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * + * Release an open file + * + * Release is called when there are no more references to an open + * file: all file descriptors are closed and all memory mappings + * are unmapped. + * + * For every open() call there will be exactly one release() call + * with the same flags and file descriptor. It is possible to + * have a file opened more than once, in which case only the last + * release will mean, that no more reads/writes will happen on the + * file. The return value of release is ignored. + * + * Changed in version 2.2 + */ + +#include <fuse.h> +//#include <gnunet-fuse.h> + +int gn_release(const char *path, struct fuse_file_info *fi) +{ + return 0; +} diff --git a/src/ext/rename.c b/src/ext/rename.c @@ -0,0 +1,22 @@ +/* + * rename.c - FUSE rename function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Rename a file + * + **/ + +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> + + +int gn_rename(const char *from, const char *to) +{ + int ret=0; + return ret; +} diff --git a/src/ext/rmdir.c b/src/ext/rmdir.c @@ -0,0 +1,21 @@ +/* + * rmdir.c - FUSE rmdir function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Remove a directory + * + * */ + +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> + + +int gn_rmdir(const char *path) +{ + return 0; +} diff --git a/src/ext/truncate.c b/src/ext/truncate.c @@ -0,0 +1,20 @@ +/* + * truncate.c - FUSE truncate function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Change the size of a file + * + * */ + +#include <errno.h> +#include <unistd.h> +#include <fuse.h> + + +int gn_truncate(const char *path, off_t size) +{ + int ret = 0; + return ret; +} diff --git a/src/ext/unlink.c b/src/ext/unlink.c @@ -0,0 +1,21 @@ +/* + * unlink.c - FUSE unlink function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Remove a file + * + * */ + +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fuse.h> + + +int gn_unlink(const char *path) +{ + return 0; +} diff --git a/src/ext/utimens.c b/src/ext/utimens.c @@ -0,0 +1,25 @@ +/* + * utimens.c - FUSE utimens function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * + * Change the access and modification times of a file with + * nanosecond resolution + * + * Introduced in version 2.6 + */ + +#include <sys/time.h> +#include <string.h> +#include <errno.h> +#include <fuse.h> + + + +int gn_utimens(const char *path, const struct timespec ts[2]) +{ + int ret = 0; + return ret; +} diff --git a/src/ext/write.c b/src/ext/write.c @@ -0,0 +1,26 @@ +/* + * write.c - FUSE write function + * + * Created on: Mar 14, 2012 + * Author: mg + * + * Write data to an open file + * + * Write should return exactly the number of bytes requested + * except on error. An exception to this is when the 'direct_io' + * mount option is specified (see read operation). + * + * Changed in version 2.2 + */ + +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <fuse.h> + + +int gn_write(const char *path, const char *buf, size_t size, off_t offset, + struct fuse_file_info *fi) +{ + return -ENOENT; +}