gnunet-fuse

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

commit 8237e5c8e4559e732108bfed0298ef009a22dfc9
parent 2c760ce07ce61a1ba45123027e76b56f229ce2a5
Author: David Barksdale <amatus.amongus@gmail.com>
Date:   Thu, 31 May 2007 05:45:44 +0000

Added support for ECRS_downloadPartialFile (requires GNUnet > 0.7.1c)

Diffstat:
MChangeLog | 2++
Mconfigure.ac | 2+-
Mdirectory.c | 42++++++++----------------------------------
Mread.c | 69++++++++++++++++++++++++++++++++++++++-------------------------------
4 files changed, 49 insertions(+), 66 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,5 @@ +2007-05-30 David Barksdale <amatus@gnu.org> 0.3 +* Added support for ECRS_downloadPartialFile (requires GNUnet > 0.7.1c) 2007-05-29 David Barksdale <amatus@gnu.org> 0.2 * Fixed ref-counting bug in gn_dirent_find * Added legal stuff to source files diff --git a/configure.ac b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(gnunet-fuse, 0.2) +AC_INIT(gnunet-fuse, 0.3) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/directory.c b/directory.c @@ -34,10 +34,7 @@ static void dpcb(unsigned long long totalBytes, (void)totalBytes; (void)completedBytes; (void)eta; - (void)lastBlockOffset; - (void)lastBlock; - (void)lastBlockSize; - (void)cls; + memcpy((char *)cls + lastBlockOffset, lastBlock, lastBlockSize); } static int tt(void *cls) @@ -110,51 +107,28 @@ static int dir_for_each_cb(const ECRS_FileInfo *fi, const HashCode512 *key, int gn_directory_for_each(struct dirent *de, gn_dir_for_each_callback cb, void *data) { - gchar filename[] = "/tmp/gnfs_dir.XXXXXX"; struct ECRS_MetaData *md; struct dir_for_each_data d; void *mem; - int ret, fd; + int ret; guint64 len; - fd = mkstemp(filename); - if(fd == -1) - { - GE_LOG_STRERROR_FILE(ectx, GE_BULK | GE_USER | GE_ERROR, - "mkstemp", filename); - goto err_out; - } - ret = ECRS_downloadFile(ectx, cfg, de->de_uri, filename, anonymity, - dpcb, NULL, tt, NULL); + len = ECRS_fileSize(de->de_uri); + mem = MALLOC(len); + ret = ECRS_downloadPartialFile(ectx, cfg, de->de_uri, "/dev/null", + anonymity, 0, len, YES, dpcb, mem, tt, NULL); if(ret != OK) { GE_LOG(ectx, GE_BULK | GE_USER | GE_ERROR, "%s: failed to download directory\n", __FUNCTION__); - goto err_out_unlink; - } - if(disk_file_size(ectx, filename, &len, YES) != OK || len == 0) - { - GE_LOG(ectx, GE_BULK | GE_USER | GE_ERROR, - "%s: file empty\n", __FUNCTION__); - goto err_out_unlink; - } - mem = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); - if(mem == MAP_FAILED) - { - GE_LOG_STRERROR(ectx, GE_BULK | GE_USER | GE_ERROR, "mmap"); - goto err_out_unlink; + goto err_out; } d.cb = cb; d.data = data; d.de = de; ECRS_listDirectory(ectx, mem, len, &md, dir_for_each_cb, &d); - munmap(mem, len); - unlink(filename); - close(fd); return 0; -err_out_unlink: - unlink(filename); err_out: - close(fd); + FREE(mem); return -1; } diff --git a/read.c b/read.c @@ -24,20 +24,45 @@ #include <unistd.h> #include "gnfs.h" +struct read_data +{ + char *buf; + guint size; + guint64 offset; +}; + static void dpcb(unsigned long long totalBytes, unsigned long long completedBytes, cron_t eta, unsigned long long lastBlockOffset, const char *lastBlock, unsigned int lastBlockSize, void *cls) { + struct read_data *d = cls; + guint64 block_end = lastBlockOffset + lastBlockSize; + guint64 buf_end = d->offset + d->size; + (void)totalBytes; (void)completedBytes; (void)eta; - (void)lastBlockOffset; - (void)lastBlock; - (void)lastBlockSize; - (void)cls; -} - + + GE_ASSERT(ectx, !(block_end < d->offset)); + GE_ASSERT(ectx, !(lastBlockOffset > buf_end)); + + /* Chop off residue at beginning of block */ + if(lastBlockOffset < d->offset) + { + lastBlock += d->offset - lastBlockOffset; + lastBlockSize -= d->offset - lastBlockOffset; + lastBlockOffset = d->offset; + } + /* Chop off residue at end of block */ + if(block_end > buf_end) + { + lastBlockSize -= block_end - buf_end; + } + memcpy(d->buf + (lastBlockOffset - d->offset), lastBlock, + lastBlockSize); +} + static int tt(void *cls) { (void)cls; @@ -47,9 +72,9 @@ static int tt(void *cls) int gn_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { - gchar filename[] = "/tmp/gnfs_file.XXXXXX"; struct dirent *de; - int ret, fd; + struct read_data d; + int ret; guint64 len; (void)fi; @@ -80,35 +105,17 @@ int gn_read(const char *path, char *buf, size_t size, off_t offset, { size = len - offset; } - fd = mkstemp(filename); - if(fd == -1) - { - GE_LOG_STRERROR_FILE(ectx, GE_BULK | GE_USER | GE_ERROR, - "mkstemp", filename); - size = -ENOBUFS; - goto out; - } - ret = ECRS_downloadFile(ectx, cfg, de->de_uri, filename, anonymity, - dpcb, NULL, tt, NULL); + d.buf = buf; + d.size = size; + d.offset = offset; + ret = ECRS_downloadPartialFile(ectx, cfg, de->de_uri, "/dev/null", + anonymity, offset, size, YES, dpcb, &d, tt, NULL); if(ret != OK) { GE_LOG(ectx, GE_BULK | GE_USER | GE_ERROR, "%s: failed to download directory\n", __FUNCTION__); size = -ENODATA; - goto out_close_file; - } - offset = lseek(fd, offset, SEEK_SET); - if(offset == -1) - { - GE_LOG_STRERROR_FILE(ectx, GE_BULK | GE_USER | GE_ERROR, - "lseek", filename); - size = -ENODATA; - goto out_close_file; } - size = read(fd, buf, size); -out_close_file: - unlink(filename); - close(fd); out: gn_dirent_put(de); return size;