aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2017-04-07 16:31:07 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2017-04-07 16:40:15 -0700
commit09862556887caf32b37aa0caa412c467f7f5a40e (patch)
tree590043362416ab85ade633ef548ff8131808936d /example
parent76218eb4614146b52f59563e85e6b5971acbfe92 (diff)
example/passthrough: use fi->fh for read, write, fallocate
No reason not to use it. May even be a little faster and will consume less resources :-).
Diffstat (limited to 'example')
-rw-r--r--example/passthrough.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/example/passthrough.c b/example/passthrough.c
index 67663ab..d5edc04 100644
--- a/example/passthrough.c
+++ b/example/passthrough.c
@@ -296,8 +296,11 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
int fd;
int res;
- (void) fi;
- fd = open(path, O_RDONLY);
+ if(fi == NULL)
+ fd = open(path, O_RDONLY);
+ else
+ fd = fi->fh;
+
if (fd == -1)
return -errno;
@@ -305,7 +308,8 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
if (res == -1)
res = -errno;
- close(fd);
+ if(fi == NULL)
+ close(fd);
return res;
}
@@ -316,7 +320,11 @@ static int xmp_write(const char *path, const char *buf, size_t size,
int res;
(void) fi;
- fd = open(path, O_WRONLY);
+ if(fi == NULL)
+ fd = open(path, O_WRONLY);
+ else
+ fd = fi->fh;
+
if (fd == -1)
return -errno;
@@ -324,7 +332,8 @@ static int xmp_write(const char *path, const char *buf, size_t size,
if (res == -1)
res = -errno;
- close(fd);
+ if(fi == NULL)
+ close(fd);
return res;
}
@@ -370,13 +379,18 @@ static int xmp_fallocate(const char *path, int mode,
if (mode)
return -EOPNOTSUPP;
- fd = open(path, O_WRONLY);
+ if(fi == NULL)
+ fd = open(path, O_WRONLY);
+ else
+ fd = fi->fh;
+
if (fd == -1)
return -errno;
res = -posix_fallocate(fd, offset, length);
- close(fd);
+ if(fi == NULL)
+ close(fd);
return res;
}
#endif