aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2005-02-07 16:10:49 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2005-02-07 16:10:49 +0000
commitb92d978c97bb4863ca89996585d8f954d26966fc (patch)
tree373f70bdf15ae575787eb1f8d9209a389c0eb769
parent7ed2e5d408037e04cb74fd275822ebbceab6b788 (diff)
downloadandroid_external_fuse-b92d978c97bb4863ca89996585d8f954d26966fc.tar.gz
android_external_fuse-b92d978c97bb4863ca89996585d8f954d26966fc.tar.bz2
android_external_fuse-b92d978c97bb4863ca89996585d8f954d26966fc.zip
cleanup
-rw-r--r--ChangeLog4
-rw-r--r--README5
-rw-r--r--lib/fuse.c82
3 files changed, 29 insertions, 62 deletions
diff --git a/ChangeLog b/ChangeLog
index 54871d7..dff2600 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-02-07 Miklos Szeredi <miklos@szeredi.hu>
+
+ * Cleaned up directory reading (temporary file is not used)
+
2005-02-02 Miklos Szeredi <miklos@szeredi.hu>
* Released 2.2
diff --git a/README b/README
index 14eed40..e14e37e 100644
--- a/README
+++ b/README
@@ -25,7 +25,10 @@ make
make install
modprobe fuse
-Also see the file 'INSTALL'
+You may also need to add '/usr/local/lib' to '/etc/ld.so.conf' and/or
+run ldconfig.
+
+For more details see the file 'INSTALL'
How To Use
==========
diff --git a/lib/fuse.c b/lib/fuse.c
index 0980388..104d654 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -60,7 +60,8 @@ struct node {
struct fuse_dirhandle {
struct fuse *fuse;
- FILE *fp;
+ unsigned char *contents;
+ unsigned len;
int filled;
};
@@ -446,17 +447,18 @@ static int fill_dir(struct fuse_dirhandle *dh, const char *name, int type,
ino_t ino)
{
size_t namelen = strlen(name);
+ size_t entsize = sizeof(struct fuse_dirhandle) + namelen + 8;
struct fuse_dirent *dirent;
- size_t reclen;
- size_t res;
if (namelen > FUSE_NAME_MAX)
namelen = FUSE_NAME_MAX;
- dirent = calloc(1, sizeof(struct fuse_dirent) + namelen + 8);
- if (dirent == NULL)
+ dh->contents = realloc(dh->contents, dh->len + entsize);
+ if (dh->contents == NULL)
return -ENOMEM;
+ dirent = (struct fuse_dirent *) (dh->contents + dh->len);
+ memset(dirent, 0, entsize);
if ((dh->fuse->flags & FUSE_USE_INO))
dirent->ino = ino;
else
@@ -464,13 +466,7 @@ static int fill_dir(struct fuse_dirhandle *dh, const char *name, int type,
dirent->namelen = namelen;
strncpy(dirent->name, name, namelen);
dirent->type = type;
- reclen = FUSE_DIRENT_SIZE(dirent);
- res = fwrite(dirent, reclen, 1, dh->fp);
- free(dirent);
- if (res == 0) {
- perror("fuse: writing directory file");
- return -EIO;
- }
+ dh->len += FUSE_DIRENT_SIZE(dirent);
return 0;
}
@@ -832,30 +828,6 @@ static int common_getdir(struct fuse *f, struct fuse_in_header *in,
return res;
}
-static void do_getdir(struct fuse *f, struct fuse_in_header *in)
-{
- int res;
- struct fuse_getdir_out arg;
- struct fuse_dirhandle dh;
-
- dh.fuse = f;
- dh.fp = tmpfile();
-
- res = -EIO;
- if (dh.fp == NULL)
- perror("fuse: failed to create temporary file");
- else {
- res = common_getdir(f, in, &dh);
- fflush(dh.fp);
- }
- memset(&arg, 0, sizeof(struct fuse_getdir_out));
- if (res == 0)
- arg.fd = fileno(dh.fp);
- send_reply(f, in, res, &arg, sizeof(arg));
- if (dh.fp != NULL)
- fclose(dh.fp);
-}
-
static void do_mknod(struct fuse *f, struct fuse_in_header *in,
struct fuse_mknod_in *inarg)
{
@@ -1556,17 +1528,11 @@ static void do_opendir(struct fuse *f, struct fuse_in_header *in,
dh = (struct fuse_dirhandle *) malloc(sizeof(struct fuse_dirhandle));
if (dh != NULL) {
dh->fuse = f;
- dh->fp = tmpfile();
+ dh->contents = NULL;
+ dh->len = 0;
dh->filled = 0;
-
- res = -EIO;
- if (dh->fp == NULL) {
- perror("fuse: failed to create temporary file");
- free(dh);
- } else {
- outarg.fh = (unsigned long) dh;
- res = 0;
- }
+ outarg.fh = (unsigned long) dh;
+ res = 0;
}
send_reply(f, in, res, &outarg, sizeof(outarg));
}
@@ -1574,12 +1540,11 @@ static void do_opendir(struct fuse *f, struct fuse_in_header *in,
static void do_readdir(struct fuse *f, struct fuse_in_header *in,
struct fuse_read_in *arg)
{
- int res;
char *outbuf;
struct fuse_dirhandle *dh = get_dirhandle(arg->fh);
if (!dh->filled) {
- res = common_getdir(f, in, dh);
+ int res = common_getdir(f, in, dh);
if (res) {
send_reply(f, in, res, NULL, 0);
return;
@@ -1594,17 +1559,16 @@ static void do_readdir(struct fuse *f, struct fuse_in_header *in,
char *buf = outbuf + sizeof(struct fuse_out_header);
size_t size = 0;
size_t outsize;
- fseek(dh->fp, arg->offset, SEEK_SET);
- res = fread(buf, 1, arg->size, dh->fp);
- if (res == 0 && ferror(dh->fp))
- res = -EIO;
- else {
- size = res;
- res = 0;
+ if (arg->offset < dh->len) {
+ size = arg->size;
+ if (arg->offset + size > dh->len)
+ size = dh->len - arg->offset;
+
+ memcpy(buf, dh->contents + arg->offset, size);
}
memset(out, 0, sizeof(struct fuse_out_header));
out->unique = in->unique;
- out->error = res;
+ out->error = 0;
outsize = sizeof(struct fuse_out_header) + size;
send_reply_raw(f, outbuf, outsize);
@@ -1616,7 +1580,7 @@ static void do_releasedir(struct fuse *f, struct fuse_in_header *in,
struct fuse_release_in *arg)
{
struct fuse_dirhandle *dh = get_dirhandle(arg->fh);
- fclose(dh->fp);
+ free(dh->contents);
free(dh);
send_reply(f, in, 0, NULL, 0);
}
@@ -1674,10 +1638,6 @@ void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd)
do_readlink(f, in);
break;
- case FUSE_GETDIR:
- do_getdir(f, in);
- break;
-
case FUSE_MKNOD:
do_mknod(f, in, (struct fuse_mknod_in *) inarg);
break;