[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r4877 - gnunet-fuse
From: |
gnunet |
Subject: |
[GNUnet-SVN] r4877 - gnunet-fuse |
Date: |
Wed, 30 May 2007 23:45:44 -0600 (MDT) |
Author: amatus
Date: 2007-05-30 23:45:44 -0600 (Wed, 30 May 2007)
New Revision: 4877
Modified:
gnunet-fuse/ChangeLog
gnunet-fuse/configure.ac
gnunet-fuse/directory.c
gnunet-fuse/read.c
Log:
Added support for ECRS_downloadPartialFile (requires GNUnet > 0.7.1c)
Modified: gnunet-fuse/ChangeLog
===================================================================
--- gnunet-fuse/ChangeLog 2007-05-31 04:36:55 UTC (rev 4876)
+++ gnunet-fuse/ChangeLog 2007-05-31 05:45:44 UTC (rev 4877)
@@ -1,3 +1,5 @@
+2007-05-30 David Barksdale <address@hidden> 0.3
+* Added support for ECRS_downloadPartialFile (requires GNUnet > 0.7.1c)
2007-05-29 David Barksdale <address@hidden> 0.2
* Fixed ref-counting bug in gn_dirent_find
* Added legal stuff to source files
Modified: gnunet-fuse/configure.ac
===================================================================
--- gnunet-fuse/configure.ac 2007-05-31 04:36:55 UTC (rev 4876)
+++ gnunet-fuse/configure.ac 2007-05-31 05:45:44 UTC (rev 4877)
@@ -1,4 +1,4 @@
-AC_INIT(gnunet-fuse, 0.2)
+AC_INIT(gnunet-fuse, 0.3)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
Modified: gnunet-fuse/directory.c
===================================================================
--- gnunet-fuse/directory.c 2007-05-31 04:36:55 UTC (rev 4876)
+++ gnunet-fuse/directory.c 2007-05-31 05:45:44 UTC (rev 4877)
@@ -34,10 +34,7 @@
(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 @@
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;
+ goto err_out;
}
- 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;
- }
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;
}
Modified: gnunet-fuse/read.c
===================================================================
--- gnunet-fuse/read.c 2007-05-31 04:36:55 UTC (rev 4876)
+++ gnunet-fuse/read.c 2007-05-31 05:45:44 UTC (rev 4877)
@@ -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 @@
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 @@
{
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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r4877 - gnunet-fuse,
gnunet <=