Read files through ipfs cat
This commit is contained in:
parent
50d62741fc
commit
8f87ae29ae
35
src/πfs.c
35
src/πfs.c
|
@ -29,8 +29,6 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <fuse/fuse.h>
|
#include <fuse/fuse.h>
|
||||||
|
|
||||||
unsigned char get_byte(int id);
|
|
||||||
|
|
||||||
struct options {
|
struct options {
|
||||||
char *mdd;
|
char *mdd;
|
||||||
} options;
|
} options;
|
||||||
|
@ -156,24 +154,31 @@ static int pifs_open(const char *path, struct fuse_file_info *info)
|
||||||
static int pifs_read(const char *path, char *buf, size_t count, off_t offset,
|
static int pifs_read(const char *path, char *buf, size_t count, off_t offset,
|
||||||
struct fuse_file_info *info)
|
struct fuse_file_info *info)
|
||||||
{
|
{
|
||||||
|
char buffer[5];
|
||||||
|
int size = 0;
|
||||||
int ret = lseek(info->fh, offset * 2, SEEK_SET);
|
int ret = lseek(info->fh, offset * 2, SEEK_SET);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
dup2(info->fh, STDIN_FILENO);
|
||||||
for (size_t i = 0; i < count; i++) {
|
FILE *fp = popen("ipfs cat", "r");
|
||||||
short index;
|
if (fp == 0) {
|
||||||
ret = read(info->fh, &index, sizeof index);
|
perror("popen(3) failed");
|
||||||
if (ret == -1) {
|
return -1;
|
||||||
return -errno;
|
|
||||||
} else if (ret == 0) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
*buf = (char) get_byte(index);
|
|
||||||
buf++;
|
|
||||||
}
|
}
|
||||||
|
do {
|
||||||
|
ret = fread(&buf[offset + size], sizeof(char), sizeof(buffer)-1, fp);
|
||||||
|
if (ret == -1 && errno != EAGAIN) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
size += ret;
|
||||||
|
// buf = realloc( buf, size * sizeof(char) + 1 );
|
||||||
|
count -= ret;
|
||||||
|
} while( ret == sizeof(buffer)-1 && count > 0 );
|
||||||
|
buf[offset + size] = '\0';
|
||||||
|
|
||||||
return count;
|
pclose(fp);
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pifs_write(const char *path, const char *buf, size_t count,
|
static int pifs_write(const char *path, const char *buf, size_t count,
|
||||||
|
@ -206,7 +211,7 @@ static int pifs_write(const char *path, const char *buf, size_t count,
|
||||||
default:
|
default:
|
||||||
// parent
|
// parent
|
||||||
close(fd[0]);
|
close(fd[0]);
|
||||||
ret = write(fd[1], buf, sizeof(buf));
|
ret = write(fd[1], buf, count);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue